User.php 247 KB

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