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