User.php 244 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020/6/18
  7. *
  8. *
  9. */
  10. namespace app\controller\api\user;
  11. use app\common\repositories\article\AgreementRepository;
  12. use app\common\repositories\merchant\order\OrderGzcRepository;
  13. use app\common\repositories\merchant\order\OrderMerchantRepository;
  14. use app\common\repositories\store\product\ProductRepository;
  15. use app\common\repositories\user\UnionUsersRepository;
  16. use app\controller\api\merchant\sxy\Access;
  17. use app\controller\api\store\product\DaTaoKe;
  18. use app\controller\api\store\product\Jd;
  19. use app\controller\api\store\product\TaoBao;
  20. use app\controller\api\store\product\TaoKe;
  21. use app\controller\api\store\product\Vip;
  22. use app\model\common\UserThirdModel;
  23. use app\traits\GzcApiRequest;
  24. use app\traits\HuiPay;
  25. use crmeb\basic\BaseController;
  26. use app\common\repositories\user\UserBillRepository;
  27. use app\common\repositories\user\UserRepository;
  28. use app\common\repositories\user\UserVisitRepository;
  29. use crmeb\services\QrcodeService;
  30. use crmeb\services\WechatService;
  31. use Symfony\Component\HttpFoundation\Request;
  32. use think\App;
  33. use think\facade\Db;
  34. use think\Exception;
  35. use think\exception\ValidateException;
  36. use think\facade\Cache;
  37. use BaiduAi\controller\Ocr;
  38. use think\facade\Log;
  39. use think\facade\Request as r;
  40. use app\common\common;
  41. use phpseclib3\Math\BigInteger\Engines\BCMath;
  42. class User extends BaseController
  43. {
  44. use HuiPay;
  45. public $repository;
  46. private $merId;
  47. private $source;
  48. public $statusName = [
  49. 0 => '未结算',
  50. 1 => '已结算',
  51. -1 => '失效'
  52. ];
  53. public function __construct(App $app, UserRepository $repository)
  54. {
  55. parent::__construct($app);
  56. $this->repository = $repository;
  57. $this->source = $this->request->header('source');
  58. $this->merId = $this->request->header('merId');
  59. }
  60. /**
  61. * 创建环信账户
  62. * @return mixed
  63. */
  64. public function hxim_create()
  65. {
  66. $uid = $this->request->uid();
  67. try {
  68. $im = new Im();
  69. $user = Db::name('user')->where('uid', $uid)->field('im_uuid,im_userid as im_user_id,im,uid,nickname,im_password as im_pass')->find();
  70. if (isset($user['im_uuid']) && $user['im_user_id']) {
  71. return app('json')->success($user);
  72. }
  73. $im_user_id = 'user' . $user['uid'];
  74. $data = [];
  75. $data['im_pass'] = mt_rand(100000, 999999);
  76. $data['im_user_id'] = $im_user_id;
  77. // 获取用户是否存在
  78. $imUser = $im->getImUser('user' . $uid);
  79. if (isset($imUser['activated']) && $imUser['activated'] == true) {
  80. $data['im_uuid'] = $imUser['uuid'];
  81. } else {
  82. $data['im_uuid'] = $im->createImUser($im_user_id, $user['nickname'], $data['im_pass']);
  83. }
  84. Db::name('User')->where(['uid' => $uid])->update([
  85. 'im' => 1,
  86. 'im_uuid' => $data['im_uuid'],
  87. 'im_userid' => $im_user_id,
  88. 'im_password' => $data['im_pass']
  89. ]);
  90. return app('json')->success($data);
  91. } catch (\Exception $e) {
  92. Db::name('log')->insert(['data' => '注册异常' . $e->getFile() . $e->getMessage() . $e->getLine()]);
  93. }
  94. return app('json')->fail('注册失败');
  95. }
  96. /**
  97. * @return mixed
  98. * @author xaboy
  99. * @day 2020/6/22
  100. */
  101. public function we_com()
  102. {
  103. $where2['mer_id'] = $this->merId;
  104. $user = Db::name('enterprise')->field('we_com,we_com_url')->where($where2)->find();
  105. return app('json')->success($user);
  106. }
  107. public function spread_image()
  108. {
  109. $type = $this->request->param('type');
  110. $res = $type == 'routine'
  111. ? $this->repository->routineSpreadImage($this->request->userInfo())
  112. : $this->repository->wxSpreadImage($this->request->userInfo());
  113. return app('json')->success($res);
  114. }
  115. /**
  116. * @return mixed
  117. * 分享每日海报
  118. */
  119. public function share_day()
  120. {
  121. /**
  122. * 1242
  123. * 2208
  124. */
  125. $user = $this->request->userInfo();
  126. $name = $user['uid'] . '_' . $user['is_promoter'] . '_user_wap.jpg';
  127. $siteUrl = systemConfig('site_url');
  128. $codeUrl = set_http_type($siteUrl . '/share?spread=' . $user['uid'], request()->isSsl() ? 0 : 1);// 二维码链接
  129. $imageInfo = app()->make(QrcodeService::class)->getQRCodePath($codeUrl, $name, $user['avatar']);
  130. if (is_string($imageInfo)) throw new ValidateException('二维码生成失败');
  131. $filename = 'https://88yx.xyz/qqh/uploads/20211101074257444.jpg';
  132. $qrcode = $imageInfo['dir'];
  133. dump($qrcode);
  134. $config = array(
  135. 'image' => array(
  136. array(
  137. 'url' => $qrcode,// 二维码资源
  138. 'stream' => 0,
  139. 'left' => 533,
  140. 'top' => 1941,
  141. 'right' => 0,
  142. 'bottom' => 0,
  143. 'width' => 184,
  144. 'height' => 182,
  145. 'opacity' => 100
  146. )
  147. ),
  148. 'background' => $filename
  149. );
  150. $data = setSharePoster($config, 'routine/spread/poster');
  151. dump($data);
  152. return app('json')->success($data);
  153. }
  154. public function spread_info()
  155. {
  156. $user = $this->request->userInfo();
  157. $user->append(['one_level_count', 'lock_brokerage', 'two_level_count', 'spread_total', 'yesterday_brokerage', 'total_extract', 'total_brokerage']);
  158. $data = [
  159. 'lock_brokerage' => $user->lock_brokerage,
  160. 'one_level_count' => $user->one_level_count,
  161. 'two_level_count' => $user->two_level_count,
  162. 'spread_total' => $user->spread_total,
  163. 'yesterday_brokerage' => $user->yesterday_brokerage,
  164. 'total_extract' => $user->total_extract,
  165. 'total_brokerage' => $user->total_brokerage,
  166. 'brokerage_price' => $user->brokerage_price,
  167. 'member_brokerage_price' => $user->member_brokerage_price,
  168. 'now_money' => $user->now_money,
  169. 'broken_day' => (int)systemConfig('lock_brokerage_timer')
  170. ];
  171. return app('json')->success($data);
  172. }
  173. // 红包
  174. public function hongbao_info(){
  175. log::info("============hongbao");
  176. $user = $this->request->userInfo();
  177. if($user->uid>0){
  178. // 已经入账红包
  179. $data['total_source']=$user->hongbao;
  180. // 为生效红包
  181. $data['no_total_source']=Db::name('user_sign_hongbao')->where('status', -1)->where('uid', $user->uid)->sum('number');;
  182. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  183. return app('json')->success($data);
  184. }
  185. }
  186. public function vr_name()
  187. {
  188. $uid = $this->request->uid();
  189. $data = [
  190. "name"=>"VR",
  191. "url"=>'https://show.hxxfb.com/?uid=' .$uid,
  192. ];
  193. return app('json')->success($data);
  194. }
  195. public function hongbao_list(){
  196. $pm = $this->request->param('pm');
  197. [$page, $limit] = $this->getPage();
  198. $uid = $this->request->uid();
  199. log::info("hongbao_list==={$uid}");
  200. $where['uid'] = $uid;
  201. if ($pm==0){
  202. $data = DB::name('user_sign_hongbao')->where($where)->where('type',1)->where('status',1)->field('id,mark,number,type,addtime,order_id,status')->page($page, $limit)->order("id desc")->select();
  203. }
  204. if($pm==1){
  205. $data = DB::name('user_sign_hongbao')->where($where)->where(['type' => 2,'status' => 1])->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  206. }
  207. if($pm==2){
  208. $data = DB::name('user_sign_hongbao')->where($where)->where('type',1)->where([['status','in','-1,0']])->field('id,mark,number,type,addtime,order_id,status')->page($page, $limit)->order("id desc")->select();
  209. if($data){
  210. $data = $data->toArray();
  211. foreach ($data as $k=>$v){
  212. if($v['status'] == 0){
  213. $data[$k]['mark'] = '(失效)' . $v['mark'];
  214. }
  215. }
  216. }
  217. }
  218. return app("json")->success($data);
  219. }
  220. public function buildTreeContribute($users, $parentId = 0) {
  221. $branch = array();
  222. foreach ($users as $user) {
  223. if ($user['spread_uid'] == $parentId) {
  224. $children = $this->buildTreeContribute($users, $user['uid']); // 递归查找子节点
  225. if ($children) {
  226. $user['children'] = $children; // 如果有子节点,添加到当前节点
  227. }else{
  228. $user['children'] = [];
  229. }
  230. $user['total_contribute'] = $user['contribute_sum']; // 初始化当前节点的总余额为自身余额
  231. if ($children) { // 如果存在子节点,计算总余额
  232. foreach ($children as $child) {
  233. $user['total_contribute'] += $child['total_contribute']; // 累加子节点的总余额
  234. }
  235. }
  236. $branch[] = $user; // 将当前节点添加到树中
  237. }
  238. }
  239. return $branch; // 返回当前分支的所有节点
  240. }
  241. // 根据父级uid,递归获取所有子级UID数组 默认深度10级
  242. public function getRecursiveChildrenChengji($parentUid, $number = 10) {
  243. $user = Db::name('user')->where('uid', $parentUid)->field('uid,spread_uid,contribute,per_contribute')->find();
  244. $user['contribute_sum'] = bcadd($user['contribute'], $user['per_contribute'], 2);
  245. $user['contribute_sum'] = 0;
  246. $uids = [];// 用于存储符合条件的子级 uid
  247. $result = [$user]; // 用于存储符合条件的子级数据
  248. // 定义递归函数
  249. $num = 0;// 当前层级
  250. $recursion = function ($parentUid, $number, $num) use (&$uids, &$result, &$recursion) {
  251. if($num >= $number){
  252. return;
  253. }
  254. // 查询当前父级的所有直接子级
  255. $children = Db::name('user')->field('uid,spread_uid,contribute,per_contribute')->where("spread_uid", $parentUid)->select()->toArray();
  256. // 如果没有子级,直接返回
  257. if (!count($children) && count($children) < 1) {
  258. return;
  259. }else{
  260. $num = $num + 1;
  261. }
  262. // 遍历每个子级
  263. foreach ($children as $childUid) {
  264. // 如果有重复的就跳过 防止死循环
  265. if(in_array($childUid['uid'], $uids)){
  266. continue;
  267. }
  268. // 将符合条件的子级 uid 添加到结果数组
  269. $uids[] = $childUid['uid'];
  270. // 将符合条件的子级 uid 添加到结果数组
  271. $childUid['contribute_sum'] = bcadd($childUid['contribute'], $childUid['per_contribute'], 2);
  272. $result[] = $childUid;
  273. // 递归查询子级的子级
  274. $recursion($childUid['uid'], $number, $num);
  275. }
  276. };
  277. // 从初始父级开始递归查询
  278. $recursion($parentUid, $number, $num);
  279. return $result; // 返回结果数组,并去重
  280. }
  281. // 贡献值
  282. public function gongxian_info(){
  283. log::info("============gongxianinfo");
  284. $user = $this->request->userInfo();
  285. if($user->uid>0){
  286. // 先去更新一下用户身份
  287. $number = Db::name("system_config_value")->where(["config_key" => "team_commission_recursion_depth"])->value("value");
  288. $this->repository->setUserIdentity($user->uid);
  289. $result = $this->repository->getUserContributeInfoByDepth($user->uid, 0);
  290. $con = DB::name('user')->where('uid', $user->uid)->find();
  291. $isNormalUser = false;
  292. if ($con['user_group'] == 1) {
  293. $isNormalUser = true;
  294. }
  295. $data = [
  296. 'no_total_source' => Db::name('user_sign_gongxian')->where('status', -1)->where('uid', $user->uid)->sum('number'),
  297. 'team_gongxian_num' => $result['arriveNumTeam'],
  298. 'zhitui' => $result['perContribute'],
  299. 'total_source' => $result['contribute'],
  300. 'largeContribute' => $result['largeContribute'],
  301. 'subordinate' => $result['subordinate'],
  302. 'isNormalUser' => $isNormalUser
  303. ];
  304. return app('json')->success($data);
  305. // $dateObj=DB::name('user_sign_gongxian')->where('uid', $user->uid)->where("status",1)->select();
  306. $con = DB::name('user')->where('uid', $user->uid)->find();
  307. // $totalcon = 0;
  308. // foreach($dateObj as $k=>$v){
  309. // $totalcon += $v['number'];
  310. // }
  311. // 已经入账贡献值
  312. // if( $con['user_group'] <= 2 ){
  313. // $data['total_source'] = $con['contribute'] + $con['per_contribute'];
  314. // }else{
  315. $data['total_source'] = $con['contribute'];
  316. $data['zhitui'] = $con['per_contribute'];
  317. // }
  318. // $getteamscon = $this->getPerformance($user->uid);
  319. //$getcon = $this->getPerformance_getcon( $user->uid);
  320. // $team_userinfo_old_jbp22 = $this->getPerformance22($user->uid);
  321. $user_id = $con['uid'];
  322. $user_group = $con['user_group'];
  323. $number = 10;
  324. if($user_group <= 1){
  325. $number = 1;
  326. }
  327. // 如果下级团队只有一个人 那就不用再查了 为0
  328. // 如果用户等级为用户身份 只查一级直推
  329. // 去除掉贡献值最大的下级
  330. $child_nums = $this->getRecursiveChildrenChengji($user_id, $number);
  331. $child_nums_Tree = $this->buildTreeContribute($child_nums, $con['spread_uid']);
  332. if (empty($child_nums_Tree)){
  333. $child_nums_Tree = $child_nums;
  334. $total_contribute = $child_nums_Tree[0]['per_contribute'];
  335. }else{
  336. // 找到贡献值最大的用户的索引
  337. if(count($child_nums_Tree[0]['children'])){
  338. $maxBalanceIndex = array_search(max(array_column($child_nums_Tree[0]['children'], 'total_contribute')), array_column($child_nums_Tree, 'total_contribute'));
  339. // 减去该用户的贡献值
  340. $total_contribute = bcsub($child_nums_Tree[0]['total_contribute'], $child_nums_Tree[0]['children'][$maxBalanceIndex]['total_contribute'], 2);
  341. }else{
  342. $total_contribute = $child_nums_Tree[0]['total_contribute'];
  343. }
  344. }
  345. $data['team_gongxian_num'] = $total_contribute;
  346. // 我的团队贡献值
  347. // if( $con['user_group'] <= 2 ){
  348. // $data['team_gongxian_num'] = $team_userinfo_old_jbp22['person_nums_pv'] - $con['per_contribute'];
  349. // }else{
  350. // $data['team_gongxian_num'] = $team_userinfo_old_jbp22['person_nums_pv'];
  351. // }
  352. // 未生效贡献值
  353. $data['no_total_source']=Db::name('user_sign_gongxian')->where('status', -1)->where('uid', $user->uid)->sum('number');
  354. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  355. return app('json')->success($data);
  356. }
  357. }
  358. // 获取团队贡献值
  359. public function gettemasconvalue($user_id) {
  360. //$user_id = 17;
  361. $children = Db::name("user")
  362. ->where("spread_uid", $user_id)
  363. ->select(); // 获取子级的 uid 列表
  364. $total_pv = 0;
  365. foreach($children as $k=>$v){
  366. //$children_pv = Db::name("store_order")->where("uid", $v['uid'])->whereIn("status",[0,1,2,3])->select();
  367. $children_pv = Db::name("user_sign_gongxian")->where("uid", $v['uid'])->where("status",1)->select();
  368. foreach($children_pv as $k1=>$v1){
  369. $total_pv += $v1['number'];
  370. }
  371. }
  372. }
  373. public function gongxian_list(){
  374. $pm = $this->request->param('pm');
  375. [$page, $limit] = $this->getPage();
  376. $uid = $this->request->uid();
  377. log::info("green_integral_list==={$uid}");
  378. $where['uid'] = $uid;
  379. if ($pm==0){
  380. $data = DB::name('user_sign_gongxian')->where($where)->where('status',1)->where('number', '<>',0)->field('id,mark,number,addtime,order_id,status')->page($page, $limit)->order("addtime DESC,id desc")->select();
  381. }
  382. // if($pm==1){
  383. // $data = DB::name('user_sign_gongxian')->where($where)->where('pm', 2)->field('id,mark,number,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  384. //
  385. // }
  386. if($pm==2){
  387. $data = DB::name('user_sign_gongxian')->where($where)->where('number', '<>',0)->where([['status','in','-1,0']])->field('id,mark,number,addtime,order_id,status')->page($page, $limit)->order("id desc")->select();
  388. if($data){
  389. $data = $data->toArray();
  390. foreach ($data as $k=>$v){
  391. if($v['status'] == 0){
  392. $data[$k]['mark'] = '(失效)' . $v['mark'];
  393. }
  394. }
  395. }
  396. }
  397. return app("json")->success($data);
  398. }
  399. // 京豆
  400. public function jingdou_info(){
  401. log::info("============hongbao");
  402. $user = $this->request->userInfo();
  403. if($user->uid>0){
  404. // 已经入账京豆
  405. //$data['total_source']=$user->vr;//原件
  406. $data['total_source'] = $user->jingdou;// 临时使用
  407. // 为生效京豆
  408. $data['no_total_source']=Db::name('user_sign_jingdou')->where('status', -1)->where('uid', $user->uid)->sum('number');;
  409. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  410. return app('json')->success($data);
  411. }
  412. }
  413. public function jingdou_list(){
  414. $pm = $this->request->param('pm');
  415. [$page, $limit] = $this->getPage();
  416. $uid = $this->request->uid();
  417. log::info("jingdou_list==={$uid}");
  418. $where['uid'] = $uid;
  419. if ($pm==0){
  420. $data = DB::name('user_sign_jingdou')->where($where)->where('type', 1)->where('status',1)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  421. }
  422. if($pm==1){
  423. $data = DB::name('user_sign_jingdou')->where($where)->where('type', 2)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  424. }
  425. if($pm==2){
  426. $data = DB::name('user_sign_jingdou')->where($where)->where([['status','in','-1,0']])->field('id,mark,number,type,addtime,order_id,status')->page($page, $limit)->order("id desc")->select();
  427. if($data){
  428. $data = $data->toArray();
  429. foreach ($data as $k=>$v){
  430. if($v['status'] == 0){
  431. $data[$k]['mark'] = '(失效)' . $v['mark'];
  432. }
  433. }
  434. }
  435. }
  436. // $data['total'] =111;
  437. return app("json")->success($data);
  438. }
  439. // 复购金
  440. public function fugou_info(){
  441. log::info("============fugou");
  442. $user = $this->request->userInfo();
  443. if($user->uid>0){
  444. // 已经入账京豆
  445. $data['total_source']=$user->fugou;
  446. // 为生效京豆
  447. $data['no_total_source']=Db::name('user_sign_fugou')->where('status', -1)->where('uid', $user->uid)->sum('number');;
  448. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  449. return app('json')->success($data);
  450. }
  451. }
  452. public function fugou_list(){
  453. $pm = $this->request->param('pm');
  454. [$page, $limit] = $this->getPage();
  455. $uid = $this->request->uid();
  456. log::info("fugou_list==={$uid}");
  457. $where['uid'] = $uid;
  458. if ($pm==0){
  459. $data = DB::name('user_sign_fugou')->where($where)->where('type', 1)->where('status',1)->field('id,mark,number,type,addtime,order_id,status')->page($page, $limit)->order("id desc")->select();
  460. }
  461. if($pm==1){
  462. $data = DB::name('user_sign_fugou')->where($where)->where('type', 2)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  463. }
  464. if($pm==2){
  465. $data = DB::name('user_sign_fugou')->where($where)->where('type', 1)->where([['status','in','-1,0']])->field('id,mark,number,type,addtime,order_id,status')->page($page, $limit)->order("id desc")->select();
  466. if($data){
  467. $data = $data->toArray();
  468. foreach ($data as $k=>$v){
  469. if($v['status'] == 0){
  470. $data[$k]['mark'] = '(失效)' . $v['mark'];
  471. }
  472. }
  473. }
  474. }
  475. return app("json")->success($data);
  476. }
  477. // VR 购物金
  478. public function vr_info(){
  479. log::info("============vr");
  480. $user = $this->request->userInfo();
  481. if($user->uid>0){
  482. // 已经入账京豆
  483. $data['total_source'] = $user->vr;
  484. // 为生效京豆
  485. $data['no_total_source']=0;
  486. //$data['no_total_source']=Db::name('user_sign_vr')->where('status', -1)->where('uid', $user->uid)->sum('number');;
  487. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  488. return app('json')->success($data);
  489. }
  490. }
  491. public function vr_list(){
  492. $pm = $this->request->param('pm');
  493. [$page, $limit] = $this->getPage();
  494. $uid = $this->request->uid();
  495. log::info("vr_list==={$uid}");
  496. $where['uid'] = $uid;
  497. $data = DB::name('user_sign_vr')->page($page, $limit)->order("id desc")->select();
  498. if ($pm==0){
  499. $data = DB::name('user_sign_vr')->where($where)->where('type', 1)->page($page, $limit)->order("id desc")->select();
  500. }
  501. if($pm==2){
  502. $data = DB::name('user_sign_vr')->where($where)->where('type', 2)->page($page, $limit)->order("id desc")->select();
  503. }
  504. // if($pm==2){
  505. // $data = DB::name('user_sign_vr')->where($where)->where('status', -1)->field('id,mark,number,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  506. //
  507. // }
  508. log::info("=======date==={$data}");
  509. return app("json")->success($data);
  510. }
  511. public function spread_info_yhc()
  512. {
  513. log::info("============ddddddddd");
  514. $user = $this->request->userInfo();
  515. if($user->uid>0){
  516. // 已经入账积分
  517. $data['total_source']=$user->score;
  518. // 为生效积分
  519. $data['no_total_source']=Db::name('user_sign_score')->where('status', -1)->where('uid', $user->uid)->sum('reward_socre');;
  520. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  521. return app('json')->success($data);
  522. }
  523. // if ($this->source == 'yhc' && $this->merId) {
  524. // $where['mer_id'] = $this->merId;
  525. // $where['uid'] = $user->uid;
  526. // $enterprise_user = Db::name('enterprise_user')->where($where)->find();
  527. // if ($enterprise_user) {
  528. // $data['current_balance'] = set_price_rtrim($enterprise_user['commission']);//收益余额
  529. // $data['unsettled_balance'] = 0;//未结算
  530. // $extract_price = Db::name('user_extract')->where($where)->whereIn('status', [0, 1])->sum('extract_price');
  531. // $data['withdrawn_balance'] = set_price_rtrim($extract_price); //已提现
  532. // $data['total_balance'] = set_price_rtrim($enterprise_user['commission'] + $data['withdrawn_balance']);//总收益=收益余额+已提现
  533. // $data['identity'] = $enterprise_user['identity'];
  534. // $data['level'] = $enterprise_user['level'];
  535. // $data['partnership'] = $enterprise_user['partnership'];
  536. // $data['green_integral'] = $enterprise_user['green_integral'];
  537. // $data['green_integral_is'] = $enterprise_user['green_integral_is'];
  538. // $data['operate'] = $enterprise_user['operate'];
  539. // $data['operate_icon'] = '';
  540. // $data['operate_text'] = '';
  541. // $member_settings = merchantConfig($this->merId, 'member_settings');
  542. // if ($data['operate'] == 101) {
  543. // $data['operate_icon'] = $member_settings['yy_one_img'];
  544. // $data['operate_text'] = $member_settings['yy_one_text'];
  545. // }
  546. // if ($data['operate'] == 102) {
  547. // $data['operate_icon'] = $member_settings['yy_two_img'];
  548. // $data['operate_text'] = $member_settings['yy_two_text'];
  549. // }
  550. //
  551. //
  552. // $data['nickname'] = $user->nickname;
  553. // $data['avatar'] = $enterprise_user['avatar'];
  554. //
  555. // $arr = $this->jisuan_fans($user->uid);
  556. // $data['fans_num'] = count($arr);//粉丝总数
  557. //
  558. // $yanglao = 0;
  559. // $offLinewhere = ['mer_id' => $this->merId, 'uid' => $user->uid, 'commission_type' => '5', 'type_shop' => 0];
  560. // $offLine1 = Db::name('user_bill')->where($offLinewhere)->where('source', 1)->where('status', 1)->sum('number');
  561. // $yanglao += $offLine1;
  562. // $offLine2 = Db::name('user_bill')->where($offLinewhere)->where('source', 0)->whereIn('status', [0, 1])->sum('number');
  563. // $yanglao += $offLine2;
  564. //
  565. //
  566. // $data['ylj'] = set_price_rtrim($yanglao);
  567. //
  568. // $data['yhc_withdrawal_money'] = merchantConfig($this->merId, 'yhc_withdrawal_money');
  569. //
  570. //
  571. // $data['uid'] = $enterprise_user['uid'];
  572. // if ($enterprise_user['identity'] > 100) {
  573. // $data['identity_data'] = Db::name('enterprise_performance_divvy')->field('name,img,content')->where('state', 1)->where('id', $enterprise_user['identity'])->find();
  574. // if (!$data['identity_data']) {
  575. // $data['identity_data'] = null;
  576. // $data['identity'] = '100';
  577. // }
  578. // } else {
  579. // $data['identity_data'] = null;
  580. // }
  581. //
  582. // $data['level_data'] = Db::name('enterprise_agent_divvy')->field('name,img,content')->where('state', 1)->where('id', $enterprise_user['level'])->find();
  583. //
  584. //
  585. // return app('json')->success($data);
  586. // }
  587. // }
  588. return app('json')->fail('用户不存在');
  589. }
  590. /**
  591. * @param UserBillRepository $billRepository
  592. * @return mixed
  593. * @author xaboy
  594. * @day 2020/6/22
  595. */
  596. public function bill(UserBillRepository $billRepository)
  597. {
  598. [$page, $limit] = $this->getPage();
  599. $where = [
  600. // 'now_money' => $this->request->param('type', 0),
  601. 'status' => $this->request->param('status'),
  602. ];
  603. if ($this->request->param('is_red') == true) {
  604. $where['is_red_brokerage'] = 1;
  605. }
  606. return app('json')->success($billRepository->userList($where, $this->request->uid(), $page, $limit));
  607. }
  608. /**
  609. * @param UserBillRepository $billRepository
  610. * @return mixed
  611. * @author xaboy
  612. * @day 2020/6/22
  613. */
  614. public function brokerage_list(UserBillRepository $billRepository)
  615. {
  616. [$page, $limit] = $this->getPage();
  617. return app('json')->success($billRepository->userList([
  618. 'category' => 'brokerage',
  619. ], $this->request->uid(), $page, $limit));
  620. }
  621. /**
  622. * @return mixed
  623. * @throws \think\db\exception\DataNotFoundException
  624. * @throws \think\db\exception\DbException
  625. * @throws \think\db\exception\ModelNotFoundException
  626. * @author xaboy
  627. * @day 2020/6/22
  628. */
  629. public function spread_order()
  630. {
  631. [$page, $limit] = $this->getPage();
  632. return app('json')->success($this->repository->subOrder($this->request->uid(), $page, $limit));
  633. }
  634. /**
  635. * TODO
  636. * @return mixed
  637. * @author Qinii
  638. * @day 2020-06-18
  639. */
  640. public function binding()
  641. {
  642. $data = $this->request->params(['phone', 'sms_code']);
  643. if (!$data['sms_code'] || !$this->checkSmsCode($data['phone'], $data['sms_code'])) return app('json')->fail('验证码不正确');
  644. $user = $this->repository->accountByUser($data['phone']);
  645. if ($user) {
  646. $data = ['phone' => $data['phone']];
  647. } else {
  648. $data = ['account' => $data['phone'], 'phone' => $data['phone']];
  649. }
  650. $this->repository->update($this->request->uid(), $data);
  651. return app('json')->success('绑定成功');
  652. }
  653. /**
  654. * TODO
  655. * @return mixed
  656. * @author Qinii
  657. * @day 2020-06-18
  658. */
  659. public function binding_verify()
  660. {
  661. $data = $this->request->params(['user_id', 'captcha']);
  662. $data['phone'] = \think\facade\Db::name("user")->where(["uid" => $data['user_id']])->value("phone");
  663. $data['sms_code'] = $data['captcha'];
  664. if (!$data['sms_code'] || !$this->checkSmsCode($data['phone'], $data['sms_code'])) return app('json')->fail('验证码不正确');
  665. return app('json')->success('验证成功');
  666. }
  667. public function checkSmsCode($phone, $code)
  668. {
  669. $sms_key = 'api.auth.sms.' . $phone;
  670. if (!$cache_code = Cache::get($sms_key)) return false;
  671. if ($code != $cache_code) return false;
  672. Cache::delete($sms_key);
  673. return true;
  674. }
  675. /**
  676. * @return mixed
  677. * @throws \think\db\exception\DataNotFoundException
  678. * @throws \think\db\exception\DbException
  679. * @throws \think\db\exception\ModelNotFoundException
  680. * @author xaboy
  681. * @day 2020/6/22
  682. */
  683. public function spread_list()
  684. {
  685. [$level, $sort, $nickname] = $this->request->params(['level', 'sort', 'keyword'], true);
  686. $uid = $this->request->uid();
  687. [$page, $limit] = $this->getPage();
  688. return app('json')->success($level == 2
  689. ? $this->repository->getTwoLevelList($uid, $nickname, $sort, $page, $limit)
  690. : $this->repository->getOneLevelList($uid, $nickname, $sort, $page, $limit));
  691. }
  692. /**
  693. * @return mixed
  694. * @author xaboy
  695. * @day 2020/6/22
  696. */
  697. public function spread_top()
  698. {
  699. [$page, $limit] = $this->getPage();
  700. $type = $this->request->param('type', 0);
  701. return app('json')->success($type == 1
  702. ? $this->repository->spreadMonthTop($page, $limit)
  703. : $this->repository->spreadWeekTop($page, $limit));
  704. }
  705. /**
  706. * @return mixed
  707. * @author xaboy
  708. * @day 2020/6/22
  709. */
  710. public function brokerage_top()
  711. {
  712. [$page, $limit] = $this->getPage();
  713. $type = $this->request->param('type', 0);
  714. return app('json')->success($type == 1
  715. ? $this->repository->brokerageMonthTop($page, $limit)
  716. : $this->repository->brokerageWeekTop($page, $limit));
  717. }
  718. public function history(UserVisitRepository $repository)
  719. {
  720. $uid = $this->request->uid();
  721. [$page, $limit] = $this->getPage();
  722. return app('json')->success($repository->getHistory($uid, $page, $limit));
  723. }
  724. public function deleteHistory($id, UserVisitRepository $repository)
  725. {
  726. $uid = $this->request->uid();
  727. if (!$repository->getWhereCount(['user_visit_id' => $id, 'uid' => $uid]))
  728. return app('json')->fail('数据不存在');
  729. $repository->delete($id);
  730. return app('json')->success('删除成功');
  731. }
  732. public function account()
  733. {
  734. $user = $this->request->userInfo();
  735. if (!$user->phone) return app('json')->fail('请绑定手机号');
  736. return app('json')->success($this->repository->selfUserList($user->phone));
  737. }
  738. public function switchUser()
  739. {
  740. $uid = (int)$this->request->param('uid');
  741. if (!$uid) return app('json')->fail('用户不存在');
  742. $userInfo = $this->request->userInfo();
  743. if (!$userInfo->phone) return app('json')->fail('请绑定手机号');
  744. $user = $this->repository->switchUser($userInfo, $uid);
  745. $tokenInfo = $this->repository->createToken($user);
  746. $this->repository->loginAfter($user);
  747. return app('json')->success($this->repository->returnToken($user, $tokenInfo));
  748. }
  749. /**
  750. * 签到 获取积分
  751. * @return mixed
  752. * @throws \think\db\exception\DataNotFoundException
  753. * @throws \think\db\exception\DbException
  754. * @throws \think\db\exception\ModelNotFoundException
  755. */
  756. public function sub_signin()
  757. {
  758. $member_id = $this->request->uid();
  759. if (!$member_id) return app('json')->fail('用户不存在');
  760. $res = $this->repository->sub_signin($member_id);
  761. return app('json')->success($res);
  762. }
  763. /**
  764. * 获取用户签到记录
  765. * data1 开始时间
  766. * data2 结束时间
  767. * @return mixed
  768. * @throws \think\db\exception\DataNotFoundException
  769. * @throws \think\db\exception\DbException
  770. * @throws \think\db\exception\ModelNotFoundException
  771. */
  772. public function get_signin()
  773. {
  774. $member_id = $this->request->uid();
  775. if (!$member_id) return app('json')->fail('用户不存在');
  776. $where = [];
  777. $data1 = input('data1');
  778. $data2 = input('data2');
  779. if ($data1 && $data2) {
  780. $where["data1"] = $data1;
  781. $where["data2"] = $data2;
  782. }
  783. $res = $this->repository->get_signin($member_id, $where);
  784. return app('json')->success($res);
  785. }
  786. /**
  787. * 提交实名认证
  788. *
  789. * @return void
  790. */
  791. public function add_certification()
  792. {
  793. $member_id = $this->request->uid();
  794. $type = input("type", 0);
  795. if ($type == 1) {
  796. $data = $this->repository->get_cer(["uid" => $member_id]);
  797. return app('json')->success($data);
  798. }
  799. if (!$member_id) return app('json')->fail('用户不存在');
  800. $params = $this->request->params([
  801. 'user_name',
  802. 'mobile',
  803. 'user_card',
  804. 'card_positive',
  805. 'card_reverse',
  806. ]);
  807. $params['create_time'] = time();
  808. $params['uid'] = $member_id;
  809. $baidu = new Ocr();
  810. $image = file_get_contents($params['card_positive']);
  811. $idCardSide = "front";
  812. $result = $baidu->idcard($image, $idCardSide);
  813. $real_user_name = $result['words_result']['姓名']['words'] ?? '';
  814. $real_user_card = $result['words_result']['公民身份号码']['words'] ?? '';
  815. if ($real_user_name != $params['user_name']) {
  816. return app('json')->fail('姓名或身份证号输入有误~');
  817. }
  818. if ($real_user_card != $params['user_card']) {
  819. return app('json')->fail('姓名或身份证号输入有误~');
  820. }
  821. if ($result['image_status'] == "normal" && $result['idcard_number_type'] == 1) {
  822. $params['status'] = 1;
  823. $res = $this->repository->add_cer($params, $member_id);
  824. if ($res) {
  825. $userRepository = app()->make(UserRepository::class);
  826. // 赠送积分 完善实名送90个积分,同时送邀请人50个积分
  827. $userRepository->sign_add($member_id, 90,1,'完善实名系统赠送90个积分','','', '', 1, '', 1);
  828. $member_info = Db::name('user')->where( array('uid' => $member_id) )->find();
  829. Db::name('user')
  830. ->where('uid', $member_id)
  831. ->update(['real_name' => $params['user_name'], 'nickname' => $params['user_name']]);
  832. if($member_info['spread_uid']){
  833. // 好友完善实名系统赠送50个积分
  834. $spreadUid = $member_info['spread_uid'];
  835. $userRepository->sign_add($spreadUid, 50,1,'好友完善实名系统赠送50个积分','','', '', 1, '', 1);
  836. }
  837. return app('json')->success($res);
  838. } else {
  839. return app('json')->fail('认证失败');
  840. }
  841. } else {
  842. return app('json')->fail('认证失败,请重新认证');
  843. }
  844. }
  845. /**
  846. * 申请代理
  847. * name:公司名称
  848. * identity:身份
  849. * license:营业执照
  850. */
  851. public function apply_agent()
  852. {
  853. $name = input("name", "");
  854. $identity = input("identity", 1);
  855. $license = input("license", "");
  856. $province_id = input("province_id", "");
  857. $city_id = input("city_id", "");
  858. $area_id = input("area_id", "");
  859. $street_id = input("street_id", "");
  860. $spread_account = input("spread_account", "");
  861. $member_id = $this->request->uid();
  862. if ($identity != 6 && (!$name || !$identity || !$license)) {
  863. return app('json')->fail('请检查参数');
  864. }
  865. if ($identity == 6 && (!$name || !$identity)) {
  866. return app('json')->fail('请检查参数');
  867. }
  868. $data = [
  869. "name" => $name,
  870. "identity" => $identity,
  871. "license" => $license,
  872. "user_id" => $member_id,
  873. "province_id" => $province_id,
  874. "city_id" => $city_id,
  875. "area_id" => $area_id,
  876. "street_id" => $street_id,
  877. 'spread_account' => $spread_account,
  878. "add_time" => time(),
  879. "update_time" => time()
  880. ];
  881. $res = $this->repository->agent($data);
  882. if ($res['code'] == 400) {
  883. return app('json')->fail($res['msg']);
  884. }
  885. return app('json')->success("申请成功", $res);
  886. }
  887. /*查询是否有已申请或者审核中的代理信息*/
  888. public function isAgent()
  889. {
  890. $uid = $this->request->uid();
  891. $data = $this->repository->isAgent($uid);
  892. return app("json")->success($data);
  893. }
  894. /*查询是否有审核成功的未支付或支付失败的订单*/
  895. public function AgentPayDetail()
  896. {
  897. $uid = $this->request->uid();
  898. if (!$uid) {
  899. return app('json')->fail('请检查参数');
  900. }
  901. $where = ['status' => 1, 'pay_status' => ['0', '2'], 'user_id' => $uid];
  902. $data = $this->repository->getAgentPayDetail($where);
  903. return app('json')->success("成功", $data);
  904. }
  905. /**
  906. * 获取信息 全民营销首页
  907. * @return mixed
  908. */
  909. public function get_agent_info()
  910. {
  911. $member_id = $this->request->uid();
  912. $res = $this->repository->get_agent_info($member_id);
  913. if ($res) {
  914. return app('json')->success($res);
  915. } else {
  916. return app('json')->fail('获取失败');
  917. }
  918. }
  919. /**
  920. * 推广统计
  921. * search 搜索
  922. * @return mixed
  923. */
  924. public function get_extension_info()
  925. {
  926. $search = input("search", "");
  927. $where = $this->request->params(["identity"]);
  928. $member_id = $this->request->uid();
  929. $res = $this->repository->get_extension_info($member_id, $search, $where);
  930. if ($res) {
  931. return app('json')->success($res);
  932. } else {
  933. return app('json')->fail('获取失败');
  934. }
  935. }
  936. /**
  937. * 收益统计
  938. * type 搜索
  939. * @return mixed
  940. */
  941. public function get_profit_info()
  942. {
  943. $where = $this->request->params([
  944. 'commission_type',
  945. 'date_on',
  946. 'date_off',
  947. 'order'
  948. ]);
  949. $member_id = $this->request->uid();
  950. $res = $this->repository->get_profit_info($member_id, $where);
  951. if ($res) {
  952. return app('json')->success($res);
  953. } else {
  954. return app('json')->fail('获取失败');
  955. }
  956. }
  957. /**
  958. * 订单统计
  959. * search 搜索
  960. * @return mixed
  961. */
  962. public function get_tuiguang_order()
  963. {
  964. $member_id = $this->request->uid();
  965. $res = $this->repository->get_tuiguang_order($member_id);
  966. if ($res) {
  967. return app('json')->success($res);
  968. } else {
  969. return app('json')->fail('获取失败');
  970. }
  971. }
  972. /*
  973. * 攒金明细统计
  974. * */
  975. public function get_commission_all()
  976. {
  977. $uid = $this->request->uid();
  978. $where['date_on'] = 1;
  979. $where['date_off'] = 0;
  980. // $where['commission_type'] = '';
  981. $date = $this->request->params(['date']);//"today","yesterday","week","month","year"
  982. $where['order'] = $date['date'];
  983. $res = $this->repository->get_profit_info($uid, $where);
  984. return app('json')->success($res);
  985. }
  986. /*
  987. * 攒金明细列表
  988. * */
  989. public function get_commission_list()
  990. {
  991. $uid = $this->request->uid();
  992. [$where['page'], $where['limit']] = $this->getPage();
  993. $data = $this->request->params(['type', 'date']);//"today","yesterday","week","month","year"
  994. $where['type'] = $data['type'];// 0线上;1线下
  995. $where['order'] = $data['date'];//"today","yesterday","week","month","year"
  996. $res = $this->repository->get_tuiguang_list($uid, $where);
  997. return app('json')->success($res);
  998. }
  999. /*
  1000. * 越攒越多佣金
  1001. * */
  1002. public function get_com_list()
  1003. {
  1004. $uid = $this->request->uid();
  1005. [$where['page'], $where['limit']] = $this->getPage();
  1006. $data = $this->request->params(['date']);//"today","yesterday","week","month","year"
  1007. $where['order'] = $data['date'];//"today","yesterday","week","month","year"
  1008. $res = $this->repository->get_com_list($uid, $where);
  1009. return app('json')->success($res);
  1010. }
  1011. /*
  1012. * 越攒越多统计
  1013. * */
  1014. public function get_com_all()
  1015. {
  1016. $uid = $this->request->uid();
  1017. $data = $this->request->params(['date']);//"today","yesterday","week","month","year"
  1018. $where['order'] = $data['date'];//"today","yesterday","week","month","year"
  1019. $res = $this->repository->get_com_all($uid, $where);
  1020. return app('json')->success($res);
  1021. }
  1022. /**
  1023. * 养老金详情
  1024. * @return mixed
  1025. */
  1026. public function get_yanglao()
  1027. {
  1028. $member_id = $this->request->uid();
  1029. $res = $this->repository->get_yanglao($member_id);
  1030. if ($res) {
  1031. return app('json')->success($res);
  1032. } else {
  1033. return app('json')->fail('获取失败');
  1034. }
  1035. }
  1036. /**
  1037. * 养老金明细
  1038. */
  1039. public function yanglaolog()
  1040. {
  1041. $member_id = $this->request->uid();
  1042. [$page, $limit] = $this->getPage();
  1043. $where = ["uid" => $member_id, "type" => "commission", "commission_type" => 5, "type_shop" => 0];
  1044. if ($this->source == 'yhc' && $this->merId) {
  1045. $where['mer_id'] = $this->merId;
  1046. }
  1047. $month = $this->request->param('month', '');// 年月搜索
  1048. $status = $this->request->param('status', 1);
  1049. // 1-全部 2-已结算 3-未结算 4-已取消
  1050. if ($status == 2) {
  1051. $where['status'] = 1;
  1052. } else if ($status == 3) {
  1053. // $where['gzc']=0;
  1054. $where['status'] = 0;
  1055. } else if ($status == 4) {
  1056. $where['status'] = -1;
  1057. }
  1058. $source = $this->request->param('source', -1);
  1059. if ($source > -1) {
  1060. $where['source'] = $source;
  1061. }
  1062. $res = $this->repository->yanglaolog($where, $page, $limit, $month,1);
  1063. if ($res) {
  1064. $res['list'] = $res['list']->toArray();
  1065. if($res['list']){
  1066. foreach ($res['list'] as $k=>$v){
  1067. if($v['status'] == -1){
  1068. $res['list'][$k]['mer_name'] = $v['mer_name'] . '(失效)';
  1069. }
  1070. }
  1071. }
  1072. return app('json')->success($res);
  1073. } else {
  1074. return app('json')->fail('获取失败');
  1075. }
  1076. }
  1077. /*养老金详情*/
  1078. public function YangLaoDetail($id)
  1079. {
  1080. $member_id = $this->request->uid();
  1081. $data = $this->request->params([
  1082. 'type',
  1083. ]);
  1084. $where = ["uid" => $member_id, "type" => "commission", "commission_type" => $data['type'], 'bill_id' => $id];
  1085. $res = $this->repository->yanglaoDetail($where);
  1086. return app('json')->success($res);
  1087. }
  1088. /**
  1089. * 消费明细
  1090. * @return mixed
  1091. */
  1092. public function tripartite()
  1093. {
  1094. $member_id = $this->request->uid();
  1095. $where = ["uid" => $member_id, "type" => "commission", "commission_type" => 5, "tripartite" => ["<>", 0]];
  1096. $res = $this->repository->yanglaolog($where);
  1097. if ($res) {
  1098. return app('json')->success($res);
  1099. } else {
  1100. return app('json')->fail('获取失败');
  1101. }
  1102. }
  1103. /**
  1104. * 提现明细
  1105. * @return mixed
  1106. */
  1107. public function withdrawal()
  1108. {
  1109. $member_id = $this->request->uid();
  1110. $data = $this->request->params([
  1111. 'type',
  1112. ]);
  1113. $where = ["uid" => $member_id, "type" => $data['type'] ? $data['type'] : 2];
  1114. if ($this->source == 'yhc') {
  1115. $where['mer_id'] = $this->merId;
  1116. }
  1117. $res = $this->repository->withdrawal_user($where);
  1118. if ($res) {
  1119. return app('json')->success($res);
  1120. } else {
  1121. return app('json')->fail('获取失败');
  1122. }
  1123. }
  1124. /**
  1125. * 提现详情
  1126. * @return mixed
  1127. * @author cabbage
  1128. * @day 2020/10/31
  1129. */
  1130. public function withdrawalDetail()
  1131. {
  1132. $member_id = $this->request->uid();
  1133. $extract_id = input("extract_id", 0);
  1134. return app('json')->success($this->repository->withdrawalDetail($extract_id, $member_id));
  1135. }
  1136. /*
  1137. * 修改个人信息*/
  1138. public function updateUser()
  1139. {
  1140. $uid = $this->request->uid();
  1141. $data['nickname'] = $this->request->param('nickname', null);
  1142. $data['avatar'] = $this->request->param('avatar', null);
  1143. $data['sex'] = $this->request->param('sex', null);
  1144. $data['birthday'] = $this->request->param('birthday', null);
  1145. $data['addres'] = $this->request->param('addres', null);
  1146. $data['mark'] = $this->request->param('mark', null);
  1147. // 新加更换用户手机号逻辑,更换手机号时需验证 当前使用手机号收到的验证码,以确认本人操作
  1148. // 需求描述说:更换用户手机号时,同步更新 商户申请表、商户表、商户管理员表
  1149. $data['phone'] = $this->request->param('phone', null);
  1150. $sms_code = $this->request->param('sms_code', null);
  1151. $data = array_filter($data, function ($value) {
  1152. return !is_null($value);
  1153. });
  1154. if (!empty($data['phone'])) {
  1155. $changeUserData = $this->repository->getOne(['phone' => $data['phone']]);
  1156. if (!empty($changeUserData)) {
  1157. return app("json")->fail("该手机号已被用户绑定");
  1158. }
  1159. if (empty($sms_code)) {
  1160. return app("json")->fail("请输入验证码");
  1161. }
  1162. $userData = $this->repository->get($uid)->toArray();
  1163. if (!$this->checkSmsCode($userData['phone'], $sms_code)) {
  1164. return app('json')->fail('验证码不正确');
  1165. }
  1166. // 商户申请表
  1167. Db::name("merchant_intention")
  1168. ->where('uid', $uid)
  1169. ->where('phone', $userData['phone'])
  1170. ->update(['phone' => $data['phone']]);
  1171. // 商户表
  1172. Db::name("merchant")
  1173. ->where('uid', $uid)
  1174. ->where('mer_phone', $userData['phone'])
  1175. ->update(['mer_phone' => $data['phone']]);
  1176. // 商户管理员表
  1177. Db::name("merchant_admin")
  1178. ->where('uid', $uid)
  1179. ->where('account', $userData['phone'])
  1180. ->update(['account' => $data['phone']]);
  1181. }
  1182. if (!empty($data['phone'])) {
  1183. $data['account'] = $data['phone'];
  1184. }
  1185. $data = array_filter($data, function($value) {
  1186. return $value !== null;
  1187. });
  1188. $res = '';
  1189. if ($this->source == 'yhc') {
  1190. $res = Db::name('enterprise_user')->where('mer_id', $this->merId)->where('uid', $uid)->update(['avatar' => $data['avatar']]);
  1191. unset($data['avatar']);
  1192. }
  1193. $data = $this->repository->updateUser($uid, $data);
  1194. if ($data || $res) {
  1195. return app("json")->success("修改成功", $data);
  1196. }
  1197. return app("json")->fail("未做任何修改");
  1198. }
  1199. /*积分记录*/
  1200. public function socreList()
  1201. {
  1202. [$page, $limit] = $this->getPage();
  1203. $uid = $this->request->uid();
  1204. $data = $this->repository->socreList($uid, $page, $limit);
  1205. return app("json")->success($data);
  1206. }
  1207. function jisuan_fans($uid)
  1208. {
  1209. $where22['node_uid'] = $uid;
  1210. $where22['mer_id'] = $this->merId;
  1211. $arr = $this->jisuantuandui($where22);
  1212. $where['puid'] = $uid;
  1213. $where['mer_id'] = $this->merId;
  1214. $direct_fans = Db::name('enterprise_user')->where($where)->column('uid');// 直属粉丝数量
  1215. $result = array_unique(array_merge($arr, $direct_fans));
  1216. return $result;
  1217. }
  1218. function jisuantuandui($where, $data = [])
  1219. {
  1220. $enterprise_user_team = DB::name('enterprise_user')->where($where)->column('uid');
  1221. $arr = array_merge($data, $enterprise_user_team);
  1222. foreach ($enterprise_user_team as $v) {
  1223. $where['node_uid'] = $v;
  1224. $arr = $this->jisuantuandui($where, $arr);
  1225. }
  1226. return $arr;
  1227. }
  1228. /**
  1229. * 一壶茶-团队列表
  1230. */
  1231. public function team_list_1()
  1232. {
  1233. $teamid = $this->request->uid();
  1234. //$teamid = $this->request->param('teamid');//测试ID
  1235. $teamid = 17;
  1236. $datas_jbp = Db::name('old_user_jbp')->where("id",$teamid)->find();// 查询旧系统是否有当前会员
  1237. $type = $this->request->param('type',0);// 1:大部门,0:小部门,2:直推
  1238. if(!empty($datas_jbp)){
  1239. $team_userinfo_old_jbp1 = $this->getPerformance($teamid);
  1240. // 判断大小团队(业绩多的是大部门,业绩小的是小部门)
  1241. $tes = $this->teamPeople($teamid,$type);// 1:团队,2:个人
  1242. // 获取分页参数
  1243. $data1= [
  1244. "total"=>100,
  1245. "per_page"=> 10,
  1246. "current_page"=> 1,
  1247. "last_page"=> 1,
  1248. ];
  1249. if($type != 2){
  1250. // 小部门和大部门列表数据
  1251. foreach($tes as $k=>$v){
  1252. $curr_pv = '';
  1253. if($v['curr_type']==0){
  1254. $curr_pv = $team_userinfo_old_jbp1['person_nums_pv'];
  1255. }else if($v['curr_type']==1){
  1256. $curr_pv = $team_userinfo_old_jbp1['common_nums_pv'];
  1257. }else{
  1258. $curr_pv = 0;
  1259. }
  1260. $data1['data'][$k] = [
  1261. "uid"=>$v["id"],
  1262. "nickname"=> $v['user_name'] . $curr_pv,
  1263. "phone"=> "137****3315",
  1264. "avatar"=>"https://cdn.bjtdba.com/vod/image/2025-01-20/20250120125206881.png",
  1265. "create_time"=>"2025-01-25 11:00:18",
  1266. "identity"=>"11",
  1267. "level"=> "40002",
  1268. "partnership"=>"22",
  1269. "total_performance"=> $curr_pv,//$v["performance"]['sum_nums_pv'],//总业绩
  1270. "new_performance"=> 0,// 新增业绩
  1271. "team_count"=> $v["performance"]['common_nums'] + $v["performance"]['person_nums'] + 1,// 团购人数(加的这个1 是当前用户的数)
  1272. ];
  1273. }
  1274. }else{
  1275. // 直推列表
  1276. foreach($tes as $k=>$v){
  1277. $data1['data'][$k] = [
  1278. "uid"=>$v["uid"],
  1279. "nickname"=> $v['nickname'],
  1280. "avatar"=>$v['avatar'],
  1281. "create_time"=>"2025-01-25 11:00:18",
  1282. ];
  1283. }
  1284. }
  1285. $data['team_list'] = $data1;
  1286. $data['fans_num'] = $team_userinfo_old_jbp1['person_nums'] + $team_userinfo_old_jbp1['common_nums'] ;// 粉丝数
  1287. $data['new_performance'] = 0;// 新增业绩
  1288. $data['total_performance']= $team_userinfo_old_jbp1['sum_nums_pv'];// 总业绩
  1289. $data['person_nums'] = $team_userinfo_old_jbp1['person_nums'];// 个人联盟
  1290. $data['common_nums'] = $team_userinfo_old_jbp1['common_nums'];// 共建联盟
  1291. $data['common_nums_pv'] =max( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);// 公共联盟PV
  1292. $data['person_nums_pv'] = min( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);// 个人联盟PV
  1293. // $data['effective_fans_num'] = DB::name('enterprise_user')
  1294. }
  1295. // var_dump($data);
  1296. // 把新表中的新增邀请用户加到数组中
  1297. //$spread_usersdata = Db::name('user')->where("spread_uid",$teamid)->select();//查询旗下会员
  1298. // 查询当前会员旗下的会员数据
  1299. // 获取分页参数
  1300. [$page, $limit] = $this->getPage();
  1301. // 查询当前会员旗下的会员数据(分页)
  1302. $subordinate_members = Db::name('user')
  1303. ->alias('u')
  1304. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1305. ->where("u.spread_uid", $teamid) // 查询旗下会员
  1306. ->where("so.mer_id", 496)
  1307. // ->where("so.douhuomall", 1)
  1308. // ->where("so.douhuomall_status", 9)
  1309. // ->where("so.status", 0)
  1310. ->group('u.uid') // 确保每个用户只出现一次
  1311. ->page($page, $limit) // 分页查询
  1312. ->select(); // 获取分页数据
  1313. // 计算团队总业绩
  1314. // $total_amount=0;
  1315. // foreach($subordinate_members as $k=>$v){
  1316. // }
  1317. // 获取总会员数
  1318. $total_members = Db::name('user') ->alias('u')
  1319. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1320. ->where("u.spread_uid", $teamid) // 查询旗下会员
  1321. ->where("so.mer_id", 496)
  1322. // ->where("so.douhuomall", 1)
  1323. // ->where("so.douhuomall_status", 9)
  1324. // ->where("so.status", 0)
  1325. ->group('u.uid') // 确保每个用户只出现一次
  1326. ->page($page, $limit) // 分页查询
  1327. ->count(); // 获取分页数据
  1328. // 构造分页信息
  1329. $data1 = [
  1330. "total" => $total_members,
  1331. "per_page" => $limit,
  1332. "current_page" => $page,
  1333. "last_page" => ceil($total_members / $limit),
  1334. "data" => []
  1335. ];
  1336. $total_amount_pv_team = 0;// 计算总业绩
  1337. // 获取团队总数量
  1338. $team_count_total = 0;
  1339. $small_count = 0;// 小部门人数
  1340. // var_dump($this->calculatePerformance($subordinate_members));
  1341. // 获取大小部门数据(新表)
  1342. $get_big_small_datas = $this->getbig_samll_datas($subordinate_members);// 下标0是大部门
  1343. // var_dump( $get_big_small_datas);
  1344. // 判断大小部门的人数(根据业绩多的就是大部门,业绩小的就是小部门来计算展示的部门人数);
  1345. $big_team_count = $get_big_small_datas[0]['team_count'];
  1346. $smallteam_count = $get_big_small_datas[1]['team_count'];
  1347. // end
  1348. // 遍历分页数据,构造每个会员的详细信息
  1349. foreach ($subordinate_members as $k => $v) {
  1350. // 计算自己和旗下的业绩
  1351. $t_teams_pv = $this->calculatePerformance($v['uid']);
  1352. $total_amount_pv_team += $t_teams_pv['total_performance'];
  1353. $data1['data'][$k] = [
  1354. "uid" => $v["uid"],
  1355. "nickname" => $v['nickname'], // 假设昵称字段为 nickname
  1356. "phone" => substr_replace($v['phone'], '****', 3, 4), // 隐藏手机号中间四位
  1357. "avatar" => $v['avatar'], // 假设头像字段为 avatar
  1358. "create_time" => $v['create_time'], // 假设创建时间为 create_time
  1359. "total_performance" => $t_teams_pv['total_performance'], // 假设总业绩字段需要额外计算
  1360. "new_performance" => $t_teams_pv['total_performance'], // 假设新增业绩字段需要额外计算
  1361. "team_count" => $t_teams_pv['team_count'], // 假设团购人数需要额外计算
  1362. ];
  1363. }
  1364. // 根据 type 参数处理数据
  1365. if ($type == 1) {
  1366. // 大部门:取 total_performance 最大的一个数组
  1367. usort($data1['data'], function ($a, $b) {
  1368. return $b['total_performance'] <=> $a['total_performance'];
  1369. });
  1370. $data1['data'] = array_slice($data1['data'], 0, 1); // 只保留最大的一个
  1371. } elseif ($type == 0) {
  1372. // 小部门:去掉 total_performance 最大的一个数组
  1373. usort($data1['data'], function ($a, $b) {
  1374. return $b['total_performance'] <=> $a['total_performance'];
  1375. });
  1376. $data1['data'] = array_slice($data1['data'], 1); // 去掉第一个
  1377. } elseif ($type == 2) {
  1378. // 直推:不做任何处理
  1379. }
  1380. // 构造最终返回的数据
  1381. $data = [
  1382. 'team_list' => $data1,
  1383. 'fans_num' => $get_big_small_datas[0]['team_count'] + $get_big_small_datas[1]['team_count'], // 粉丝数
  1384. 'new_performance' => $get_big_small_datas[0]['total_performance'] + $get_big_small_datas[1]['total_performance'], // 新增业绩
  1385. 'total_performance' => $get_big_small_datas[0]['total_performance'] + $get_big_small_datas[1]['total_performance'], // 总业绩
  1386. 'person_nums' => $big_team_count, // 大部门人数
  1387. 'common_nums' => $smallteam_count, // 小部门人数
  1388. 'common_nums_pv' => $get_big_small_datas[0]['total_performance'], // 公共联盟PV
  1389. 'person_nums_pv' => $get_big_small_datas[1]['total_performance'], // 个人联盟PV
  1390. ];
  1391. return app("json")->success($data);
  1392. }
  1393. public function buildTreePv($users, $parentId = 0, $keyword = 'level_id' , $is_b = 1) {
  1394. $branch = array();
  1395. foreach ($users as $user) {
  1396. if ($user[$keyword] == $parentId) {
  1397. if($keyword == 'spread_uid' && $is_b == 1) {
  1398. $children = $this->buildTreePv($users, $user['uid'], 'spread_uid', $is_b+1); // 递归查找子节点
  1399. } else {
  1400. $children = $this->buildTreePv($users, $user['uid'], 'level_id', $is_b+1); // 递归查找子节点
  1401. }
  1402. if ($children) {
  1403. $user['children'] = $children; // 如果有子节点,添加到当前节点
  1404. }else{
  1405. $user['children'] = [];
  1406. }
  1407. $user['team_count'] = count($children);
  1408. $user['total_pv'] = $user['pv']; // 初始化当前节点的总余额为自身余额
  1409. if ($children) { // 如果存在子节点,计算总余额
  1410. foreach ($children as $child) {
  1411. $user['total_pv'] += $child['total_pv']; // 累加子节点的总余额
  1412. $user['team_count'] += $child['team_count'];
  1413. }
  1414. }
  1415. $branch[] = $user; // 将当前节点添加到树中
  1416. }
  1417. }
  1418. return $branch; // 返回当前分支的所有节点
  1419. }
  1420. // 根据父级uid,递归获取所有子级UID数组 默认深度10级
  1421. public function getdepartmentStatistics($parentUid, $keyword = 'level_id') {
  1422. $user = Db::name('user')->where('uid', $parentUid)->field('uid,nickname,avatar,spread_uid,pv,create_time,level_id')->find();
  1423. $user['pv'] = 0;
  1424. $uids = [];// 用于存储符合条件的子级 uid
  1425. $result = [$user]; // 用于存储符合条件的子级数据
  1426. // 定义递归函数
  1427. $is_a = true;
  1428. $recursion = function ($parentUid) use (&$uids, &$result, &$recursion, &$keyword, &$is_a) {
  1429. if ($keyword == 'spread_uid' && $is_a) {
  1430. $children = Db::name('user')->field('uid,nickname,avatar,spread_uid,pv,create_time,level_id')->where($keyword, $parentUid)->select()->toArray();
  1431. $is_a = false;
  1432. } else {
  1433. $children = Db::name('user')->field('uid,nickname,avatar,spread_uid,pv,create_time,level_id')->where('level_id', $parentUid)->select()->toArray();
  1434. }
  1435. // 查询当前父级的所有直接子级
  1436. // 如果没有子级,直接返回
  1437. if (!count($children) && count($children) < 1) {
  1438. return;
  1439. }
  1440. // 遍历每个子级
  1441. foreach ($children as $childUid) {
  1442. // 如果有重复的就跳过 防止死循环
  1443. if(in_array($childUid['uid'], $uids)){
  1444. continue;
  1445. }
  1446. // 将符合条件的子级 uid 添加到结果数组
  1447. $uids[] = $childUid['uid'];
  1448. $result[] = $childUid;
  1449. // 递归查询子级的子级
  1450. $recursion($childUid['uid']);
  1451. }
  1452. };
  1453. // 从初始父级开始递归查询
  1454. $recursion($parentUid);
  1455. return $result; // 返回结果数组,并去重
  1456. }
  1457. /**
  1458. * 一壶茶-团队列表
  1459. */
  1460. public function team_list()
  1461. {
  1462. $teamid = $this->request->uid();
  1463. [$page, $limit] = $this->getPage();
  1464. // 小夏重写部分
  1465. $user_id = $teamid;
  1466. // 如果下级团队只有一个人 那就不用再查了 为0
  1467. // 如果用户等级为用户身份 只查一级直推
  1468. // 去除掉贡献值最大的下级
  1469. $user = Db::name('user')->where('uid', $user_id)->field('uid,nickname,avatar,spread_uid,pv,create_time,level_id')->find();
  1470. $child_nums = $this->getdepartmentStatistics($user_id, 'level_id');
  1471. $child_nums_Tree = $this->buildTreePv($child_nums, $user['level_id'], 'level_id');
  1472. $new_performance = 0; // 一周内新增总业绩
  1473. // 这周的时间区间
  1474. // $end_time = date('Y-m-d ' . '00:00:00', strtotime('-7 days'));
  1475. $now = time();
  1476. $startTime = date('Y-m-d 00:00:00', strtotime('monday this week', $now)); // 这周星期一的开始时间
  1477. $endTime = date('Y-m-d 23:59:59', strtotime('sunday this week', $now)); // 这周星期日的结束时间
  1478. $person_nums_pv = 0;// 大部门业绩
  1479. $common_nums_pv = 0;// 小部门业绩
  1480. $aLL_list = [];// 直推数据
  1481. $person_list = [];// 大部门数据
  1482. $common_list = [];// 小部门数据
  1483. if (count($child_nums_Tree) && isset($child_nums_Tree[0]['children']) && count($child_nums_Tree[0]['children'])) {
  1484. // 计算总新增业绩
  1485. $uid_list = array_column($child_nums, 'uid');
  1486. $uid_list = array_diff($uid_list, [$user_id]);
  1487. $new_performance = Db::name("user_pv_log")
  1488. ->whereIn('uid', $uid_list)
  1489. ->whereBetween('settlement_time', [$startTime, $endTime])
  1490. ->sum('pv');
  1491. // 获取大部门的key
  1492. $maxBalanceIndex = array_search(max(array_column($child_nums_Tree[0]['children'], 'total_pv')), array_column($child_nums_Tree[0]['children'], 'total_pv'));
  1493. foreach ($child_nums_Tree[0]['children'] as $k => $v) {
  1494. $child_nums = $this->getdepartmentStatistics($v['uid'], 'level_id');
  1495. $uid_list = array_column($child_nums, 'uid');
  1496. array_push($uid_list, $v['uid']);
  1497. $new_performance_child = Db::name("user_pv_log")
  1498. ->whereIn('uid', $uid_list)
  1499. ->whereBetween('settlement_time', [$startTime, $endTime])
  1500. ->sum('pv');
  1501. if ($k == $maxBalanceIndex) {
  1502. $person_list[] = [
  1503. "uid" => $v["uid"],
  1504. "spread_uid" => $v['spread_uid'],
  1505. "level_id" => $v['level_id'],
  1506. "nickname" => $v['nickname'],
  1507. "avatar" => $v['avatar'],
  1508. "pv" =>round( $v['pv'],2),
  1509. "total_performance" => round($v['total_pv'],2),
  1510. "create_time" => $v['create_time'],
  1511. 'team_count' => $v['team_count'],
  1512. 'new_performance' => $new_performance_child
  1513. ];
  1514. $person_nums_pv = bcadd($person_nums_pv, $v['total_pv'],2);
  1515. } else {
  1516. $common_list[] = [
  1517. "uid" => $v["uid"],
  1518. "spread_uid" => $v['spread_uid'],
  1519. "level_id" => $v['level_id'],
  1520. "nickname" => $v['nickname'],
  1521. "avatar" => $v['avatar'],
  1522. "pv" => round($v['pv'],2),
  1523. "total_performance" => round($v['total_pv'],2),
  1524. "create_time" => $v['create_time'],
  1525. 'team_count' => $v['team_count'],
  1526. 'new_performance' => $new_performance_child
  1527. ];
  1528. $common_nums_pv = bcadd($common_nums_pv, $v['total_pv'],2);
  1529. }
  1530. // 我的直推 不是大小团队 加起来
  1531. // $aLL_list[] = [
  1532. // "uid" => $v["uid"],
  1533. // "spread_uid" => $v['spread_uid'],
  1534. // "nickname" => $v['nickname'],
  1535. // "avatar" => $v['avatar'],
  1536. // "pv" => $v['pv'],
  1537. // "total_performance" => (int)$v['total_pv'],
  1538. // "create_time" => $v['create_time'],
  1539. // 'team_count'=> $v['team_count'],
  1540. // 'new_performance' => $new_performance_child
  1541. // ];
  1542. }
  1543. }
  1544. $type = $this->request->param('type', 0);// 1:大部门,0:小部门,2:直推
  1545. // 初始化最终返回的数据
  1546. $data = [
  1547. 'team_list' => [],
  1548. 'fans_num' => 0, // 粉丝数
  1549. 'new_performance' => 0, // 新增业绩
  1550. 'total_performance' => 0, // 总业绩
  1551. 'person_nums' => 0, // 个人联盟人数
  1552. 'common_nums' => 0, // 公共联盟人数
  1553. 'common_nums_pv' => 0, // 公共联盟PV
  1554. 'person_nums_pv' => 0, // 个人联盟PV
  1555. ];
  1556. if ($type != 2) {
  1557. if ($type == 1) {
  1558. $data1 = [
  1559. "total" => count($person_list),
  1560. "per_page" => (int)$limit,
  1561. "current_page" => $page,
  1562. "last_page" => ceil(count($person_list) / $limit),
  1563. "data" => array_slice($person_list, ($page - 1) * $limit, $limit)
  1564. ];
  1565. } else {
  1566. $data1 = [
  1567. "total" => count($common_list),
  1568. "per_page" => (int)$limit,
  1569. "current_page" => $page,
  1570. "last_page" => ceil(count($common_list) / $limit),
  1571. "data" => array_slice($common_list, ($page - 1) * $limit, $limit)
  1572. ];
  1573. }
  1574. } else {
  1575. $child_nums = $this->getdepartmentStatistics($user_id, 'spread_uid');
  1576. $child_nums_Tree_spread = $this->buildTreePv($child_nums, $user['spread_uid'], 'spread_uid');
  1577. if (count($child_nums_Tree_spread) && isset($child_nums_Tree_spread[0]['children']) && count($child_nums_Tree_spread[0]['children'])) {
  1578. // 计算总新增业绩
  1579. $uid_list = array_column($child_nums, 'uid');
  1580. $uid_list = array_diff($uid_list, [$user_id]);
  1581. foreach ($child_nums_Tree_spread[0]['children'] as $k => $v) {
  1582. $child_nums = $this->getdepartmentStatistics($v['uid']);
  1583. $uid_list = array_column($child_nums, 'uid');
  1584. array_push($uid_list, $v['uid']);
  1585. $new_performance_child = Db::name("user_pv_log")
  1586. ->whereIn('uid', $uid_list)
  1587. ->whereBetween('settlement_time', [$startTime, $endTime])
  1588. ->sum('pv');
  1589. $aLL_list[] = [
  1590. "uid" => $v["uid"],
  1591. "spread_uid" => $v['spread_uid'],
  1592. "level_id" => $v['level_id'],
  1593. "nickname" => $v['nickname'],
  1594. "avatar" => $v['avatar'],
  1595. "pv" => round($v['pv'],2),
  1596. "total_performance" => round($v['total_pv'], 2),
  1597. "create_time" => $v['create_time'],
  1598. 'team_count'=> $v['team_count'],
  1599. 'new_performance' => $new_performance_child
  1600. ];
  1601. }
  1602. }
  1603. $data1 = [
  1604. "total" => count($aLL_list),
  1605. "per_page" => (int)$limit,
  1606. "current_page" => $page,
  1607. "last_page" => ceil(count($aLL_list) / $limit),
  1608. "data" => array_slice($aLL_list, ($page - 1) * $limit, $limit)
  1609. ];
  1610. }
  1611. // 旧系统中的公共部分数据
  1612. $data['teamid'] = $teamid;
  1613. $data['team_list'] = $data1;
  1614. $data['fans_num'] = $child_nums_Tree[0]['team_count'];// 总人数
  1615. $data['new_performance'] = $new_performance;// 新增总业绩
  1616. $data['total_performance'] = bcadd($child_nums_Tree[0]['total_pv'] ?? 0, 0, 2);// 总业绩
  1617. $data['person_nums'] = count($person_list);// 大部门人数
  1618. $data['common_nums'] = count($common_list);// 小部门人数
  1619. $data['common_nums_pv'] = $person_nums_pv;// 大部门业绩
  1620. $data['person_nums_pv'] = $common_nums_pv;// 小部门业绩
  1621. return app("json")->success($data);
  1622. // // 查询当前会员旗下的会员数据(分页)
  1623. // [$page, $limit] = $this->getPage();
  1624. // $subordinate_members = Db::name('user')
  1625. // // ->alias('u')
  1626. // // ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1627. // ->where("spread_uid", $teamid)
  1628. // // ->where("so.mer_id", 496)
  1629. // // ->group('u.uid')
  1630. // ->page($page, $limit)
  1631. // ->select();
  1632. // $total_members = Db::name('user')
  1633. // // ->alias('u')
  1634. // // ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1635. // ->where("spread_uid", $teamid)
  1636. // // ->where("so.mer_id", 496)
  1637. // // ->group('u.uid')
  1638. // ->count();
  1639. // $data1 = [
  1640. // "total" => $total_members,
  1641. // "per_page" => $limit,
  1642. // "current_page" => $page,
  1643. // "last_page" => ceil($total_members / $limit),
  1644. // "data" => []
  1645. // ];
  1646. // $total_amount_pv_team = 0;
  1647. // $team_count_total = 0;
  1648. // foreach ($subordinate_members as $k => $v) {
  1649. // $t_teams_pv = $this->calculatePerformance($v['uid']);
  1650. // $total_amount_pv_team += $t_teams_pv['total_performance'];
  1651. // $team_count_total += $t_teams_pv['team_count'];
  1652. // $data1['data'][$k] = [
  1653. // "uid" => $v["uid"],
  1654. // "nickname" => $v['nickname'],
  1655. // "phone" => substr_replace($v['phone'], '****', 3, 4),
  1656. // "avatar" => $v['avatar'],
  1657. // "create_time" => $v['create_time'],
  1658. // "total_performance" => $t_teams_pv['total_performance'],
  1659. // "new_performance" => $t_teams_pv['total_performance'],
  1660. // "team_count" => $t_teams_pv['team_count'],
  1661. // ];
  1662. // }
  1663. // // 获取大小部门数据
  1664. // $get_big_small_datas = $this->getbig_samll_datas($subordinate_members);
  1665. // // 判断大小部门的人数
  1666. // $big_team_count = $get_big_small_datas[0]['team_count'];
  1667. // $small_team_count = $get_big_small_datas[1]['team_count'];
  1668. // // 根据 type 参数处理数据
  1669. // if ($type == 1) {
  1670. // usort($data1['data'], function ($a, $b) {
  1671. // return $b['total_performance'] <=> $a['total_performance'];
  1672. // });
  1673. // $data1['data'] = array_slice($data1['data'], 0, 1);
  1674. // } elseif ($type == 0) {
  1675. // usort($data1['data'], function ($a, $b) {
  1676. // return $b['total_performance'] <=> $a['total_performance'];
  1677. // });
  1678. // $data1['data'] = array_slice($data1['data'], 1);
  1679. // }
  1680. // // 合并数据
  1681. // if (!empty($datas_jbp)) {
  1682. // // 如果旧系统中有数据,合并新旧数据
  1683. // $data['team_list']['data'] = array_merge($data['team_list']['data'], $data1['data']);
  1684. // $data['fans_num'] += $team_count_total;
  1685. // $data['new_performance'] += $total_amount_pv_team;
  1686. // $data['total_performance'] += $total_amount_pv_team;
  1687. // $data['person_nums'] += $big_team_count;
  1688. // $data['common_nums'] += $small_team_count;
  1689. // $data['common_nums_pv'] += $get_big_small_datas[0]['total_performance'];
  1690. // $data['person_nums_pv'] += $get_big_small_datas[1]['total_performance'];
  1691. // } else {
  1692. // // 如果旧系统中没有数据,直接使用新数据
  1693. // $data['team_list'] = $data1;
  1694. // $data['fans_num'] = $team_count_total;
  1695. // $data['new_performance'] = $total_amount_pv_team;
  1696. // $data['total_performance'] = $total_amount_pv_team;
  1697. // $data['person_nums'] = $big_team_count;
  1698. // $data['common_nums'] = $small_team_count;
  1699. // $data['common_nums_pv'] = $get_big_small_datas[0]['total_performance'];
  1700. // $data['person_nums_pv'] = $get_big_small_datas[1]['total_performance'];
  1701. // }
  1702. // return app("json")->success($data);
  1703. }
  1704. // 计算自己和自己团队下面的业绩。新表
  1705. // 计算自己和自己团队下面的业绩。新表
  1706. public function calculatePerformance($uid)
  1707. {
  1708. // 初始化业绩数组
  1709. $performance = [
  1710. 'personal_performance' => 0, // 个人业绩
  1711. 'team_performance' => 0, // 团队业绩
  1712. 'total_performance' => 0, // 总业绩
  1713. 'team_count' => 0, // 加上自己的团队数量
  1714. ];
  1715. // 定义业绩换算规则
  1716. $performanceMapping = [
  1717. 1180 => 700,
  1718. 10620 => 6300,
  1719. 11800 => 7000
  1720. ];
  1721. // 计算个人业绩
  1722. $personalOrder = Db::name('store_order')->where("uid", $uid)->find();
  1723. if ($personalOrder) {
  1724. // 将浮点数转换为整数
  1725. $totalPrice = (int)$personalOrder['total_price'];
  1726. if (isset($performanceMapping[$totalPrice])) {
  1727. $performance['personal_performance'] = $performanceMapping[$totalPrice];
  1728. }
  1729. }
  1730. if($uid <= 611){
  1731. // 计算旗下团队成员的业绩
  1732. $teamOrders = Db::name('user')
  1733. ->alias('u')
  1734. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1735. ->where("u.spread_uid", $uid) // 查询旗下会员
  1736. ->where("so.mer_id", 496)
  1737. // ->where("so.douhuomall", 1)
  1738. // ->where("so.douhuomall_status", 9)
  1739. // ->where("so.status", 0)
  1740. ->select();
  1741. $teamOrders_count = Db::name('user')
  1742. ->alias('u')
  1743. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1744. ->where("u.spread_uid", $uid) // 查询旗下会员
  1745. ->where("so.mer_id", 496)
  1746. // ->where("so.douhuomall", 1)
  1747. // ->where("so.douhuomall_status", 9)
  1748. // ->where("so.status", 0)
  1749. ->count();
  1750. $performance['team_count'] = $teamOrders_count + 1; // 赋值团队数量
  1751. foreach ($teamOrders as $order) {
  1752. if ($order['total_price']) {
  1753. // 将浮点数转换为整数
  1754. $totalPrice = (int)$order['total_price'];
  1755. if (isset($performanceMapping[$totalPrice])) {
  1756. $performance['team_performance'] += $performanceMapping[$totalPrice];
  1757. }
  1758. }
  1759. }
  1760. // 计算总业绩
  1761. $performance['total_performance'] = $performance['personal_performance'] + $performance['team_performance'];
  1762. // 假设总业绩最大值需要通过后续逻辑判断,这里暂时设置为 false
  1763. return $performance;
  1764. }
  1765. }
  1766. // 获取大小部门业绩(新表)
  1767. public function getbig_samll_datas($subordinate_members){
  1768. // 单独写一个方法获取大小部门的数据
  1769. $arr_team = [];
  1770. foreach ($subordinate_members as $k => $v) {
  1771. // 计算自己和旗下的业绩
  1772. $arr_team[] = $this->calculatePerformance($v['uid']);
  1773. }
  1774. // 初始化变量
  1775. $maxPerformance = 0;
  1776. $maxIndex = -1;
  1777. // 找出 total_performance 最高的记录
  1778. foreach ($arr_team as $index => $item) {
  1779. if ($item['total_performance'] > $maxPerformance) {
  1780. $maxPerformance = $item['total_performance'];
  1781. $maxIndex = $index;
  1782. }
  1783. }
  1784. // 如果找到了最高记录
  1785. if ($maxIndex !== -1) {
  1786. // 提取最高记录
  1787. $maxRecord = $arr_team[$maxIndex];
  1788. // 从原数组中移除该记录
  1789. unset($arr_team[$maxIndex]);
  1790. // 重新索引数组
  1791. $arr_team = array_values($arr_team);
  1792. } else {
  1793. // 如果没有找到记录,可以设置一个默认值
  1794. $maxRecord = null;
  1795. }
  1796. // 计算大部门和小部门的汇总信息
  1797. $majorDepartmentSummary = [
  1798. "total_person_performance" => $maxRecord ? $maxRecord['personal_performance'] : 0,
  1799. "total_team_performance" => $maxRecord ? $maxRecord['team_performance'] : 0,
  1800. "total_performance" => $maxRecord ? $maxRecord['total_performance'] : 0,
  1801. "team_count" => $maxRecord ? $maxRecord['team_count'] : 0,
  1802. "data" => $maxRecord ? [$maxRecord] : []
  1803. ];
  1804. $minorDepartmentSummary = [
  1805. "total_person_performance" => array_sum(array_column($arr_team, 'personal_performance')),
  1806. "total_team_performance" => array_sum(array_column($arr_team, 'team_performance')),
  1807. "total_performance" => array_sum(array_column($arr_team, 'total_performance')),
  1808. "team_count" => array_sum(array_column($arr_team, 'team_count')),
  1809. "data" => $arr_team
  1810. ];
  1811. // 输出结果
  1812. // echo "大部门汇总信息:\n";
  1813. // print_r($majorDepartmentSummary);
  1814. // echo "小部门汇总信息:\n";
  1815. // print_r($minorDepartmentSummary);
  1816. return array($majorDepartmentSummary,$minorDepartmentSummary);
  1817. }
  1818. // 计算自己和自己团队下面的业绩。新表
  1819. public function calculatePerformance_copy($uid)
  1820. {
  1821. // 初始化业绩数组
  1822. $performance = [
  1823. 'personal_performance' => 0, // 个人业绩
  1824. 'team_performance' => 0, // 团队业绩
  1825. 'total_performance' => 0, // 总业绩
  1826. 'team_count' =>0, // 加上自己的团队数量
  1827. //'team_count_pr'=>0,//实际团队数量(没有加上自己)
  1828. ];
  1829. // 定义业绩换算规则
  1830. $performanceMapping = [
  1831. 1180 => 700,
  1832. 10620 => 6300,
  1833. 11800 => 7000
  1834. ];
  1835. // 计算个人业绩
  1836. $personalOrder = Db::name('store_order')->where("uid", $uid)->find();
  1837. if ($personalOrder) {
  1838. // 将浮点数转换为整数
  1839. $totalPrice = (int)$personalOrder['total_price'];
  1840. if (isset($performanceMapping[$totalPrice])) {
  1841. $performance['personal_performance'] = $performanceMapping[$totalPrice];
  1842. }
  1843. }
  1844. // 计算旗下团队成员的业绩
  1845. $teamOrders = Db::name('user')
  1846. ->alias('u')
  1847. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1848. ->where("u.spread_uid", $uid) // 查询旗下会员
  1849. ->where("so.mer_id", 496)
  1850. // ->where("so.douhuomall", 1)
  1851. // ->where("so.douhuomall_status", 9)
  1852. // ->where("so.status", 0)
  1853. ->select();
  1854. $teamOrders_count = Db::name('user')
  1855. ->alias('u')
  1856. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1857. ->where("u.spread_uid", $uid) // 查询旗下会员
  1858. ->where("so.mer_id", 496)
  1859. // ->where("so.douhuomall", 1)
  1860. // ->where("so.douhuomall_status", 9)
  1861. // ->where("so.status", 0)
  1862. ->count();
  1863. $performance['team_count'] = $teamOrders_count+1;// 赋值团队数量
  1864. //$performance['team_count_pr'] = $teamOrders_count;//没有加上父级赋值团队数量
  1865. foreach ($teamOrders as $order) {
  1866. if ($order['total_price']) {
  1867. // 将浮点数转换为整数
  1868. $totalPrice = (int)$order['total_price'];
  1869. if (isset($performanceMapping[$totalPrice])) {
  1870. $performance['team_performance'] += $performanceMapping[$totalPrice];
  1871. }
  1872. }
  1873. }
  1874. // 计算总业绩
  1875. $performance['total_performance'] = $performance['personal_performance'] + $performance['team_performance'];
  1876. return $performance;
  1877. }
  1878. public function team_list_copy旧表使用()
  1879. {
  1880. $teamid = $this->request->uid();
  1881. //$teamid = $this->request->param('teamid');//测试ID
  1882. $teamid = 17;
  1883. $type = $this->request->param('type',0);// 1:大部门,0:小部门,2:直推
  1884. $team_userinfo_old_jbp1= $this->getPerformance($teamid);
  1885. // 判断大小团队(业绩多的是大部门,业绩小的是小部门)
  1886. $tes = $this->teamPeople($teamid,$type);// 1:团队,2:个人
  1887. $data1= [
  1888. "total"=>100,
  1889. "per_page"=> 10,
  1890. "current_page"=> 1,
  1891. "last_page"=> 1,
  1892. ];
  1893. if($type != 2){
  1894. // 小部门和大部门列表数据
  1895. foreach($tes as $k=>$v){
  1896. $curr_pv = '';
  1897. if($v['curr_type']==0){
  1898. $curr_pv = $team_userinfo_old_jbp1['person_nums_pv'];
  1899. }else if($v['curr_type']==1){
  1900. $curr_pv = $team_userinfo_old_jbp1['common_nums_pv'];
  1901. }else{
  1902. $curr_pv = 0;
  1903. }
  1904. $data1['data'][$k] = [
  1905. "uid"=>$v["id"],
  1906. "nickname"=> $v['user_name'] . $curr_pv,
  1907. "phone"=> "137****3315",
  1908. "avatar"=>"https://cdn.bjtdba.com/vod/image/2025-01-20/20250120125206881.png",
  1909. "create_time"=>"2025-01-25 11:00:18",
  1910. "identity"=>"11",
  1911. "level"=> "40002",
  1912. "partnership"=>"22",
  1913. "total_performance"=> $curr_pv,//$v["performance"]['sum_nums_pv'],//总业绩
  1914. "new_performance"=> 0,// 新增业绩
  1915. "team_count"=> $v["performance"]['common_nums'] + $v["performance"]['person_nums'] + 1,// 团购人数(加的这个1 是当前用户的数)
  1916. ];
  1917. }
  1918. }else{
  1919. // 直推列表
  1920. foreach($tes as $k=>$v){
  1921. $data1['data'][$k] = [
  1922. "uid"=>$v["uid"],
  1923. "nickname"=> $v['nickname'],
  1924. "avatar"=>$v['avatar'],
  1925. "create_time"=>"2025-01-25 11:00:18",
  1926. ];
  1927. }
  1928. }
  1929. $data['team_list'] = $data1;
  1930. $data['fans_num'] = $team_userinfo_old_jbp1['person_nums'] + $team_userinfo_old_jbp1['common_nums'] ;// 粉丝数
  1931. $data['new_performance'] = 0;// 新增业绩
  1932. $data['total_performance']= $team_userinfo_old_jbp1['sum_nums_pv'];// 总业绩
  1933. $data['person_nums'] = $team_userinfo_old_jbp1['person_nums'];// 个人联盟
  1934. $data['common_nums'] = $team_userinfo_old_jbp1['common_nums'];// 共建联盟
  1935. $data['common_nums_pv'] =max( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);// 公共联盟PV
  1936. $data['person_nums_pv'] = min( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);// 个人联盟PV
  1937. // $data['effective_fans_num'] = DB::name('enterprise_user')
  1938. // 把新表中的新增邀请用户加到数组中
  1939. return app("json")->success($data);
  1940. }
  1941. /**
  1942. * 一壶茶-团队列表
  1943. */
  1944. public function team_list_copy()
  1945. {
  1946. $uid = $this->request->uid();
  1947. $where['puid'] = $uid;
  1948. $where['mer_id'] = $this->merId;
  1949. $data['direct_fans_num'] = Db::name('enterprise_user')->where($where)->count();// 直属粉丝数量
  1950. // var_dump($uid);
  1951. $arr = $this->jisuan_fans($uid);
  1952. $data['fans_num'] = count($arr);// 粉丝总数
  1953. $data['total_performance'] = 12555;// 总业绩
  1954. $data['new_performance'] = 15;// 新增业绩
  1955. [$page, $limit] = $this->getPage();
  1956. $where2['eu.mer_id'] = $this->merId;
  1957. $type = $this->request->param('type', 0);// 1:大部门,0:小部门
  1958. // var_dump($where2);
  1959. $enterprise_user_team = DB::name('enterprise_user')
  1960. ->alias('eu')
  1961. ->join('user u', 'eu.uid=u.uid')
  1962. ->where($where2)
  1963. ->when($type < 1 || $type == 2, function ($q) use ($arr) {
  1964. $q->whereIn('eu.uid', $arr);
  1965. })
  1966. ->when($type == 1, function ($q) use ($uid) {
  1967. $q->whereIn('eu.puid', $uid);
  1968. })
  1969. ->when($type == 2, function ($q) use ($uid) {
  1970. $q->whereIn('eu.identity', [100, 101, 102, 103, 104, 105]);
  1971. })
  1972. ->field('eu.uid,u.nickname,u.phone,eu.avatar,eu.create_time,eu.identity,eu.level,eu.partnership')
  1973. ->order('eu.enterprise_user_id desc')
  1974. ->paginate($limit)
  1975. ->each(function ($item) {
  1976. $item['phone'] = substr_replace($item['phone'], '****', 3, 4);
  1977. return $item;
  1978. });
  1979. // var_dump($enterprise_user_team);
  1980. $data['team_list'] = $enterprise_user_team;
  1981. $data['effective_fans_num'] = DB::name('enterprise_user')
  1982. ->alias('eu')
  1983. ->join('user u', 'eu.uid=u.uid')
  1984. ->where($where2)
  1985. ->whereIn('eu.uid', $arr)
  1986. ->whereIn('eu.identity', [100, 101, 102, 103, 104, 105])
  1987. ->count();// 有效粉丝数量
  1988. return app("json")->success($data);
  1989. }
  1990. public function team_details()
  1991. {
  1992. $uid = $this->request->param('uid', 0);
  1993. $where2['eu.uid'] = $uid;
  1994. $where2['eu.mer_id'] = $this->merId;
  1995. $enterprise_user_team = DB::name('enterprise_user')
  1996. ->alias('eu')
  1997. ->join('user u', 'eu.uid=u.uid')
  1998. ->where($where2)
  1999. ->field('eu.uid,u.nickname,u.phone,u.avatar,eu.create_time,eu.identity,eu.level,eu.partnership,eu.puid')
  2000. ->find();;
  2001. if ($enterprise_user_team) {
  2002. $enterprise_user_team['phone'] = substr_replace($enterprise_user_team['phone'], '****', 3, 4);
  2003. $enterprise_user_team['p_nickname'] = '';
  2004. $enterprise_user_team['p_phone'] = '';
  2005. $yanglao = 0;
  2006. $offLinewhere = ['mer_id' => $this->merId, 'uid' => $uid, 'commission_type' => '5', 'type_shop' => 0];
  2007. $offLine1 = Db::name('user_bill')->where($offLinewhere)->where('source', 1)->where('status', 1)->sum('number');
  2008. $yanglao += $offLine1;
  2009. $offLine2 = Db::name('user_bill')->where($offLinewhere)->where('source', 0)->whereIn('status', [0, 1])->sum('number');
  2010. $yanglao += $offLine2;
  2011. $enterprise_user_team['ylj'] = set_price_rtrim($yanglao);
  2012. if ($enterprise_user_team['puid'] > 0) {
  2013. $user = Db::name('user')->where('uid', $enterprise_user_team['puid'])->find();
  2014. if ($user) {
  2015. $enterprise_user_team['p_nickname'] = $user['nickname'];
  2016. $enterprise_user_team['p_phone'] = substr_replace($user['phone'], '****', 3, 4);
  2017. }
  2018. }
  2019. }
  2020. return app("json")->success($enterprise_user_team);
  2021. }
  2022. /**
  2023. * 率积分明细
  2024. */
  2025. public function green_integral_list()
  2026. {
  2027. $pm = $this->request->param('pm');
  2028. $status = $this->request->param('status');
  2029. [$page, $limit] = $this->getPage();
  2030. $uid = $this->request->uid();
  2031. log::info("green_integral_list==={$uid}");
  2032. $where['uid'] = $uid;
  2033. // $where['mer_id'] = $this->merId;
  2034. // if ($pm == 1) {
  2035. // $pm_arr = [1, 3];
  2036. // } else {
  2037. // $pm_arr = [2, 4];
  2038. // }
  2039. if ($pm==0){
  2040. $data = DB::name('user_sign_score')->where($where)->where('pm', 1)->where('status',1)->field('id,mark,reward_socre,pm,addtime,order_id,status')->page($page, $limit)->order("id desc")->select();
  2041. }
  2042. if($pm==1){
  2043. $data = DB::name('user_sign_score')->where($where)->where('pm', 2)->where('status', 1)->field('id,mark,reward_socre,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  2044. }
  2045. if($pm==2){
  2046. $data = DB::name('user_sign_score')->where($where)->where([['status','in','-1,0']])->field('id,mark,reward_socre,pm,addtime,order_id,status')->page($page, $limit)->order("id desc")->select();
  2047. if($data){
  2048. $data = $data->toArray();
  2049. foreach ($data as $k=>$v){
  2050. if($v['status'] == 0){
  2051. $data[$k]['mark'] = '(失效)' . $v['mark'];
  2052. }
  2053. }
  2054. }
  2055. }
  2056. return app("json")->success($data);
  2057. }
  2058. public function user_invite_profit_list()
  2059. {
  2060. $uid = $this->request->uid();
  2061. [$page, $limit] = $this->getPage();
  2062. $commission_type = $this->request->param('commission_type', 0);
  2063. if ($commission_type) {
  2064. $where['commission_type'] = $commission_type;
  2065. }
  2066. $month = $this->request->param('month', '') ?: date('Y-m');
  2067. $startMonth = date('Y-m-01 00:00:00', strtotime($month));
  2068. $endMonth = date("Y-m-d 00:00:00", strtotime("first day of next month", strtotime($month)));
  2069. $data['yanglao_clear_all'] = Db::name('user_bill')
  2070. ->where('uid', $uid)
  2071. ->whereBetween('create_time', [$startMonth, $endMonth])
  2072. ->where('commission_type', 5)
  2073. ->where('pm', 1)
  2074. ->where('status', 1)
  2075. ->sum('number');
  2076. $data['yanglao_nclear_all'] = Db::name('user_bill')
  2077. ->where('uid', $uid)
  2078. ->whereBetween('create_time', [$startMonth, $endMonth])
  2079. ->where('commission_type', 5)
  2080. ->where('pm', 1)
  2081. ->where('status', 0)
  2082. ->sum('number');
  2083. $data['yanglao_yugu_all'] = $data['yanglao_clear_all'] + $data['yanglao_nclear_all'];
  2084. $where['uid'] = $uid;
  2085. $data['totel_money'] = Db::name('user_bill')->where($where)
  2086. ->whereNotIn('commission_type', [0, 5, 17, 19])
  2087. ->when($commission_type == 5, function ($query) use ($where, $startMonth, $endMonth) {
  2088. $query->whereBetween('create_time', [$startMonth, $endMonth]);
  2089. }, function ($query) use ($where, $month, $startMonth, $endMonth) {
  2090. $query->where('commission_type', '<>', 5)
  2091. ->whereBetween('create_time', [$startMonth, $endMonth]);
  2092. })
  2093. ->sum('number');
  2094. $pageInfo = Db::name('user_bill')
  2095. ->where($where)
  2096. ->whereNotIn('commission_type', [0, 5, 17, 19])
  2097. ->when($commission_type == 5, function ($query) use ($where, $startMonth, $endMonth) {
  2098. $query->whereBetween('create_time', [$startMonth, $endMonth]);
  2099. }, function ($query) use ($where, $month, $startMonth, $endMonth) {
  2100. $query->where('commission_type', '<>', 5)
  2101. ->whereBetween('create_time', [$startMonth, $endMonth]);
  2102. })
  2103. ->order('bill_id desc')
  2104. ->paginate($limit);
  2105. $data_arr = [];
  2106. foreach ($pageInfo->items() as $k => $v) {
  2107. $v['money'] = set_price_rtrim($v['number']);
  2108. $v['order_money'] = set_price_rtrim(0);
  2109. $v['commission_rate'] = set_price_rtrim(0);
  2110. $order = Db::name('store_order')->where('order_sn', $v['order_sn'])->find();
  2111. if (!empty($order)) {
  2112. $v['order_money'] = set_price_rtrim($order['total_price']);
  2113. $v['commission_rate'] = set_price_rtrim(bcdiv($v['money'], $v['order_money'], 2));
  2114. }
  2115. if ($v['status'] == 0) {
  2116. // $v['create_time'] = '--';
  2117. }
  2118. if ($v['status'] == 1) {
  2119. // $v['create_time'] = $v['take_time'];
  2120. $v['sett_time'] = date('Y-m-d H:i:s',$v['take_time']);
  2121. }
  2122. if ($v['status'] == -1) {
  2123. $v['mark'] = '(失效)' . $v['mark'];
  2124. // $v['status'] = 0;
  2125. }
  2126. $v['status_name'] = $this->statusName[$v['status']];
  2127. $data_arr[] = $v;
  2128. }
  2129. $data['pageInfo']['current_page'] = $pageInfo->currentPage();
  2130. $data['pageInfo']['data'] = $data_arr;
  2131. $data['pageInfo']['last_page'] = $pageInfo->lastPage();
  2132. return app("json")->success($data);
  2133. }
  2134. /*导航转链-用于用户下单绑定*/
  2135. public function changeLink()
  2136. {
  2137. $uid = $this->request->uid();
  2138. if (!$uid) {
  2139. return app("json")->error("请登录");
  2140. }
  2141. $data = $data = $this->request->params([
  2142. 'url',
  2143. 'name'
  2144. ]);
  2145. $data['url'] = urldecode($data['url']);
  2146. $data['name'] = urldecode($data['name']);
  2147. if (in_array($data['name'], ['京东', '苏宁易购', '饿了么', '唯品会', '拼多多'])) {
  2148. if ($data['name'] == '京东') {
  2149. $url = app()->make(Jd::class)->linkChange($data['url'], $uid);
  2150. }
  2151. if ($data['name'] == '拼多多') {
  2152. $url = app()->make(TaoKe::class)->changeLink($data['url'], $uid);
  2153. }
  2154. if ($data['name'] == '唯品会') {
  2155. $url = app()->make(Vip::class)->changeLink($data['url'], $uid);
  2156. }
  2157. if ($data['name'] == '苏宁易购') {
  2158. $url = $data['url'];
  2159. //$url = app()->make(Su::class)->changeLink($data['url'],$uid);
  2160. }
  2161. if ($data['name'] == '饿了么') {// 获取饿了么官方活动链接
  2162. // 如果用户没有拉取relation_id,
  2163. $where = ['uid' => $uid, 'type' => 5];
  2164. $isRelation = UserThirdModel::where($where)->find();
  2165. if ($isRelation) {
  2166. $result = DaTaoKe::activityChangeLink('20150318020002597', $uid);
  2167. if ($result['code'] == 0) {
  2168. return \app('json')->fail("获取饿了么链接出错", $result['raw']);
  2169. }
  2170. $url = $result['link'];
  2171. } else {// 如果还没有获取用户的relation_id还需要拉淘宝授权
  2172. $state = "{$uid}_h5";
  2173. $url = \app()->make(TaoBao::class)->getAuthUrl($state);
  2174. }
  2175. }
  2176. }
  2177. return app("json")->success($url);
  2178. }
  2179. /*获取协议*/
  2180. public function xieyi()
  2181. {
  2182. $data = $this->request->params([
  2183. 'type'
  2184. ]);
  2185. $data = app()->make(\app\common\repositories\agreement\AgreementRepository::class)->getTypeDetail($data['type']);
  2186. return app("json")->success($data);
  2187. }
  2188. /*获取规则文章*/
  2189. public function guize()
  2190. {
  2191. $id = $this->request->param('id');
  2192. $data = app()->make(\app\common\repositories\agreement\AgreementRepository::class)->getTypeDetail($id);
  2193. if(!$data){
  2194. $data['title']='';
  2195. $data['content']='';
  2196. }
  2197. $html='<!DOCTYPE html>
  2198. <html lang="en">
  2199. <head>
  2200. <meta charset="UTF-8">
  2201. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  2202. <title>'.$data['title'].'</title>
  2203. <style>
  2204. body {
  2205. font-family: Arial, sans-serif;
  2206. margin: 0;
  2207. padding: 0;
  2208. }
  2209. .container {
  2210. margin: 0 auto;
  2211. padding: 20px;
  2212. }
  2213. </style>
  2214. </head>
  2215. <body>
  2216. <div class="container">
  2217. '.$data['content'].'
  2218. </div>
  2219. </body>
  2220. </html';
  2221. return $html;
  2222. }
  2223. /**
  2224. * 支付宝获取授权
  2225. * @return mixed
  2226. * @author php迷途小书童
  2227. * @created 2021/1/16 17:03
  2228. */
  2229. public function alipayAuthorization(UserRepository $userRepository)
  2230. {
  2231. $authorization_code = $this->request->param('code');
  2232. $type = $this->request->param('type', 'h5');
  2233. $paramStr = $userRepository->getTokenByCode($authorization_code, false, $type);
  2234. return app("json")->success($paramStr);
  2235. }
  2236. /**
  2237. * 微信获取授权
  2238. * @return mixed
  2239. * @author php迷途小书童
  2240. * @created 2021/1/16 19:08
  2241. */
  2242. public function wechatAuthorization()
  2243. {
  2244. $request = $this->request;
  2245. $wxConfig = [
  2246. "appid" => "wx66f5f8def2b755da",
  2247. "appsecret" => "891572d83222105a635cf9f502363ff8"
  2248. ];
  2249. $oauth = WechatService::create()->getApplication()->oauth;
  2250. // dump($oauth);
  2251. $oauth->setRequest(new Request($request->get(), $request->post(), [], [], [], $request->server(), $request->getContent()));
  2252. try {
  2253. $wechatInfo = $oauth->user()->getOriginal();
  2254. } catch (\Exception $e) {
  2255. return app('json')->fail('授权失败[001]', ['message' => $e->getMessage()]);
  2256. }
  2257. if (!isset($wechatInfo['nickname'])) {
  2258. return app('json')->fail('授权失败[002]');
  2259. }
  2260. return app("json")->success($wechatInfo);
  2261. }
  2262. /**
  2263. * 解绑微信 支付宝账号
  2264. * 严格来说 应该给 user_account 加一个的字段来表明生效失效,但增加后 需要调整的模块较多,又不能直接删除(担心直接删除后,出问题没地方查)
  2265. * @param UserRepository $userRepository
  2266. * @return mixed
  2267. */
  2268. public function unbindAccount(UserRepository $userRepository)
  2269. {
  2270. $type = $this->request->param('type');
  2271. $uid = $this->request->uid();
  2272. makeLock()->lock();
  2273. Db::startTrans();
  2274. try {
  2275. if ($type == 1) {
  2276. $user_extract_openid = Db::name('user_extract_openid')->where('uid', $uid)->find();
  2277. if (!empty($user_extract_openid)) {
  2278. Db::name('log')->insert(['data' => '三方授权解绑(' . $uid . ')' . json_encode($user_extract_openid)]);
  2279. Db::name('user_extract_openid')->where('uid', $uid)->delete(); // 使用 Db 对象删除
  2280. }
  2281. Db::name("user")->where(['uid' => $uid])->update(["wechat_user_id" => 0]);
  2282. Db::name('user_account')->where('uid', $uid)->where('type', 1)->delete();
  2283. } else {
  2284. Db::name("user")->where(['uid' => $uid])->update(["ali_user_id" => 0]);
  2285. Db::name('user_account')->where('uid', $uid)->where('type', 2)->delete();
  2286. }
  2287. } catch (\Throwable $e) {
  2288. Db::rollback();
  2289. makeLock()->unlock();
  2290. return app("json")->fail("失败" . $e->getMessage());
  2291. }
  2292. Db::commit();
  2293. makeLock()->unlock();
  2294. return app("json")->success("解绑成功", []);
  2295. }
  2296. /**
  2297. * 更新绑定微信支付宝账号
  2298. * type=1 微信 2 支付宝
  2299. * openid openid
  2300. */
  2301. public function updateAccount(UserRepository $userRepository)
  2302. {
  2303. $type = $this->request->param('type');
  2304. $openid = $this->request->param('openid');// 前端传的是unionid
  2305. $nickname = $this->request->param('nickname');
  2306. $avater = $this->request->param('avater');
  2307. $alinfo = $this->request->param('alinfo');
  2308. $uid = $this->request->uid();
  2309. $user = $this->request->userInfo();
  2310. if (!$type) {
  2311. return app("json")->fail("失败");
  2312. }
  2313. makeLock()->lock();
  2314. try {
  2315. if ($type == 1) {
  2316. $data = ["wechat_user_id" => $openid];
  2317. $unionId = $openid;
  2318. $existUid = Db::name('user_extract_openid')->where('openid',$unionId)->value('uid');
  2319. if (!empty($existUid) && $existUid != $uid) throw new \Exception("此微信号已被绑定");
  2320. $check = Db::name('user_extract_openid')->where('uid',$uid)->value('openid');
  2321. if (!empty($check) && $check != $unionId) throw new \Exception("当前用户已绑定其他微信号");
  2322. Db::name("user_extract_openid")->insert([
  2323. 'uid' => $uid,
  2324. 'openid' => $unionId,
  2325. 'type' => 1
  2326. ]);
  2327. } else {
  2328. $alinfo = json_decode($alinfo, true);
  2329. if (!$alinfo) throw new \Exception("参数异常");
  2330. $data = ["ali_user_id" => $alinfo["userId"]];
  2331. $unionId = $alinfo["userId"];
  2332. $check = Db::name("user")->where("ali_user_id", $unionId)->find();
  2333. if ($check) throw new \Exception("此支付宝号已被绑定");
  2334. // $paramStr = $userRepository->getTokenByCode($alinfo["authCode"], true);
  2335. $paramStr = $userRepository->getTokenByCodeWithCert($alinfo["authCode"], true);
  2336. $nickname = empty($paramStr["nick_name"]) ? "al" . $alinfo["userId"] : $paramStr["nick_name"];
  2337. $avater = empty($paramStr["avatar"]) ? "https://cdn.bjtdba.com/vod/image/2025-01-21/20250121180855764.png" : $paramStr["avatar"];
  2338. }
  2339. $data2 = [
  2340. "type" => $type,
  2341. "uid" => $uid,
  2342. "nickname" => $nickname,
  2343. "avater" => $avater,
  2344. ];
  2345. $result = $this->repository->updateUser($uid, $data, $data2);
  2346. if (!$result) throw new \Exception("修改失败");
  2347. $userRepository = app()->make(UserRepository::class);
  2348. $userInfo = $userRepository->getOne(['uid' => $uid]);
  2349. // 绑定线下充值金额
  2350. $unionUsersRepository = app()->make(UnionUsersRepository::class);
  2351. $orderMerchantRepository = app()->make(OrderMerchantRepository::class);
  2352. $notBind = $unionUsersRepository->getAllNotBind($unionId);
  2353. if ($notBind) {
  2354. $orderMerchantRepository->doBindUser($userInfo, $type);
  2355. }
  2356. } catch (\Throwable $e) {
  2357. makeLock()->unlock();
  2358. return app("json")->fail("失败" . $e->getMessage());
  2359. }
  2360. makeLock()->unlock();
  2361. return app("json")->success("修改成功", $data);
  2362. }
  2363. /**
  2364. * 获取账号绑定信息
  2365. * @return mixed
  2366. */
  2367. public function getAccount()
  2368. {
  2369. $uid = $this->request->uid();
  2370. // $data = $this->repository->getUser($uid, "wechat_user_id,ali_user_id");
  2371. $data = $this->repository->getAccount($uid);
  2372. if ($data) {
  2373. return app("json")->success("查询成功", $data);
  2374. }
  2375. return app("json")->fail("未绑定");
  2376. }
  2377. // /*
  2378. // * 养老金统计
  2379. // * */
  2380. // public function get_yanglao_statistics()
  2381. // {
  2382. // $uid = $this->request->uid();
  2383. // //线下数量
  2384. // // 查询未结算
  2385. //
  2386. // $gzc_order_list = Db::name('gzc_logs')->where('uid', $uid)->column('out_trade_no');
  2387. //
  2388. // $onlineYanglaoUserBill = Db::name('user_bill')->where('commission_type', 5)->whereNotIn('order_sn',$gzc_order_list)->where('status', 0)->where('uid', $uid)->sum('number');
  2389. // $onlineYanglaoGzc = Db::name('gzc_logs')->where('success', 0)->where('uid', $uid)->sum('pension');
  2390. // $clearYanglao = Db::name('gzc_logs')->where('success', 1)->where('uid', $uid)->sum('pension');
  2391. //
  2392. // $userInfo = Db::name('UserCertification')->where('uid', $uid)->field('user_name,user_card')->find();
  2393. // $res = GzcApiRequest::checkAmount($userInfo);
  2394. // $gzc = $res['extendData']['amount'] * 0.01;
  2395. // // PCPC-中信公证处
  2396. // $data['all_gzc'] = set_price_rtrim(sprintf("%01.2f", $gzc));
  2397. // // 总养老金
  2398. // $data['all_yanglao'] = set_price_rtrim($onlineYanglaoUserBill + $onlineYanglaoGzc + $clearYanglao + $gzc);
  2399. // // 平台养老金
  2400. // $data['all_yanglao_yhc'] = set_price_rtrim($onlineYanglaoUserBill + $onlineYanglaoGzc + $clearYanglao);
  2401. // // 未结算养老金=预估养老金,不能包含进入公证处未成功的记录(这部分是已结算的)
  2402. // $data['all_yanglao_yugu'] = set_price_rtrim(round($onlineYanglaoUserBill, 2));
  2403. // // 已结算养老金 已入账
  2404. // $data['all_yanglao_clear'] = set_price_rtrim(round($onlineYanglaoGzc+$clearYanglao, 2));
  2405. // // 已入账养老金
  2406. // $data['all_yanglao_in'] = set_price_rtrim(round($clearYanglao, 2));
  2407. // // 平台未入账养老金
  2408. // $data['all_yanglao_nclear'] = set_price_rtrim(round($onlineYanglaoGzc + $onlineYanglaoUserBill, 2));
  2409. // // 待发起
  2410. // $data['all_yanglao_wait'] = set_price_rtrim(round($onlineYanglaoGzc, 2));
  2411. //
  2412. // return app("json")->success("查询成功", $data);
  2413. // }
  2414. /*
  2415. * 养老金统计
  2416. * */
  2417. public function get_yanglao_statistics()
  2418. {
  2419. $uid = $this->request->uid();
  2420. // 线下数量
  2421. $offLine = \think\facade\Db::name('order_merchant')->where('uid', $uid)->where('status', 1)->field('pension yanglao')->select()->toArray();
  2422. $data['offLine'] = array(
  2423. 'num' => count($offLine),
  2424. 'yanglao' => round($this->num($offLine, 'yanglao'), 2)
  2425. );
  2426. $offLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>1,'type_shop'=>0];
  2427. if($this->source=='yhc' && $this->merId){
  2428. $offLinewhere['mer_id']=$this->merId;
  2429. }
  2430. $offLine= \think\facade\Db::name('user_bill')->where($offLinewhere)->select()->toArray();
  2431. $data['offLine'] = array(
  2432. 'num' => count($offLine),
  2433. 'yanglao' => round($this->num($offLine, 'number'), 2)
  2434. );
  2435. // $offLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>0,'type_shop'=>0];
  2436. // $offLine= \think\facade\Db::name('user_bill')->where($offLinewhere)->select()->toArray();
  2437. // $data['offLine'] = array(
  2438. // 'num' => count($offLine),
  2439. // 'yanglao' => round($this->num($offLine, 'number'), 2)
  2440. // );
  2441. // 线上已确认收货
  2442. // $onLine = \think\facade\Db::name('store_order')->where('uid', $uid)->where('paid', 1)->where('status', 'in', '2,3')->select()
  2443. // ->each(function ($item) {
  2444. // //查询养老金金额
  2445. // $UserBillRepository = app()->make(UserBillRepository::class);
  2446. // $bill = $UserBillRepository->getWhere(['uid' => $item['uid'], 'link_id' => $item['order_id'], 'order_sn' => $item['order_sn'], 'title' => '养老金']);
  2447. // $pension = $bill->number ?? 0;
  2448. // $item['yanglao'] = $pension;
  2449. // return $item;
  2450. // })
  2451. // ->toArray();
  2452. $onLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>0,'type_shop'=>0];
  2453. if($this->source=='yhc' && $this->merId){
  2454. $onLinewhere['mer_id']=$this->merId;
  2455. }
  2456. $onLine= \think\facade\Db::name('user_bill')->where($onLinewhere)->select()->toArray();
  2457. $data['onLine'] = array(
  2458. 'num' => count($onLine),
  2459. 'yanglao' => round($this->num($onLine, 'number'), 2)
  2460. );
  2461. // 线上未确认收货
  2462. // $onLine = \think\facade\Db::name('store_order')->where('uid', $uid)->where('paid', 1)->where('status', 'in', '0,1')->select()
  2463. // ->each(function ($item) {
  2464. // //查询养老金金额
  2465. // $UserBillRepository = app()->make(UserBillRepository::class);
  2466. // $bill = $UserBillRepository->getWhere(['uid' => $item['uid'], 'link_id' => $item['order_id'], 'order_sn' => $item['order_sn'], 'title' => '养老金']);
  2467. // $pension = $bill->number ?? 0;
  2468. // $item['yanglao'] = $pension;
  2469. // return $item;
  2470. // })
  2471. // ->toArray();
  2472. $onLine_take_nowhere=['uid'=>$uid,'status'=>'0','commission_type' => '5','source'=>0,'type_shop'=>0];
  2473. if($this->source=='yhc' && $this->merId){
  2474. $onLine_take_nowhere['mer_id']=$this->merId;
  2475. }
  2476. $onLine_take_no=\think\facade\Db::name('user_bill')->where($onLine_take_nowhere)->select()->toArray();
  2477. $data['onLine_take_no'] = array(
  2478. 'num' => count($onLine_take_no),
  2479. 'yanglao' => round($this->num($onLine_take_no, 'number'), 2)
  2480. );
  2481. if($this->source=='yhc' && $this->merId){
  2482. $data['all_num'] = $data['offLine']['num'] +$data['onLine_take_no']['num'] + $data['onLine']['num'];
  2483. $data['all_yanglao_yhc'] = set_price_rtrim(round($data['offLine']['yanglao']+$data['onLine']['yanglao'] + $data['onLine_take_no']['yanglao'] , 2));// 总养老金
  2484. $data['all_yanglao_a'] = set_price_rtrim(round($data['offLine']['yanglao'] + $data['onLine']['yanglao'], 2));// 已结算养老金
  2485. $data['all_yanglao_yugu'] = set_price_rtrim(round($data['all_yanglao_yhc']-$data['all_yanglao_a'],2));// 预估养老金
  2486. $userInfo = Db::name('UserCertification') -> where('uid',$uid) -> field('user_name,user_card') -> find();
  2487. $res = GzcApiRequest::checkAmount($userInfo);
  2488. $data['all_gzc']=set_price_rtrim(sprintf("%01.2f", $res['extendData']['amount'] * 0.01));
  2489. $data['all_yanglao']=set_price_rtrim( $data['all_yanglao_yhc'] + $data['all_gzc']);
  2490. return app("json")->success("查询成功", $data);
  2491. }
  2492. // 淘宝
  2493. $tb_a = 0;
  2494. $tb_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>5];
  2495. $tb = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($tb_where)->where('status','<>','-1')->select()->each(function ($value) use (&$tb_a) {
  2496. $value['yanglao'] = 0;
  2497. $value['yanglao'] = $value['number'];
  2498. $value['yanglao_a'] = 0;
  2499. if ($value['status'] == 1) {
  2500. $value['yanglao_a'] = $value['yanglao'];
  2501. $tb_a++;
  2502. }
  2503. return $value;
  2504. })->toArray();
  2505. $data['tb'] = array(
  2506. 'num' => count($tb),
  2507. 'num_a' => $tb_a,
  2508. 'yanglao' => round($this->num($tb, 'yanglao'), 2),
  2509. 'yanglao_a' => round($this->num($tb, 'yanglao_a'), 2),
  2510. );
  2511. // 京东
  2512. $jd_a = 0;
  2513. $jd_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>6];
  2514. $jd = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($jd_where)->where('status','<>','-1')->select()->each(function ($value) use (&$jd_a) {
  2515. $value['yanglao'] = 0;
  2516. $value['yanglao'] = $value['number'];
  2517. $value['yanglao_a'] = 0;
  2518. if ($value['status'] == 1) {
  2519. $value['yanglao_a'] = $value['yanglao'];
  2520. $jd_a++;
  2521. }
  2522. return $value;
  2523. })->toArray();
  2524. $data['jd'] = array(
  2525. 'num' => count($jd),
  2526. 'num_a' => $jd_a,
  2527. 'yanglao' => round($this->num($jd, 'yanglao'), 2),
  2528. 'yanglao_a' => round($this->num($jd, 'yanglao_a'), 2),
  2529. );
  2530. // 苏宁
  2531. $su_a = 0;
  2532. $su_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>3];
  2533. $su = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($su_where)->where('status','<>','-1')->select()->each(function ($value) use (&$su_a) {
  2534. $value['yanglao'] = 0;
  2535. $value['yanglao'] = $value['number'];
  2536. $value['yanglao_a'] = 0;
  2537. if ($value['status'] == 1) {
  2538. $value['yanglao_a'] = $value['yanglao'];
  2539. $su_a++;
  2540. }
  2541. return $value;
  2542. })->toArray();
  2543. $data['su'] = array(
  2544. 'num' => count($su),
  2545. 'num_a' => $su_a,
  2546. 'yanglao' => round($this->num($su, 'yanglao'), 2),
  2547. 'yanglao_a' => round($this->num($su, 'yanglao_a'), 2),
  2548. );
  2549. // 拼多多
  2550. $pdd_a = 0;
  2551. $pdd_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>1];
  2552. $pdd = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($pdd_where)->where('status','<>','-1')->select()->each(function ($value) use (&$pdd_a) {
  2553. $value['yanglao'] = 0;
  2554. $value['yanglao'] = $value['number'];
  2555. $value['yanglao_a'] = 0;
  2556. if ($value['status'] == 1) {
  2557. $value['yanglao_a'] = $value['yanglao'];
  2558. $pdd_a++;
  2559. }
  2560. return $value;
  2561. })->toArray();
  2562. $data['pdd'] = array(
  2563. 'num' => count($pdd),
  2564. 'num_a' => $pdd_a,
  2565. 'yanglao' => round($this->num($pdd, 'yanglao'), 2),
  2566. 'yanglao_a' => round($this->num($pdd, 'yanglao_a'), 2),
  2567. );
  2568. // 唯品会
  2569. $vip_a = 0;
  2570. $vip_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>2];
  2571. $vip = \think\facade\Db::name('user_bill')->where($vip_where)->where('uid', $uid)->where('status','<>','-1')->select()->each(function ($value) use (&$vip_a) {
  2572. $value['yanglao'] = 0;
  2573. $value['yanglao'] = $value['number'];
  2574. $value['yanglao_a'] = 0;
  2575. if ($value['status'] == 1) {
  2576. $value['yanglao_a'] = $value['yanglao'];
  2577. $vip_a++;
  2578. }
  2579. return $value;
  2580. })->toArray();
  2581. $data['vip'] = array(
  2582. 'num' => count($vip),
  2583. 'num_a' => $vip_a,
  2584. 'yanglao' => round($this->num($vip, 'yanglao'), 2),
  2585. 'yanglao_a' => round($this->num($vip, 'yanglao_a'), 2),
  2586. );
  2587. // 抖音
  2588. $dy_a = 0;
  2589. $dy_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>9];
  2590. $dy = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($dy_where)->where('status','<>','-1')->select()->each(function ($value) use (&$dy_a) {
  2591. $value['yanglao'] = 0;
  2592. $value['yanglao'] = $value['number'];
  2593. $value['yanglao_a'] = 0;
  2594. if ($value['status'] == 1) {
  2595. $value['yanglao_a'] = $value['yanglao'];
  2596. $dy_a++;
  2597. }
  2598. return $value;
  2599. })->toArray();
  2600. $data['dy'] = array(
  2601. 'num' => count($dy),
  2602. 'num_a' => $dy_a,
  2603. 'yanglao' => round($this->num($dy, 'yanglao'), 2),
  2604. 'yanglao_a' => round($this->num($dy, 'yanglao_a'), 2),
  2605. );
  2606. $data['all_num'] = $data['offLine']['num'] +$data['onLine_take_no']['num'] + $data['onLine']['num'] + $data['tb']['num'] + $data['jd']['num'] + $data['su']['num'] + $data['pdd']['num'] + $data['vip']['num'] + $data['dy']['num'];
  2607. $data['all_yanglao'] = round($data['offLine']['yanglao']+$data['onLine']['yanglao'] + $data['onLine_take_no']['yanglao'] + $data['tb']['yanglao'] + $data['jd']['yanglao'] + $data['su']['yanglao'] + $data['pdd']['yanglao'] + $data['vip']['yanglao'] + $data['dy']['yanglao'], 2);
  2608. $data['all_yanglao_a'] = round($data['offLine']['yanglao'] + $data['onLine']['yanglao'] + $data['tb']['yanglao_a'] + $data['jd']['yanglao_a'] + $data['su']['yanglao_a'] + $data['pdd']['yanglao_a'] + $data['vip']['yanglao_a'] + $data['dy']['yanglao_a'], 2);
  2609. $data['third_party_num']=['all_num'=>$data['tb']['num']+$data['jd']['num']+$data['su']['num']+ $data['pdd']['num'] + $data['vip']['num']+ $data['dy']['num']];
  2610. $data['third_party_num_a']=['all_num_a'=>$data['tb']['num_a']+$data['jd']['num_a']+$data['su']['num_a']+ $data['pdd']['num_a'] + $data['vip']['num_a']+ $data['dy']['num_a']];
  2611. $data['third_party_num_n']=['all_num_n'=>$data['third_party_num']['all_num']-$data['third_party_num_a']['all_num_a']];
  2612. return app("json")->success("查询成功", $data);
  2613. }
  2614. public function num($data, $field)
  2615. {
  2616. $sum = 0;
  2617. foreach ($data as $item) {
  2618. $sum += $item[$field];
  2619. }
  2620. return $sum;
  2621. }
  2622. // 志愿者升级
  2623. public function changeVolunteer()
  2624. {
  2625. $uid = $this->request->uid();
  2626. // 志愿者条件
  2627. $volunteer_achievement = systemConfig("volunteer_achievement");// volunteer_achievement:用户本人满足养老金要求可升级为志愿者
  2628. $volunteer_class = new Volunteer();
  2629. $volunteer = $volunteer_class->volunteer($uid);
  2630. if ($volunteer['self_yanglao'] < $volunteer_achievement) {
  2631. $data['grade'] = 0;
  2632. $data['self_yanglao'] = $volunteer['self_yanglao'];
  2633. $data['condition_one'] = systemConfig("volunteer_achievement");// 用户本人满足养老金要求可升级为志愿者
  2634. return app('json')->success($data);
  2635. }
  2636. $volunteer_class->grade($uid, 1, $volunteer);
  2637. return app('json')->success('申请成功');
  2638. }
  2639. public function GZC($uid)
  2640. {
  2641. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  2642. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  2643. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  2644. $where = [
  2645. 'uid' => $uid,
  2646. 'pm' => 1,
  2647. 'status' => 1,
  2648. 'type' => 'commission'
  2649. ];
  2650. $user_data = \think\facade\Db::name('user')->where('uid', $uid)->find();
  2651. $certification = ['user_name' => $user_data['real_name'], 'mobile' => $user_data['account'], 'user_card' => $user_data['card_id']];
  2652. $user_data['real_name'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('user_name');
  2653. $user_data['account'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('mobile');
  2654. $user_data['card_id'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('user_card');
  2655. Db::name('user_bill')->where($where)->select()->each(function ($item) use ($uid, $orderId, $OrderGzcRepository, $user_data, $certification) {
  2656. $is_implement = 1;
  2657. if ($item['source'] == 0) {
  2658. $order_data = \think\facade\Db::name('store_order')->where('order_sn', $item['order_sn'])->value('uid');
  2659. if ($order_data['uid'] == $item['uid']) {
  2660. $is_implement = 0;
  2661. } else {
  2662. $is_implement = 1;
  2663. }
  2664. } else {
  2665. $order_data = \think\facade\Db::name('order_merchant')->where('out_trade_no', $item['order_sn'])->value('uid');
  2666. if ($order_data['uid'] == $item['uid']) {
  2667. $is_implement = 0;
  2668. } else {
  2669. $is_implement = 1;
  2670. }
  2671. }
  2672. if ($is_implement == 1) {
  2673. $online = ['uid' => $uid, 'pay_type' => '1', 'order_sn' => $item['order_sn'], 'order_id' => $item['link_id']];
  2674. $create = [
  2675. 'uid' => $online['uid'],
  2676. 'platform_no' => $orderId,
  2677. 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
  2678. 'user_name' => $certification['user_name'],
  2679. 'mobile' => $certification['mobile'],
  2680. 'user_card' => $certification['user_card'],
  2681. 'pension' => $item['number'],
  2682. 'order_type' => 2,
  2683. 'out_trade_no' => $online['order_sn']
  2684. ];
  2685. $OrderGzcRepository->create($create);
  2686. }
  2687. });
  2688. }
  2689. // 20220712版签到
  2690. public function new_sign()
  2691. {
  2692. // return app('json')->fail('不允许签到');
  2693. $uid = $this->request->uid();// 签到用户
  2694. $user = Db::name('user')->where('uid', $uid)->field("spread_uid,first_sign")->find();// 上级用户
  2695. // 第一天签到获得2积分,第二天获得4积分,第三天获得6积分,第四天获得 10 积分,第五天获得 14积分第六天获得 20积分,
  2696. // 连续签到从第七天开始,每日签到获得3积分,第七天连续签到额外奖励 38积分,第 14 天连续签到额外奖励 68 积分,第 21天连续签到额外奖励 128 积分第 30 天连续签到额外奖励 188 积分
  2697. // 前6天积分
  2698. $score = [
  2699. 2,// 1
  2700. 4,// 2
  2701. 6,// 3
  2702. 10,// 4
  2703. 14,// 5
  2704. 20// 6
  2705. ];
  2706. // 7-30天积分
  2707. $scoreS = 3;
  2708. // 额外积分
  2709. $scoreExtra = [
  2710. 7 => 38,
  2711. 14 => 68,
  2712. 21 => 128,
  2713. 30 => 188
  2714. ];
  2715. $today_signintime = strtotime(date('Y-m-d', time()));
  2716. $today_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid))->whereDay('signin_time')->find();
  2717. if (!empty($today_signin_info)) {
  2718. return app('json')->fail('今天已经签到过了');
  2719. } else {
  2720. // 查询昨天是否已经签到了
  2721. $yes_signintime = strtotime(date('Y-m-d')) - 86400;
  2722. $yes_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid, 'signin_time' => $yes_signintime))->find();
  2723. $has_qian = 1;
  2724. if (!empty($yes_signin_info)) {
  2725. $has_qian = $yes_signin_info['continuity_day'] + 1;
  2726. $has_qian = $has_qian > 30 ? 1 : $has_qian;
  2727. }
  2728. $get_score = 0;
  2729. $get_gw_score = 0;
  2730. if ($has_qian <= 6) {
  2731. $get_score = $score[$has_qian - 1];
  2732. } else {
  2733. $get_score = $scoreS;
  2734. if (isset($scoreExtra[$has_qian])) {
  2735. $get_gw_score = $scoreExtra[$has_qian];
  2736. }
  2737. }
  2738. $userRepository = app()->make(UserRepository::class);
  2739. $userRepository->sign_add($uid, $get_score, 1, '签到赠送积分', $has_qian, $today_signintime, '', 1, '', 1);
  2740. if($get_gw_score > 0){
  2741. $userRepository->sign_add($uid, $get_gw_score,1,'连续签到赠送额外奖励积分', $has_qian, $today_signintime, '', 1, '', 1);
  2742. }
  2743. // 首次签到
  2744. if ($user['first_sign'] == 0) {
  2745. // //首次签到送30积分,同时赠送邀请人30积分
  2746. // $userRepository->sign_add($uid, 30,1,'首次签到送30积分','','', '', 1, '', 1);
  2747. // $member_info = Db::name('user')->where( array('uid' => $uid) )->find();
  2748. // if($member_info['spread_uid']){
  2749. // $spreadUid = $member_info['spread_uid'];
  2750. // $userRepository->sign_add($spreadUid, 30,1,'邀请人首次签到送30积分','','', '', 1, '', 1);
  2751. // }
  2752. Db::name('user')->where('uid', $uid)->update(['first_sign' => 1]);
  2753. } elseif ($user['first_sign'] == 1 && $has_qian == 1) {
  2754. Db::name('user')->where('uid', $uid)->update(['first_sign' => 2]);
  2755. }
  2756. // //非首次签到,第一天,断签
  2757. // //好友连续签到3天 奖励50
  2758. // //好友连续签到14天 奖励100
  2759. // //好友联系签到30天 奖励300
  2760. // if ($user['first_sign'] < 2) {
  2761. // if ($has_qian == 3) {
  2762. // $userRepository->sign_add($user['spread_uid'], 50, 1, '好友签到赠送积分', '', $today_signintime, '');
  2763. // } elseif ($has_qian == 14) {
  2764. // $userRepository->sign_add($user['spread_uid'], 100, 1, '好友签到赠送积分', '', $today_signintime, '');
  2765. // } elseif ($has_qian == 30) {
  2766. // $userRepository->sign_add($user['spread_uid'], 300, 1, '好友签到赠送积分', '', $today_signintime, '');
  2767. // Db::name('user')->where('uid', $uid)->update(['first_sign' => 3]);
  2768. // }
  2769. // }
  2770. return app('json')->success('签到成功', ['score' => $get_score]);
  2771. }
  2772. }
  2773. public function new_sign_info()
  2774. {
  2775. $uid = $this->request->uid();
  2776. // 查询今天是否已经签到
  2777. $today_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid))->whereDay('signin_time')->find();
  2778. // 查询昨天是否已经签到了
  2779. $yes_signintime = strtotime(date('Y-m-d')) - 86400;
  2780. $yes_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid, 'signin_time' => $yes_signintime))->find();
  2781. $data = [
  2782. 'today' => 0,
  2783. 'day' => 0
  2784. ];
  2785. if ($yes_signin_info) $data['day'] = (int)$yes_signin_info['continuity_day'];
  2786. if ($yes_signin_info['continuity_day'] >= 30) $data['day'] = 0;
  2787. if ($today_signin_info) {
  2788. $data['today'] = 1;
  2789. $data['day'] = $data['day'] + 1;
  2790. }
  2791. return app('json')->success($data);
  2792. }
  2793. /**
  2794. * 积分列表
  2795. * @return mixed
  2796. * @throws \think\db\exception\DataNotFoundException
  2797. * @throws \think\db\exception\DbException
  2798. * @throws \think\db\exception\ModelNotFoundException
  2799. */
  2800. public function sign_list()
  2801. {
  2802. [$page, $limit] = $this->getPage();
  2803. $uid = $this->request->uid();
  2804. $month = $this->request->param('month', '') ?: date('Y-m');
  2805. $status = $this->request->param('status');
  2806. $pm = $this->request->param('pm');
  2807. $startMonth = strtotime(date('Y-m-01 00:00:00', strtotime($month)));
  2808. $endMonth = strtotime(date("Y-m-d 00:00:00", strtotime("first day of next month", strtotime($month))));
  2809. $count = Db::name('user_sign_score')
  2810. ->whereBetween('addtime', [$startMonth, $endMonth])
  2811. ->when(isset($status) && $status !== '', function ($query) use ($status) {
  2812. $query->where('status', $status);
  2813. })
  2814. ->when(isset($pm) && $pm !== '', function ($query) use ($pm) {
  2815. $query->where('pm', $pm);
  2816. })
  2817. ->where('uid', $uid)->count();
  2818. $list = Db::name('user_sign_score')
  2819. ->whereBetween('addtime', [$startMonth, $endMonth])
  2820. ->where('uid', $uid)
  2821. ->when(isset($status) && $status !== '', function ($query) use ($status) {
  2822. $query->where('status', $status);
  2823. })
  2824. ->when(isset($pm) && $pm !== '', function ($query) use ($pm) {
  2825. $query->where('pm', $pm);
  2826. })
  2827. ->page($page, $limit)->order('id DESC')->select()->each(function ($item) {
  2828. $item['signin_time'] = date('Y-m-d', $item['signin_time']);
  2829. $item['addtime'] = date('Y-m-d H:i:s', $item['addtime']);
  2830. if (!empty($item['order_id'])) {
  2831. // 线上订单
  2832. if ($item['order_type'] == 'store_order' || $item['order_type'] == 'store_order_beishengtang') {
  2833. $item['order_sn'] = Db::name("store_order")->where("order_id", $item['order_id'])->value("order_sn");
  2834. } elseif ($item['order_type'] == 'order_merchant') {
  2835. $item['order_sn'] = Db::name("order_merchant")->where("id", $item['order_id'])->value("out_trade_no");
  2836. } elseif ($item['order_type'] == 'extract') {
  2837. $item['order_sn'] = Db::name("user_extract")->where("extract_id", $item['order_id'])->value("order_sn");
  2838. } else {
  2839. $item['order_sn'] = '';
  2840. }
  2841. } else {
  2842. $item['order_sn'] = '';
  2843. }
  2844. return $item;
  2845. });
  2846. $data['list'] = $list;
  2847. $data['count'] = $count;
  2848. return app('json')->success($data);
  2849. }
  2850. public function getAmountFromGzc()
  2851. {
  2852. $uid = $this->request->uid();
  2853. $userInfo = Db::name('UserCertification')->where('uid', $uid)->field('user_name,user_card')->find();
  2854. $res = GzcApiRequest::checkAmount($userInfo);
  2855. return app('json')->success(['amount' => sprintf("%01.2f", $res['extendData']['amount'] * 0.01)]);
  2856. }
  2857. public function check_user_annual_fee()
  2858. {
  2859. // INSERT INTO rrx_user_pension_account (uid) SELECT uid FROM rrx_user;
  2860. // UPDATE `renrenxiang`.`rrx_user_pension_account` SET `start_time` = '2023-04-07 00:00:00', `end_time` = '2024-04-07 23:59:59', `status` = 1, `give` = 1 WHERE `id` > 0;
  2861. $uid = $this->request->uid();
  2862. $check = Db::name("user_pension_account")->where("uid", $uid)->find();
  2863. $data = [
  2864. "status" => 3,// 0:未交年费,1:年费到期。2:未实名认证,3:正常
  2865. ];
  2866. // //未交年费
  2867. // if (!$check || $check["status"] == 0) {
  2868. // $data["status"] = 0;
  2869. // return app('json')->success($data);
  2870. // }
  2871. // //到期时间小于当前时间。年费到期
  2872. // if (strtotime($check['end_time']) < time()){
  2873. // $data["status"] = 1;
  2874. // return app('json')->success($data);
  2875. // }
  2876. // $data["start_time"] = $check['start_time'];
  2877. // $data["end_time"] = $check['end_time'];
  2878. //
  2879. // //检查实名认证
  2880. // $checkCertification = Db::name("user_certification") -> where("uid",$uid) -> find();
  2881. // if (!$checkCertification){
  2882. // $data["status"] = 2;
  2883. // return app('json')->success($data);
  2884. // }
  2885. return app('json')->success($data);
  2886. }
  2887. /**
  2888. *
  2889. * @remarks 创建年费订单
  2890. * @author 小菜菜
  2891. * @created 2023/04/10 14:37
  2892. */
  2893. public function create_annual_order()
  2894. {
  2895. $uid = $this->request->uid();
  2896. $type = $this->request->param('type', 1);
  2897. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  2898. if ($type == 1) $price = "12.00";
  2899. elseif ($type == 2) $price = systemConfig('offline_a');
  2900. elseif ($type == 3) $price = systemConfig('offline_b');
  2901. elseif ($type == 4) $price = systemConfig('offline_c');
  2902. else return app('json')->fail("参数错误");
  2903. $check = Db::name("user_pension_account")->where("uid", $uid)->find();
  2904. // 到期时间小于当前时间。年费到期
  2905. if (strtotime($check['end_time']) > time() && $check['status'] == 1) {
  2906. return app('json')->fail("账户已开通,不可重复开通账户");
  2907. }
  2908. $insertData = [
  2909. 'pay_price' => $price,
  2910. 'status' => 0,
  2911. 'order_no' => $OrderMerchantRepository->getNewOrderId("mt"),
  2912. 'uid' => $uid,
  2913. 'type' => $type,
  2914. ];
  2915. $order_id = Db::name('user_pension_account_order')->insertGetId($insertData);
  2916. try {
  2917. return app('json')->success(['order_id' => $order_id]);
  2918. } catch (\Exception $e) {
  2919. return app('json')->status('error', $e->getMessage(), ['order_id' => $order_id]);
  2920. }
  2921. }
  2922. /**
  2923. * @remarks 会员支付
  2924. * @author Tang
  2925. * @created 2021/8/27 9:18
  2926. */
  2927. public function pay_user_annual()
  2928. {
  2929. try {
  2930. $oid = r::param('oid', '');
  2931. $code = r::param('code', '');
  2932. $payType = r::param('type', '');// wx.ALI
  2933. if ($oid == '') return app('json')->fail("请检查参数是否正确");
  2934. $groupOrder = Db::name('user_pension_account_order')->where('id', $oid)->where('status', 0)->find();
  2935. if (!$groupOrder) return app('json')->fail('订单不存在或已支付');
  2936. $access = new Access();
  2937. $res = $access->pay_huifu($payType, $code, $groupOrder, "年费", env('APP_URL') . "/api/hf_notify/pay_user_annual");
  2938. Db::name('log')->insert(['data' => '汇付用户年费支付---' . json_encode($res)]);
  2939. Db::name('user_pension_account_order')->where('id', $oid)->update(['hf_pay_id' => $res['id']]);
  2940. return app('json')->success($res);
  2941. } catch (\Exception $exception) {
  2942. return app('json')->fail();
  2943. }
  2944. }
  2945. /**
  2946. * @remarks 会员支付 线下
  2947. * @author Tang
  2948. * @created 2021/8/27 9:18
  2949. */
  2950. public function pay_user_annual_offline()
  2951. {
  2952. try {
  2953. $oid = r::param('oid', '');
  2954. $payType = r::param('type', '');// WX.ALI
  2955. $pay_user_id = r::param('pay_user_id', '');// 如果是微信。传open_id 如果是支付宝。传user_id
  2956. if ($oid == '') return app('json')->fail("请检查参数是否正确");
  2957. if ($pay_user_id == '') return app('json')->fail("请检查参数是否正确");
  2958. $order = Db::name('user_pension_account_order')->where('id', $oid)->where('status', 0)->find();
  2959. if (!$order) return app('json')->fail('订单不存在或已支付');
  2960. if ($order['type'] == 1) {
  2961. $title = "开通账户";
  2962. } elseif ($order['type'] == 2) {
  2963. $title = "大礼包1";
  2964. } elseif ($order['type'] == 3) {
  2965. $title = "大礼包2";
  2966. } elseif ($order['type'] == 4) {
  2967. $title = "大礼包3";
  2968. } else {
  2969. return app('json')->fail('订单异常');
  2970. }
  2971. if ($order['type'] > 1) {
  2972. // 本人给养老金10%
  2973. $ylj = sprintf("%01.2f", bcmul($order['pay_price'], '0.1', 5));// 10%的养老金
  2974. $commission = 0;
  2975. // 上级给佣金10%
  2976. $order_user = Db::name("user")->where("uid", $order["uid"])->field("spread_uid")->find();
  2977. // 推广员id
  2978. $spread_uid = $order_user["spread_uid"];
  2979. if (!empty($spread_uid)) {
  2980. $commission = sprintf("%01.2f", bcmul($order['pay_price'], '0.1', 5));// 10%的佣金
  2981. }
  2982. $pt = sprintf("%01.2f", 12 + $ylj + $commission);
  2983. $merchant_money = sprintf("%01.2f", $order['pay_price'] - $pt);
  2984. } else {
  2985. $pt = "12.00";
  2986. $merchant_money = "0.00";
  2987. }
  2988. if ($payType == 'WX') {
  2989. $pay_wx = systemConfig('pay_wx');
  2990. // 微信
  2991. if ($pay_wx == 3) {
  2992. $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 3)->value('member_id');
  2993. $key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
  2994. $app_id = 'app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0';
  2995. } else {
  2996. $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 2)->value('member_id');
  2997. $key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  2998. $app_id = 'app_0827b960-b932-45ec-b800-4e850091b419';
  2999. }
  3000. $type = '2';
  3001. $pay_channel = 'wx_pub';
  3002. $expend = [
  3003. 'open_id' => $pay_user_id
  3004. ];
  3005. } elseif ($payType == 'ALI') {
  3006. $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 1)->value('member_id');
  3007. $app_id = 'app_44108546-d27a-48ee-88c1-84b45b75114f';
  3008. $type = '1';
  3009. $pay_channel = 'alipay_pub';
  3010. $expend = [
  3011. 'buyer_id' => $pay_user_id
  3012. ];
  3013. $key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  3014. }
  3015. if ($merchant_money == '0.00') {
  3016. $div_members = [
  3017. [
  3018. 'member_id' => 0,
  3019. 'amount' => $pt,
  3020. 'fee_flag' => 'Y'
  3021. ]
  3022. ];
  3023. } else {
  3024. $div_members = [
  3025. [
  3026. 'member_id' => $member_id,
  3027. 'amount' => $merchant_money,
  3028. 'fee_flag' => 'Y'
  3029. ],
  3030. [
  3031. 'member_id' => 0,
  3032. 'amount' => $pt,
  3033. 'fee_flag' => 'N'
  3034. ]
  3035. ];
  3036. }
  3037. $params = [
  3038. 'order_no' => $order['order_no'] . '_' . rand(000, 999),
  3039. 'app_id' => $app_id,
  3040. 'pay_channel' => $pay_channel,
  3041. 'pay_amt' => (string)$order['pay_price'],
  3042. 'goods_title' => "幸福宝",
  3043. 'goods_desc' => $title,
  3044. 'device_info' => [
  3045. 'device_ip' => app('request')->ip()
  3046. // 'device_ip'=>'115.171.134.68'
  3047. ],
  3048. 'expend' => json_encode($expend),
  3049. 'div_members' => json_encode($div_members),
  3050. 'fee_mode' => 'I',
  3051. 'notify_url' => env('APP_URL') . "/api/jsapiPay/notify/HF_pay_user_annual"
  3052. ];
  3053. $res = $this->Payment_create_traits($params, $type, $key);
  3054. if (!empty($res['error_code'])) {
  3055. return app('json')->fail($res['return_msg']);
  3056. } else {
  3057. Db::name('user_pension_account_order')->where('id', $oid)->update(['hf_pay_id' => $res['id']]);
  3058. return app('json')->success($res);
  3059. }
  3060. } catch (\Exception $exception) {
  3061. Db::name('log')->insert(['data' => '大礼包支付error:' . $exception->getFile() . ':' . $exception->getLine() . '【' . $exception->getMessage() . '】']);
  3062. return app('json')->fail();
  3063. }
  3064. }
  3065. public function red_log()
  3066. {
  3067. $uid = $this->request->uid();
  3068. [$page, $limit] = $this->getPage();
  3069. $user_rich_log = Db::name('user_rich_log')->where('uid', $uid)->field('uid,red,pm,time,mark')->page($page, $limit)->order('id DESC')->select()->each(function ($item) {
  3070. $item['create_time'] = date('Y-m-d H:i:s', $item['time']);
  3071. $item['red'] = set_price_rtrim($item['red']);
  3072. return $item;
  3073. });
  3074. return app('json')->success($user_rich_log);
  3075. }
  3076. public function apply_bang_fu()
  3077. {
  3078. $uid = $this->request->uid();
  3079. $check = Db::name('user_rich')->where('uid', $uid)->find();
  3080. if ($check['type'] < 3) {
  3081. return app('json')->fail("不满足申请条件");
  3082. }
  3083. $check = Db::name('user_bangfu')->where('uid', $uid)->value('status');
  3084. if ($check == 0) {
  3085. return app('json')->fail("审核中");
  3086. }
  3087. if ($check == 1) {
  3088. return app('json')->fail("已是帮扶中心");
  3089. }
  3090. if ($check == 2) {
  3091. return app('json')->fail("审核被拒绝");
  3092. }
  3093. $bang_fu_number = systemConfig("bang_fu_number");
  3094. // 检测用户是否满足条件
  3095. $number = $this->getNumber($uid, $bang_fu_number) - 1;// 满足条件人数 减去自己
  3096. // 条件
  3097. if ($number >= $bang_fu_number) {
  3098. // echo '满足';
  3099. Db::name('user_bangfu')->insert([
  3100. 'uid' => $uid,
  3101. 'time' => time(),
  3102. 'status' => 0
  3103. ]);
  3104. return app('json')->success("提交申请成功");
  3105. }
  3106. return app('json')->fail("不满足申请条件");
  3107. // echo '不满足';
  3108. }
  3109. // 获得满足 1+5 的下级数量
  3110. public function getNumber($uid, $bang_fu_number): int
  3111. {
  3112. $number = 0;
  3113. $getUid = Db::name('user')->where('level_id', $uid)->field('uid')->select();
  3114. $count = count($getUid);
  3115. if ($count >= 5) {
  3116. $number = 1;
  3117. foreach ($getUid as $value) {
  3118. $number += $this->getNumber($value['uid'], $bang_fu_number);
  3119. if ($number >= $bang_fu_number) {
  3120. break;
  3121. }
  3122. }
  3123. }
  3124. return $number;
  3125. }
  3126. /**
  3127. * 积分明细
  3128. * @return mixed
  3129. */
  3130. public function score_info()
  3131. {
  3132. $uid = $this->request->uid();;
  3133. $data['score'] = decimal2(Db::name('user_sign_score')
  3134. ->where('uid', $uid)
  3135. ->where('status', 1)
  3136. ->where('pm', 1)
  3137. ->sum('reward_socre'));;
  3138. $data['no_clear_score'] = decimal2(Db::name('user_sign_score')
  3139. ->where('uid', $uid)
  3140. ->where('status', -1)
  3141. ->where('pm', 1)
  3142. ->sum('reward_socre'));
  3143. $data['lose_score'] = decimal2(Db::name('user_sign_score')
  3144. ->where('uid', $uid)
  3145. ->where('pm', 2)
  3146. ->sum('reward_socre'));
  3147. $data['clear_score'] = $score = decimal2($data['score'] - $data['lose_score']);
  3148. $data['score'] = $data['clear_score'] + $data['no_clear_score'] + $data['lose_score'];
  3149. $data['score'] = decimal2($data['score']);
  3150. Db::name('user')->where('uid', $uid)->update([
  3151. 'score' => $score
  3152. ]);
  3153. // clear_score 可用积分,score 积分总数 lose_score 已使用积分 no_clear_score 未结算积分
  3154. return app('json')->success($data);
  3155. }
  3156. /**
  3157. * 新版我的团队
  3158. */
  3159. public function get_team_list()
  3160. {
  3161. $data = [];
  3162. [$page, $limit] = $this->getPage();
  3163. $uid = $this->request->uid();
  3164. $type = intval($this->request->param('type'));
  3165. // 查询团队列表
  3166. $userRepository = app()->make(UserRepository::class);
  3167. $chilid_userids = $userRepository->getSpreadUidBreak($uid);
  3168. $data['fans_count'] = count($chilid_userids);
  3169. $direct_uid_list = Db::name('user')->where('spread_uid', $uid)->where('is_del', 0)->column('uid');
  3170. $data['direct_count'] = count($direct_uid_list);
  3171. $valid_uid_list = Db::name('store_order')
  3172. ->whereIn('uid', $chilid_userids)
  3173. ->where('paid', 1)
  3174. ->group('uid')
  3175. ->column('uid');
  3176. $data['valid_count'] = count($valid_uid_list);
  3177. $data['count'] = Db::name('user')
  3178. ->whereIn('uid', $chilid_userids)
  3179. ->count();
  3180. $data['list'] = Db::name('user')
  3181. ->field('uid,phone,nickname,user_group,create_time,avatar as picture')
  3182. ->page($page, $limit)
  3183. ->whereIn('uid', $chilid_userids)
  3184. ->when($type == 1, function ($query) use ($direct_uid_list) {
  3185. return $query->whereIn('uid', $direct_uid_list);
  3186. })
  3187. ->when($type == 2, function ($query) use ($valid_uid_list) {
  3188. return $query->whereIn('uid', $valid_uid_list);
  3189. })
  3190. ->order('uid DESC')
  3191. ->select()
  3192. ->toArray();
  3193. foreach ($data['list'] as &$user) {
  3194. $user ['phone'] = substr_replace($user['phone'], '****', 3, 4);
  3195. }
  3196. return app('json')->success($data);
  3197. }
  3198. /**
  3199. * 我的粉丝详情
  3200. */
  3201. public function get_team_info()
  3202. {
  3203. $uid = $this->request->param('uid', '');
  3204. if (!$uid)
  3205. return app('json')->fail("uid不正确");
  3206. $userRepository = app()->make(UserRepository::class);
  3207. $chilid_userids = $userRepository->getSpreadUidBreak($this->request->uid());
  3208. if (!in_array($uid, $chilid_userids))
  3209. return app('json')->fail("该用户不在所属团队内");
  3210. $data = Db::name('user')
  3211. ->field('uid,phone,nickname,spread_uid,user_group,create_time,manage_address')
  3212. ->where('uid', $uid)
  3213. ->find();
  3214. $data['regimental_commander_count'] = Db::name('user')
  3215. ->where('spread_uid', $uid)
  3216. ->where('user_group', 2)
  3217. ->count();
  3218. $data['clear_order_amount'] = Db::name('store_order')
  3219. ->where('uid', $uid)
  3220. ->where('is_settlement', 1)
  3221. ->sum('pay_price');
  3222. $data['mybuy_order_amount'] = Db::name('store_order')
  3223. ->where('uid', $uid)
  3224. ->where('paid', 1)
  3225. ->sum('pay_price');
  3226. $spread_user = Db::name('user')
  3227. ->field('nickname as spread_nickname,phone as spread_phone')
  3228. ->where('uid', $data['spread_uid'])
  3229. ->find();
  3230. $spread_user ['spread_phone'] = substr_replace($spread_user['spread_phone'], '****', 3, 4);
  3231. $spread_user ['spread_nick_name'] = $spread_user['spread_nickname'] ?? '';
  3232. $data ['phone'] = substr_replace($data['phone'], '****', 3, 4);
  3233. $data = array_merge($data, $spread_user);
  3234. if (in_array($data['user_group'], [5, 6])) {
  3235. $data['area_name'] = Db::name('regions')->field('type,code_list')->where('id', 'in', $data['manage_address'])->cache('code:' . $data['manage_address'], 7200)->column('name');
  3236. $data['area_name'] = join($data['area_name']);
  3237. $data['area_bonus_money'] = Db::name('user_bill')
  3238. ->where('uid', $uid)
  3239. ->sum('number');
  3240. }
  3241. unset($data['manage_address']);
  3242. if (in_array($data['user_group'], [4])) {
  3243. $merchant = Db::name('merchant')->where('uid', $uid)->field('mer_id,mer_name')->find();
  3244. $data['mer_id'] = $merchant['mer_id'] ?? 0;
  3245. $data['mer_name'] = $merchant['mer_name'] ?? '';
  3246. }
  3247. return app('json')->success($data);
  3248. }
  3249. /**
  3250. * 我的佣金
  3251. */
  3252. public function get_brokerage_info()
  3253. {
  3254. $uid = $this->request->uid();
  3255. // 佣金余额
  3256. $data['brokerage_price'] = Db::name('user')->where('uid', $uid)->value('brokerage_price');
  3257. // 总收益
  3258. $data['sum_amount'] = Db::name('user_bill')
  3259. ->where('uid', $uid)
  3260. ->where('commission_type', '<>', 5)
  3261. ->where('commission_type', '<>', 0)
  3262. ->where('pm', 1)
  3263. ->sum('number');
  3264. // 未结算
  3265. $data['no_clear_amount'] = Db::name('user_bill')
  3266. ->where('uid', $uid)
  3267. ->where('commission_type', '<>', 5)
  3268. ->where('commission_type', '<>', 0)
  3269. ->where('pm', 1)
  3270. ->where('status', 0)
  3271. ->sum('number');
  3272. // 已提现
  3273. $data['withdraw_amount'] = Db::name('user_extract')
  3274. ->where('uid', $uid)
  3275. ->whereIn('status', [0, 1])
  3276. ->sum('extract_price');
  3277. // 转VR
  3278. $data['transition_vr_amount'] = Db::name('user_transition_vr')
  3279. ->where('uid', $uid)
  3280. ->where('type', 1)
  3281. ->sum('number');
  3282. // 最终 总收益是 = 佣金余额 + 已提现 + 已转VR
  3283. // $data['sum_amount'] = $data['sum_amount'] + $data['transition_vr_amount'];
  3284. $data['sum_amount'] = set_price_rtrim($data['sum_amount']);
  3285. return app('json')->success($data);
  3286. }
  3287. public function get_token_by_phone(UserRepository $repository){
  3288. $user = $repository->accountByUser($this->request->param('phone'));
  3289. $tokenInfo = $repository->createToken($user);
  3290. return app('json')->success($repository->returnToken($user, $tokenInfo));
  3291. }
  3292. /**
  3293. * 转VR
  3294. */
  3295. public function transition_vr()
  3296. {
  3297. $uid = $this->request->uid();
  3298. $user = $this->request->userInfo();
  3299. $type = $this->request->param('type', 'brokerage');
  3300. $extract_amount = $this->request->param('extract_amount', 0);
  3301. if ($type == 'brokerage') {
  3302. $brokerage_price = Db::name('user')->where('uid', $uid)->value('brokerage_price');
  3303. // 参考结算任务中的代码片段, 余额中 应不包含未结算余额
  3304. // $no_clear_amount = Db::name('user_bill')
  3305. // ->where('uid', $uid)
  3306. // ->where('commission_type', '<>', 5)
  3307. // ->where('pm', 1)
  3308. // ->where('status', 0)
  3309. // ->sum('number');
  3310. // $clear_amount = $brokerage_price - $no_clear_amount;
  3311. $clear_amount = $brokerage_price;
  3312. // if ($user['brokerage_price'] < (systemConfig('withdrawal_money'))){
  3313. // return app('json')->fail('未到达提现最低额度');
  3314. // }
  3315. if($extract_amount > $clear_amount){
  3316. return app('json')->fail("可用金额不足提现");
  3317. }
  3318. $brokerage_price = bcsub($user['brokerage_price'], $extract_amount,2);
  3319. $user->brokerage_price = $brokerage_price;
  3320. $vr = bcadd($user['vr'], $extract_amount, 2);
  3321. $user->vr = $vr;
  3322. $res = $user->save();
  3323. if ($res){
  3324. // 加入转VR记录
  3325. $insertdata = [
  3326. 'uid'=> $uid,
  3327. 'number' => $extract_amount,
  3328. 'surplus' => $vr,
  3329. 'mark' => '佣金转VR',
  3330. 'type' => 1,
  3331. 'create_time' => time(),
  3332. ];
  3333. Db::name('user_transition_vr')->insertGetId($insertdata);
  3334. // VR入账
  3335. $insertdata = [
  3336. 'uid'=> $uid,
  3337. 'number' => $extract_amount,
  3338. 'surplus' => $vr,
  3339. 'mark' => '佣金转VR',
  3340. 'order_id'=> 0,
  3341. 'type' => 1,
  3342. 'addtime' => time(),
  3343. 'settlement_time'=> date('Y-m-d H:i:s', time())
  3344. ];
  3345. Db::name('user_sign_vr')->insertGetId($insertdata);
  3346. return app('json')->success('转VR成功');
  3347. }else{
  3348. return app('json')->fail('转VR失败');
  3349. }
  3350. }
  3351. if ($type == 'hongbao') {
  3352. $hongbao = Db::name('user')->where('uid', $uid)->value('hongbao');
  3353. $no_clear_amount = Db::name('user_sign_hongbao')
  3354. ->where('uid', $uid)
  3355. ->where('type', 1)
  3356. ->where('status', -1)
  3357. ->sum('number');
  3358. $clear_amount = $hongbao - $no_clear_amount;
  3359. // if ($user['hongbao'] < (systemConfig('withdrawal_money'))){
  3360. // return app('json')->fail('未到达提现最低额度');
  3361. // }
  3362. if($extract_amount > $clear_amount){
  3363. return app('json')->fail("可用金额不足提现");
  3364. }
  3365. $hongbao = bcsub($user['hongbao'], $extract_amount,2);
  3366. $user->hongbao = $hongbao;
  3367. $vr = bcadd($user['vr'], $extract_amount, 2);
  3368. $user->vr = $vr;
  3369. $res = $user->save();
  3370. if ($res){
  3371. // 加入转VR记录
  3372. $insertdata = [
  3373. 'uid'=> $uid,
  3374. 'number' => $extract_amount,
  3375. 'surplus' => $vr,
  3376. 'mark' => '红包转VR',
  3377. 'type' => 2,
  3378. 'status' => 1,
  3379. 'addtime' => time(),
  3380. ];
  3381. Db::name('user_sign_hongbao')->insertGetId($insertdata);
  3382. // VR入账
  3383. $insertdata = [
  3384. 'uid'=> $uid,
  3385. 'number' => $extract_amount,
  3386. 'surplus' => $vr,
  3387. 'mark' => '红包转VR',
  3388. 'order_id'=> 0,
  3389. 'type' => 1,
  3390. 'addtime' => time(),
  3391. 'settlement_time'=> date('Y-m-d H:i:s', time())
  3392. ];
  3393. Db::name('user_sign_vr')->insertGetId($insertdata);
  3394. return app('json')->success('转VR成功');
  3395. }else{
  3396. return app('json')->fail('转VR失败');
  3397. }
  3398. }
  3399. return app('json')->fail('转VR失败');
  3400. }
  3401. /**
  3402. * 转VR记录
  3403. */
  3404. public function transition_vr_log()
  3405. {
  3406. $uid = $this->request->uid();
  3407. $type = $this->request->param('type', 1);
  3408. [$page, $limit] = $this->getPage();
  3409. $where = [];
  3410. $where[] = ['uid', '=', $uid];
  3411. $where[] = ['type', '=', $type];
  3412. $query = Db::name("user_transition_vr");
  3413. $count = $query->where($where)->count();
  3414. $list = $query->page($page, $limit)->where($where)->select()->each(function ($item){
  3415. $item['create_time'] = date("Y-m-d H:i:s", $item['create_time']);
  3416. return $item;
  3417. });
  3418. return app('json')->success('获取转VR记录成功', ['list'=>$list, 'count'=>$count]);
  3419. }
  3420. // 根据父级uid,递归获取所有子级UID数组
  3421. public function getRecursiveChildren($parentUid) {
  3422. $result = []; // 用于存储符合条件的子级 uid
  3423. // 定义递归函数
  3424. $recursion = function ($parentUid) use (&$result, &$recursion) {
  3425. // 查询当前父级的所有直接子级
  3426. $children = Db::name("user")
  3427. ->where("spread_uid", $parentUid)
  3428. ->column("uid"); // 获取子级的 uid 列表
  3429. // 如果没有子级,直接返回
  3430. if (empty($children)) {
  3431. return;
  3432. }
  3433. // 遍历每个子级
  3434. foreach ($children as $childUid) {
  3435. // 如果子级的 uid 小于或等于 611,跳过该子级及其所有子级
  3436. if ($childUid <= 611) {
  3437. continue;
  3438. }
  3439. // 将符合条件的子级 uid 添加到结果数组
  3440. $result[] = $childUid;
  3441. // 递归查询子级的子级
  3442. $recursion($childUid);
  3443. }
  3444. };
  3445. // 从初始父级开始递归查询
  3446. $recursion($parentUid);
  3447. return array_unique($result); // 返回结果数组,并去重
  3448. }
  3449. // 2.0 根据父级uid,找到当前用户下面的UID
  3450. public function getChildren($parentUid) {
  3451. $result = []; // 用于存储所有子级的 uid
  3452. $children = Db::name("user")
  3453. ->where("spread_uid", $parentUid)
  3454. ->column("uid"); // 获取子级的 uid 列表
  3455. return $children; // 返回结果数组,并去重
  3456. }
  3457. public function getNewTeamPv($common_nums) {
  3458. // 初始化结果数组
  3459. $result = [
  3460. 'max_value' => null,
  3461. 'max_uid' => null,
  3462. 'remaining_values' => 0, // 剩余值的总和
  3463. 'remaining_uids' => [] // 剩余值对应的 UID
  3464. ];
  3465. // 递归获取所有子级 UID 的函数
  3466. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  3467. $children = Db::name("user")
  3468. ->where("spread_uid", $parentUid)
  3469. ->column("uid");
  3470. $allChildren = [];
  3471. foreach ($children as $childUid) {
  3472. $allChildren[] = $childUid;
  3473. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  3474. }
  3475. return $allChildren;
  3476. };
  3477. // 获取每个用户的总业绩,包括子级的业绩
  3478. $userTotalPv = [];
  3479. foreach ($common_nums as $uid) {
  3480. // 获取当前用户及其所有子级的 UID
  3481. $allUids = array_merge([$uid], $getRecursiveChildren($uid));
  3482. // 查询当前用户及其子级的所有订单
  3483. $orders = Db::name("store_order")
  3484. ->whereIn('status', [0, 1, 2, 3])
  3485. ->whereIn("uid", $allUids)
  3486. ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  3487. ->select();
  3488. // 计算总业绩
  3489. $totalPv = 0;
  3490. foreach ($orders as $order) {
  3491. if ($order['total_price'] == 1180) {
  3492. $totalPv += 700;
  3493. } else if ($order['total_price'] == 11800) {
  3494. $totalPv += 7000;
  3495. } else if ($order['total_price'] == 10620) {
  3496. $totalPv += 6300;
  3497. } else if ($order['total_price'] == 2360) {
  3498. $totalPv += 1400;
  3499. } else if ($order['total_price'] == 9440) {
  3500. $totalPv += 5600;
  3501. }
  3502. }
  3503. // 将当前用户的总业绩和 UID 存入数组
  3504. $userTotalPv[] = ['uid' => $uid, 'totalPv' => $totalPv];
  3505. }
  3506. // 如果没有符合条件的订单,直接返回空数组
  3507. if (empty($userTotalPv)) {
  3508. return [];
  3509. }
  3510. // 找到最大值及其对应的 UID
  3511. usort($userTotalPv, function($a, $b) {
  3512. return $b['totalPv'] <=> $a['totalPv']; // 按 totalPv 降序排序
  3513. });
  3514. // 获取最大值及其 UID
  3515. $result['max_value'] = $userTotalPv[0]['totalPv'];
  3516. $result['max_uid'] = $userTotalPv[0]['uid'];
  3517. // 计算剩余值的总和和对应的 UID
  3518. foreach ($userTotalPv as $index => $user) {
  3519. if ($index > 0) { // 跳过第一个(最大值)
  3520. $result['remaining_values'] += $user['totalPv'];
  3521. $result['remaining_uids'][] = $user['uid'];
  3522. }
  3523. }
  3524. return $result;
  3525. }
  3526. // 只获取数组中的业绩
  3527. public function getteampv($common_nums) {
  3528. // 查询当前用户及其子级的所有订单
  3529. $orders = Db::name("store_order")
  3530. ->whereIn('status', [0, 1, 2, 3])
  3531. ->whereIn("uid", $common_nums)
  3532. ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  3533. ->select();
  3534. // 初始化业绩和人数
  3535. $totalPv = 0;
  3536. $totalUsers = count($common_nums); // 初始化人数为子级总数
  3537. // 遍历订单计算业绩
  3538. foreach ($orders as $order) {
  3539. if ($order['total_price'] == 1180) {
  3540. $totalPv += 700;
  3541. } else if ($order['total_price'] == 11800) {
  3542. $totalPv += 7000;
  3543. } else if ($order['total_price'] == 10620) {
  3544. $totalPv += 6300;
  3545. } else if ($order['total_price'] == 2360) {
  3546. $totalPv += 1400;
  3547. } else if ($order['total_price'] == 9440) {
  3548. $totalPv += 5600;
  3549. }
  3550. }
  3551. // 返回业绩和人数
  3552. return [
  3553. 'totalPv' => $totalPv,
  3554. 'totalUsers' => $totalUsers
  3555. ];
  3556. }
  3557. // 递归获取所有子级 UID 的业绩
  3558. public function getTeamPv11($parentUid) {
  3559. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  3560. $children = Db::name("user")
  3561. ->where("spread_uid", $parentUid)
  3562. ->column("uid");
  3563. $allChildren = [];
  3564. foreach ($children as $childUid) {
  3565. $allChildren[] = $childUid;
  3566. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  3567. }
  3568. return $allChildren;
  3569. };
  3570. // 获取当前用户及其所有子级的 UID
  3571. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  3572. // 查询当前用户及其子级的所有订单
  3573. $orders = Db::name("store_order")
  3574. ->whereIn('status', [0, 1, 2, 3])
  3575. ->whereIn("uid", $allUids)
  3576. ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  3577. ->select();
  3578. // 计算总业绩
  3579. $totalPv = 0;
  3580. foreach ($orders as $order) {
  3581. switch ($order['total_price']) {
  3582. case 1180:
  3583. $totalPv += 700;
  3584. break;
  3585. case 11800:
  3586. $totalPv += 7000;
  3587. break;
  3588. case 10620:
  3589. $totalPv += 6300;
  3590. break;
  3591. case 2360:
  3592. $totalPv += 1400;
  3593. break;
  3594. case 9440:
  3595. $totalPv += 5600;
  3596. break;
  3597. }
  3598. }
  3599. return $totalPv;
  3600. }
  3601. // 根据传递的父级数组,返回他的对应子级的个数
  3602. public function getTeamSize($parentUids) {
  3603. // 初始化结果数组
  3604. $result = [];
  3605. // 遍历每个父级ID
  3606. foreach ($parentUids as $parentUid) {
  3607. // 递归获取所有子级 UID
  3608. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  3609. $children = Db::name("user")
  3610. ->where("spread_uid", $parentUid)
  3611. ->column("uid");
  3612. // 确保返回的是数组
  3613. if (!is_array($children)) {
  3614. return [];
  3615. }
  3616. $allChildren = [];
  3617. foreach ($children as $childUid) {
  3618. $allChildren[] = $childUid;
  3619. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  3620. }
  3621. return $allChildren;
  3622. };
  3623. // 获取当前父级及其所有子级的 UID
  3624. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  3625. // 计算总个数(包括父级自身)
  3626. $totalUids = count($allUids);
  3627. // 将结果存入数组
  3628. $result[] = [
  3629. 'parent_uid' => $parentUid,
  3630. 'total_count' => $totalUids
  3631. ];
  3632. }
  3633. return $result;
  3634. }
  3635. public function processArray($array) {
  3636. // 初始化结果数组
  3637. $result = [
  3638. 'max_value' => null, // 最大值
  3639. 'max_index' => null, // 最大值的下标
  3640. 'remaining_sum' => 0 // 剩余值的总和
  3641. ];
  3642. // 检查数组是否为空
  3643. if (empty($array)) {
  3644. return $result;
  3645. }
  3646. // 找出最大值及其下标
  3647. $maxValue = $array[0];
  3648. $maxIndex = 0;
  3649. for ($i = 1; $i < count($array); $i++) {
  3650. if ($array[$i] > $maxValue) {
  3651. $maxValue = $array[$i];
  3652. $maxIndex = $i;
  3653. }
  3654. }
  3655. // 计算剩余值的总和
  3656. $remainingSum = 0;
  3657. for ($i = 0; $i < count($array); $i++) {
  3658. if ($i != $maxIndex) {
  3659. $remainingSum += $array[$i];
  3660. }
  3661. }
  3662. // 将结果存入数组
  3663. $result['max_value'] = $maxValue;
  3664. $result['max_index'] = $maxIndex;
  3665. $result['remaining_sum'] = $remainingSum;
  3666. return $result;
  3667. }
  3668. // 获取当前uesr_id下面在2.0中是否还有直接下级,并计算她的大部门和小部门
  3669. public function getparents_child_pv($user_id){
  3670. // 获取直接下级的 UID 列表
  3671. $get_childs = Db::name("user")
  3672. ->where("spread_uid", $user_id)
  3673. ->column("uid");
  3674. // var_dump($get_childs);
  3675. // 初始化总业绩和总人数
  3676. $total_value = 0;
  3677. $total_count = 0;
  3678. $max_value = 0;
  3679. $max_count = 0;
  3680. // 遍历每个直接下级
  3681. foreach ($get_childs as $child) {
  3682. // echo $child;
  3683. // 获取当前下级及其子级
  3684. $child_group = [$child];
  3685. $recursive_children = $this->getRecursiveChildren($child);
  3686. $child_group = array_merge($child_group, $recursive_children);
  3687. // var_dump($child_group );
  3688. // 获取当前分组的业绩和人数
  3689. $result = $this->getteampv($child_group);
  3690. // var_dump($result);
  3691. $group_pv = $result['totalPv'];
  3692. $group_count = $result['totalUsers'];
  3693. // 累加总业绩和总人数
  3694. $total_value += $group_pv;
  3695. $total_count += $group_count;
  3696. // 更新最大业绩及其对应的人数
  3697. if ($group_pv > $max_value) {
  3698. $max_value = $group_pv;
  3699. $max_count = $group_count;
  3700. }
  3701. }
  3702. // 计算小部门的业绩和人数
  3703. $small_department_value = $total_value - $max_value;
  3704. $small_department_count = $total_count - $max_count;
  3705. // 返回结果
  3706. return [
  3707. 'team_pv' => $max_value,
  3708. 'team_num' => $max_count,
  3709. 'per_pv' => $small_department_value,
  3710. 'per_num' => $small_department_count
  3711. ];
  3712. }
  3713. // 1.0用户直属的部门和2.0直属的部门,进行比较,获取大部门和小部门数据
  3714. public function getparents_child_pv11($user_id, $bigamount, $smallamount, $common_nums, $person_nums) {
  3715. // 获取直接下级的 UID 列表
  3716. $get_childs = Db::name("user")
  3717. ->where("spread_uid", $user_id)
  3718. ->column("uid");
  3719. // 初始化变量
  3720. $all_departments = []; // 用于存储所有直属下级的业绩和人数
  3721. // 遍历每个直属下级
  3722. foreach ($get_childs as $child) {
  3723. // 获取当前下级及其子级
  3724. $child_group = [$child];
  3725. $recursive_children = $this->getRecursiveChildren($child);
  3726. $child_group = array_merge($child_group, $recursive_children);
  3727. // 获取当前分组的业绩和人数
  3728. $result = $this->getteampv($child_group);
  3729. // if($user_id == 593){
  3730. // var_dump($result);
  3731. // }
  3732. // 将直属下级的业绩和人数加入数组
  3733. $all_departments[] = [
  3734. 'value' => $result['totalPv'],
  3735. 'count' => $result['totalUsers']
  3736. ];
  3737. }
  3738. // 将传入的 $bigamount 和 $smallamount 以及对应的人数加入数组
  3739. $all_departments[] = [
  3740. 'value' => $bigamount,
  3741. 'count' => $common_nums // 大部门的人数
  3742. ];
  3743. $all_departments[] = [
  3744. 'value' => $smallamount,
  3745. 'count' => $person_nums // 小部门的人数
  3746. ];
  3747. // 初始化最大部门和小部门
  3748. $max_department = null;
  3749. $small_department = [
  3750. 'value' => 0,
  3751. 'count' => 0
  3752. ];
  3753. // 遍历 $all_departments,找出最大值并累加小部门的值
  3754. foreach ($all_departments as $department) {
  3755. if ($max_department === null || $department['value'] > $max_department['value']) {
  3756. // 如果当前部门的业绩大于最大部门的业绩,更新最大部门
  3757. $small_department['value'] += $max_department['value'] ?? 0; // 将旧的最大值累加到小部门
  3758. $small_department['count'] += $max_department['count'] ?? 0;
  3759. $max_department = $department; // 更新最大部门
  3760. } else {
  3761. // 如果当前部门的业绩小于或等于最大部门的业绩,累加到小部门
  3762. $small_department['value'] += $department['value'];
  3763. $small_department['count'] += $department['count'];
  3764. }
  3765. }
  3766. // 返回结果
  3767. return [
  3768. 'big_department' => $max_department,
  3769. 'small_department' => $small_department
  3770. ];
  3771. }
  3772. // 根据父级IDS获取伞下的所有子级ID
  3773. public function getRecursiveChildren_s($parentUid) {
  3774. $result = []; // 用于存储所有子级的 uid
  3775. // 定义递归函数
  3776. $recursion = function ($currentUid) use (&$result, &$recursion) {
  3777. // 查询当前父级的所有直接子级
  3778. $children = Db::name("user")
  3779. ->where("spread_uid", $currentUid)
  3780. ->column("uid"); // 获取子级的 uid 列表
  3781. // 如果没有子级,直接返回
  3782. if (empty($children)) {
  3783. return;
  3784. }
  3785. // 遍历每个子级
  3786. foreach ($children as $childUid) {
  3787. $result[] = $childUid; // 将子级的 uid 添加到结果数组
  3788. $recursion($childUid); // 递归查询子级的子级
  3789. }
  3790. };
  3791. // 从初始父级开始递归查询
  3792. $recursion($parentUid);
  3793. return array_unique($result); // 返回结果数组,并去重
  3794. }
  3795. /**
  3796. * 获取当前用户业绩
  3797. */
  3798. public function userupdates($user_id) {
  3799. //$user_id = 17;
  3800. $children = Db::name("user")
  3801. ->where("spread_uid", $user_id)
  3802. ->select(); // 获取子级的 uid 列表
  3803. $total_pv = 0;
  3804. foreach($children as $k=>$v){
  3805. //$children_pv = Db::name("store_order")->where("uid", $v['uid'])->whereIn("status",[0,1,2,3])->select();
  3806. $children_pv = Db::name("user_sign_gongxian")->where("uid", $v['uid'])->where("status",1)->select();
  3807. foreach($children_pv as $k1=>$v1){
  3808. $total_pv += $v1['number'];
  3809. }
  3810. }
  3811. return $total_pv;
  3812. $userdatas = Db::name("user")->where("uid", $user_id)->find();
  3813. // var_dump($userdatas['user_group']);
  3814. // 如果当前用户是普通消费者的情况下
  3815. if($userdatas['user_group'] == 1){
  3816. if($total_pv != 0){
  3817. if($total_pv >= 1180 && $total_pv < 11800){
  3818. Db::name("user")->where("uid", $user_id)->update(['user_group',2]);
  3819. }
  3820. }
  3821. }
  3822. // 如果当前用户是业务员消费者的情况下
  3823. if($userdatas['user_group'] <= 2){
  3824. if($total_pv != 0){
  3825. if(11800 <= $total_pv){
  3826. Db::name("user")->where("uid", $user_id)->update(['user_group',3]);
  3827. }
  3828. }
  3829. }
  3830. }
  3831. /**
  3832. * 获取当前用户业绩
  3833. */
  3834. public function getPerformance22($user_id) {
  3835. $team_amount = 0;
  3836. $person_amount = 0;
  3837. // $user_id = 17; //598 523 536
  3838. $result_big_team_arr = [];
  3839. $get_teams_comm_datas = [];// 在2.0中获取父级下面的所有团队数据
  3840. // 共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  3841. $common_nums = $this->getCommonNums($user_id);
  3842. // var_dump( $common_nums);
  3843. $get_teams_comm_num = 0;
  3844. $get_teams_comm_pv = 0;
  3845. $get_teams_per_num = 0;// 小部门人数
  3846. // 1.0系统中有下级,需要在2.0中再加下级数据
  3847. if($user_id < 611){
  3848. // 梅红在2.0中的ID是780
  3849. // 用户三峡所有在2.0系统下面的业绩和人数 start
  3850. $child_nums = [];
  3851. // 获取当前用户
  3852. foreach($common_nums as $v){
  3853. $child_nums[] = $this->getRecursiveChildren($v);
  3854. }
  3855. // var_dump($child_nums);
  3856. // 去除空数组,并重新组合有数据的数组
  3857. $filteredData = array_filter($child_nums, function($array) {
  3858. return !empty($array); // 如果数组不为空,则保留
  3859. });
  3860. // 合并所有非空数组
  3861. foreach ($filteredData as $array) {
  3862. $result_big_team_arr = array_merge($result_big_team_arr, $array);
  3863. }
  3864. // var_dump($result_big_team_arr);
  3865. // 获取当前用户下面在2.0中的下级所有PV
  3866. //$get_teams_comm_pv = $this->getteampv($result_big_team_arr);
  3867. $t_pv = $this->getteampv($result_big_team_arr);
  3868. $get_teams_comm_pv =$t_pv['totalPv'];
  3869. // var_dump($t_pv);echo "ttt";
  3870. // 获取当前用户下面在2.0中的下级所有人数
  3871. $get_teams_comm_num = count($result_big_team_arr);
  3872. // 用户伞下小部门所有在2.0系统下面的业绩和人数 end
  3873. }else{
  3874. // 当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
  3875. $child_nums = $this->getChildren($user_id);
  3876. // 获取父级子级下面的个人
  3877. $num_teams = $this->getTeamSize($child_nums);
  3878. // var_dump($num_teams);
  3879. foreach($child_nums as $v){
  3880. $get_teams_comm_datas[] = $this->getTeamPv11($v);// 如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
  3881. }
  3882. //$s = $this->getparents_child_pv($user_id);
  3883. // var_dump($get_teams_comm_datas);
  3884. // 如果只有一个部门,就是默认大部门
  3885. if( count($get_teams_comm_datas) ==1 ){
  3886. $get_teams_comm_pv =$get_teams_comm_datas[0];
  3887. $get_teams_comm_num = $num_teams[0]['total_count'];
  3888. }else if(count($get_teams_comm_datas) >1){
  3889. // var_dump( $get_teams_comm_datas);
  3890. // 获取一个最大值,设为大部门,其他的加载一块是小部门
  3891. $getss = $this->processArray($get_teams_comm_datas);
  3892. $max_value_count = $num_teams[$getss['max_index']]['total_count'];
  3893. unset($num_teams[$getss['max_index']]);
  3894. // 获取小部门的人数
  3895. $per_num = 0;
  3896. foreach($num_teams as $k=>$v){
  3897. $per_num +=$v['total_count'];
  3898. }
  3899. // 找到最大值的(大部门)
  3900. $get_teams_comm_num = $max_value_count;
  3901. // 小部门的数量
  3902. $get_teams_per_num = $per_num;
  3903. // var_dump($getss['max_value']);
  3904. $person_amount = $getss['remaining_sum'];
  3905. $get_teams_comm_pv = $getss['max_value'];
  3906. }
  3907. }
  3908. // var_dump($get_teams_comm_pv);
  3909. // 合并业绩和人数
  3910. $team_amount += $get_teams_comm_pv;
  3911. // var_dump($team_amount);
  3912. // 1.0获取小区业绩
  3913. $person_nums = $this->getPersonageNums($user_id);
  3914. // var_dump($person_nums);
  3915. $result_small_team_arr = [];
  3916. // 1.0系统中有下级,需要在2.0中再加下级数据
  3917. // 用户三峡所有在2.0系统下面的业绩和人数 start
  3918. $child_nums_mix = [];
  3919. // 获取当前用户
  3920. foreach($person_nums as $v){
  3921. $child_nums_mix[] = $this->getRecursiveChildren($v);
  3922. }
  3923. // 去除空数组,并重新组合有数据的数组
  3924. $filteredData_1 = array_filter($child_nums_mix, function($array) {
  3925. return !empty($array); // 如果数组不为空,则保留
  3926. });
  3927. // 合并所有非空数组
  3928. $result_small_team_arr = [];
  3929. foreach ($filteredData_1 as $array) {
  3930. $result_small_team_arr = array_merge($result_small_team_arr, $array);
  3931. }
  3932. // var_dump($result_small_team_arr);
  3933. // 获取当前用户下面在2.0中的下级所有PV
  3934. // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
  3935. $t_pv = $this->getteampv($result_small_team_arr);
  3936. $get_teams_per_pv =$t_pv['totalPv'];
  3937. // var_dump( $get_teams_per_pv);
  3938. // 获取当前用户下面在2.0中的下级所有人数
  3939. $get_teams_per_num += count($result_small_team_arr);
  3940. // 合并业绩和人数
  3941. $person_amount += $get_teams_per_pv;
  3942. // if($user_id == 593){
  3943. // $person_amount = 2800;
  3944. // }
  3945. // var_dump($person_amount);
  3946. // 用户小部门所有在2.0系统下面的业绩和人数 end
  3947. // var_dump($team_amount);
  3948. // $common_nums[] = $user_id;
  3949. foreach ($common_nums as $key => $value) {
  3950. # code...
  3951. $amount = $this->getPerformance1($value);
  3952. $team_amount += $amount;
  3953. }
  3954. foreach ($person_nums as $key => $value) {
  3955. # code...
  3956. $amount = $this->getPerformance1($value);
  3957. $person_amount += $amount;
  3958. }
  3959. // var_dump($team_amount);
  3960. // var_dump($person_amount);
  3961. //
  3962. // var_dump($team_amount);
  3963. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
  3964. //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
  3965. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  3966. $money1180Sum = 0;
  3967. foreach ($user_team_amount as $record) {
  3968. $money1180Sum += $record['money'] - 300 - 180;
  3969. }
  3970. // var_dump($money1180Sum );
  3971. // 获取 status 为 1 且 money 为 11800 的记录集合
  3972. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
  3973. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  3974. $money11800Sum = 0;
  3975. foreach ($money11800Records as $record) {
  3976. $money11800Sum += $record['money'] - 3000 - 1800;
  3977. }
  3978. // var_dump($money11800Sum );
  3979. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
  3980. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  3981. $money10620Sum = 0;
  3982. foreach ($money10620Records as $record) {
  3983. $money10620Sum += $record['money'] - 2700 - 1620;
  3984. }
  3985. // var_dump($money10620Sum );
  3986. // 计算除去特定值后的总和
  3987. //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
  3988. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  3989. $otherMoneySum = 0;
  3990. foreach ($otherMoneyRecords as $record) {
  3991. $otherMoneySum += $record['money'];
  3992. }
  3993. // 分别处理特定值的情况并加上其他值的总和
  3994. $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  3995. // var_dump($all_record_nums);
  3996. $team_amount += $all_record_nums;
  3997. // var_dump($team_amount);
  3998. // 计算自己的个人联盟总流水
  3999. // // //计算自己的个人联盟总流水
  4000. // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
  4001. // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  4002. // $person_amount += $user_person_amount;
  4003. // 计算个人的1180单价的业绩 集合
  4004. $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
  4005. $money1180Sum = 0;
  4006. foreach ($money1180Records as $record) {
  4007. $money1180Sum += $record['money'] - 300 - 180;
  4008. }
  4009. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
  4010. // var_dump($person_nums);
  4011. // 计算个人的11800单价的业绩 集合
  4012. $money11800Sum = 0;
  4013. foreach ($money11800Records as $record) {
  4014. $money11800Sum += $record['money'] - 3000 - 1800;
  4015. }
  4016. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
  4017. // var_dump($person_nums);
  4018. // 计算个人的10620单价的业绩 集合
  4019. $money10620Sum = 0;
  4020. foreach ($money10620Records as $record) {
  4021. $money10620Sum += $record['money'] - 2700 - 1620;
  4022. }
  4023. // 计算除去特定值后的总和
  4024. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4025. $otherMoneySum = 0;
  4026. foreach ($otherMoneyRecords as $record) {
  4027. $otherMoneySum += $record['money'];
  4028. }
  4029. // 分别处理特定值的情况并加上其他值的总和
  4030. $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
  4031. $person_amount += $user_person_amount;
  4032. // 大部门人数
  4033. $teams_num = count($common_nums) + $get_teams_comm_num;
  4034. // 小部门人数
  4035. $per_num = count($person_nums) + $get_teams_per_num;
  4036. // var_dump($team_amount);
  4037. // var_dump($person_amount);
  4038. // 如果当前用户是1.0用户,找到其直推所有的业绩,根据业绩找到大小部门的同时,还要比对1.0中大小部门的业绩,摘出一个最大业绩的部门是大部门,其余都是小部门()
  4039. if($user_id < 611){
  4040. // var_dump($team_amount);
  4041. // var_dump($person_amount);
  4042. // 获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
  4043. // 例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
  4044. $b_s = $this->getparents_child_pv11($user_id,$team_amount,$person_amount,count($common_nums)+ $get_teams_comm_num,count($person_nums)+ $get_teams_per_num);
  4045. // var_dump($b_s);
  4046. // var_dump($team_amount,$person_amount);
  4047. // var_dump(count($common_nums)+ $get_teams_comm_num,count($person_nums)+ $get_teams_per_num);
  4048. // var_dump( $b_s);echo "yyyyyyyyyyyyy";
  4049. $team_amount = $b_s['big_department']['value'];
  4050. $teams_num = $b_s['big_department']['count'];
  4051. // var_dump($b_s['team_pv']);
  4052. // var_dump($b_s['per_pv']);
  4053. $person_amount = $b_s['small_department']['value'];
  4054. $per_num = $b_s['small_department']['count'];// 小部门人数
  4055. // var_dump( $b_s['team_num'],$b_s['per_num']);
  4056. }
  4057. // 级别信息
  4058. $userInfo = Db::name("user")->find($user_id);//
  4059. $zk_level = 4;
  4060. $is_zk = false;
  4061. if($userInfo['user_level_id_old'] == $zk_level) {
  4062. $is_zk = true;
  4063. $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
  4064. $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
  4065. } else{
  4066. $sales_incentive = 0;
  4067. }
  4068. $return_data = [
  4069. 'common_nums'=>$teams_num,
  4070. 'person_nums'=>$per_num,
  4071. 'common_nums_pv'=> $team_amount,
  4072. 'person_nums_pv'=> $person_amount,
  4073. 'sum_nums_pv' =>$team_amount + $person_amount,
  4074. 'sales_incentive' => $sales_incentive,
  4075. "is_zk"=>$is_zk
  4076. ];
  4077. return $return_data;
  4078. }
  4079. /**
  4080. * 获取当前用户业绩
  4081. */
  4082. public function getPerformance($user_id) {
  4083. $team_amount = 0;
  4084. $person_amount = 0;
  4085. $result_big_team_arr = [];
  4086. $get_teams_comm_datas = [];// 在2.0中获取父级下面的所有团队数据
  4087. // 共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  4088. $common_nums = $this->getCommonNums($user_id);
  4089. // var_dump($user_id);
  4090. $get_teams_comm_num = 0;
  4091. $get_teams_comm_pv = 0;
  4092. $get_teams_per_num = 0;// 小部门人数
  4093. // 1.0系统中有下级,需要在2.0中再加下级数据
  4094. if($user_id < 611){
  4095. // 梅红在2.0中的ID是780
  4096. // if($user_id == 593){
  4097. // $common_nums[] = 780;
  4098. // unset($common_nums[0]);
  4099. // }
  4100. // var_dump($common_nums);
  4101. // 用户三峡所有在2.0系统下面的业绩和人数 start
  4102. $child_nums = [];
  4103. // 再加上当前用户直属的子级
  4104. $common_ns = $common_nums;
  4105. $common_ns[] = $user_id;
  4106. // var_dump($common_ns);return;
  4107. // 获取当前用户
  4108. foreach($common_nums as $v){
  4109. $child_nums[] = $this->getRecursiveChildren($v);
  4110. }
  4111. // 梅红在2.0中的ID是780
  4112. // if($user_id == 593){
  4113. // $child_nums[0][] = 780;
  4114. // }
  4115. // 去除空数组,并重新组合有数据的数组
  4116. $filteredData = array_filter($child_nums, function($array) {
  4117. return !empty($array); // 如果数组不为空,则保留
  4118. });
  4119. // 合并所有非空数组
  4120. foreach ($filteredData as $array) {
  4121. $result_big_team_arr = array_merge($result_big_team_arr, $array);
  4122. }
  4123. // var_dump($result_big_team_arr);echo "ppppppppppppppppp";
  4124. // 获取当前用户下面在2.0中的下级所有PV
  4125. $t_pv = $this->getteampv($result_big_team_arr);
  4126. $get_teams_comm_pv =$t_pv['totalPv'];
  4127. // if($user_id == 593){
  4128. // $get_teams_comm_pv = 7000;
  4129. // }
  4130. // var_dump($get_teams_comm_pv);
  4131. // 获取当前用户下面在2.0中的下级所有人数
  4132. $get_teams_comm_num = count($result_big_team_arr);
  4133. // 用户伞下小部门所有在2.0系统下面的业绩和人数 end
  4134. }else{
  4135. // 当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
  4136. $child_nums = $this->getChildren($user_id);
  4137. // 获取父级子级下面的个人
  4138. $num_teams = $this->getTeamSize($child_nums);
  4139. foreach($child_nums as $v){
  4140. $get_teams_comm_datas[] = $this->getTeamPv11($v);// 如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
  4141. }
  4142. if( count($get_teams_comm_datas) ==1 ){
  4143. $get_teams_comm_pv =$get_teams_comm_datas[0];
  4144. $get_teams_comm_num = $num_teams[0]['total_count'];
  4145. }else if(count($get_teams_comm_datas) >1){
  4146. // $getss = $this->processArray($get_teams_comm_datas);
  4147. // $team_datas = $num_teams[$getss['max_index']];
  4148. // var_dump( $get_teams_comm_datas);
  4149. // 获取一个最大值,设为大部门,其他的加载一块是小部门
  4150. $getss = $this->processArray($get_teams_comm_datas);
  4151. $max_value_count = $num_teams[$getss['max_index']]['total_count'];
  4152. unset($num_teams[$getss['max_index']]);
  4153. // 获取小部门的人数
  4154. $per_num = 0;
  4155. foreach($num_teams as $k=>$v){
  4156. $per_num +=$v['total_count'];
  4157. }
  4158. // 找到最大值的(大部门)
  4159. $get_teams_comm_num = $max_value_count;
  4160. // 小部门的数量
  4161. $get_teams_per_num = $per_num;
  4162. // var_dump($getss['max_value']);
  4163. $person_amount = $getss['remaining_sum'];
  4164. $get_teams_comm_pv = $getss['max_value'];
  4165. }
  4166. }
  4167. // 合并业绩和人数
  4168. $team_amount += $get_teams_comm_pv;
  4169. // var_dump($team_amount);
  4170. // 1.0获取小区业绩
  4171. $person_nums = $this->getPersonageNums($user_id);
  4172. // var_dump($person_nums);
  4173. $result_small_team_arr = [];
  4174. // 1.0系统中有下级,需要在2.0中再加下级数据
  4175. // 用户三峡所有在2.0系统下面的业绩和人数 start
  4176. $child_nums_mix = [];
  4177. // 再加上当前用户直属的子级
  4178. $common_ns1 = $person_nums;
  4179. $common_ns1[] = $user_id;
  4180. // 获取当前用户
  4181. foreach($person_nums as $v){
  4182. $child_nums_mix[] = $this->getRecursiveChildren($v);
  4183. }
  4184. // 去除空数组,并重新组合有数据的数组
  4185. $filteredData_1 = array_filter($child_nums_mix, function($array) {
  4186. return !empty($array); // 如果数组不为空,则保留
  4187. });
  4188. // 合并所有非空数组
  4189. $result_small_team_arr = [];
  4190. foreach ($filteredData_1 as $array) {
  4191. $result_small_team_arr = array_merge($result_small_team_arr, $array);
  4192. }
  4193. // 获取当前用户下面在2.0中的下级所有PV
  4194. // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
  4195. $t_pv = $this->getteampv($result_small_team_arr);
  4196. $get_teams_per_pv =$t_pv['totalPv'];
  4197. // 获取当前用户下面在2.0中的下级所有人数
  4198. $get_teams_per_num += count($result_small_team_arr);
  4199. // 合并业绩和人数
  4200. $person_amount += $get_teams_per_pv;
  4201. // if($user_id == 593){
  4202. // $person_amount = 2800;
  4203. // }
  4204. // var_dump($person_amount);
  4205. // 用户小部门所有在2.0系统下面的业绩和人数 end
  4206. // $common_nums[] = $user_id;
  4207. foreach ($common_nums as $key => $value) {
  4208. # code...
  4209. $amount = $this->getPerformance1($value);
  4210. $team_amount += $amount;
  4211. }
  4212. foreach ($person_nums as $key => $value) {
  4213. # code...
  4214. $amount = $this->getPerformance1($value);
  4215. $person_amount += $amount;
  4216. }
  4217. // var_dump($team_amount);
  4218. // if($user_id < 611){
  4219. // //获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
  4220. // //例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
  4221. // $b_s = $this->getparents_child_pv($user_id);
  4222. // //var_dump( $b_s);echo "yyyyyyyyyyyyy";
  4223. // $team_amount += $b_s['team_pv'];
  4224. // $get_teams_comm_num += $b_s['team_num'];
  4225. // $person_amount += $b_s['per_pv'];
  4226. // $get_teams_per_num += $b_s['per_num'];//小部门人数
  4227. // //var_dump($team_amount,$person_amount );
  4228. // }
  4229. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
  4230. //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
  4231. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  4232. $money1180Sum = 0;
  4233. foreach ($user_team_amount as $record) {
  4234. $money1180Sum += $record['money'] - 300 - 180;
  4235. }
  4236. if($user_id == 593){
  4237. $money1180Sum -= 700;
  4238. }
  4239. // 获取 status 为 1 且 money 为 11800 的记录集合
  4240. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
  4241. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4242. $money11800Sum = 0;
  4243. foreach ($money11800Records as $record) {
  4244. $money11800Sum += $record['money'] - 3000 - 1800;
  4245. }
  4246. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
  4247. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4248. $money10620Sum = 0;
  4249. foreach ($money10620Records as $record) {
  4250. $money10620Sum += $record['money'] - 2700 - 1620;
  4251. }
  4252. // 计算除去特定值后的总和
  4253. //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
  4254. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4255. $otherMoneySum = 0;
  4256. foreach ($otherMoneyRecords as $record) {
  4257. $otherMoneySum += $record['money'];
  4258. }
  4259. // 分别处理特定值的情况并加上其他值的总和
  4260. $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  4261. // var_dump($all_record_nums);
  4262. $team_amount += $all_record_nums;
  4263. // var_dump($user_team_amount);
  4264. // 计算自己的个人联盟总流水
  4265. // // //计算自己的个人联盟总流水
  4266. // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
  4267. // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  4268. // $person_amount += $user_person_amount;
  4269. // 计算个人的1180单价的业绩 集合
  4270. $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
  4271. $money1180Sum = 0;
  4272. foreach ($money1180Records as $record) {
  4273. $money1180Sum += $record['money'] - 300 - 180;
  4274. }
  4275. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
  4276. // var_dump($person_nums);
  4277. // 计算个人的11800单价的业绩 集合
  4278. $money11800Sum = 0;
  4279. foreach ($money11800Records as $record) {
  4280. $money11800Sum += $record['money'] - 3000 - 1800;
  4281. }
  4282. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
  4283. // var_dump($person_nums);
  4284. // 计算个人的10620单价的业绩 集合
  4285. $money10620Sum = 0;
  4286. foreach ($money10620Records as $record) {
  4287. $money10620Sum += $record['money'] - 2700 - 1620;
  4288. }
  4289. // 计算除去特定值后的总和
  4290. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4291. $otherMoneySum = 0;
  4292. foreach ($otherMoneyRecords as $record) {
  4293. $otherMoneySum += $record['money'];
  4294. }
  4295. // 分别处理特定值的情况并加上其他值的总和
  4296. $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
  4297. $person_amount += $user_person_amount;
  4298. // //临时设置
  4299. // if($user_id == 536){
  4300. // $person_amount = 2800;
  4301. // $team_amount = 7000;
  4302. // }
  4303. // //临时设置
  4304. // if($user_id == 222){
  4305. // $person_amount = 2800;
  4306. // $team_amount = 11900;
  4307. // }
  4308. // 大部门人数
  4309. $teams_num = count($common_nums) + $get_teams_comm_num;
  4310. // 小部门人数
  4311. $per_num = count($person_nums) + $get_teams_per_num;
  4312. // 如果当前用户是1.0用户,找到其直推所有的业绩,根据业绩找到大小部门的同时,还要比对1.0中大小部门的业绩,摘出一个最大业绩的部门是大部门,其余都是小部门()
  4313. if($user_id < 611){
  4314. // var_dump($team_amount);
  4315. // var_dump($person_amount);
  4316. // 获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
  4317. // 例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
  4318. $b_s = $this->getparents_child_pv11($user_id,$team_amount,$person_amount,count($common_nums)+ $get_teams_comm_num,count($person_nums)+ $get_teams_per_num);
  4319. // var_dump($b_s);
  4320. // var_dump($team_amount,$person_amount);
  4321. // var_dump(count($common_nums)+ $get_teams_comm_num,count($person_nums)+ $get_teams_per_num);
  4322. // var_dump( $b_s);echo "yyyyyyyyyyyyy";
  4323. $team_amount = $b_s['big_department']['value'];
  4324. $teams_num = $b_s['big_department']['count'];
  4325. // var_dump($b_s['team_pv']);
  4326. // var_dump($b_s['per_pv']);
  4327. $person_amount = $b_s['small_department']['value'];
  4328. $per_num = $b_s['small_department']['count'];// 小部门人数
  4329. // var_dump( $b_s['team_num'],$b_s['per_num']);
  4330. }
  4331. // 级别信息
  4332. $userInfo = Db::name("user")->find($user_id);//
  4333. $zk_level = 4;
  4334. $is_zk = false;
  4335. if($userInfo['user_level_id_old'] == $zk_level) {
  4336. $is_zk = true;
  4337. $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
  4338. $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
  4339. } else{
  4340. $sales_incentive = 0;
  4341. }
  4342. $return_data = [
  4343. 'common_nums' => $teams_num,
  4344. 'person_nums' => $per_num,
  4345. 'common_nums_pv'=> $team_amount,
  4346. 'person_nums_pv'=> $person_amount,
  4347. 'sum_nums_pv' =>$team_amount + $person_amount,
  4348. 'sales_incentive' => $sales_incentive,
  4349. "is_zk"=>$is_zk
  4350. ];
  4351. return $return_data;
  4352. }
  4353. /**
  4354. * 获取当前用户业绩
  4355. */
  4356. public function getPerformance_copy($user_id) {
  4357. // $user_id = $this->request->post("user_id");
  4358. // 共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  4359. $common_nums = $this->getCommonNums($user_id);
  4360. // 1.0获取小区业绩
  4361. $person_nums = $this->getPersonageNums($user_id);
  4362. // return $person_nums;
  4363. // var_dump( $common_nums);
  4364. $team_amount = 0;
  4365. $person_amount = 0;
  4366. // $common_nums[] = $user_id;
  4367. foreach ($common_nums as $key => $value) {
  4368. # code...
  4369. $amount = $this->getPerformance1($value);
  4370. $team_amount += $amount;
  4371. }
  4372. foreach ($person_nums as $key => $value) {
  4373. # code...
  4374. $amount = $this->getPerformance1($value);
  4375. $person_amount += $amount;
  4376. }
  4377. // var_dump($team_amount);
  4378. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
  4379. //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
  4380. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  4381. $money1180Sum = 0;
  4382. foreach ($user_team_amount as $record) {
  4383. $money1180Sum += $record['money'] - 300 - 180;
  4384. }
  4385. // 获取 status 为 1 且 money 为 11800 的记录集合
  4386. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
  4387. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4388. $money11800Sum = 0;
  4389. foreach ($money11800Records as $record) {
  4390. $money11800Sum += $record['money'] - 3000 - 1800;
  4391. }
  4392. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
  4393. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4394. $money10620Sum = 0;
  4395. foreach ($money10620Records as $record) {
  4396. $money10620Sum += $record['money'] - 2700 - 1620;
  4397. }
  4398. // 计算除去特定值后的总和
  4399. //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
  4400. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4401. $otherMoneySum = 0;
  4402. foreach ($otherMoneyRecords as $record) {
  4403. $otherMoneySum += $record['money'];
  4404. }
  4405. // 分别处理特定值的情况并加上其他值的总和
  4406. $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  4407. // var_dump($all_record_nums);
  4408. $team_amount += $all_record_nums;
  4409. // 计算自己的个人联盟总流水
  4410. // // //计算自己的个人联盟总流水
  4411. // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
  4412. // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  4413. // $person_amount += $user_person_amount;
  4414. // 计算个人的1180单价的业绩 集合
  4415. $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
  4416. $money1180Sum = 0;
  4417. foreach ($money1180Records as $record) {
  4418. $money1180Sum += $record['money'] - 300 - 180;
  4419. }
  4420. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
  4421. // var_dump($person_nums);
  4422. // 计算个人的11800单价的业绩 集合
  4423. $money11800Sum = 0;
  4424. foreach ($money11800Records as $record) {
  4425. $money11800Sum += $record['money'] - 3000 - 1800;
  4426. }
  4427. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
  4428. // var_dump($person_nums);
  4429. // 计算个人的10620单价的业绩 集合
  4430. $money10620Sum = 0;
  4431. foreach ($money10620Records as $record) {
  4432. $money10620Sum += $record['money'] - 2700 - 1620;
  4433. }
  4434. // 计算除去特定值后的总和
  4435. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4436. $otherMoneySum = 0;
  4437. foreach ($otherMoneyRecords as $record) {
  4438. $otherMoneySum += $record['money'];
  4439. }
  4440. // 分别处理特定值的情况并加上其他值的总和
  4441. $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
  4442. $person_amount += $user_person_amount;
  4443. // 级别信息
  4444. $userInfo = Db::name("user")->find($user_id);//
  4445. $zk_level = 4;
  4446. $is_zk = false;
  4447. if($userInfo['user_level_id_old'] == $zk_level) {
  4448. $is_zk = true;
  4449. $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
  4450. $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
  4451. } else{
  4452. $sales_incentive = 0;
  4453. }
  4454. $return_data = [
  4455. 'common_nums'=>count($common_nums),
  4456. 'person_nums'=>count($person_nums),
  4457. 'common_nums_pv'=> $team_amount,
  4458. 'person_nums_pv'=> $person_amount,
  4459. 'sum_nums_pv' =>$team_amount + $person_amount,
  4460. 'sales_incentive' => $sales_incentive,
  4461. "is_zk"=>$is_zk
  4462. ];
  4463. return $return_data;
  4464. }
  4465. /**
  4466. * 获取指定用户业绩
  4467. */
  4468. public function getPerformanceOf($user_id) {
  4469. // 共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  4470. $common_nums = $this->getCommonNums($user_id);
  4471. $person_nums = $this->getPersonageNums($user_id);
  4472. $team_amount = 0;
  4473. $person_amount = 0;
  4474. // $common_nums[] = $user_id;
  4475. foreach ($common_nums as $key => $value) {
  4476. # code...
  4477. $amount = $this->getPerformance1($value);
  4478. $team_amount += $amount;
  4479. }
  4480. foreach ($person_nums as $key => $value) {
  4481. # code...
  4482. $amount = $this->getPerformance1($value);
  4483. $person_amount += $amount;
  4484. }
  4485. // return $person_nums;
  4486. // 添加自己共建联盟的流水
  4487. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("spread_id",$user_id)->sum("money");
  4488. $user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
  4489. $team_amount += $user_team_amount;
  4490. // //计算自己的个人联盟总流水
  4491. $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("spread_id",$user_id)->sum("money");
  4492. $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  4493. $person_amount += $user_person_amount;
  4494. $sum_nums_pv = $team_amount + $person_amount;
  4495. $sum_nums_pv = isset($sum_nums_pv) ? $sum_nums_pv :0;
  4496. return $sum_nums_pv;
  4497. }
  4498. /**
  4499. * 获取用户星级
  4500. */
  4501. public function getStarLevel($user_id,$team_money=0,$person_money=0) {
  4502. if(empty($team_money)) {
  4503. $common_nums = $this->getCommonNums($user_id);
  4504. $team_money = 0;
  4505. foreach ($common_nums as $key => $value) {
  4506. # code...
  4507. $amount = $this->getPerformance1($value);
  4508. $team_money += $amount;
  4509. }
  4510. // 计算自己的共建联盟流水
  4511. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->sum("money");
  4512. $user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
  4513. $team_money += $user_team_amount;
  4514. }else{
  4515. $common_nums = $this->getCommonNums($user_id);
  4516. }
  4517. if(empty($person_money)) {
  4518. $person_nums = $this->getPersonageNums($user_id);
  4519. $person_amount = 0;
  4520. foreach ($person_nums as $key => $value) {
  4521. # code...
  4522. $amount = $this->getPerformance1($value);
  4523. $person_amount += $amount;
  4524. }
  4525. $person_money = $person_amount;
  4526. // 计算自己的个人联盟总流水
  4527. $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->sum("money");
  4528. $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  4529. $person_money += $user_person_amount;
  4530. }else{
  4531. $person_nums = $this->getPersonageNums($user_id);
  4532. }
  4533. $slow = $person_money;
  4534. if($team_money < $person_money) {
  4535. $slow = $team_money;
  4536. }
  4537. $sum_money = $team_money + $person_money;
  4538. // $data = ['sum_money'=>$sum_money,"team_money"=>$team_money,"person_money"=>$person_money];
  4539. // $this->error(0,$data);
  4540. $star_list = Db::name("old_user_star")->order("statement_all_num desc")->select();
  4541. $start_level = "";
  4542. foreach ($star_list as $key => $value) {
  4543. # code...
  4544. if( $sum_money>=$value['statement_all_num'] && $slow >= $value['person_statement']) {
  4545. return $value;
  4546. }
  4547. }
  4548. return $start_level;
  4549. }
  4550. /**
  4551. * 获取流水信息
  4552. */
  4553. public function getPerformance1($user_id) {
  4554. // $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money");
  4555. // $amount = isset($amount) ? round($amount*0.7,2) : 0;
  4556. // return $amount;
  4557. $money1180Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",1180)->where("status",1)->select();
  4558. $money1180Sum = 0;
  4559. foreach ($money1180Records as $record) {
  4560. $money1180Sum += $record['money'] - 300 - 180;
  4561. }
  4562. // var_dump($money1180Sum);
  4563. $money11800Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",11800)->where("status",1)->select();
  4564. // var_dump($person_nums);
  4565. // 计算个人的11800单价的业绩 集合
  4566. $money11800Sum = 0;
  4567. foreach ($money11800Records as $record) {
  4568. $money11800Sum += $record['money'] - 3000 - 1800;
  4569. }
  4570. $money10620Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",10620)->where("status",1)->select();
  4571. // var_dump($person_nums);
  4572. // 计算个人的11800单价的业绩 集合
  4573. $money10620Sum = 0;
  4574. foreach ($money10620Records as $record) {
  4575. $money10620Sum += $record['money'] - 2700 - 1620;
  4576. }
  4577. // 计算除去特定值后的总和
  4578. $otherMoneyRecords = Db::name("old_user_of_goods")->where("node_id",$user_id)->where('status', 1)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4579. $otherMoneySum = 0;
  4580. foreach ($otherMoneyRecords as $record) {
  4581. $otherMoneySum += $record['money'];
  4582. }
  4583. // 分别处理特定值的情况并加上其他值的总和
  4584. $user_person_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  4585. return $user_person_amount;
  4586. }
  4587. /**
  4588. * 获取个人业绩统计信息
  4589. */
  4590. public function getPerformanceOfId($user_id)
  4591. {
  4592. // var_dump($user_id);
  4593. // 联盟总人数 共建联盟人数 个人联盟人数 总流水 共建联盟流水 个人联盟流水 所属星级(钻卡专属)
  4594. $common_nums = $this->getCommonNums($user_id);
  4595. $person_nums = $this->getPersonageNums($user_id);
  4596. // 联盟业绩 查询 共建联盟业绩 个人联盟业绩
  4597. $team_amount = 0;
  4598. $person_amount = 0;
  4599. // $common_nums[] = $user_id;
  4600. foreach ($common_nums as $key => $value) {
  4601. # code...
  4602. $amount = $this->getPerformance1($value);
  4603. $team_amount += $amount;
  4604. }
  4605. // 计算自己的共建联盟流水
  4606. //$user_team_amount = Db::name("user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where("status",1)->sum("money");
  4607. // $this->error(0,$team_amount);
  4608. //$user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
  4609. $money1180Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 1180)->select();
  4610. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  4611. $money1180Sum = 0;
  4612. foreach ($money1180Records as $record) {
  4613. $money1180Sum += $record['money'] - 300 - 180;
  4614. }
  4615. // 获取 status 为 1 且 money 为 11800 的记录集合
  4616. $money11800Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 11800)->select();
  4617. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4618. $money11800Sum = 0;
  4619. foreach ($money11800Records as $record) {
  4620. $money11800Sum += $record['money'] - 3000 - 1800;
  4621. }
  4622. // 获取 status 为 1 且 money 为 11800 的记录集合
  4623. $money10620Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 10620)->select();
  4624. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4625. $money10620Sum = 0;
  4626. foreach ($money10620Records as $record) {
  4627. $money10620Sum += $record['money'] - 2700 - 1620;
  4628. }
  4629. // 计算除去特定值后的总和
  4630. $otherMoneyRecords = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->whereNotIn('money', [1180, 11800,10620])->select();
  4631. $otherMoneySum = 0;
  4632. foreach ($otherMoneyRecords as $record) {
  4633. $otherMoneySum += $record['money'];
  4634. }
  4635. // 分别处理特定值的情况并加上其他值的总和
  4636. $user_team_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  4637. $team_amount += $user_team_amount;
  4638. foreach ($person_nums as $key => $value) {
  4639. # code...
  4640. $amount = $this->getPerformance1($value);
  4641. $person_amount += $amount;
  4642. }
  4643. // //计算自己的个人联盟总流水
  4644. $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("status",1)->sum("money");
  4645. $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  4646. $person_amount += $user_person_amount;
  4647. // $this->error(0,$common_nums);
  4648. return $team_amount + $person_amount;
  4649. }
  4650. /**
  4651. * 获取该用户共建联盟
  4652. */
  4653. public function getCommonNums($user_id){
  4654. // 先获取共建联盟下用户的id
  4655. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->select()->toArray();
  4656. $new_array_ids =[];
  4657. foreach ($son_ids as $key => $value) {
  4658. # code...
  4659. $son_id = $value['id'];
  4660. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  4661. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  4662. if(count($son_value_ids) > 0) {
  4663. $son_value_ids = array_column($son_value_ids,"id");
  4664. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  4665. }
  4666. }
  4667. return $new_array_ids;
  4668. }
  4669. /**
  4670. * 获取该用户个人联盟
  4671. */
  4672. public function getPersonageNums($user_id){
  4673. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("id")->select();
  4674. $new_array_ids =[];
  4675. // return 3343;
  4676. foreach ($son_ids as $key => $value) {
  4677. # code...
  4678. $son_id = $value['id'];
  4679. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  4680. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  4681. if(count($son_value_ids) > 0) {
  4682. $son_value_ids = array_column($son_value_ids,"id");
  4683. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  4684. }
  4685. }
  4686. return $new_array_ids;
  4687. }
  4688. // 获取团队递归聚宝盆1
  4689. public function teamPeople( $user_id,$type){
  4690. // var_dump($type);
  4691. //$ftype = 1:大部门,0:小部门
  4692. // 业绩小是小部门,业绩大是大部门
  4693. if($type == 1) {
  4694. $list = Db::name("old_user_jbp")
  4695. ->where("spread", $user_id)
  4696. ->where("is_team", 1)
  4697. ->field("user_name, id")
  4698. ->select()
  4699. ->toArray();
  4700. $list = $this->get_yj_amount($list,1);
  4701. $list1 = Db::name("old_user_jbp")
  4702. ->where("spread", $user_id)
  4703. ->where("is_team", 0)
  4704. ->field("user_name, id")
  4705. ->select()
  4706. ->toArray();
  4707. $list1 = $this->get_yj_amount($list1, 0);
  4708. // 检查数组和字段是否存在
  4709. if (isset($list[0]['performance']['common_nums_pv']) && isset($list1[0]['performance']['common_nums_pv'])) {
  4710. // 如果$list的值小于或等于$list1的值,选择$list
  4711. if ($list[0]['performance']['common_nums_pv'] <= $list1[0]['performance']['common_nums_pv']) {
  4712. return $list1;
  4713. } else {
  4714. return $list;
  4715. }
  4716. } elseif (isset($list[0]['performance']['common_nums_pv'])) {
  4717. // 如果只有$list有值,返回$list
  4718. return $list;
  4719. } elseif (isset($list1[0]['performance']['common_nums_pv'])) {
  4720. // 如果只有$list1有值,返回$list1
  4721. return $list1;
  4722. } else {
  4723. // 如果两个数组都没有该字段,返回空数组
  4724. return [];
  4725. }
  4726. }else if($type == 0) {
  4727. $list = Db::name("old_user_jbp")
  4728. ->where("spread", $user_id)
  4729. ->where("is_team", 1)
  4730. ->field("user_name, id")
  4731. ->select()
  4732. ->toArray();
  4733. $list = $this->get_yj_amount($list,1);
  4734. $list1 = Db::name("old_user_jbp")
  4735. ->where("spread", $user_id)
  4736. ->where("is_team", 0)
  4737. ->field("user_name, id")
  4738. ->select()
  4739. ->toArray();
  4740. $list1 = $this->get_yj_amount($list1, 0);
  4741. // 检查数组和字段是否存在
  4742. if (isset($list[0]['performance']['common_nums_pv']) && isset($list1[0]['performance']['common_nums_pv'])) {
  4743. // 如果$list的值小于或等于$list1的值,选择$list
  4744. if ($list[0]['performance']['common_nums_pv'] <= $list1[0]['performance']['common_nums_pv']) {
  4745. return $list;
  4746. } else {
  4747. return $list1;
  4748. }
  4749. } elseif (isset($list[0]['performance']['common_nums_pv'])) {
  4750. // 如果只有$list有值,返回$list
  4751. return $list;
  4752. } elseif (isset($list1[0]['performance']['common_nums_pv'])) {
  4753. // 如果只有$list1有值,返回$list1
  4754. return $list1;
  4755. } else {
  4756. // 如果两个数组都没有该字段,返回空数组
  4757. return [];
  4758. }
  4759. }else if($type == 2){
  4760. $list = Db::name("user")->where("spread_uid",$user_id)->field("nickname,uid,avatar")->select()->toArray();
  4761. return $list;
  4762. }
  4763. // foreach ($list as $key => $value) {
  4764. // $list[$key]['user_name'] = $value['user_name'] . "业绩";
  4765. // $list[$key]['performance'] = $this->getPerformance($value['id']);
  4766. // //辨别当前是大部门还是小部门。用于显示大小业绩展示
  4767. // $list[$key]['curr_type'] = '';
  4768. // if($type == 1){
  4769. // $list[$key]['curr_type'] = 1;
  4770. // }else if($type == 0){
  4771. // $list[$key]['curr_type'] = 0;
  4772. // }else{
  4773. // $list[$key]['curr_type'] = '';
  4774. // }
  4775. // }
  4776. return $list;
  4777. }
  4778. public function get_yj_amount($list,$type){
  4779. foreach ($list as $key => $value) {
  4780. # code...
  4781. // $amount = $this->getPerformanceOfId($value['id']);
  4782. $list[$key]['user_name'] = $value['user_name'] . "业绩";
  4783. //$list[$key]['total_performance'] = $amount;
  4784. //$performance = $this->getPerformanceOfId($search_name['id']);
  4785. $list[$key]['performance'] = $this->getPerformance($value['id']);
  4786. // 辨别当前是大部门还是小部门。用于显示大小业绩展示
  4787. $list[$key]['curr_type'] = '';
  4788. if($type == 1){
  4789. $list[$key]['curr_type'] = 1;
  4790. }else if($type == 0){
  4791. $list[$key]['curr_type'] = 0;
  4792. }else{
  4793. $list[$key]['curr_type'] = '';
  4794. }
  4795. }
  4796. return $list;
  4797. }
  4798. // 获取团队递归聚宝盆1
  4799. public function teamPeople_copy( $user_id,$type){
  4800. // var_dump($type);
  4801. //$ftype = 1:大部门,0:小部门
  4802. //$user_id = $this->request->post("user_id");
  4803. //$type = $this->request->post("type",0);
  4804. // 查找当前用户id下节点
  4805. if($type == 1) {
  4806. // echo 33;
  4807. $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->field("user_name,id")->select()->toArray();
  4808. }else if($type == 0) {
  4809. // echo 44;
  4810. $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("user_name,id")->select()->toArray();
  4811. }else if($type == 2){
  4812. $list = Db::name("user")->where("spread_uid",$user_id)->field("nickname,uid")->select()->toArray();
  4813. return $list;
  4814. }else {
  4815. // echo 55;
  4816. $list = Db::name("old_user_jbp")->where("spread",$user_id)->field("user_name,id")->select()->toArray();
  4817. }
  4818. foreach ($list as $key => $value) {
  4819. # code...
  4820. // $amount = $this->getPerformanceOfId($value['id']);
  4821. $list[$key]['user_name'] = $value['user_name'] . "业绩";
  4822. //$list[$key]['total_performance'] = $amount;
  4823. //$performance = $this->getPerformanceOfId($search_name['id']);
  4824. $list[$key]['performance'] = $this->getPerformance($value['id']);
  4825. // 辨别当前是大部门还是小部门。用于显示大小业绩展示
  4826. $list[$key]['curr_type'] = '';
  4827. if($type == 1){
  4828. $list[$key]['curr_type'] = 1;
  4829. }else if($type == 0){
  4830. $list[$key]['curr_type'] = 0;
  4831. }else{
  4832. $list[$key]['curr_type'] = '';
  4833. }
  4834. }
  4835. return $list;
  4836. }
  4837. // //获取团队递归聚宝盆1
  4838. // public function teamPeople( $user_id,$type){
  4839. // //$user_id = $this->request->post("user_id");
  4840. // //$type = $this->request->post("type",0);
  4841. // //查找当前用户id下节点
  4842. // if($type == 1) {
  4843. // $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->field("user_name,id")->select()->toArray();
  4844. // }else if($type == 2) {
  4845. // $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("user_name,id")->select()->toArray();
  4846. // }else {
  4847. // $list = Db::name("old_user_jbp")->where("spread",$user_id)->field("user_name,id")->select()->toArray();
  4848. // }
  4849. // foreach ($list as $key => $value) {
  4850. // # code...
  4851. // $amount = $this->getPerformanceOfId($value['id']);
  4852. // $list[$key]['user_name'] = $value['user_name'] . "-----业绩" . $amount;
  4853. // }
  4854. // return $list;
  4855. // }
  4856. // 获取大小部门贡献值
  4857. /**
  4858. * 获取当前用户大小部门贡献值
  4859. */
  4860. public function getPerformance_getcon($user_id) {
  4861. $team_amount = 0;
  4862. $person_amount = 0;
  4863. // $user_id = 593; //598 523 536
  4864. $result_big_team_arr = [];
  4865. $get_teams_comm_datas = [];// 在2.0中获取父级下面的所有团队数据
  4866. // 共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  4867. $common_nums = $this->getCommonNums_getcon($user_id);
  4868. // var_dump($common_nums);
  4869. $get_teams_comm_num = 0;
  4870. $get_teams_comm_pv = 0;
  4871. $get_teams_per_num = 0;// 小部门人数
  4872. // 1.0系统中有下级,需要在2.0中再加下级数据
  4873. if($user_id < 611){
  4874. // 梅红在2.0中的ID是780
  4875. // var_dump( $common_nums);
  4876. // 用户三峡所有在2.0系统下面的业绩和人数 start
  4877. $child_nums = [];
  4878. // 获取当前用户
  4879. foreach($common_nums as $v){
  4880. $child_nums[] = $this->getRecursiveChildren_getcon($v);
  4881. }
  4882. // 去除空数组,并重新组合有数据的数组
  4883. $filteredData = array_filter($child_nums, function($array) {
  4884. return !empty($array); // 如果数组不为空,则保留
  4885. });
  4886. // 合并所有非空数组
  4887. foreach ($filteredData as $array) {
  4888. $result_big_team_arr = array_merge($result_big_team_arr, $array);
  4889. }
  4890. // var_dump($result_big_team_arr);
  4891. // 获取当前用户下面在2.0中的下级所有PV
  4892. //$get_teams_comm_pv = $this->getteampv($result_big_team_arr);
  4893. $t_pv = $this->getteampv_getcon($result_big_team_arr);
  4894. $get_teams_comm_pv = $t_pv;
  4895. // var_dump($get_teams_comm_pv);echo "ttt";
  4896. // 用户伞下小部门所有在2.0系统下面的业绩和人数 end
  4897. }else{
  4898. // 当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
  4899. $child_nums = $this->getChildren_getcon($user_id);
  4900. // 获取父级子级下面的个人
  4901. $num_teams = $this->getTeamSize_getcon($child_nums);
  4902. // var_dump($num_teams);
  4903. foreach($child_nums as $v){
  4904. $get_teams_comm_datas[] = $this->getTeamPv11_getcon($v);// 如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
  4905. }
  4906. //$s = $this->getparents_child_pv($user_id);
  4907. // var_dump($get_teams_comm_datas);
  4908. // 如果只有一个部门,就是默认大部门
  4909. if( count($get_teams_comm_datas) ==1 ){
  4910. $get_teams_comm_pv =$get_teams_comm_datas[0];
  4911. $get_teams_comm_num = $num_teams[0]['total_count'];
  4912. }else if(count($get_teams_comm_datas) >1){
  4913. // var_dump( $get_teams_comm_datas);
  4914. // 获取一个最大值,设为大部门,其他的加载一块是小部门
  4915. $getss = $this->processArray_getcon($get_teams_comm_datas);
  4916. // var_dump($getss);
  4917. $max_value_count = $num_teams[$getss['max_index']]['total_count'];
  4918. unset($num_teams[$getss['max_index']]);
  4919. // 获取小部门的人数
  4920. $per_num = 0;
  4921. foreach($num_teams as $k=>$v){
  4922. $per_num +=$v['total_count'];
  4923. }
  4924. // 找到最大值的(大部门)
  4925. //$get_teams_comm_num = $max_value_count;
  4926. // 小部门的数量
  4927. // $get_teams_per_num = $per_num;
  4928. // var_dump($getss['max_value']);
  4929. $person_amount = $getss['remaining_sum'];
  4930. $get_teams_comm_pv = $getss['max_value'];
  4931. }
  4932. }
  4933. // var_dump($get_teams_comm_pv);
  4934. // 合并业绩和人数
  4935. $team_amount += $get_teams_comm_pv;
  4936. // var_dump($team_amount);
  4937. // 1.0获取小区业绩
  4938. $person_nums = $this->getPersonageNums_getcon($user_id);
  4939. // var_dump($person_nums);
  4940. $result_small_team_arr = [];
  4941. // 1.0系统中有下级,需要在2.0中再加下级数据
  4942. // 用户三峡所有在2.0系统下面的业绩和人数 start
  4943. $child_nums_mix = [];
  4944. // 获取当前用户
  4945. foreach($person_nums as $v){
  4946. $child_nums_mix[] = $this->getRecursiveChildren_getcon($v);
  4947. }
  4948. // 去除空数组,并重新组合有数据的数组
  4949. $filteredData_1 = array_filter($child_nums_mix, function($array) {
  4950. return !empty($array); // 如果数组不为空,则保留
  4951. });
  4952. // 合并所有非空数组
  4953. $result_small_team_arr = [];
  4954. foreach ($filteredData_1 as $array) {
  4955. $result_small_team_arr = array_merge($result_small_team_arr, $array);
  4956. }
  4957. // var_dump($result_small_team_arr);
  4958. // 获取当前用户下面在2.0中的下级所有PV
  4959. // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
  4960. $t_pv = $this->getteampv_getcon($result_small_team_arr);
  4961. $get_teams_per_pv =$t_pv;
  4962. // var_dump( $get_teams_per_pv);
  4963. // 获取当前用户下面在2.0中的下级所有人数
  4964. // $get_teams_per_num += count($result_small_team_arr);
  4965. // 合并业绩和人数
  4966. $person_amount += $get_teams_per_pv;
  4967. // 当前会员直属的业绩(1.0大部门)
  4968. $t_pv = $this->getteampv_getcon($common_nums);
  4969. $team_amount += $t_pv;
  4970. // 当前会员直属的业绩(1.0大部门)
  4971. $p_pv = $this->getteampv_getcon($person_nums);
  4972. $person_amount += $p_pv;
  4973. // var_dump($team_amount,$person_amount);
  4974. // 如果当前用户是1.0用户,找到其直推所有的业绩,根据业绩找到大小部门的同时,还要比对1.0中大小部门的业绩,摘出一个最大业绩的部门是大部门,其余都是小部门()
  4975. if($user_id < 611){
  4976. // 获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
  4977. // 例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
  4978. $b_s = $this->getparents_child_pv11_getcon($user_id,$team_amount,$person_amount);
  4979. $team_amount = $b_s[0];
  4980. $person_amount = $b_s[1];
  4981. }
  4982. $return_data = [
  4983. 'common_nums_pv'=> $team_amount,
  4984. 'person_nums_pv'=> $person_amount,
  4985. ];
  4986. return $return_data;
  4987. }
  4988. /**
  4989. * 获取该用户共建联盟
  4990. */
  4991. public function getCommonNums_getcon($user_id){
  4992. // 先获取共建联盟下用户的id
  4993. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->select()->toArray();
  4994. $new_array_ids =[];
  4995. foreach ($son_ids as $key => $value) {
  4996. # code...
  4997. $son_id = $value['id'];
  4998. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  4999. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  5000. if(count($son_value_ids) > 0) {
  5001. $son_value_ids = array_column($son_value_ids,"id");
  5002. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  5003. }
  5004. }
  5005. return $new_array_ids;
  5006. }
  5007. /**
  5008. * 获取该用户个人联盟
  5009. */
  5010. public function getPersonageNums_getcon($user_id){
  5011. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("id")->select();
  5012. $new_array_ids =[];
  5013. // return 3343;
  5014. foreach ($son_ids as $key => $value) {
  5015. # code...
  5016. $son_id = $value['id'];
  5017. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  5018. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  5019. if(count($son_value_ids) > 0) {
  5020. $son_value_ids = array_column($son_value_ids,"id");
  5021. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  5022. }
  5023. }
  5024. return $new_array_ids;
  5025. }
  5026. // 根据父级uid,递归获取所有子级UID数组
  5027. public function getRecursiveChildren_getcon($parentUid) {
  5028. $result = []; // 用于存储所有子级的 uid
  5029. // 定义递归函数
  5030. $recursion = function ($parentUid) use (&$result, &$recursion) {
  5031. // 查询当前父级的所有直接子级
  5032. $children = Db::name("user")
  5033. ->where("spread_uid", $parentUid)
  5034. ->column("uid"); // 获取子级的 uid 列表
  5035. // 如果没有子级,直接返回
  5036. if (empty($children)) {
  5037. return;
  5038. }
  5039. // 遍历每个子级
  5040. foreach ($children as $childUid) {
  5041. $result[] = $childUid; // 将子级的 uid 添加到结果数组
  5042. $recursion($childUid); // 递归查询子级的子级
  5043. }
  5044. };
  5045. // 从初始父级开始递归查询
  5046. $recursion($parentUid);
  5047. return array_unique($result); // 返回结果数组,并去重
  5048. }
  5049. // 只获取数组中的业绩
  5050. public function getteampv_getcon($common_nums) {
  5051. // // 查询当前用户及其子级的所有订单
  5052. $orders_gongxian = Db::name("user_sign_gongxian")
  5053. ->whereIn('status', [1])
  5054. ->whereIn("uid", $common_nums)
  5055. ->select();
  5056. // var_dump( $common_nums);
  5057. $total_gongxian = 0;
  5058. // // 遍历订单计算业绩
  5059. foreach ($orders_gongxian as $order) {
  5060. if (strpos($order['mark'], "购买") !== false) {
  5061. $total_gongxian += $order['number'];
  5062. }
  5063. }
  5064. return $total_gongxian;
  5065. // // // 查询当前用户及其子级的所有订单
  5066. // $orders = Db::name("store_order")
  5067. // ->whereIn('status', [0, 1, 2, 3])
  5068. // ->whereIn("uid", $common_nums)
  5069. // ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  5070. // ->select();
  5071. // // 初始化业绩和人数
  5072. // $totalPv = 0;
  5073. // $totalUsers = count($common_nums); // 初始化人数为子级总数
  5074. // // 遍历订单计算业绩
  5075. // foreach ($orders as $order) {
  5076. // if ($order['total_price'] == 1180) {
  5077. // $totalPv += 700;
  5078. // } else if ($order['total_price'] == 11800) {
  5079. // $totalPv += 7000;
  5080. // } else if ($order['total_price'] == 10620) {
  5081. // $totalPv += 6300;
  5082. // } else if ($order['total_price'] == 2360) {
  5083. // $totalPv += 1400;
  5084. // } else if ($order['total_price'] == 9440) {
  5085. // $totalPv += 5600;
  5086. // }
  5087. // }
  5088. // // 返回业绩和人数
  5089. // return [
  5090. // 'totalPv' => $totalPv,
  5091. // 'totalUsers' => $totalUsers
  5092. // ];
  5093. }
  5094. // 2.0 根据父级uid,找到当前用户下面的UID
  5095. public function getChildren_getcon($parentUid) {
  5096. $result = []; // 用于存储所有子级的 uid
  5097. $children = Db::name("user")
  5098. ->where("spread_uid", $parentUid)
  5099. ->column("uid"); // 获取子级的 uid 列表
  5100. return $children; // 返回结果数组,并去重
  5101. }
  5102. // 递归获取所有子级 UID 的业绩
  5103. public function getTeamPv11_getcon($parentUid) {
  5104. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  5105. $children = Db::name("user")
  5106. ->where("spread_uid", $parentUid)
  5107. ->column("uid");
  5108. $allChildren = [];
  5109. foreach ($children as $childUid) {
  5110. $allChildren[] = $childUid;
  5111. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  5112. }
  5113. return $allChildren;
  5114. };
  5115. // 获取当前用户及其所有子级的 UID
  5116. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  5117. $orders_gongxian = Db::name("user_sign_gongxian")
  5118. ->whereIn('status', [1])
  5119. ->whereIn("uid", $allUids)
  5120. ->select();
  5121. $total_gongxian = 0;
  5122. // // 遍历订单计算业绩
  5123. foreach ($orders_gongxian as $order) {
  5124. if (strpos($order['mark'], "购买") !== false) {
  5125. $total_gongxian += $order['number'];
  5126. }
  5127. }
  5128. return $total_gongxian;
  5129. // // 查询当前用户及其子级的所有订单
  5130. // $orders = Db::name("store_order")
  5131. // ->whereIn('status', [0, 1, 2, 3])
  5132. // ->whereIn("uid", $allUids)
  5133. // ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  5134. // ->select();
  5135. // // 计算总业绩
  5136. // $totalPv = 0;
  5137. // foreach ($orders as $order) {
  5138. // switch ($order['total_price']) {
  5139. // case 1180:
  5140. // $totalPv += 700;
  5141. // break;
  5142. // case 11800:
  5143. // $totalPv += 7000;
  5144. // break;
  5145. // case 10620:
  5146. // $totalPv += 6300;
  5147. // break;
  5148. // case 2360:
  5149. // $totalPv += 1400;
  5150. // break;
  5151. // case 9440:
  5152. // $totalPv += 5600;
  5153. // break;
  5154. // }
  5155. // }
  5156. // return $totalPv;
  5157. }
  5158. // 根据传递的父级数组,返回他的对应子级的个数
  5159. public function getTeamSize_getcon($parentUids) {
  5160. // 初始化结果数组
  5161. $result = [];
  5162. // 遍历每个父级ID
  5163. foreach ($parentUids as $parentUid) {
  5164. // 递归获取所有子级 UID
  5165. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  5166. $children = Db::name("user")
  5167. ->where("spread_uid", $parentUid)
  5168. ->column("uid");
  5169. // 确保返回的是数组
  5170. if (!is_array($children)) {
  5171. return [];
  5172. }
  5173. $allChildren = [];
  5174. foreach ($children as $childUid) {
  5175. $allChildren[] = $childUid;
  5176. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  5177. }
  5178. return $allChildren;
  5179. };
  5180. // 获取当前父级及其所有子级的 UID
  5181. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  5182. // 计算总个数(包括父级自身)
  5183. $totalUids = count($allUids);
  5184. // 将结果存入数组
  5185. $result[] = [
  5186. 'parent_uid' => $parentUid,
  5187. 'total_count' => $totalUids
  5188. ];
  5189. }
  5190. return $result;
  5191. }
  5192. public function processArray_getcon($array) {
  5193. // 初始化结果数组
  5194. $result = [
  5195. 'max_value' => null, // 最大值
  5196. 'max_index' => null, // 最大值的下标
  5197. 'remaining_sum' => 0 // 剩余值的总和
  5198. ];
  5199. // 检查数组是否为空
  5200. if (empty($array)) {
  5201. return $result;
  5202. }
  5203. // 找出最大值及其下标
  5204. $maxValue = $array[0];
  5205. $maxIndex = 0;
  5206. for ($i = 1; $i < count($array); $i++) {
  5207. if ($array[$i] > $maxValue) {
  5208. $maxValue = $array[$i];
  5209. $maxIndex = $i;
  5210. }
  5211. }
  5212. // 计算剩余值的总和
  5213. $remainingSum = 0;
  5214. for ($i = 0; $i < count($array); $i++) {
  5215. if ($i != $maxIndex) {
  5216. $remainingSum += $array[$i];
  5217. }
  5218. }
  5219. // 将结果存入数组
  5220. $result['max_value'] = $maxValue;
  5221. $result['max_index'] = $maxIndex;
  5222. $result['remaining_sum'] = $remainingSum;
  5223. return $result;
  5224. }
  5225. /**
  5226. * 获取流水信息
  5227. */
  5228. public function getPerformance1_getcon($user_id) {
  5229. // $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money");
  5230. // $amount = isset($amount) ? round($amount*0.7,2) : 0;
  5231. // return $amount;
  5232. $money1180Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",1180)->where("status",1)->select();
  5233. $money1180Sum = 0;
  5234. foreach ($money1180Records as $record) {
  5235. $money1180Sum += $record['money'] - 300 - 180;
  5236. }
  5237. // var_dump($money1180Sum);
  5238. $money11800Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",11800)->where("status",1)->select();
  5239. // var_dump($person_nums);
  5240. // 计算个人的11800单价的业绩 集合
  5241. $money11800Sum = 0;
  5242. foreach ($money11800Records as $record) {
  5243. $money11800Sum += $record['money'] - 3000 - 1800;
  5244. }
  5245. $money10620Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",10620)->where("status",1)->select();
  5246. // var_dump($person_nums);
  5247. // 计算个人的11800单价的业绩 集合
  5248. $money10620Sum = 0;
  5249. foreach ($money10620Records as $record) {
  5250. $money10620Sum += $record['money'] - 2700 - 1620;
  5251. }
  5252. // 计算除去特定值后的总和
  5253. $otherMoneyRecords = Db::name("old_user_of_goods")->where("node_id",$user_id)->where('status', 1)->whereNotIn('money', [1180, 11800 ,10620])->select();
  5254. $otherMoneySum = 0;
  5255. foreach ($otherMoneyRecords as $record) {
  5256. $otherMoneySum += $record['money'];
  5257. }
  5258. // 分别处理特定值的情况并加上其他值的总和
  5259. $user_person_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  5260. return $user_person_amount;
  5261. }
  5262. // 1.0用户直属的部门和2.0直属的部门,进行比较,获取大部门和小部门数据
  5263. public function getparents_child_pv11_getcon($user_id, $bigamount, $smallamount) {
  5264. // 获取直接下级的 UID 列表
  5265. $get_childs = Db::name("user")
  5266. ->where("spread_uid", $user_id)
  5267. ->column("uid");
  5268. // 初始化变量
  5269. $all_departments = []; // 用于存储所有直属下级的业绩
  5270. // 遍历每个直属下级
  5271. foreach ($get_childs as $child) {
  5272. // 获取当前下级及其子级
  5273. $child_group = [$child];
  5274. $recursive_children = $this->getRecursiveChildren_getcon($child);
  5275. $child_group = array_merge($child_group, $recursive_children);
  5276. // 获取当前分组的业绩
  5277. $result = $this->getteampv_getcon($child_group);
  5278. // 将直属下级的业绩加入数组
  5279. $all_departments[] = $result;
  5280. }
  5281. // 将传入的 $bigamount 和 $smallamount 加入数组
  5282. $all_departments[] = $bigamount;
  5283. $all_departments[] = $smallamount;
  5284. // 检查是否所有业绩都是 0
  5285. if (count(array_filter($all_departments, function($value) { return $value != 0; })) == 0) {
  5286. return [0, 0];
  5287. }
  5288. // 初始化最大部门和小部门
  5289. $max_department = 0;
  5290. $small_department = 0;
  5291. // 遍历 $all_departments,找出最大值并累加小部门的值
  5292. foreach ($all_departments as $department) {
  5293. if ($department > $max_department) {
  5294. // 如果当前部门的业绩大于最大部门的业绩,更新最大部门
  5295. if ($max_department != 0) {
  5296. $small_department += $max_department; // 将旧的最大值累加到小部门
  5297. }
  5298. $max_department = $department; // 更新最大部门
  5299. } else {
  5300. // 如果当前部门的业绩小于或等于最大部门的业绩,累加到小部门
  5301. $small_department += $department;
  5302. }
  5303. }
  5304. // 返回结果
  5305. return [
  5306. $max_department, // 大部门业绩
  5307. $small_department // 小部门业绩
  5308. ];
  5309. // 拿$bigamount, $smallamount业绩和get_childs产生的result业绩去对比。如果都是0.说明没有大小部门了,直接返回0,0如果只有一个数组有数据,
  5310. // 说明只有大部门,默认返回大部门数据,小部门返回0,如果有多条数组数据是一样的,那么就是选一个,设为大部门。剩下的数据叠加设为小部门
  5311. }
  5312. // 获取当前uesr_id下面在2.0中是否还有直接下级,并计算她的大部门和小部门
  5313. public function getparents_child_pv_getcon($user_id){
  5314. // 获取直接下级的 UID 列表
  5315. //$user_id = 593;
  5316. // $get_childs = $this->getRecursiveChildren($user_id);
  5317. $get_childs = Db::name("user")
  5318. ->where("spread_uid", $user_id)
  5319. ->column("uid"); // 获取子级的 uid 列表
  5320. // 根据获得的直接推荐下级2.0,来获取他们和她伞下的子级PV。对比拿一个最大的值,设为大部门,其余的是小部门
  5321. // 获取直接下级
  5322. $children_group = []; // 用于存储每个直接下级及其子级的分组
  5323. // 遍历每个直接下级
  5324. foreach ($get_childs as $child) {
  5325. $child_group = [$child]; // 将直接下级加入分组
  5326. $recursive_children = $this->getRecursiveChildren($child); // 获取直接下级的所有子级
  5327. $child_group = array_merge($child_group, $recursive_children); // 将子级加入分组
  5328. $children_group[] = $child_group; // 将分组加入最终结果
  5329. }
  5330. $get_teams_comm_datas = [];
  5331. foreach($children_group as $v){
  5332. $get_teams_comm_datas[] = $this->getteampv($v);// 如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
  5333. }
  5334. if(count($get_teams_comm_datas) > 0){
  5335. // 找到最大值作为大部门
  5336. $max_value = max($get_teams_comm_datas);
  5337. $total_sum = array_sum($get_teams_comm_datas); // 计算数组的总和
  5338. // 小部门为总和减去最大值
  5339. $small_department = $total_sum - $max_value;
  5340. // 返回大部门和小部门
  5341. return [
  5342. $max_value,
  5343. $small_department
  5344. ];
  5345. }else{
  5346. return [
  5347. 0,
  5348. 0
  5349. ];
  5350. }
  5351. }
  5352. /**
  5353. * 解绑微信或支付宝
  5354. * @return void
  5355. */
  5356. public function unBindVxOrAli()
  5357. {
  5358. $uid = $this->request->uid();
  5359. $type = request()->param('type','');
  5360. if(!$type) return app('json')->fail('请选择解绑类型');
  5361. if(!$uid) return app('json')->fail('请登录');
  5362. // 1 = 微信 2 = 支付宝 3 = 全部
  5363. if($type == 1){
  5364. Db::name('user')->where('uid',$uid)->update(['wechat_user_id' => 0]);
  5365. }else if ($type == 2){
  5366. Db::name('user')->where('uid',$uid)->update(['ali_user_id' => 0]);
  5367. }else{
  5368. Db::name('user')->where('uid',$uid)->update(['wechat_user_id' => 0,'ali_user_id' => 0]);
  5369. }
  5370. Db::name('log')->insert(['data' => '用户uid:' . $uid . '进行解绑操作type类型为' . $type]);
  5371. return app('json')->success('解绑成功');
  5372. }
  5373. }