User.php 246 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450
  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. $existUid = Db::name('user_extract_openid')->where('openid',$unionId)->value('uid');
  2335. if (!empty($existUid) && $existUid != $uid) {
  2336. $existUserData = Db::name("user")->where("uid", $existUid)->find();
  2337. if ($existUserData['is_del'] != 1) {
  2338. throw new \Exception("此微信号已被绑定");
  2339. } else {
  2340. Db::name('user_extract_openid')->where('openid',$unionId)->delete();
  2341. Db::name("user")->where(['uid' => $existUid])->update(["wechat_user_id" => 0]);
  2342. }
  2343. }
  2344. $check = Db::name('user_extract_openid')->where('uid',$uid)->value('openid');
  2345. if (!empty($check)){
  2346. if ($check != $unionId) throw new \Exception("当前用户已绑定其他微信号");
  2347. } else {
  2348. Db::name("user_extract_openid")->insert([
  2349. 'uid' => $uid,
  2350. 'openid' => $unionId,
  2351. 'type' => 1
  2352. ]);
  2353. }
  2354. } else {
  2355. $alinfo = json_decode($alinfo, true);
  2356. if (!$alinfo) throw new \Exception("参数异常");
  2357. $data = ["ali_user_id" => $alinfo["userId"]];
  2358. $unionId = $alinfo["userId"];
  2359. $check = Db::name("user")->where("ali_user_id", $unionId)->find();
  2360. if ($check) throw new \Exception("此支付宝号已被绑定");
  2361. // $paramStr = $userRepository->getTokenByCode($alinfo["authCode"], true);
  2362. $paramStr = $userRepository->getTokenByCodeWithCert($alinfo["authCode"], true);
  2363. $nickname = empty($paramStr["nick_name"]) ? "al" . $alinfo["userId"] : $paramStr["nick_name"];
  2364. $avater = empty($paramStr["avatar"]) ? "https://cdn.bjtdba.com/vod/image/2025-01-21/20250121180855764.png" : $paramStr["avatar"];
  2365. }
  2366. $data2 = [
  2367. "type" => $type,
  2368. "uid" => $uid,
  2369. "nickname" => $nickname,
  2370. "avater" => $avater,
  2371. ];
  2372. $result = $this->repository->updateUser($uid, $data, $data2);
  2373. if (!$result) throw new \Exception("修改失败");
  2374. $userRepository = app()->make(UserRepository::class);
  2375. $userInfo = $userRepository->getOne(['uid' => $uid]);
  2376. // 绑定线下充值金额
  2377. $unionUsersRepository = app()->make(UnionUsersRepository::class);
  2378. $orderMerchantRepository = app()->make(OrderMerchantRepository::class);
  2379. $notBind = $unionUsersRepository->getAllNotBind($unionId);
  2380. if ($notBind) {
  2381. $orderMerchantRepository->doBindUser($userInfo, $type);
  2382. }
  2383. } catch (\Throwable $e) {
  2384. makeLock()->unlock();
  2385. return app("json")->fail("失败" . $e->getMessage());
  2386. }
  2387. makeLock()->unlock();
  2388. return app("json")->success("修改成功", $data);
  2389. }
  2390. /**
  2391. * 获取账号绑定信息
  2392. * @return mixed
  2393. */
  2394. public function getAccount()
  2395. {
  2396. $uid = $this->request->uid();
  2397. // $data = $this->repository->getUser($uid, "wechat_user_id,ali_user_id");
  2398. $data = $this->repository->getAccount($uid);
  2399. if ($data) {
  2400. return app("json")->success("查询成功", $data);
  2401. }
  2402. return app("json")->fail("未绑定");
  2403. }
  2404. // /*
  2405. // * 养老金统计
  2406. // * */
  2407. // public function get_yanglao_statistics()
  2408. // {
  2409. // $uid = $this->request->uid();
  2410. // //线下数量
  2411. // // 查询未结算
  2412. //
  2413. // $gzc_order_list = Db::name('gzc_logs')->where('uid', $uid)->column('out_trade_no');
  2414. //
  2415. // $onlineYanglaoUserBill = Db::name('user_bill')->where('commission_type', 5)->whereNotIn('order_sn',$gzc_order_list)->where('status', 0)->where('uid', $uid)->sum('number');
  2416. // $onlineYanglaoGzc = Db::name('gzc_logs')->where('success', 0)->where('uid', $uid)->sum('pension');
  2417. // $clearYanglao = Db::name('gzc_logs')->where('success', 1)->where('uid', $uid)->sum('pension');
  2418. //
  2419. // $userInfo = Db::name('UserCertification')->where('uid', $uid)->field('user_name,user_card')->find();
  2420. // $res = GzcApiRequest::checkAmount($userInfo);
  2421. // $gzc = $res['extendData']['amount'] * 0.01;
  2422. // // PCPC-中信公证处
  2423. // $data['all_gzc'] = set_price_rtrim(sprintf("%01.2f", $gzc));
  2424. // // 总养老金
  2425. // $data['all_yanglao'] = set_price_rtrim($onlineYanglaoUserBill + $onlineYanglaoGzc + $clearYanglao + $gzc);
  2426. // // 平台养老金
  2427. // $data['all_yanglao_yhc'] = set_price_rtrim($onlineYanglaoUserBill + $onlineYanglaoGzc + $clearYanglao);
  2428. // // 未结算养老金=预估养老金,不能包含进入公证处未成功的记录(这部分是已结算的)
  2429. // $data['all_yanglao_yugu'] = set_price_rtrim(round($onlineYanglaoUserBill, 2));
  2430. // // 已结算养老金 已入账
  2431. // $data['all_yanglao_clear'] = set_price_rtrim(round($onlineYanglaoGzc+$clearYanglao, 2));
  2432. // // 已入账养老金
  2433. // $data['all_yanglao_in'] = set_price_rtrim(round($clearYanglao, 2));
  2434. // // 平台未入账养老金
  2435. // $data['all_yanglao_nclear'] = set_price_rtrim(round($onlineYanglaoGzc + $onlineYanglaoUserBill, 2));
  2436. // // 待发起
  2437. // $data['all_yanglao_wait'] = set_price_rtrim(round($onlineYanglaoGzc, 2));
  2438. //
  2439. // return app("json")->success("查询成功", $data);
  2440. // }
  2441. /*
  2442. * 养老金统计
  2443. * */
  2444. public function get_yanglao_statistics()
  2445. {
  2446. $uid = $this->request->uid();
  2447. // 线下数量
  2448. $offLine = \think\facade\Db::name('order_merchant')->where('uid', $uid)->where('status', 1)->field('pension yanglao')->select()->toArray();
  2449. $data['offLine'] = array(
  2450. 'num' => count($offLine),
  2451. 'yanglao' => round($this->num($offLine, 'yanglao'), 2)
  2452. );
  2453. $offLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>1,'type_shop'=>10];
  2454. if($this->source=='yhc' && $this->merId){
  2455. $offLinewhere['mer_id']=$this->merId;
  2456. }
  2457. $offLine= \think\facade\Db::name('user_bill')->where($offLinewhere)->select()->toArray();
  2458. $data['offLine'] = array(
  2459. 'num' => count($offLine),
  2460. 'yanglao' => round($this->num($offLine, 'number'), 2)
  2461. );
  2462. // $offLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>0,'type_shop'=>0];
  2463. // $offLine= \think\facade\Db::name('user_bill')->where($offLinewhere)->select()->toArray();
  2464. // $data['offLine'] = array(
  2465. // 'num' => count($offLine),
  2466. // 'yanglao' => round($this->num($offLine, 'number'), 2)
  2467. // );
  2468. // 线上已确认收货
  2469. // $onLine = \think\facade\Db::name('store_order')->where('uid', $uid)->where('paid', 1)->where('status', 'in', '2,3')->select()
  2470. // ->each(function ($item) {
  2471. // //查询养老金金额
  2472. // $UserBillRepository = app()->make(UserBillRepository::class);
  2473. // $bill = $UserBillRepository->getWhere(['uid' => $item['uid'], 'link_id' => $item['order_id'], 'order_sn' => $item['order_sn'], 'title' => '养老金']);
  2474. // $pension = $bill->number ?? 0;
  2475. // $item['yanglao'] = $pension;
  2476. // return $item;
  2477. // })
  2478. // ->toArray();
  2479. $onLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>0,'type_shop'=>0];
  2480. if($this->source=='yhc' && $this->merId){
  2481. $onLinewhere['mer_id']=$this->merId;
  2482. }
  2483. $onLine= \think\facade\Db::name('user_bill')->where($onLinewhere)->select()->toArray();
  2484. $data['onLine'] = array(
  2485. 'num' => count($onLine),
  2486. 'yanglao' => round($this->num($onLine, 'number'), 2)
  2487. );
  2488. // 线上未确认收货
  2489. // $onLine = \think\facade\Db::name('store_order')->where('uid', $uid)->where('paid', 1)->where('status', 'in', '0,1')->select()
  2490. // ->each(function ($item) {
  2491. // //查询养老金金额
  2492. // $UserBillRepository = app()->make(UserBillRepository::class);
  2493. // $bill = $UserBillRepository->getWhere(['uid' => $item['uid'], 'link_id' => $item['order_id'], 'order_sn' => $item['order_sn'], 'title' => '养老金']);
  2494. // $pension = $bill->number ?? 0;
  2495. // $item['yanglao'] = $pension;
  2496. // return $item;
  2497. // })
  2498. // ->toArray();
  2499. $onLine_take_nowhere=['uid'=>$uid,'status'=>'0','commission_type' => '5','source'=>0,'type_shop'=>0];
  2500. if($this->source=='yhc' && $this->merId){
  2501. $onLine_take_nowhere['mer_id']=$this->merId;
  2502. }
  2503. $onLine_take_no=\think\facade\Db::name('user_bill')->where($onLine_take_nowhere)->select()->toArray();
  2504. $data['onLine_take_no'] = array(
  2505. 'num' => count($onLine_take_no),
  2506. 'yanglao' => round($this->num($onLine_take_no, 'number'), 2)
  2507. );
  2508. if($this->source=='yhc' && $this->merId){
  2509. $data['all_num'] = $data['offLine']['num'] +$data['onLine_take_no']['num'] + $data['onLine']['num'];
  2510. $data['all_yanglao_yhc'] = set_price_rtrim(round($data['offLine']['yanglao']+$data['onLine']['yanglao'] + $data['onLine_take_no']['yanglao'] , 2));// 总养老金
  2511. $data['all_yanglao_a'] = set_price_rtrim(round($data['offLine']['yanglao'] + $data['onLine']['yanglao'], 2));// 已结算养老金
  2512. $data['all_yanglao_yugu'] = set_price_rtrim(round($data['all_yanglao_yhc']-$data['all_yanglao_a'],2));// 预估养老金
  2513. $userInfo = Db::name('UserCertification') -> where('uid',$uid) -> field('user_name,user_card') -> find();
  2514. $res = GzcApiRequest::checkAmount($userInfo);
  2515. $data['all_gzc']=set_price_rtrim(sprintf("%01.2f", $res['extendData']['amount'] * 0.01));
  2516. $data['all_yanglao']=set_price_rtrim( $data['all_yanglao_yhc'] + $data['all_gzc']);
  2517. return app("json")->success("查询成功", $data);
  2518. }
  2519. // 淘宝
  2520. $tb_a = 0;
  2521. $tb_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>5];
  2522. $tb = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($tb_where)->where('status','<>','-1')->select()->each(function ($value) use (&$tb_a) {
  2523. $value['yanglao'] = 0;
  2524. $value['yanglao'] = $value['number'];
  2525. $value['yanglao_a'] = 0;
  2526. if ($value['status'] == 1) {
  2527. $value['yanglao_a'] = $value['yanglao'];
  2528. $tb_a++;
  2529. }
  2530. return $value;
  2531. })->toArray();
  2532. $data['tb'] = array(
  2533. 'num' => count($tb),
  2534. 'num_a' => $tb_a,
  2535. 'yanglao' => round($this->num($tb, 'yanglao'), 2),
  2536. 'yanglao_a' => round($this->num($tb, 'yanglao_a'), 2),
  2537. );
  2538. // 京东
  2539. $jd_a = 0;
  2540. $jd_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>6];
  2541. $jd = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($jd_where)->where('status','<>','-1')->select()->each(function ($value) use (&$jd_a) {
  2542. $value['yanglao'] = 0;
  2543. $value['yanglao'] = $value['number'];
  2544. $value['yanglao_a'] = 0;
  2545. if ($value['status'] == 1) {
  2546. $value['yanglao_a'] = $value['yanglao'];
  2547. $jd_a++;
  2548. }
  2549. return $value;
  2550. })->toArray();
  2551. $data['jd'] = array(
  2552. 'num' => count($jd),
  2553. 'num_a' => $jd_a,
  2554. 'yanglao' => round($this->num($jd, 'yanglao'), 2),
  2555. 'yanglao_a' => round($this->num($jd, 'yanglao_a'), 2),
  2556. );
  2557. // 苏宁
  2558. $su_a = 0;
  2559. $su_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>3];
  2560. $su = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($su_where)->where('status','<>','-1')->select()->each(function ($value) use (&$su_a) {
  2561. $value['yanglao'] = 0;
  2562. $value['yanglao'] = $value['number'];
  2563. $value['yanglao_a'] = 0;
  2564. if ($value['status'] == 1) {
  2565. $value['yanglao_a'] = $value['yanglao'];
  2566. $su_a++;
  2567. }
  2568. return $value;
  2569. })->toArray();
  2570. $data['su'] = array(
  2571. 'num' => count($su),
  2572. 'num_a' => $su_a,
  2573. 'yanglao' => round($this->num($su, 'yanglao'), 2),
  2574. 'yanglao_a' => round($this->num($su, 'yanglao_a'), 2),
  2575. );
  2576. // 拼多多
  2577. $pdd_a = 0;
  2578. $pdd_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>1];
  2579. $pdd = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($pdd_where)->where('status','<>','-1')->select()->each(function ($value) use (&$pdd_a) {
  2580. $value['yanglao'] = 0;
  2581. $value['yanglao'] = $value['number'];
  2582. $value['yanglao_a'] = 0;
  2583. if ($value['status'] == 1) {
  2584. $value['yanglao_a'] = $value['yanglao'];
  2585. $pdd_a++;
  2586. }
  2587. return $value;
  2588. })->toArray();
  2589. $data['pdd'] = array(
  2590. 'num' => count($pdd),
  2591. 'num_a' => $pdd_a,
  2592. 'yanglao' => round($this->num($pdd, 'yanglao'), 2),
  2593. 'yanglao_a' => round($this->num($pdd, 'yanglao_a'), 2),
  2594. );
  2595. // 唯品会
  2596. $vip_a = 0;
  2597. $vip_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>2];
  2598. $vip = \think\facade\Db::name('user_bill')->where($vip_where)->where('uid', $uid)->where('status','<>','-1')->select()->each(function ($value) use (&$vip_a) {
  2599. $value['yanglao'] = 0;
  2600. $value['yanglao'] = $value['number'];
  2601. $value['yanglao_a'] = 0;
  2602. if ($value['status'] == 1) {
  2603. $value['yanglao_a'] = $value['yanglao'];
  2604. $vip_a++;
  2605. }
  2606. return $value;
  2607. })->toArray();
  2608. $data['vip'] = array(
  2609. 'num' => count($vip),
  2610. 'num_a' => $vip_a,
  2611. 'yanglao' => round($this->num($vip, 'yanglao'), 2),
  2612. 'yanglao_a' => round($this->num($vip, 'yanglao_a'), 2),
  2613. );
  2614. // 抖音
  2615. $dy_a = 0;
  2616. $dy_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>9];
  2617. $dy = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($dy_where)->where('status','<>','-1')->select()->each(function ($value) use (&$dy_a) {
  2618. $value['yanglao'] = 0;
  2619. $value['yanglao'] = $value['number'];
  2620. $value['yanglao_a'] = 0;
  2621. if ($value['status'] == 1) {
  2622. $value['yanglao_a'] = $value['yanglao'];
  2623. $dy_a++;
  2624. }
  2625. return $value;
  2626. })->toArray();
  2627. $data['dy'] = array(
  2628. 'num' => count($dy),
  2629. 'num_a' => $dy_a,
  2630. 'yanglao' => round($this->num($dy, 'yanglao'), 2),
  2631. 'yanglao_a' => round($this->num($dy, 'yanglao_a'), 2),
  2632. );
  2633. $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'];
  2634. $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);
  2635. $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);
  2636. $data['third_party_num']=['all_num'=>$data['tb']['num']+$data['jd']['num']+$data['su']['num']+ $data['pdd']['num'] + $data['vip']['num']+ $data['dy']['num']];
  2637. $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']];
  2638. $data['third_party_num_n']=['all_num_n'=>$data['third_party_num']['all_num']-$data['third_party_num_a']['all_num_a']];
  2639. return app("json")->success("查询成功", $data);
  2640. }
  2641. public function num($data, $field)
  2642. {
  2643. $sum = 0;
  2644. foreach ($data as $item) {
  2645. $sum += $item[$field];
  2646. }
  2647. return $sum;
  2648. }
  2649. // 志愿者升级
  2650. public function changeVolunteer()
  2651. {
  2652. $uid = $this->request->uid();
  2653. // 志愿者条件
  2654. $volunteer_achievement = systemConfig("volunteer_achievement");// volunteer_achievement:用户本人满足养老金要求可升级为志愿者
  2655. $volunteer_class = new Volunteer();
  2656. $volunteer = $volunteer_class->volunteer($uid);
  2657. if ($volunteer['self_yanglao'] < $volunteer_achievement) {
  2658. $data['grade'] = 0;
  2659. $data['self_yanglao'] = $volunteer['self_yanglao'];
  2660. $data['condition_one'] = systemConfig("volunteer_achievement");// 用户本人满足养老金要求可升级为志愿者
  2661. return app('json')->success($data);
  2662. }
  2663. $volunteer_class->grade($uid, 1, $volunteer);
  2664. return app('json')->success('申请成功');
  2665. }
  2666. public function GZC($uid)
  2667. {
  2668. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  2669. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  2670. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  2671. $where = [
  2672. 'uid' => $uid,
  2673. 'pm' => 1,
  2674. 'status' => 1,
  2675. 'type' => 'commission'
  2676. ];
  2677. $user_data = \think\facade\Db::name('user')->where('uid', $uid)->find();
  2678. $certification = ['user_name' => $user_data['real_name'], 'mobile' => $user_data['account'], 'user_card' => $user_data['card_id']];
  2679. $user_data['real_name'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('user_name');
  2680. $user_data['account'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('mobile');
  2681. $user_data['card_id'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('user_card');
  2682. Db::name('user_bill')->where($where)->select()->each(function ($item) use ($uid, $orderId, $OrderGzcRepository, $user_data, $certification) {
  2683. $is_implement = 1;
  2684. if ($item['source'] == 0) {
  2685. $order_data = \think\facade\Db::name('store_order')->where('order_sn', $item['order_sn'])->value('uid');
  2686. if ($order_data['uid'] == $item['uid']) {
  2687. $is_implement = 0;
  2688. } else {
  2689. $is_implement = 1;
  2690. }
  2691. } else {
  2692. $order_data = \think\facade\Db::name('order_merchant')->where('out_trade_no', $item['order_sn'])->value('uid');
  2693. if ($order_data['uid'] == $item['uid']) {
  2694. $is_implement = 0;
  2695. } else {
  2696. $is_implement = 1;
  2697. }
  2698. }
  2699. if ($is_implement == 1) {
  2700. $online = ['uid' => $uid, 'pay_type' => '1', 'order_sn' => $item['order_sn'], 'order_id' => $item['link_id']];
  2701. $create = [
  2702. 'uid' => $online['uid'],
  2703. 'platform_no' => $orderId,
  2704. 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
  2705. 'user_name' => $certification['user_name'],
  2706. 'mobile' => $certification['mobile'],
  2707. 'user_card' => $certification['user_card'],
  2708. 'pension' => $item['number'],
  2709. 'order_type' => 2,
  2710. 'out_trade_no' => $online['order_sn']
  2711. ];
  2712. $OrderGzcRepository->create($create);
  2713. }
  2714. });
  2715. }
  2716. // 20220712版签到
  2717. public function new_sign()
  2718. {
  2719. // return app('json')->fail('不允许签到');
  2720. $uid = $this->request->uid();// 签到用户
  2721. $user = Db::name('user')->where('uid', $uid)->field("spread_uid,first_sign")->find();// 上级用户
  2722. // 第一天签到获得2积分,第二天获得4积分,第三天获得6积分,第四天获得 10 积分,第五天获得 14积分第六天获得 20积分,
  2723. // 连续签到从第七天开始,每日签到获得3积分,第七天连续签到额外奖励 38积分,第 14 天连续签到额外奖励 68 积分,第 21天连续签到额外奖励 128 积分第 30 天连续签到额外奖励 188 积分
  2724. // 前6天积分
  2725. $score = [
  2726. 2,// 1
  2727. 4,// 2
  2728. 6,// 3
  2729. 10,// 4
  2730. 14,// 5
  2731. 20// 6
  2732. ];
  2733. // 7-30天积分
  2734. $scoreS = 3;
  2735. // 额外积分
  2736. $scoreExtra = [
  2737. 7 => 38,
  2738. 14 => 68,
  2739. 21 => 128,
  2740. 30 => 188
  2741. ];
  2742. $today_signintime = strtotime(date('Y-m-d', time()));
  2743. $today_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid))->whereDay('signin_time')->find();
  2744. if (!empty($today_signin_info)) {
  2745. return app('json')->fail('今天已经签到过了');
  2746. } else {
  2747. // 查询昨天是否已经签到了
  2748. $yes_signintime = strtotime(date('Y-m-d')) - 86400;
  2749. $yes_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid, 'signin_time' => $yes_signintime))->find();
  2750. $has_qian = 1;
  2751. if (!empty($yes_signin_info)) {
  2752. $has_qian = $yes_signin_info['continuity_day'] + 1;
  2753. $has_qian = $has_qian > 30 ? 1 : $has_qian;
  2754. }
  2755. $get_score = 0;
  2756. $get_gw_score = 0;
  2757. if ($has_qian <= 6) {
  2758. $get_score = $score[$has_qian - 1];
  2759. } else {
  2760. $get_score = $scoreS;
  2761. if (isset($scoreExtra[$has_qian])) {
  2762. $get_gw_score = $scoreExtra[$has_qian];
  2763. }
  2764. }
  2765. $userRepository = app()->make(UserRepository::class);
  2766. $userRepository->sign_add($uid, $get_score, 1, '签到赠送积分', $has_qian, $today_signintime, '', 1, '', 1);
  2767. if($get_gw_score > 0){
  2768. $userRepository->sign_add($uid, $get_gw_score,1,'连续签到赠送额外奖励积分', $has_qian, $today_signintime, '', 1, '', 1);
  2769. }
  2770. // 首次签到
  2771. if ($user['first_sign'] == 0) {
  2772. // //首次签到送30积分,同时赠送邀请人30积分
  2773. // $userRepository->sign_add($uid, 30,1,'首次签到送30积分','','', '', 1, '', 1);
  2774. // $member_info = Db::name('user')->where( array('uid' => $uid) )->find();
  2775. // if($member_info['spread_uid']){
  2776. // $spreadUid = $member_info['spread_uid'];
  2777. // $userRepository->sign_add($spreadUid, 30,1,'邀请人首次签到送30积分','','', '', 1, '', 1);
  2778. // }
  2779. Db::name('user')->where('uid', $uid)->update(['first_sign' => 1]);
  2780. } elseif ($user['first_sign'] == 1 && $has_qian == 1) {
  2781. Db::name('user')->where('uid', $uid)->update(['first_sign' => 2]);
  2782. }
  2783. // //非首次签到,第一天,断签
  2784. // //好友连续签到3天 奖励50
  2785. // //好友连续签到14天 奖励100
  2786. // //好友联系签到30天 奖励300
  2787. // if ($user['first_sign'] < 2) {
  2788. // if ($has_qian == 3) {
  2789. // $userRepository->sign_add($user['spread_uid'], 50, 1, '好友签到赠送积分', '', $today_signintime, '');
  2790. // } elseif ($has_qian == 14) {
  2791. // $userRepository->sign_add($user['spread_uid'], 100, 1, '好友签到赠送积分', '', $today_signintime, '');
  2792. // } elseif ($has_qian == 30) {
  2793. // $userRepository->sign_add($user['spread_uid'], 300, 1, '好友签到赠送积分', '', $today_signintime, '');
  2794. // Db::name('user')->where('uid', $uid)->update(['first_sign' => 3]);
  2795. // }
  2796. // }
  2797. return app('json')->success('签到成功', ['score' => $get_score]);
  2798. }
  2799. }
  2800. public function new_sign_info()
  2801. {
  2802. $uid = $this->request->uid();
  2803. // 查询今天是否已经签到
  2804. $today_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid))->whereDay('signin_time')->find();
  2805. // 查询昨天是否已经签到了
  2806. $yes_signintime = strtotime(date('Y-m-d')) - 86400;
  2807. $yes_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid, 'signin_time' => $yes_signintime))->find();
  2808. $data = [
  2809. 'today' => 0,
  2810. 'day' => 0
  2811. ];
  2812. if ($yes_signin_info) $data['day'] = (int)$yes_signin_info['continuity_day'];
  2813. if ($yes_signin_info['continuity_day'] >= 30) $data['day'] = 0;
  2814. if ($today_signin_info) {
  2815. $data['today'] = 1;
  2816. $data['day'] = $data['day'] + 1;
  2817. }
  2818. return app('json')->success($data);
  2819. }
  2820. /**
  2821. * 积分列表
  2822. * @return mixed
  2823. * @throws \think\db\exception\DataNotFoundException
  2824. * @throws \think\db\exception\DbException
  2825. * @throws \think\db\exception\ModelNotFoundException
  2826. */
  2827. public function sign_list()
  2828. {
  2829. [$page, $limit] = $this->getPage();
  2830. $uid = $this->request->uid();
  2831. $month = $this->request->param('month', '') ?: date('Y-m');
  2832. $status = $this->request->param('status');
  2833. $pm = $this->request->param('pm');
  2834. $startMonth = strtotime(date('Y-m-01 00:00:00', strtotime($month)));
  2835. $endMonth = strtotime(date("Y-m-d 00:00:00", strtotime("first day of next month", strtotime($month))));
  2836. $count = Db::name('user_sign_score')
  2837. ->whereBetween('addtime', [$startMonth, $endMonth])
  2838. ->when(isset($status) && $status !== '', function ($query) use ($status) {
  2839. $query->where('status', $status);
  2840. })
  2841. ->when(isset($pm) && $pm !== '', function ($query) use ($pm) {
  2842. $query->where('pm', $pm);
  2843. })
  2844. ->where('uid', $uid)->count();
  2845. $list = Db::name('user_sign_score')
  2846. ->whereBetween('addtime', [$startMonth, $endMonth])
  2847. ->where('uid', $uid)
  2848. ->when(isset($status) && $status !== '', function ($query) use ($status) {
  2849. $query->where('status', $status);
  2850. })
  2851. ->when(isset($pm) && $pm !== '', function ($query) use ($pm) {
  2852. $query->where('pm', $pm);
  2853. })
  2854. ->page($page, $limit)->order('id DESC')->select()->each(function ($item) {
  2855. $item['signin_time'] = date('Y-m-d', $item['signin_time']);
  2856. $item['addtime'] = date('Y-m-d H:i:s', $item['addtime']);
  2857. if (!empty($item['order_id'])) {
  2858. // 线上订单
  2859. if ($item['order_type'] == 'store_order' || $item['order_type'] == 'store_order_beishengtang') {
  2860. $item['order_sn'] = Db::name("store_order")->where("order_id", $item['order_id'])->value("order_sn");
  2861. } elseif ($item['order_type'] == 'order_merchant') {
  2862. $item['order_sn'] = Db::name("order_merchant")->where("id", $item['order_id'])->value("out_trade_no");
  2863. } elseif ($item['order_type'] == 'extract') {
  2864. $item['order_sn'] = Db::name("user_extract")->where("extract_id", $item['order_id'])->value("order_sn");
  2865. } else {
  2866. $item['order_sn'] = '';
  2867. }
  2868. } else {
  2869. $item['order_sn'] = '';
  2870. }
  2871. return $item;
  2872. });
  2873. $data['list'] = $list;
  2874. $data['count'] = $count;
  2875. return app('json')->success($data);
  2876. }
  2877. public function getAmountFromGzc()
  2878. {
  2879. $uid = $this->request->uid();
  2880. $userInfo = Db::name('UserCertification')->where('uid', $uid)->field('user_name,user_card')->find();
  2881. $res = GzcApiRequest::checkAmount($userInfo);
  2882. return app('json')->success(['amount' => sprintf("%01.2f", $res['extendData']['amount'] * 0.01)]);
  2883. }
  2884. public function check_user_annual_fee()
  2885. {
  2886. // INSERT INTO rrx_user_pension_account (uid) SELECT uid FROM rrx_user;
  2887. // 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;
  2888. $uid = $this->request->uid();
  2889. $check = Db::name("user_pension_account")->where("uid", $uid)->find();
  2890. $data = [
  2891. "status" => 3,// 0:未交年费,1:年费到期。2:未实名认证,3:正常
  2892. ];
  2893. // //未交年费
  2894. // if (!$check || $check["status"] == 0) {
  2895. // $data["status"] = 0;
  2896. // return app('json')->success($data);
  2897. // }
  2898. // //到期时间小于当前时间。年费到期
  2899. // if (strtotime($check['end_time']) < time()){
  2900. // $data["status"] = 1;
  2901. // return app('json')->success($data);
  2902. // }
  2903. // $data["start_time"] = $check['start_time'];
  2904. // $data["end_time"] = $check['end_time'];
  2905. //
  2906. // //检查实名认证
  2907. // $checkCertification = Db::name("user_certification") -> where("uid",$uid) -> find();
  2908. // if (!$checkCertification){
  2909. // $data["status"] = 2;
  2910. // return app('json')->success($data);
  2911. // }
  2912. return app('json')->success($data);
  2913. }
  2914. /**
  2915. *
  2916. * @remarks 创建年费订单
  2917. * @author 小菜菜
  2918. * @created 2023/04/10 14:37
  2919. */
  2920. public function create_annual_order()
  2921. {
  2922. $uid = $this->request->uid();
  2923. $type = $this->request->param('type', 1);
  2924. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  2925. if ($type == 1) $price = "12.00";
  2926. elseif ($type == 2) $price = systemConfig('offline_a');
  2927. elseif ($type == 3) $price = systemConfig('offline_b');
  2928. elseif ($type == 4) $price = systemConfig('offline_c');
  2929. else return app('json')->fail("参数错误");
  2930. $check = Db::name("user_pension_account")->where("uid", $uid)->find();
  2931. // 到期时间小于当前时间。年费到期
  2932. if (strtotime($check['end_time']) > time() && $check['status'] == 1) {
  2933. return app('json')->fail("账户已开通,不可重复开通账户");
  2934. }
  2935. $insertData = [
  2936. 'pay_price' => $price,
  2937. 'status' => 0,
  2938. 'order_no' => $OrderMerchantRepository->getNewOrderId("mt"),
  2939. 'uid' => $uid,
  2940. 'type' => $type,
  2941. ];
  2942. $order_id = Db::name('user_pension_account_order')->insertGetId($insertData);
  2943. try {
  2944. return app('json')->success(['order_id' => $order_id]);
  2945. } catch (\Exception $e) {
  2946. return app('json')->status('error', $e->getMessage(), ['order_id' => $order_id]);
  2947. }
  2948. }
  2949. /**
  2950. * @remarks 会员支付
  2951. * @author Tang
  2952. * @created 2021/8/27 9:18
  2953. */
  2954. public function pay_user_annual()
  2955. {
  2956. try {
  2957. $oid = r::param('oid', '');
  2958. $code = r::param('code', '');
  2959. $payType = r::param('type', '');// wx.ALI
  2960. if ($oid == '') return app('json')->fail("请检查参数是否正确");
  2961. $groupOrder = Db::name('user_pension_account_order')->where('id', $oid)->where('status', 0)->find();
  2962. if (!$groupOrder) return app('json')->fail('订单不存在或已支付');
  2963. $access = new Access();
  2964. $res = $access->pay_huifu($payType, $code, $groupOrder, "年费", env('APP_URL') . "/api/hf_notify/pay_user_annual");
  2965. Db::name('log')->insert(['data' => '汇付用户年费支付---' . json_encode($res)]);
  2966. Db::name('user_pension_account_order')->where('id', $oid)->update(['hf_pay_id' => $res['id']]);
  2967. return app('json')->success($res);
  2968. } catch (\Exception $exception) {
  2969. return app('json')->fail();
  2970. }
  2971. }
  2972. /**
  2973. * @remarks 会员支付 线下
  2974. * @author Tang
  2975. * @created 2021/8/27 9:18
  2976. */
  2977. public function pay_user_annual_offline()
  2978. {
  2979. try {
  2980. $oid = r::param('oid', '');
  2981. $payType = r::param('type', '');// WX.ALI
  2982. $pay_user_id = r::param('pay_user_id', '');// 如果是微信。传open_id 如果是支付宝。传user_id
  2983. if ($oid == '') return app('json')->fail("请检查参数是否正确");
  2984. if ($pay_user_id == '') return app('json')->fail("请检查参数是否正确");
  2985. $order = Db::name('user_pension_account_order')->where('id', $oid)->where('status', 0)->find();
  2986. if (!$order) return app('json')->fail('订单不存在或已支付');
  2987. if ($order['type'] == 1) {
  2988. $title = "开通账户";
  2989. } elseif ($order['type'] == 2) {
  2990. $title = "大礼包1";
  2991. } elseif ($order['type'] == 3) {
  2992. $title = "大礼包2";
  2993. } elseif ($order['type'] == 4) {
  2994. $title = "大礼包3";
  2995. } else {
  2996. return app('json')->fail('订单异常');
  2997. }
  2998. if ($order['type'] > 1) {
  2999. // 本人给养老金10%
  3000. $ylj = sprintf("%01.2f", bcmul($order['pay_price'], '0.1', 5));// 10%的养老金
  3001. $commission = 0;
  3002. // 上级给佣金10%
  3003. $order_user = Db::name("user")->where("uid", $order["uid"])->field("spread_uid")->find();
  3004. // 推广员id
  3005. $spread_uid = $order_user["spread_uid"];
  3006. if (!empty($spread_uid)) {
  3007. $commission = sprintf("%01.2f", bcmul($order['pay_price'], '0.1', 5));// 10%的佣金
  3008. }
  3009. $pt = sprintf("%01.2f", 12 + $ylj + $commission);
  3010. $merchant_money = sprintf("%01.2f", $order['pay_price'] - $pt);
  3011. } else {
  3012. $pt = "12.00";
  3013. $merchant_money = "0.00";
  3014. }
  3015. if ($payType == 'WX') {
  3016. $pay_wx = systemConfig('pay_wx');
  3017. // 微信
  3018. if ($pay_wx == 3) {
  3019. $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 3)->value('member_id');
  3020. $key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
  3021. $app_id = 'app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0';
  3022. } else {
  3023. $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 2)->value('member_id');
  3024. $key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  3025. $app_id = 'app_0827b960-b932-45ec-b800-4e850091b419';
  3026. }
  3027. $type = '2';
  3028. $pay_channel = 'wx_pub';
  3029. $expend = [
  3030. 'open_id' => $pay_user_id
  3031. ];
  3032. } elseif ($payType == 'ALI') {
  3033. $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 1)->value('member_id');
  3034. $app_id = 'app_44108546-d27a-48ee-88c1-84b45b75114f';
  3035. $type = '1';
  3036. $pay_channel = 'alipay_pub';
  3037. $expend = [
  3038. 'buyer_id' => $pay_user_id
  3039. ];
  3040. $key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  3041. }
  3042. if ($merchant_money == '0.00') {
  3043. $div_members = [
  3044. [
  3045. 'member_id' => 0,
  3046. 'amount' => $pt,
  3047. 'fee_flag' => 'Y'
  3048. ]
  3049. ];
  3050. } else {
  3051. $div_members = [
  3052. [
  3053. 'member_id' => $member_id,
  3054. 'amount' => $merchant_money,
  3055. 'fee_flag' => 'Y'
  3056. ],
  3057. [
  3058. 'member_id' => 0,
  3059. 'amount' => $pt,
  3060. 'fee_flag' => 'N'
  3061. ]
  3062. ];
  3063. }
  3064. $params = [
  3065. 'order_no' => $order['order_no'] . '_' . rand(000, 999),
  3066. 'app_id' => $app_id,
  3067. 'pay_channel' => $pay_channel,
  3068. 'pay_amt' => (string)$order['pay_price'],
  3069. 'goods_title' => "幸福宝",
  3070. 'goods_desc' => $title,
  3071. 'device_info' => [
  3072. 'device_ip' => app('request')->ip()
  3073. // 'device_ip'=>'115.171.134.68'
  3074. ],
  3075. 'expend' => json_encode($expend),
  3076. 'div_members' => json_encode($div_members),
  3077. 'fee_mode' => 'I',
  3078. 'notify_url' => env('APP_URL') . "/api/jsapiPay/notify/HF_pay_user_annual"
  3079. ];
  3080. $res = $this->Payment_create_traits($params, $type, $key);
  3081. if (!empty($res['error_code'])) {
  3082. return app('json')->fail($res['return_msg']);
  3083. } else {
  3084. Db::name('user_pension_account_order')->where('id', $oid)->update(['hf_pay_id' => $res['id']]);
  3085. return app('json')->success($res);
  3086. }
  3087. } catch (\Exception $exception) {
  3088. Db::name('log')->insert(['data' => '大礼包支付error:' . $exception->getFile() . ':' . $exception->getLine() . '【' . $exception->getMessage() . '】']);
  3089. return app('json')->fail();
  3090. }
  3091. }
  3092. public function red_log()
  3093. {
  3094. $uid = $this->request->uid();
  3095. [$page, $limit] = $this->getPage();
  3096. $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) {
  3097. $item['create_time'] = date('Y-m-d H:i:s', $item['time']);
  3098. $item['red'] = set_price_rtrim($item['red']);
  3099. return $item;
  3100. });
  3101. return app('json')->success($user_rich_log);
  3102. }
  3103. public function apply_bang_fu()
  3104. {
  3105. $uid = $this->request->uid();
  3106. $check = Db::name('user_rich')->where('uid', $uid)->find();
  3107. if ($check['type'] < 3) {
  3108. return app('json')->fail("不满足申请条件");
  3109. }
  3110. $check = Db::name('user_bangfu')->where('uid', $uid)->value('status');
  3111. if ($check == 0) {
  3112. return app('json')->fail("审核中");
  3113. }
  3114. if ($check == 1) {
  3115. return app('json')->fail("已是帮扶中心");
  3116. }
  3117. if ($check == 2) {
  3118. return app('json')->fail("审核被拒绝");
  3119. }
  3120. $bang_fu_number = systemConfig("bang_fu_number");
  3121. // 检测用户是否满足条件
  3122. $number = $this->getNumber($uid, $bang_fu_number) - 1;// 满足条件人数 减去自己
  3123. // 条件
  3124. if ($number >= $bang_fu_number) {
  3125. // echo '满足';
  3126. Db::name('user_bangfu')->insert([
  3127. 'uid' => $uid,
  3128. 'time' => time(),
  3129. 'status' => 0
  3130. ]);
  3131. return app('json')->success("提交申请成功");
  3132. }
  3133. return app('json')->fail("不满足申请条件");
  3134. // echo '不满足';
  3135. }
  3136. // 获得满足 1+5 的下级数量
  3137. public function getNumber($uid, $bang_fu_number): int
  3138. {
  3139. $number = 0;
  3140. $getUid = Db::name('user')->where('level_id', $uid)->field('uid')->select();
  3141. $count = count($getUid);
  3142. if ($count >= 5) {
  3143. $number = 1;
  3144. foreach ($getUid as $value) {
  3145. $number += $this->getNumber($value['uid'], $bang_fu_number);
  3146. if ($number >= $bang_fu_number) {
  3147. break;
  3148. }
  3149. }
  3150. }
  3151. return $number;
  3152. }
  3153. /**
  3154. * 积分明细
  3155. * @return mixed
  3156. */
  3157. public function score_info()
  3158. {
  3159. $uid = $this->request->uid();;
  3160. $data['score'] = decimal2(Db::name('user_sign_score')
  3161. ->where('uid', $uid)
  3162. ->where('status', 1)
  3163. ->where('pm', 1)
  3164. ->sum('reward_socre'));;
  3165. $data['no_clear_score'] = decimal2(Db::name('user_sign_score')
  3166. ->where('uid', $uid)
  3167. ->where('status', -1)
  3168. ->where('pm', 1)
  3169. ->sum('reward_socre'));
  3170. $data['lose_score'] = decimal2(Db::name('user_sign_score')
  3171. ->where('uid', $uid)
  3172. ->where('pm', 2)
  3173. ->sum('reward_socre'));
  3174. $data['clear_score'] = $score = decimal2($data['score'] - $data['lose_score']);
  3175. $data['score'] = $data['clear_score'] + $data['no_clear_score'] + $data['lose_score'];
  3176. $data['score'] = decimal2($data['score']);
  3177. Db::name('user')->where('uid', $uid)->update([
  3178. 'score' => $score
  3179. ]);
  3180. // clear_score 可用积分,score 积分总数 lose_score 已使用积分 no_clear_score 未结算积分
  3181. return app('json')->success($data);
  3182. }
  3183. /**
  3184. * 新版我的团队
  3185. */
  3186. public function get_team_list()
  3187. {
  3188. $data = [];
  3189. [$page, $limit] = $this->getPage();
  3190. $uid = $this->request->uid();
  3191. $type = intval($this->request->param('type'));
  3192. // 查询团队列表
  3193. $userRepository = app()->make(UserRepository::class);
  3194. $chilid_userids = $userRepository->getSpreadUidBreak($uid);
  3195. $data['fans_count'] = count($chilid_userids);
  3196. $direct_uid_list = Db::name('user')->where('spread_uid', $uid)->where('is_del', 0)->column('uid');
  3197. $data['direct_count'] = count($direct_uid_list);
  3198. $valid_uid_list = Db::name('store_order')
  3199. ->whereIn('uid', $chilid_userids)
  3200. ->where('paid', 1)
  3201. ->group('uid')
  3202. ->column('uid');
  3203. $data['valid_count'] = count($valid_uid_list);
  3204. $data['count'] = Db::name('user')
  3205. ->whereIn('uid', $chilid_userids)
  3206. ->count();
  3207. $data['list'] = Db::name('user')
  3208. ->field('uid,phone,nickname,user_group,create_time,avatar as picture')
  3209. ->page($page, $limit)
  3210. ->whereIn('uid', $chilid_userids)
  3211. ->when($type == 1, function ($query) use ($direct_uid_list) {
  3212. return $query->whereIn('uid', $direct_uid_list);
  3213. })
  3214. ->when($type == 2, function ($query) use ($valid_uid_list) {
  3215. return $query->whereIn('uid', $valid_uid_list);
  3216. })
  3217. ->order('uid DESC')
  3218. ->select()
  3219. ->toArray();
  3220. foreach ($data['list'] as &$user) {
  3221. $user ['phone'] = substr_replace($user['phone'], '****', 3, 4);
  3222. }
  3223. return app('json')->success($data);
  3224. }
  3225. /**
  3226. * 我的粉丝详情
  3227. */
  3228. public function get_team_info()
  3229. {
  3230. $uid = $this->request->param('uid', '');
  3231. if (!$uid)
  3232. return app('json')->fail("uid不正确");
  3233. $userRepository = app()->make(UserRepository::class);
  3234. $chilid_userids = $userRepository->getSpreadUidBreak($this->request->uid());
  3235. if (!in_array($uid, $chilid_userids))
  3236. return app('json')->fail("该用户不在所属团队内");
  3237. $data = Db::name('user')
  3238. ->field('uid,phone,nickname,spread_uid,user_group,create_time,manage_address')
  3239. ->where('uid', $uid)
  3240. ->find();
  3241. $data['regimental_commander_count'] = Db::name('user')
  3242. ->where('spread_uid', $uid)
  3243. ->where('user_group', 2)
  3244. ->count();
  3245. $data['clear_order_amount'] = Db::name('store_order')
  3246. ->where('uid', $uid)
  3247. ->where('is_settlement', 1)
  3248. ->sum('pay_price');
  3249. $data['mybuy_order_amount'] = Db::name('store_order')
  3250. ->where('uid', $uid)
  3251. ->where('paid', 1)
  3252. ->sum('pay_price');
  3253. $spread_user = Db::name('user')
  3254. ->field('nickname as spread_nickname,phone as spread_phone')
  3255. ->where('uid', $data['spread_uid'])
  3256. ->find();
  3257. $spread_user ['spread_phone'] = substr_replace($spread_user['spread_phone'], '****', 3, 4);
  3258. $spread_user ['spread_nick_name'] = $spread_user['spread_nickname'] ?? '';
  3259. $data ['phone'] = substr_replace($data['phone'], '****', 3, 4);
  3260. $data = array_merge($data, $spread_user);
  3261. if (in_array($data['user_group'], [5, 6])) {
  3262. $data['area_name'] = Db::name('regions')->field('type,code_list')->where('id', 'in', $data['manage_address'])->cache('code:' . $data['manage_address'], 7200)->column('name');
  3263. $data['area_name'] = join($data['area_name']);
  3264. $data['area_bonus_money'] = Db::name('user_bill')
  3265. ->where('uid', $uid)
  3266. ->sum('number');
  3267. }
  3268. unset($data['manage_address']);
  3269. if (in_array($data['user_group'], [4])) {
  3270. $merchant = Db::name('merchant')->where('uid', $uid)->field('mer_id,mer_name')->find();
  3271. $data['mer_id'] = $merchant['mer_id'] ?? 0;
  3272. $data['mer_name'] = $merchant['mer_name'] ?? '';
  3273. }
  3274. return app('json')->success($data);
  3275. }
  3276. /**
  3277. * 我的佣金
  3278. */
  3279. public function get_brokerage_info()
  3280. {
  3281. $uid = $this->request->uid();
  3282. // 佣金余额
  3283. $data['brokerage_price'] = Db::name('user')->where('uid', $uid)->value('brokerage_price');
  3284. // 总收益
  3285. $data['sum_amount'] = Db::name('user_bill')
  3286. ->where('uid', $uid)
  3287. ->where('commission_type', '<>', 5)
  3288. ->where('commission_type', '<>', 0)
  3289. ->where('pm', 1)
  3290. ->sum('number');
  3291. // 未结算
  3292. $data['no_clear_amount'] = Db::name('user_bill')
  3293. ->where('uid', $uid)
  3294. ->where('commission_type', '<>', 5)
  3295. ->where('commission_type', '<>', 0)
  3296. ->where('pm', 1)
  3297. ->where('status', 0)
  3298. ->sum('number');
  3299. // 已提现
  3300. $data['withdraw_amount'] = Db::name('user_extract')
  3301. ->where('uid', $uid)
  3302. ->whereIn('status', [0, 1])
  3303. ->sum('extract_price');
  3304. // 转VR
  3305. $data['transition_vr_amount'] = Db::name('user_transition_vr')
  3306. ->where('uid', $uid)
  3307. ->where('type', 1)
  3308. ->sum('number');
  3309. // 最终 总收益是 = 佣金余额 + 已提现 + 已转VR
  3310. // $data['sum_amount'] = $data['sum_amount'] + $data['transition_vr_amount'];
  3311. $data['sum_amount'] = set_price_rtrim($data['sum_amount']);
  3312. return app('json')->success($data);
  3313. }
  3314. public function get_token_by_phone(UserRepository $repository){
  3315. $user = $repository->accountByUser($this->request->param('phone'));
  3316. $tokenInfo = $repository->createToken($user);
  3317. return app('json')->success($repository->returnToken($user, $tokenInfo));
  3318. }
  3319. /**
  3320. * 转VR
  3321. */
  3322. public function transition_vr()
  3323. {
  3324. $uid = $this->request->uid();
  3325. $user = $this->request->userInfo();
  3326. $type = $this->request->param('type', 'brokerage');
  3327. $extract_amount = $this->request->param('extract_amount', 0);
  3328. if ($type == 'brokerage') {
  3329. $brokerage_price = Db::name('user')->where('uid', $uid)->value('brokerage_price');
  3330. // 参考结算任务中的代码片段, 余额中 应不包含未结算余额
  3331. // $no_clear_amount = Db::name('user_bill')
  3332. // ->where('uid', $uid)
  3333. // ->where('commission_type', '<>', 5)
  3334. // ->where('pm', 1)
  3335. // ->where('status', 0)
  3336. // ->sum('number');
  3337. // $clear_amount = $brokerage_price - $no_clear_amount;
  3338. $clear_amount = $brokerage_price;
  3339. // if ($user['brokerage_price'] < (systemConfig('withdrawal_money'))){
  3340. // return app('json')->fail('未到达提现最低额度');
  3341. // }
  3342. if($extract_amount > $clear_amount){
  3343. return app('json')->fail("可用金额不足提现");
  3344. }
  3345. $brokerage_price = bcsub($user['brokerage_price'], $extract_amount,2);
  3346. $user->brokerage_price = $brokerage_price;
  3347. $vr = bcadd($user['vr'], $extract_amount, 2);
  3348. $user->vr = $vr;
  3349. $res = $user->save();
  3350. if ($res){
  3351. // 加入转VR记录
  3352. $insertdata = [
  3353. 'uid'=> $uid,
  3354. 'number' => $extract_amount,
  3355. 'surplus' => $vr,
  3356. 'mark' => '佣金转VR',
  3357. 'type' => 1,
  3358. 'create_time' => time(),
  3359. ];
  3360. Db::name('user_transition_vr')->insertGetId($insertdata);
  3361. // VR入账
  3362. $insertdata = [
  3363. 'uid'=> $uid,
  3364. 'number' => $extract_amount,
  3365. 'surplus' => $vr,
  3366. 'mark' => '佣金转VR',
  3367. 'order_id'=> 0,
  3368. 'type' => 1,
  3369. 'addtime' => time(),
  3370. 'settlement_time'=> date('Y-m-d H:i:s', time())
  3371. ];
  3372. Db::name('user_sign_vr')->insertGetId($insertdata);
  3373. return app('json')->success('转VR成功');
  3374. }else{
  3375. return app('json')->fail('转VR失败');
  3376. }
  3377. }
  3378. if ($type == 'hongbao') {
  3379. $hongbao = Db::name('user')->where('uid', $uid)->value('hongbao');
  3380. $no_clear_amount = Db::name('user_sign_hongbao')
  3381. ->where('uid', $uid)
  3382. ->where('type', 1)
  3383. ->where('status', -1)
  3384. ->sum('number');
  3385. $clear_amount = $hongbao - $no_clear_amount;
  3386. // if ($user['hongbao'] < (systemConfig('withdrawal_money'))){
  3387. // return app('json')->fail('未到达提现最低额度');
  3388. // }
  3389. if($extract_amount > $clear_amount){
  3390. return app('json')->fail("可用金额不足提现");
  3391. }
  3392. $hongbao = bcsub($user['hongbao'], $extract_amount,2);
  3393. $user->hongbao = $hongbao;
  3394. $vr = bcadd($user['vr'], $extract_amount, 2);
  3395. $user->vr = $vr;
  3396. $res = $user->save();
  3397. if ($res){
  3398. // 加入转VR记录
  3399. $insertdata = [
  3400. 'uid'=> $uid,
  3401. 'number' => $extract_amount,
  3402. 'surplus' => $vr,
  3403. 'mark' => '红包转VR',
  3404. 'type' => 2,
  3405. 'status' => 1,
  3406. 'addtime' => time(),
  3407. ];
  3408. Db::name('user_sign_hongbao')->insertGetId($insertdata);
  3409. // VR入账
  3410. $insertdata = [
  3411. 'uid'=> $uid,
  3412. 'number' => $extract_amount,
  3413. 'surplus' => $vr,
  3414. 'mark' => '红包转VR',
  3415. 'order_id'=> 0,
  3416. 'type' => 1,
  3417. 'addtime' => time(),
  3418. 'settlement_time'=> date('Y-m-d H:i:s', time())
  3419. ];
  3420. Db::name('user_sign_vr')->insertGetId($insertdata);
  3421. return app('json')->success('转VR成功');
  3422. }else{
  3423. return app('json')->fail('转VR失败');
  3424. }
  3425. }
  3426. return app('json')->fail('转VR失败');
  3427. }
  3428. /**
  3429. * 转VR记录
  3430. */
  3431. public function transition_vr_log()
  3432. {
  3433. $uid = $this->request->uid();
  3434. $type = $this->request->param('type', 1);
  3435. [$page, $limit] = $this->getPage();
  3436. $where = [];
  3437. $where[] = ['uid', '=', $uid];
  3438. $where[] = ['type', '=', $type];
  3439. $query = Db::name("user_transition_vr");
  3440. $count = $query->where($where)->count();
  3441. $list = $query->page($page, $limit)->where($where)->order('id desc')->select()->each(function ($item){
  3442. $item['create_time'] = date("Y-m-d H:i:s", $item['create_time']);
  3443. return $item;
  3444. });
  3445. return app('json')->success('获取转VR记录成功', ['list'=>$list, 'count'=>$count]);
  3446. }
  3447. // 根据父级uid,递归获取所有子级UID数组
  3448. public function getRecursiveChildren($parentUid) {
  3449. $result = []; // 用于存储符合条件的子级 uid
  3450. // 定义递归函数
  3451. $recursion = function ($parentUid) use (&$result, &$recursion) {
  3452. // 查询当前父级的所有直接子级
  3453. $children = Db::name("user")
  3454. ->where("spread_uid", $parentUid)
  3455. ->column("uid"); // 获取子级的 uid 列表
  3456. // 如果没有子级,直接返回
  3457. if (empty($children)) {
  3458. return;
  3459. }
  3460. // 遍历每个子级
  3461. foreach ($children as $childUid) {
  3462. // 如果子级的 uid 小于或等于 611,跳过该子级及其所有子级
  3463. if ($childUid <= 611) {
  3464. continue;
  3465. }
  3466. // 将符合条件的子级 uid 添加到结果数组
  3467. $result[] = $childUid;
  3468. // 递归查询子级的子级
  3469. $recursion($childUid);
  3470. }
  3471. };
  3472. // 从初始父级开始递归查询
  3473. $recursion($parentUid);
  3474. return array_unique($result); // 返回结果数组,并去重
  3475. }
  3476. // 2.0 根据父级uid,找到当前用户下面的UID
  3477. public function getChildren($parentUid) {
  3478. $result = []; // 用于存储所有子级的 uid
  3479. $children = Db::name("user")
  3480. ->where("spread_uid", $parentUid)
  3481. ->column("uid"); // 获取子级的 uid 列表
  3482. return $children; // 返回结果数组,并去重
  3483. }
  3484. public function getNewTeamPv($common_nums) {
  3485. // 初始化结果数组
  3486. $result = [
  3487. 'max_value' => null,
  3488. 'max_uid' => null,
  3489. 'remaining_values' => 0, // 剩余值的总和
  3490. 'remaining_uids' => [] // 剩余值对应的 UID
  3491. ];
  3492. // 递归获取所有子级 UID 的函数
  3493. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  3494. $children = Db::name("user")
  3495. ->where("spread_uid", $parentUid)
  3496. ->column("uid");
  3497. $allChildren = [];
  3498. foreach ($children as $childUid) {
  3499. $allChildren[] = $childUid;
  3500. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  3501. }
  3502. return $allChildren;
  3503. };
  3504. // 获取每个用户的总业绩,包括子级的业绩
  3505. $userTotalPv = [];
  3506. foreach ($common_nums as $uid) {
  3507. // 获取当前用户及其所有子级的 UID
  3508. $allUids = array_merge([$uid], $getRecursiveChildren($uid));
  3509. // 查询当前用户及其子级的所有订单
  3510. $orders = Db::name("store_order")
  3511. ->whereIn('status', [0, 1, 2, 3])
  3512. ->whereIn("uid", $allUids)
  3513. ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  3514. ->select();
  3515. // 计算总业绩
  3516. $totalPv = 0;
  3517. foreach ($orders as $order) {
  3518. if ($order['total_price'] == 1180) {
  3519. $totalPv += 700;
  3520. } else if ($order['total_price'] == 11800) {
  3521. $totalPv += 7000;
  3522. } else if ($order['total_price'] == 10620) {
  3523. $totalPv += 6300;
  3524. } else if ($order['total_price'] == 2360) {
  3525. $totalPv += 1400;
  3526. } else if ($order['total_price'] == 9440) {
  3527. $totalPv += 5600;
  3528. }
  3529. }
  3530. // 将当前用户的总业绩和 UID 存入数组
  3531. $userTotalPv[] = ['uid' => $uid, 'totalPv' => $totalPv];
  3532. }
  3533. // 如果没有符合条件的订单,直接返回空数组
  3534. if (empty($userTotalPv)) {
  3535. return [];
  3536. }
  3537. // 找到最大值及其对应的 UID
  3538. usort($userTotalPv, function($a, $b) {
  3539. return $b['totalPv'] <=> $a['totalPv']; // 按 totalPv 降序排序
  3540. });
  3541. // 获取最大值及其 UID
  3542. $result['max_value'] = $userTotalPv[0]['totalPv'];
  3543. $result['max_uid'] = $userTotalPv[0]['uid'];
  3544. // 计算剩余值的总和和对应的 UID
  3545. foreach ($userTotalPv as $index => $user) {
  3546. if ($index > 0) { // 跳过第一个(最大值)
  3547. $result['remaining_values'] += $user['totalPv'];
  3548. $result['remaining_uids'][] = $user['uid'];
  3549. }
  3550. }
  3551. return $result;
  3552. }
  3553. // 只获取数组中的业绩
  3554. public function getteampv($common_nums) {
  3555. // 查询当前用户及其子级的所有订单
  3556. $orders = Db::name("store_order")
  3557. ->whereIn('status', [0, 1, 2, 3])
  3558. ->whereIn("uid", $common_nums)
  3559. ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  3560. ->select();
  3561. // 初始化业绩和人数
  3562. $totalPv = 0;
  3563. $totalUsers = count($common_nums); // 初始化人数为子级总数
  3564. // 遍历订单计算业绩
  3565. foreach ($orders as $order) {
  3566. if ($order['total_price'] == 1180) {
  3567. $totalPv += 700;
  3568. } else if ($order['total_price'] == 11800) {
  3569. $totalPv += 7000;
  3570. } else if ($order['total_price'] == 10620) {
  3571. $totalPv += 6300;
  3572. } else if ($order['total_price'] == 2360) {
  3573. $totalPv += 1400;
  3574. } else if ($order['total_price'] == 9440) {
  3575. $totalPv += 5600;
  3576. }
  3577. }
  3578. // 返回业绩和人数
  3579. return [
  3580. 'totalPv' => $totalPv,
  3581. 'totalUsers' => $totalUsers
  3582. ];
  3583. }
  3584. // 递归获取所有子级 UID 的业绩
  3585. public function getTeamPv11($parentUid) {
  3586. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  3587. $children = Db::name("user")
  3588. ->where("spread_uid", $parentUid)
  3589. ->column("uid");
  3590. $allChildren = [];
  3591. foreach ($children as $childUid) {
  3592. $allChildren[] = $childUid;
  3593. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  3594. }
  3595. return $allChildren;
  3596. };
  3597. // 获取当前用户及其所有子级的 UID
  3598. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  3599. // 查询当前用户及其子级的所有订单
  3600. $orders = Db::name("store_order")
  3601. ->whereIn('status', [0, 1, 2, 3])
  3602. ->whereIn("uid", $allUids)
  3603. ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  3604. ->select();
  3605. // 计算总业绩
  3606. $totalPv = 0;
  3607. foreach ($orders as $order) {
  3608. switch ($order['total_price']) {
  3609. case 1180:
  3610. $totalPv += 700;
  3611. break;
  3612. case 11800:
  3613. $totalPv += 7000;
  3614. break;
  3615. case 10620:
  3616. $totalPv += 6300;
  3617. break;
  3618. case 2360:
  3619. $totalPv += 1400;
  3620. break;
  3621. case 9440:
  3622. $totalPv += 5600;
  3623. break;
  3624. }
  3625. }
  3626. return $totalPv;
  3627. }
  3628. // 根据传递的父级数组,返回他的对应子级的个数
  3629. public function getTeamSize($parentUids) {
  3630. // 初始化结果数组
  3631. $result = [];
  3632. // 遍历每个父级ID
  3633. foreach ($parentUids as $parentUid) {
  3634. // 递归获取所有子级 UID
  3635. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  3636. $children = Db::name("user")
  3637. ->where("spread_uid", $parentUid)
  3638. ->column("uid");
  3639. // 确保返回的是数组
  3640. if (!is_array($children)) {
  3641. return [];
  3642. }
  3643. $allChildren = [];
  3644. foreach ($children as $childUid) {
  3645. $allChildren[] = $childUid;
  3646. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  3647. }
  3648. return $allChildren;
  3649. };
  3650. // 获取当前父级及其所有子级的 UID
  3651. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  3652. // 计算总个数(包括父级自身)
  3653. $totalUids = count($allUids);
  3654. // 将结果存入数组
  3655. $result[] = [
  3656. 'parent_uid' => $parentUid,
  3657. 'total_count' => $totalUids
  3658. ];
  3659. }
  3660. return $result;
  3661. }
  3662. public function processArray($array) {
  3663. // 初始化结果数组
  3664. $result = [
  3665. 'max_value' => null, // 最大值
  3666. 'max_index' => null, // 最大值的下标
  3667. 'remaining_sum' => 0 // 剩余值的总和
  3668. ];
  3669. // 检查数组是否为空
  3670. if (empty($array)) {
  3671. return $result;
  3672. }
  3673. // 找出最大值及其下标
  3674. $maxValue = $array[0];
  3675. $maxIndex = 0;
  3676. for ($i = 1; $i < count($array); $i++) {
  3677. if ($array[$i] > $maxValue) {
  3678. $maxValue = $array[$i];
  3679. $maxIndex = $i;
  3680. }
  3681. }
  3682. // 计算剩余值的总和
  3683. $remainingSum = 0;
  3684. for ($i = 0; $i < count($array); $i++) {
  3685. if ($i != $maxIndex) {
  3686. $remainingSum += $array[$i];
  3687. }
  3688. }
  3689. // 将结果存入数组
  3690. $result['max_value'] = $maxValue;
  3691. $result['max_index'] = $maxIndex;
  3692. $result['remaining_sum'] = $remainingSum;
  3693. return $result;
  3694. }
  3695. // 获取当前uesr_id下面在2.0中是否还有直接下级,并计算她的大部门和小部门
  3696. public function getparents_child_pv($user_id){
  3697. // 获取直接下级的 UID 列表
  3698. $get_childs = Db::name("user")
  3699. ->where("spread_uid", $user_id)
  3700. ->column("uid");
  3701. // var_dump($get_childs);
  3702. // 初始化总业绩和总人数
  3703. $total_value = 0;
  3704. $total_count = 0;
  3705. $max_value = 0;
  3706. $max_count = 0;
  3707. // 遍历每个直接下级
  3708. foreach ($get_childs as $child) {
  3709. // echo $child;
  3710. // 获取当前下级及其子级
  3711. $child_group = [$child];
  3712. $recursive_children = $this->getRecursiveChildren($child);
  3713. $child_group = array_merge($child_group, $recursive_children);
  3714. // var_dump($child_group );
  3715. // 获取当前分组的业绩和人数
  3716. $result = $this->getteampv($child_group);
  3717. // var_dump($result);
  3718. $group_pv = $result['totalPv'];
  3719. $group_count = $result['totalUsers'];
  3720. // 累加总业绩和总人数
  3721. $total_value += $group_pv;
  3722. $total_count += $group_count;
  3723. // 更新最大业绩及其对应的人数
  3724. if ($group_pv > $max_value) {
  3725. $max_value = $group_pv;
  3726. $max_count = $group_count;
  3727. }
  3728. }
  3729. // 计算小部门的业绩和人数
  3730. $small_department_value = $total_value - $max_value;
  3731. $small_department_count = $total_count - $max_count;
  3732. // 返回结果
  3733. return [
  3734. 'team_pv' => $max_value,
  3735. 'team_num' => $max_count,
  3736. 'per_pv' => $small_department_value,
  3737. 'per_num' => $small_department_count
  3738. ];
  3739. }
  3740. // 1.0用户直属的部门和2.0直属的部门,进行比较,获取大部门和小部门数据
  3741. public function getparents_child_pv11($user_id, $bigamount, $smallamount, $common_nums, $person_nums) {
  3742. // 获取直接下级的 UID 列表
  3743. $get_childs = Db::name("user")
  3744. ->where("spread_uid", $user_id)
  3745. ->column("uid");
  3746. // 初始化变量
  3747. $all_departments = []; // 用于存储所有直属下级的业绩和人数
  3748. // 遍历每个直属下级
  3749. foreach ($get_childs as $child) {
  3750. // 获取当前下级及其子级
  3751. $child_group = [$child];
  3752. $recursive_children = $this->getRecursiveChildren($child);
  3753. $child_group = array_merge($child_group, $recursive_children);
  3754. // 获取当前分组的业绩和人数
  3755. $result = $this->getteampv($child_group);
  3756. // if($user_id == 593){
  3757. // var_dump($result);
  3758. // }
  3759. // 将直属下级的业绩和人数加入数组
  3760. $all_departments[] = [
  3761. 'value' => $result['totalPv'],
  3762. 'count' => $result['totalUsers']
  3763. ];
  3764. }
  3765. // 将传入的 $bigamount 和 $smallamount 以及对应的人数加入数组
  3766. $all_departments[] = [
  3767. 'value' => $bigamount,
  3768. 'count' => $common_nums // 大部门的人数
  3769. ];
  3770. $all_departments[] = [
  3771. 'value' => $smallamount,
  3772. 'count' => $person_nums // 小部门的人数
  3773. ];
  3774. // 初始化最大部门和小部门
  3775. $max_department = null;
  3776. $small_department = [
  3777. 'value' => 0,
  3778. 'count' => 0
  3779. ];
  3780. // 遍历 $all_departments,找出最大值并累加小部门的值
  3781. foreach ($all_departments as $department) {
  3782. if ($max_department === null || $department['value'] > $max_department['value']) {
  3783. // 如果当前部门的业绩大于最大部门的业绩,更新最大部门
  3784. $small_department['value'] += $max_department['value'] ?? 0; // 将旧的最大值累加到小部门
  3785. $small_department['count'] += $max_department['count'] ?? 0;
  3786. $max_department = $department; // 更新最大部门
  3787. } else {
  3788. // 如果当前部门的业绩小于或等于最大部门的业绩,累加到小部门
  3789. $small_department['value'] += $department['value'];
  3790. $small_department['count'] += $department['count'];
  3791. }
  3792. }
  3793. // 返回结果
  3794. return [
  3795. 'big_department' => $max_department,
  3796. 'small_department' => $small_department
  3797. ];
  3798. }
  3799. // 根据父级IDS获取伞下的所有子级ID
  3800. public function getRecursiveChildren_s($parentUid) {
  3801. $result = []; // 用于存储所有子级的 uid
  3802. // 定义递归函数
  3803. $recursion = function ($currentUid) use (&$result, &$recursion) {
  3804. // 查询当前父级的所有直接子级
  3805. $children = Db::name("user")
  3806. ->where("spread_uid", $currentUid)
  3807. ->column("uid"); // 获取子级的 uid 列表
  3808. // 如果没有子级,直接返回
  3809. if (empty($children)) {
  3810. return;
  3811. }
  3812. // 遍历每个子级
  3813. foreach ($children as $childUid) {
  3814. $result[] = $childUid; // 将子级的 uid 添加到结果数组
  3815. $recursion($childUid); // 递归查询子级的子级
  3816. }
  3817. };
  3818. // 从初始父级开始递归查询
  3819. $recursion($parentUid);
  3820. return array_unique($result); // 返回结果数组,并去重
  3821. }
  3822. /**
  3823. * 获取当前用户业绩
  3824. */
  3825. public function userupdates($user_id) {
  3826. //$user_id = 17;
  3827. $children = Db::name("user")
  3828. ->where("spread_uid", $user_id)
  3829. ->select(); // 获取子级的 uid 列表
  3830. $total_pv = 0;
  3831. foreach($children as $k=>$v){
  3832. //$children_pv = Db::name("store_order")->where("uid", $v['uid'])->whereIn("status",[0,1,2,3])->select();
  3833. $children_pv = Db::name("user_sign_gongxian")->where("uid", $v['uid'])->where("status",1)->select();
  3834. foreach($children_pv as $k1=>$v1){
  3835. $total_pv += $v1['number'];
  3836. }
  3837. }
  3838. return $total_pv;
  3839. $userdatas = Db::name("user")->where("uid", $user_id)->find();
  3840. // var_dump($userdatas['user_group']);
  3841. // 如果当前用户是普通消费者的情况下
  3842. if($userdatas['user_group'] == 1){
  3843. if($total_pv != 0){
  3844. if($total_pv >= 1180 && $total_pv < 11800){
  3845. Db::name("user")->where("uid", $user_id)->update(['user_group',2]);
  3846. }
  3847. }
  3848. }
  3849. // 如果当前用户是业务员消费者的情况下
  3850. if($userdatas['user_group'] <= 2){
  3851. if($total_pv != 0){
  3852. if(11800 <= $total_pv){
  3853. Db::name("user")->where("uid", $user_id)->update(['user_group',3]);
  3854. }
  3855. }
  3856. }
  3857. }
  3858. /**
  3859. * 获取当前用户业绩
  3860. */
  3861. public function getPerformance22($user_id) {
  3862. $team_amount = 0;
  3863. $person_amount = 0;
  3864. // $user_id = 17; //598 523 536
  3865. $result_big_team_arr = [];
  3866. $get_teams_comm_datas = [];// 在2.0中获取父级下面的所有团队数据
  3867. // 共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  3868. $common_nums = $this->getCommonNums($user_id);
  3869. // var_dump( $common_nums);
  3870. $get_teams_comm_num = 0;
  3871. $get_teams_comm_pv = 0;
  3872. $get_teams_per_num = 0;// 小部门人数
  3873. // 1.0系统中有下级,需要在2.0中再加下级数据
  3874. if($user_id < 611){
  3875. // 梅红在2.0中的ID是780
  3876. // 用户三峡所有在2.0系统下面的业绩和人数 start
  3877. $child_nums = [];
  3878. // 获取当前用户
  3879. foreach($common_nums as $v){
  3880. $child_nums[] = $this->getRecursiveChildren($v);
  3881. }
  3882. // var_dump($child_nums);
  3883. // 去除空数组,并重新组合有数据的数组
  3884. $filteredData = array_filter($child_nums, function($array) {
  3885. return !empty($array); // 如果数组不为空,则保留
  3886. });
  3887. // 合并所有非空数组
  3888. foreach ($filteredData as $array) {
  3889. $result_big_team_arr = array_merge($result_big_team_arr, $array);
  3890. }
  3891. // var_dump($result_big_team_arr);
  3892. // 获取当前用户下面在2.0中的下级所有PV
  3893. //$get_teams_comm_pv = $this->getteampv($result_big_team_arr);
  3894. $t_pv = $this->getteampv($result_big_team_arr);
  3895. $get_teams_comm_pv =$t_pv['totalPv'];
  3896. // var_dump($t_pv);echo "ttt";
  3897. // 获取当前用户下面在2.0中的下级所有人数
  3898. $get_teams_comm_num = count($result_big_team_arr);
  3899. // 用户伞下小部门所有在2.0系统下面的业绩和人数 end
  3900. }else{
  3901. // 当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
  3902. $child_nums = $this->getChildren($user_id);
  3903. // 获取父级子级下面的个人
  3904. $num_teams = $this->getTeamSize($child_nums);
  3905. // var_dump($num_teams);
  3906. foreach($child_nums as $v){
  3907. $get_teams_comm_datas[] = $this->getTeamPv11($v);// 如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
  3908. }
  3909. //$s = $this->getparents_child_pv($user_id);
  3910. // var_dump($get_teams_comm_datas);
  3911. // 如果只有一个部门,就是默认大部门
  3912. if( count($get_teams_comm_datas) ==1 ){
  3913. $get_teams_comm_pv =$get_teams_comm_datas[0];
  3914. $get_teams_comm_num = $num_teams[0]['total_count'];
  3915. }else if(count($get_teams_comm_datas) >1){
  3916. // var_dump( $get_teams_comm_datas);
  3917. // 获取一个最大值,设为大部门,其他的加载一块是小部门
  3918. $getss = $this->processArray($get_teams_comm_datas);
  3919. $max_value_count = $num_teams[$getss['max_index']]['total_count'];
  3920. unset($num_teams[$getss['max_index']]);
  3921. // 获取小部门的人数
  3922. $per_num = 0;
  3923. foreach($num_teams as $k=>$v){
  3924. $per_num +=$v['total_count'];
  3925. }
  3926. // 找到最大值的(大部门)
  3927. $get_teams_comm_num = $max_value_count;
  3928. // 小部门的数量
  3929. $get_teams_per_num = $per_num;
  3930. // var_dump($getss['max_value']);
  3931. $person_amount = $getss['remaining_sum'];
  3932. $get_teams_comm_pv = $getss['max_value'];
  3933. }
  3934. }
  3935. // var_dump($get_teams_comm_pv);
  3936. // 合并业绩和人数
  3937. $team_amount += $get_teams_comm_pv;
  3938. // var_dump($team_amount);
  3939. // 1.0获取小区业绩
  3940. $person_nums = $this->getPersonageNums($user_id);
  3941. // var_dump($person_nums);
  3942. $result_small_team_arr = [];
  3943. // 1.0系统中有下级,需要在2.0中再加下级数据
  3944. // 用户三峡所有在2.0系统下面的业绩和人数 start
  3945. $child_nums_mix = [];
  3946. // 获取当前用户
  3947. foreach($person_nums as $v){
  3948. $child_nums_mix[] = $this->getRecursiveChildren($v);
  3949. }
  3950. // 去除空数组,并重新组合有数据的数组
  3951. $filteredData_1 = array_filter($child_nums_mix, function($array) {
  3952. return !empty($array); // 如果数组不为空,则保留
  3953. });
  3954. // 合并所有非空数组
  3955. $result_small_team_arr = [];
  3956. foreach ($filteredData_1 as $array) {
  3957. $result_small_team_arr = array_merge($result_small_team_arr, $array);
  3958. }
  3959. // var_dump($result_small_team_arr);
  3960. // 获取当前用户下面在2.0中的下级所有PV
  3961. // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
  3962. $t_pv = $this->getteampv($result_small_team_arr);
  3963. $get_teams_per_pv =$t_pv['totalPv'];
  3964. // var_dump( $get_teams_per_pv);
  3965. // 获取当前用户下面在2.0中的下级所有人数
  3966. $get_teams_per_num += count($result_small_team_arr);
  3967. // 合并业绩和人数
  3968. $person_amount += $get_teams_per_pv;
  3969. // if($user_id == 593){
  3970. // $person_amount = 2800;
  3971. // }
  3972. // var_dump($person_amount);
  3973. // 用户小部门所有在2.0系统下面的业绩和人数 end
  3974. // var_dump($team_amount);
  3975. // $common_nums[] = $user_id;
  3976. foreach ($common_nums as $key => $value) {
  3977. # code...
  3978. $amount = $this->getPerformance1($value);
  3979. $team_amount += $amount;
  3980. }
  3981. foreach ($person_nums as $key => $value) {
  3982. # code...
  3983. $amount = $this->getPerformance1($value);
  3984. $person_amount += $amount;
  3985. }
  3986. // var_dump($team_amount);
  3987. // var_dump($person_amount);
  3988. //
  3989. // var_dump($team_amount);
  3990. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
  3991. //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
  3992. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  3993. $money1180Sum = 0;
  3994. foreach ($user_team_amount as $record) {
  3995. $money1180Sum += $record['money'] - 300 - 180;
  3996. }
  3997. // var_dump($money1180Sum );
  3998. // 获取 status 为 1 且 money 为 11800 的记录集合
  3999. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
  4000. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4001. $money11800Sum = 0;
  4002. foreach ($money11800Records as $record) {
  4003. $money11800Sum += $record['money'] - 3000 - 1800;
  4004. }
  4005. // var_dump($money11800Sum );
  4006. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
  4007. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4008. $money10620Sum = 0;
  4009. foreach ($money10620Records as $record) {
  4010. $money10620Sum += $record['money'] - 2700 - 1620;
  4011. }
  4012. // var_dump($money10620Sum );
  4013. // 计算除去特定值后的总和
  4014. //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
  4015. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4016. $otherMoneySum = 0;
  4017. foreach ($otherMoneyRecords as $record) {
  4018. $otherMoneySum += $record['money'];
  4019. }
  4020. // 分别处理特定值的情况并加上其他值的总和
  4021. $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  4022. // var_dump($all_record_nums);
  4023. $team_amount += $all_record_nums;
  4024. // var_dump($team_amount);
  4025. // 计算自己的个人联盟总流水
  4026. // // //计算自己的个人联盟总流水
  4027. // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
  4028. // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  4029. // $person_amount += $user_person_amount;
  4030. // 计算个人的1180单价的业绩 集合
  4031. $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
  4032. $money1180Sum = 0;
  4033. foreach ($money1180Records as $record) {
  4034. $money1180Sum += $record['money'] - 300 - 180;
  4035. }
  4036. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
  4037. // var_dump($person_nums);
  4038. // 计算个人的11800单价的业绩 集合
  4039. $money11800Sum = 0;
  4040. foreach ($money11800Records as $record) {
  4041. $money11800Sum += $record['money'] - 3000 - 1800;
  4042. }
  4043. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
  4044. // var_dump($person_nums);
  4045. // 计算个人的10620单价的业绩 集合
  4046. $money10620Sum = 0;
  4047. foreach ($money10620Records as $record) {
  4048. $money10620Sum += $record['money'] - 2700 - 1620;
  4049. }
  4050. // 计算除去特定值后的总和
  4051. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4052. $otherMoneySum = 0;
  4053. foreach ($otherMoneyRecords as $record) {
  4054. $otherMoneySum += $record['money'];
  4055. }
  4056. // 分别处理特定值的情况并加上其他值的总和
  4057. $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
  4058. $person_amount += $user_person_amount;
  4059. // 大部门人数
  4060. $teams_num = count($common_nums) + $get_teams_comm_num;
  4061. // 小部门人数
  4062. $per_num = count($person_nums) + $get_teams_per_num;
  4063. // var_dump($team_amount);
  4064. // var_dump($person_amount);
  4065. // 如果当前用户是1.0用户,找到其直推所有的业绩,根据业绩找到大小部门的同时,还要比对1.0中大小部门的业绩,摘出一个最大业绩的部门是大部门,其余都是小部门()
  4066. if($user_id < 611){
  4067. // var_dump($team_amount);
  4068. // var_dump($person_amount);
  4069. // 获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
  4070. // 例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
  4071. $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);
  4072. // var_dump($b_s);
  4073. // var_dump($team_amount,$person_amount);
  4074. // var_dump(count($common_nums)+ $get_teams_comm_num,count($person_nums)+ $get_teams_per_num);
  4075. // var_dump( $b_s);echo "yyyyyyyyyyyyy";
  4076. $team_amount = $b_s['big_department']['value'];
  4077. $teams_num = $b_s['big_department']['count'];
  4078. // var_dump($b_s['team_pv']);
  4079. // var_dump($b_s['per_pv']);
  4080. $person_amount = $b_s['small_department']['value'];
  4081. $per_num = $b_s['small_department']['count'];// 小部门人数
  4082. // var_dump( $b_s['team_num'],$b_s['per_num']);
  4083. }
  4084. // 级别信息
  4085. $userInfo = Db::name("user")->find($user_id);//
  4086. $zk_level = 4;
  4087. $is_zk = false;
  4088. if($userInfo['user_level_id_old'] == $zk_level) {
  4089. $is_zk = true;
  4090. $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
  4091. $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
  4092. } else{
  4093. $sales_incentive = 0;
  4094. }
  4095. $return_data = [
  4096. 'common_nums'=>$teams_num,
  4097. 'person_nums'=>$per_num,
  4098. 'common_nums_pv'=> $team_amount,
  4099. 'person_nums_pv'=> $person_amount,
  4100. 'sum_nums_pv' =>$team_amount + $person_amount,
  4101. 'sales_incentive' => $sales_incentive,
  4102. "is_zk"=>$is_zk
  4103. ];
  4104. return $return_data;
  4105. }
  4106. /**
  4107. * 获取当前用户业绩
  4108. */
  4109. public function getPerformance($user_id) {
  4110. $team_amount = 0;
  4111. $person_amount = 0;
  4112. $result_big_team_arr = [];
  4113. $get_teams_comm_datas = [];// 在2.0中获取父级下面的所有团队数据
  4114. // 共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  4115. $common_nums = $this->getCommonNums($user_id);
  4116. // var_dump($user_id);
  4117. $get_teams_comm_num = 0;
  4118. $get_teams_comm_pv = 0;
  4119. $get_teams_per_num = 0;// 小部门人数
  4120. // 1.0系统中有下级,需要在2.0中再加下级数据
  4121. if($user_id < 611){
  4122. // 梅红在2.0中的ID是780
  4123. // if($user_id == 593){
  4124. // $common_nums[] = 780;
  4125. // unset($common_nums[0]);
  4126. // }
  4127. // var_dump($common_nums);
  4128. // 用户三峡所有在2.0系统下面的业绩和人数 start
  4129. $child_nums = [];
  4130. // 再加上当前用户直属的子级
  4131. $common_ns = $common_nums;
  4132. $common_ns[] = $user_id;
  4133. // var_dump($common_ns);return;
  4134. // 获取当前用户
  4135. foreach($common_nums as $v){
  4136. $child_nums[] = $this->getRecursiveChildren($v);
  4137. }
  4138. // 梅红在2.0中的ID是780
  4139. // if($user_id == 593){
  4140. // $child_nums[0][] = 780;
  4141. // }
  4142. // 去除空数组,并重新组合有数据的数组
  4143. $filteredData = array_filter($child_nums, function($array) {
  4144. return !empty($array); // 如果数组不为空,则保留
  4145. });
  4146. // 合并所有非空数组
  4147. foreach ($filteredData as $array) {
  4148. $result_big_team_arr = array_merge($result_big_team_arr, $array);
  4149. }
  4150. // var_dump($result_big_team_arr);echo "ppppppppppppppppp";
  4151. // 获取当前用户下面在2.0中的下级所有PV
  4152. $t_pv = $this->getteampv($result_big_team_arr);
  4153. $get_teams_comm_pv =$t_pv['totalPv'];
  4154. // if($user_id == 593){
  4155. // $get_teams_comm_pv = 7000;
  4156. // }
  4157. // var_dump($get_teams_comm_pv);
  4158. // 获取当前用户下面在2.0中的下级所有人数
  4159. $get_teams_comm_num = count($result_big_team_arr);
  4160. // 用户伞下小部门所有在2.0系统下面的业绩和人数 end
  4161. }else{
  4162. // 当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
  4163. $child_nums = $this->getChildren($user_id);
  4164. // 获取父级子级下面的个人
  4165. $num_teams = $this->getTeamSize($child_nums);
  4166. foreach($child_nums as $v){
  4167. $get_teams_comm_datas[] = $this->getTeamPv11($v);// 如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
  4168. }
  4169. if( count($get_teams_comm_datas) ==1 ){
  4170. $get_teams_comm_pv =$get_teams_comm_datas[0];
  4171. $get_teams_comm_num = $num_teams[0]['total_count'];
  4172. }else if(count($get_teams_comm_datas) >1){
  4173. // $getss = $this->processArray($get_teams_comm_datas);
  4174. // $team_datas = $num_teams[$getss['max_index']];
  4175. // var_dump( $get_teams_comm_datas);
  4176. // 获取一个最大值,设为大部门,其他的加载一块是小部门
  4177. $getss = $this->processArray($get_teams_comm_datas);
  4178. $max_value_count = $num_teams[$getss['max_index']]['total_count'];
  4179. unset($num_teams[$getss['max_index']]);
  4180. // 获取小部门的人数
  4181. $per_num = 0;
  4182. foreach($num_teams as $k=>$v){
  4183. $per_num +=$v['total_count'];
  4184. }
  4185. // 找到最大值的(大部门)
  4186. $get_teams_comm_num = $max_value_count;
  4187. // 小部门的数量
  4188. $get_teams_per_num = $per_num;
  4189. // var_dump($getss['max_value']);
  4190. $person_amount = $getss['remaining_sum'];
  4191. $get_teams_comm_pv = $getss['max_value'];
  4192. }
  4193. }
  4194. // 合并业绩和人数
  4195. $team_amount += $get_teams_comm_pv;
  4196. // var_dump($team_amount);
  4197. // 1.0获取小区业绩
  4198. $person_nums = $this->getPersonageNums($user_id);
  4199. // var_dump($person_nums);
  4200. $result_small_team_arr = [];
  4201. // 1.0系统中有下级,需要在2.0中再加下级数据
  4202. // 用户三峡所有在2.0系统下面的业绩和人数 start
  4203. $child_nums_mix = [];
  4204. // 再加上当前用户直属的子级
  4205. $common_ns1 = $person_nums;
  4206. $common_ns1[] = $user_id;
  4207. // 获取当前用户
  4208. foreach($person_nums as $v){
  4209. $child_nums_mix[] = $this->getRecursiveChildren($v);
  4210. }
  4211. // 去除空数组,并重新组合有数据的数组
  4212. $filteredData_1 = array_filter($child_nums_mix, function($array) {
  4213. return !empty($array); // 如果数组不为空,则保留
  4214. });
  4215. // 合并所有非空数组
  4216. $result_small_team_arr = [];
  4217. foreach ($filteredData_1 as $array) {
  4218. $result_small_team_arr = array_merge($result_small_team_arr, $array);
  4219. }
  4220. // 获取当前用户下面在2.0中的下级所有PV
  4221. // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
  4222. $t_pv = $this->getteampv($result_small_team_arr);
  4223. $get_teams_per_pv =$t_pv['totalPv'];
  4224. // 获取当前用户下面在2.0中的下级所有人数
  4225. $get_teams_per_num += count($result_small_team_arr);
  4226. // 合并业绩和人数
  4227. $person_amount += $get_teams_per_pv;
  4228. // if($user_id == 593){
  4229. // $person_amount = 2800;
  4230. // }
  4231. // var_dump($person_amount);
  4232. // 用户小部门所有在2.0系统下面的业绩和人数 end
  4233. // $common_nums[] = $user_id;
  4234. foreach ($common_nums as $key => $value) {
  4235. # code...
  4236. $amount = $this->getPerformance1($value);
  4237. $team_amount += $amount;
  4238. }
  4239. foreach ($person_nums as $key => $value) {
  4240. # code...
  4241. $amount = $this->getPerformance1($value);
  4242. $person_amount += $amount;
  4243. }
  4244. // var_dump($team_amount);
  4245. // if($user_id < 611){
  4246. // //获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
  4247. // //例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
  4248. // $b_s = $this->getparents_child_pv($user_id);
  4249. // //var_dump( $b_s);echo "yyyyyyyyyyyyy";
  4250. // $team_amount += $b_s['team_pv'];
  4251. // $get_teams_comm_num += $b_s['team_num'];
  4252. // $person_amount += $b_s['per_pv'];
  4253. // $get_teams_per_num += $b_s['per_num'];//小部门人数
  4254. // //var_dump($team_amount,$person_amount );
  4255. // }
  4256. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
  4257. //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
  4258. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  4259. $money1180Sum = 0;
  4260. foreach ($user_team_amount as $record) {
  4261. $money1180Sum += $record['money'] - 300 - 180;
  4262. }
  4263. if($user_id == 593){
  4264. $money1180Sum -= 700;
  4265. }
  4266. // 获取 status 为 1 且 money 为 11800 的记录集合
  4267. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
  4268. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4269. $money11800Sum = 0;
  4270. foreach ($money11800Records as $record) {
  4271. $money11800Sum += $record['money'] - 3000 - 1800;
  4272. }
  4273. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
  4274. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4275. $money10620Sum = 0;
  4276. foreach ($money10620Records as $record) {
  4277. $money10620Sum += $record['money'] - 2700 - 1620;
  4278. }
  4279. // 计算除去特定值后的总和
  4280. //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
  4281. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4282. $otherMoneySum = 0;
  4283. foreach ($otherMoneyRecords as $record) {
  4284. $otherMoneySum += $record['money'];
  4285. }
  4286. // 分别处理特定值的情况并加上其他值的总和
  4287. $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  4288. // var_dump($all_record_nums);
  4289. $team_amount += $all_record_nums;
  4290. // var_dump($user_team_amount);
  4291. // 计算自己的个人联盟总流水
  4292. // // //计算自己的个人联盟总流水
  4293. // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
  4294. // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  4295. // $person_amount += $user_person_amount;
  4296. // 计算个人的1180单价的业绩 集合
  4297. $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
  4298. $money1180Sum = 0;
  4299. foreach ($money1180Records as $record) {
  4300. $money1180Sum += $record['money'] - 300 - 180;
  4301. }
  4302. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
  4303. // var_dump($person_nums);
  4304. // 计算个人的11800单价的业绩 集合
  4305. $money11800Sum = 0;
  4306. foreach ($money11800Records as $record) {
  4307. $money11800Sum += $record['money'] - 3000 - 1800;
  4308. }
  4309. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
  4310. // var_dump($person_nums);
  4311. // 计算个人的10620单价的业绩 集合
  4312. $money10620Sum = 0;
  4313. foreach ($money10620Records as $record) {
  4314. $money10620Sum += $record['money'] - 2700 - 1620;
  4315. }
  4316. // 计算除去特定值后的总和
  4317. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4318. $otherMoneySum = 0;
  4319. foreach ($otherMoneyRecords as $record) {
  4320. $otherMoneySum += $record['money'];
  4321. }
  4322. // 分别处理特定值的情况并加上其他值的总和
  4323. $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
  4324. $person_amount += $user_person_amount;
  4325. // //临时设置
  4326. // if($user_id == 536){
  4327. // $person_amount = 2800;
  4328. // $team_amount = 7000;
  4329. // }
  4330. // //临时设置
  4331. // if($user_id == 222){
  4332. // $person_amount = 2800;
  4333. // $team_amount = 11900;
  4334. // }
  4335. // 大部门人数
  4336. $teams_num = count($common_nums) + $get_teams_comm_num;
  4337. // 小部门人数
  4338. $per_num = count($person_nums) + $get_teams_per_num;
  4339. // 如果当前用户是1.0用户,找到其直推所有的业绩,根据业绩找到大小部门的同时,还要比对1.0中大小部门的业绩,摘出一个最大业绩的部门是大部门,其余都是小部门()
  4340. if($user_id < 611){
  4341. // var_dump($team_amount);
  4342. // var_dump($person_amount);
  4343. // 获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
  4344. // 例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
  4345. $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);
  4346. // var_dump($b_s);
  4347. // var_dump($team_amount,$person_amount);
  4348. // var_dump(count($common_nums)+ $get_teams_comm_num,count($person_nums)+ $get_teams_per_num);
  4349. // var_dump( $b_s);echo "yyyyyyyyyyyyy";
  4350. $team_amount = $b_s['big_department']['value'];
  4351. $teams_num = $b_s['big_department']['count'];
  4352. // var_dump($b_s['team_pv']);
  4353. // var_dump($b_s['per_pv']);
  4354. $person_amount = $b_s['small_department']['value'];
  4355. $per_num = $b_s['small_department']['count'];// 小部门人数
  4356. // var_dump( $b_s['team_num'],$b_s['per_num']);
  4357. }
  4358. // 级别信息
  4359. $userInfo = Db::name("user")->find($user_id);//
  4360. $zk_level = 4;
  4361. $is_zk = false;
  4362. if($userInfo['user_level_id_old'] == $zk_level) {
  4363. $is_zk = true;
  4364. $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
  4365. $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
  4366. } else{
  4367. $sales_incentive = 0;
  4368. }
  4369. $return_data = [
  4370. 'common_nums' => $teams_num,
  4371. 'person_nums' => $per_num,
  4372. 'common_nums_pv'=> $team_amount,
  4373. 'person_nums_pv'=> $person_amount,
  4374. 'sum_nums_pv' =>$team_amount + $person_amount,
  4375. 'sales_incentive' => $sales_incentive,
  4376. "is_zk"=>$is_zk
  4377. ];
  4378. return $return_data;
  4379. }
  4380. /**
  4381. * 获取当前用户业绩
  4382. */
  4383. public function getPerformance_copy($user_id) {
  4384. // $user_id = $this->request->post("user_id");
  4385. // 共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  4386. $common_nums = $this->getCommonNums($user_id);
  4387. // 1.0获取小区业绩
  4388. $person_nums = $this->getPersonageNums($user_id);
  4389. // return $person_nums;
  4390. // var_dump( $common_nums);
  4391. $team_amount = 0;
  4392. $person_amount = 0;
  4393. // $common_nums[] = $user_id;
  4394. foreach ($common_nums as $key => $value) {
  4395. # code...
  4396. $amount = $this->getPerformance1($value);
  4397. $team_amount += $amount;
  4398. }
  4399. foreach ($person_nums as $key => $value) {
  4400. # code...
  4401. $amount = $this->getPerformance1($value);
  4402. $person_amount += $amount;
  4403. }
  4404. // var_dump($team_amount);
  4405. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
  4406. //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
  4407. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  4408. $money1180Sum = 0;
  4409. foreach ($user_team_amount as $record) {
  4410. $money1180Sum += $record['money'] - 300 - 180;
  4411. }
  4412. // 获取 status 为 1 且 money 为 11800 的记录集合
  4413. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
  4414. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4415. $money11800Sum = 0;
  4416. foreach ($money11800Records as $record) {
  4417. $money11800Sum += $record['money'] - 3000 - 1800;
  4418. }
  4419. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
  4420. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4421. $money10620Sum = 0;
  4422. foreach ($money10620Records as $record) {
  4423. $money10620Sum += $record['money'] - 2700 - 1620;
  4424. }
  4425. // 计算除去特定值后的总和
  4426. //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
  4427. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4428. $otherMoneySum = 0;
  4429. foreach ($otherMoneyRecords as $record) {
  4430. $otherMoneySum += $record['money'];
  4431. }
  4432. // 分别处理特定值的情况并加上其他值的总和
  4433. $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  4434. // var_dump($all_record_nums);
  4435. $team_amount += $all_record_nums;
  4436. // 计算自己的个人联盟总流水
  4437. // // //计算自己的个人联盟总流水
  4438. // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
  4439. // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  4440. // $person_amount += $user_person_amount;
  4441. // 计算个人的1180单价的业绩 集合
  4442. $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
  4443. $money1180Sum = 0;
  4444. foreach ($money1180Records as $record) {
  4445. $money1180Sum += $record['money'] - 300 - 180;
  4446. }
  4447. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
  4448. // var_dump($person_nums);
  4449. // 计算个人的11800单价的业绩 集合
  4450. $money11800Sum = 0;
  4451. foreach ($money11800Records as $record) {
  4452. $money11800Sum += $record['money'] - 3000 - 1800;
  4453. }
  4454. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
  4455. // var_dump($person_nums);
  4456. // 计算个人的10620单价的业绩 集合
  4457. $money10620Sum = 0;
  4458. foreach ($money10620Records as $record) {
  4459. $money10620Sum += $record['money'] - 2700 - 1620;
  4460. }
  4461. // 计算除去特定值后的总和
  4462. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4463. $otherMoneySum = 0;
  4464. foreach ($otherMoneyRecords as $record) {
  4465. $otherMoneySum += $record['money'];
  4466. }
  4467. // 分别处理特定值的情况并加上其他值的总和
  4468. $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
  4469. $person_amount += $user_person_amount;
  4470. // 级别信息
  4471. $userInfo = Db::name("user")->find($user_id);//
  4472. $zk_level = 4;
  4473. $is_zk = false;
  4474. if($userInfo['user_level_id_old'] == $zk_level) {
  4475. $is_zk = true;
  4476. $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
  4477. $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
  4478. } else{
  4479. $sales_incentive = 0;
  4480. }
  4481. $return_data = [
  4482. 'common_nums'=>count($common_nums),
  4483. 'person_nums'=>count($person_nums),
  4484. 'common_nums_pv'=> $team_amount,
  4485. 'person_nums_pv'=> $person_amount,
  4486. 'sum_nums_pv' =>$team_amount + $person_amount,
  4487. 'sales_incentive' => $sales_incentive,
  4488. "is_zk"=>$is_zk
  4489. ];
  4490. return $return_data;
  4491. }
  4492. /**
  4493. * 获取指定用户业绩
  4494. */
  4495. public function getPerformanceOf($user_id) {
  4496. // 共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  4497. $common_nums = $this->getCommonNums($user_id);
  4498. $person_nums = $this->getPersonageNums($user_id);
  4499. $team_amount = 0;
  4500. $person_amount = 0;
  4501. // $common_nums[] = $user_id;
  4502. foreach ($common_nums as $key => $value) {
  4503. # code...
  4504. $amount = $this->getPerformance1($value);
  4505. $team_amount += $amount;
  4506. }
  4507. foreach ($person_nums as $key => $value) {
  4508. # code...
  4509. $amount = $this->getPerformance1($value);
  4510. $person_amount += $amount;
  4511. }
  4512. // return $person_nums;
  4513. // 添加自己共建联盟的流水
  4514. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("spread_id",$user_id)->sum("money");
  4515. $user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
  4516. $team_amount += $user_team_amount;
  4517. // //计算自己的个人联盟总流水
  4518. $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("spread_id",$user_id)->sum("money");
  4519. $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  4520. $person_amount += $user_person_amount;
  4521. $sum_nums_pv = $team_amount + $person_amount;
  4522. $sum_nums_pv = isset($sum_nums_pv) ? $sum_nums_pv :0;
  4523. return $sum_nums_pv;
  4524. }
  4525. /**
  4526. * 获取用户星级
  4527. */
  4528. public function getStarLevel($user_id,$team_money=0,$person_money=0) {
  4529. if(empty($team_money)) {
  4530. $common_nums = $this->getCommonNums($user_id);
  4531. $team_money = 0;
  4532. foreach ($common_nums as $key => $value) {
  4533. # code...
  4534. $amount = $this->getPerformance1($value);
  4535. $team_money += $amount;
  4536. }
  4537. // 计算自己的共建联盟流水
  4538. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->sum("money");
  4539. $user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
  4540. $team_money += $user_team_amount;
  4541. }else{
  4542. $common_nums = $this->getCommonNums($user_id);
  4543. }
  4544. if(empty($person_money)) {
  4545. $person_nums = $this->getPersonageNums($user_id);
  4546. $person_amount = 0;
  4547. foreach ($person_nums as $key => $value) {
  4548. # code...
  4549. $amount = $this->getPerformance1($value);
  4550. $person_amount += $amount;
  4551. }
  4552. $person_money = $person_amount;
  4553. // 计算自己的个人联盟总流水
  4554. $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->sum("money");
  4555. $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  4556. $person_money += $user_person_amount;
  4557. }else{
  4558. $person_nums = $this->getPersonageNums($user_id);
  4559. }
  4560. $slow = $person_money;
  4561. if($team_money < $person_money) {
  4562. $slow = $team_money;
  4563. }
  4564. $sum_money = $team_money + $person_money;
  4565. // $data = ['sum_money'=>$sum_money,"team_money"=>$team_money,"person_money"=>$person_money];
  4566. // $this->error(0,$data);
  4567. $star_list = Db::name("old_user_star")->order("statement_all_num desc")->select();
  4568. $start_level = "";
  4569. foreach ($star_list as $key => $value) {
  4570. # code...
  4571. if( $sum_money>=$value['statement_all_num'] && $slow >= $value['person_statement']) {
  4572. return $value;
  4573. }
  4574. }
  4575. return $start_level;
  4576. }
  4577. /**
  4578. * 获取流水信息
  4579. */
  4580. public function getPerformance1($user_id) {
  4581. // $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money");
  4582. // $amount = isset($amount) ? round($amount*0.7,2) : 0;
  4583. // return $amount;
  4584. $money1180Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",1180)->where("status",1)->select();
  4585. $money1180Sum = 0;
  4586. foreach ($money1180Records as $record) {
  4587. $money1180Sum += $record['money'] - 300 - 180;
  4588. }
  4589. // var_dump($money1180Sum);
  4590. $money11800Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",11800)->where("status",1)->select();
  4591. // var_dump($person_nums);
  4592. // 计算个人的11800单价的业绩 集合
  4593. $money11800Sum = 0;
  4594. foreach ($money11800Records as $record) {
  4595. $money11800Sum += $record['money'] - 3000 - 1800;
  4596. }
  4597. $money10620Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",10620)->where("status",1)->select();
  4598. // var_dump($person_nums);
  4599. // 计算个人的11800单价的业绩 集合
  4600. $money10620Sum = 0;
  4601. foreach ($money10620Records as $record) {
  4602. $money10620Sum += $record['money'] - 2700 - 1620;
  4603. }
  4604. // 计算除去特定值后的总和
  4605. $otherMoneyRecords = Db::name("old_user_of_goods")->where("node_id",$user_id)->where('status', 1)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4606. $otherMoneySum = 0;
  4607. foreach ($otherMoneyRecords as $record) {
  4608. $otherMoneySum += $record['money'];
  4609. }
  4610. // 分别处理特定值的情况并加上其他值的总和
  4611. $user_person_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  4612. return $user_person_amount;
  4613. }
  4614. /**
  4615. * 获取个人业绩统计信息
  4616. */
  4617. public function getPerformanceOfId($user_id)
  4618. {
  4619. // var_dump($user_id);
  4620. // 联盟总人数 共建联盟人数 个人联盟人数 总流水 共建联盟流水 个人联盟流水 所属星级(钻卡专属)
  4621. $common_nums = $this->getCommonNums($user_id);
  4622. $person_nums = $this->getPersonageNums($user_id);
  4623. // 联盟业绩 查询 共建联盟业绩 个人联盟业绩
  4624. $team_amount = 0;
  4625. $person_amount = 0;
  4626. // $common_nums[] = $user_id;
  4627. foreach ($common_nums as $key => $value) {
  4628. # code...
  4629. $amount = $this->getPerformance1($value);
  4630. $team_amount += $amount;
  4631. }
  4632. // 计算自己的共建联盟流水
  4633. //$user_team_amount = Db::name("user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where("status",1)->sum("money");
  4634. // $this->error(0,$team_amount);
  4635. //$user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
  4636. $money1180Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 1180)->select();
  4637. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  4638. $money1180Sum = 0;
  4639. foreach ($money1180Records as $record) {
  4640. $money1180Sum += $record['money'] - 300 - 180;
  4641. }
  4642. // 获取 status 为 1 且 money 为 11800 的记录集合
  4643. $money11800Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 11800)->select();
  4644. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4645. $money11800Sum = 0;
  4646. foreach ($money11800Records as $record) {
  4647. $money11800Sum += $record['money'] - 3000 - 1800;
  4648. }
  4649. // 获取 status 为 1 且 money 为 11800 的记录集合
  4650. $money10620Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 10620)->select();
  4651. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4652. $money10620Sum = 0;
  4653. foreach ($money10620Records as $record) {
  4654. $money10620Sum += $record['money'] - 2700 - 1620;
  4655. }
  4656. // 计算除去特定值后的总和
  4657. $otherMoneyRecords = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->whereNotIn('money', [1180, 11800,10620])->select();
  4658. $otherMoneySum = 0;
  4659. foreach ($otherMoneyRecords as $record) {
  4660. $otherMoneySum += $record['money'];
  4661. }
  4662. // 分别处理特定值的情况并加上其他值的总和
  4663. $user_team_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  4664. $team_amount += $user_team_amount;
  4665. foreach ($person_nums as $key => $value) {
  4666. # code...
  4667. $amount = $this->getPerformance1($value);
  4668. $person_amount += $amount;
  4669. }
  4670. // //计算自己的个人联盟总流水
  4671. $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("status",1)->sum("money");
  4672. $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  4673. $person_amount += $user_person_amount;
  4674. // $this->error(0,$common_nums);
  4675. return $team_amount + $person_amount;
  4676. }
  4677. /**
  4678. * 获取该用户共建联盟
  4679. */
  4680. public function getCommonNums($user_id){
  4681. // 先获取共建联盟下用户的id
  4682. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->select()->toArray();
  4683. $new_array_ids =[];
  4684. foreach ($son_ids as $key => $value) {
  4685. # code...
  4686. $son_id = $value['id'];
  4687. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  4688. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  4689. if(count($son_value_ids) > 0) {
  4690. $son_value_ids = array_column($son_value_ids,"id");
  4691. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  4692. }
  4693. }
  4694. return $new_array_ids;
  4695. }
  4696. /**
  4697. * 获取该用户个人联盟
  4698. */
  4699. public function getPersonageNums($user_id){
  4700. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("id")->select();
  4701. $new_array_ids =[];
  4702. // return 3343;
  4703. foreach ($son_ids as $key => $value) {
  4704. # code...
  4705. $son_id = $value['id'];
  4706. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  4707. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  4708. if(count($son_value_ids) > 0) {
  4709. $son_value_ids = array_column($son_value_ids,"id");
  4710. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  4711. }
  4712. }
  4713. return $new_array_ids;
  4714. }
  4715. // 获取团队递归聚宝盆1
  4716. public function teamPeople( $user_id,$type){
  4717. // var_dump($type);
  4718. //$ftype = 1:大部门,0:小部门
  4719. // 业绩小是小部门,业绩大是大部门
  4720. if($type == 1) {
  4721. $list = Db::name("old_user_jbp")
  4722. ->where("spread", $user_id)
  4723. ->where("is_team", 1)
  4724. ->field("user_name, id")
  4725. ->select()
  4726. ->toArray();
  4727. $list = $this->get_yj_amount($list,1);
  4728. $list1 = Db::name("old_user_jbp")
  4729. ->where("spread", $user_id)
  4730. ->where("is_team", 0)
  4731. ->field("user_name, id")
  4732. ->select()
  4733. ->toArray();
  4734. $list1 = $this->get_yj_amount($list1, 0);
  4735. // 检查数组和字段是否存在
  4736. if (isset($list[0]['performance']['common_nums_pv']) && isset($list1[0]['performance']['common_nums_pv'])) {
  4737. // 如果$list的值小于或等于$list1的值,选择$list
  4738. if ($list[0]['performance']['common_nums_pv'] <= $list1[0]['performance']['common_nums_pv']) {
  4739. return $list1;
  4740. } else {
  4741. return $list;
  4742. }
  4743. } elseif (isset($list[0]['performance']['common_nums_pv'])) {
  4744. // 如果只有$list有值,返回$list
  4745. return $list;
  4746. } elseif (isset($list1[0]['performance']['common_nums_pv'])) {
  4747. // 如果只有$list1有值,返回$list1
  4748. return $list1;
  4749. } else {
  4750. // 如果两个数组都没有该字段,返回空数组
  4751. return [];
  4752. }
  4753. }else if($type == 0) {
  4754. $list = Db::name("old_user_jbp")
  4755. ->where("spread", $user_id)
  4756. ->where("is_team", 1)
  4757. ->field("user_name, id")
  4758. ->select()
  4759. ->toArray();
  4760. $list = $this->get_yj_amount($list,1);
  4761. $list1 = Db::name("old_user_jbp")
  4762. ->where("spread", $user_id)
  4763. ->where("is_team", 0)
  4764. ->field("user_name, id")
  4765. ->select()
  4766. ->toArray();
  4767. $list1 = $this->get_yj_amount($list1, 0);
  4768. // 检查数组和字段是否存在
  4769. if (isset($list[0]['performance']['common_nums_pv']) && isset($list1[0]['performance']['common_nums_pv'])) {
  4770. // 如果$list的值小于或等于$list1的值,选择$list
  4771. if ($list[0]['performance']['common_nums_pv'] <= $list1[0]['performance']['common_nums_pv']) {
  4772. return $list;
  4773. } else {
  4774. return $list1;
  4775. }
  4776. } elseif (isset($list[0]['performance']['common_nums_pv'])) {
  4777. // 如果只有$list有值,返回$list
  4778. return $list;
  4779. } elseif (isset($list1[0]['performance']['common_nums_pv'])) {
  4780. // 如果只有$list1有值,返回$list1
  4781. return $list1;
  4782. } else {
  4783. // 如果两个数组都没有该字段,返回空数组
  4784. return [];
  4785. }
  4786. }else if($type == 2){
  4787. $list = Db::name("user")->where("spread_uid",$user_id)->field("nickname,uid,avatar")->select()->toArray();
  4788. return $list;
  4789. }
  4790. // foreach ($list as $key => $value) {
  4791. // $list[$key]['user_name'] = $value['user_name'] . "业绩";
  4792. // $list[$key]['performance'] = $this->getPerformance($value['id']);
  4793. // //辨别当前是大部门还是小部门。用于显示大小业绩展示
  4794. // $list[$key]['curr_type'] = '';
  4795. // if($type == 1){
  4796. // $list[$key]['curr_type'] = 1;
  4797. // }else if($type == 0){
  4798. // $list[$key]['curr_type'] = 0;
  4799. // }else{
  4800. // $list[$key]['curr_type'] = '';
  4801. // }
  4802. // }
  4803. return $list;
  4804. }
  4805. public function get_yj_amount($list,$type){
  4806. foreach ($list as $key => $value) {
  4807. # code...
  4808. // $amount = $this->getPerformanceOfId($value['id']);
  4809. $list[$key]['user_name'] = $value['user_name'] . "业绩";
  4810. //$list[$key]['total_performance'] = $amount;
  4811. //$performance = $this->getPerformanceOfId($search_name['id']);
  4812. $list[$key]['performance'] = $this->getPerformance($value['id']);
  4813. // 辨别当前是大部门还是小部门。用于显示大小业绩展示
  4814. $list[$key]['curr_type'] = '';
  4815. if($type == 1){
  4816. $list[$key]['curr_type'] = 1;
  4817. }else if($type == 0){
  4818. $list[$key]['curr_type'] = 0;
  4819. }else{
  4820. $list[$key]['curr_type'] = '';
  4821. }
  4822. }
  4823. return $list;
  4824. }
  4825. // 获取团队递归聚宝盆1
  4826. public function teamPeople_copy( $user_id,$type){
  4827. // var_dump($type);
  4828. //$ftype = 1:大部门,0:小部门
  4829. //$user_id = $this->request->post("user_id");
  4830. //$type = $this->request->post("type",0);
  4831. // 查找当前用户id下节点
  4832. if($type == 1) {
  4833. // echo 33;
  4834. $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->field("user_name,id")->select()->toArray();
  4835. }else if($type == 0) {
  4836. // echo 44;
  4837. $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("user_name,id")->select()->toArray();
  4838. }else if($type == 2){
  4839. $list = Db::name("user")->where("spread_uid",$user_id)->field("nickname,uid")->select()->toArray();
  4840. return $list;
  4841. }else {
  4842. // echo 55;
  4843. $list = Db::name("old_user_jbp")->where("spread",$user_id)->field("user_name,id")->select()->toArray();
  4844. }
  4845. foreach ($list as $key => $value) {
  4846. # code...
  4847. // $amount = $this->getPerformanceOfId($value['id']);
  4848. $list[$key]['user_name'] = $value['user_name'] . "业绩";
  4849. //$list[$key]['total_performance'] = $amount;
  4850. //$performance = $this->getPerformanceOfId($search_name['id']);
  4851. $list[$key]['performance'] = $this->getPerformance($value['id']);
  4852. // 辨别当前是大部门还是小部门。用于显示大小业绩展示
  4853. $list[$key]['curr_type'] = '';
  4854. if($type == 1){
  4855. $list[$key]['curr_type'] = 1;
  4856. }else if($type == 0){
  4857. $list[$key]['curr_type'] = 0;
  4858. }else{
  4859. $list[$key]['curr_type'] = '';
  4860. }
  4861. }
  4862. return $list;
  4863. }
  4864. // //获取团队递归聚宝盆1
  4865. // public function teamPeople( $user_id,$type){
  4866. // //$user_id = $this->request->post("user_id");
  4867. // //$type = $this->request->post("type",0);
  4868. // //查找当前用户id下节点
  4869. // if($type == 1) {
  4870. // $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->field("user_name,id")->select()->toArray();
  4871. // }else if($type == 2) {
  4872. // $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("user_name,id")->select()->toArray();
  4873. // }else {
  4874. // $list = Db::name("old_user_jbp")->where("spread",$user_id)->field("user_name,id")->select()->toArray();
  4875. // }
  4876. // foreach ($list as $key => $value) {
  4877. // # code...
  4878. // $amount = $this->getPerformanceOfId($value['id']);
  4879. // $list[$key]['user_name'] = $value['user_name'] . "-----业绩" . $amount;
  4880. // }
  4881. // return $list;
  4882. // }
  4883. // 获取大小部门贡献值
  4884. /**
  4885. * 获取当前用户大小部门贡献值
  4886. */
  4887. public function getPerformance_getcon($user_id) {
  4888. $team_amount = 0;
  4889. $person_amount = 0;
  4890. // $user_id = 593; //598 523 536
  4891. $result_big_team_arr = [];
  4892. $get_teams_comm_datas = [];// 在2.0中获取父级下面的所有团队数据
  4893. // 共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  4894. $common_nums = $this->getCommonNums_getcon($user_id);
  4895. // var_dump($common_nums);
  4896. $get_teams_comm_num = 0;
  4897. $get_teams_comm_pv = 0;
  4898. $get_teams_per_num = 0;// 小部门人数
  4899. // 1.0系统中有下级,需要在2.0中再加下级数据
  4900. if($user_id < 611){
  4901. // 梅红在2.0中的ID是780
  4902. // var_dump( $common_nums);
  4903. // 用户三峡所有在2.0系统下面的业绩和人数 start
  4904. $child_nums = [];
  4905. // 获取当前用户
  4906. foreach($common_nums as $v){
  4907. $child_nums[] = $this->getRecursiveChildren_getcon($v);
  4908. }
  4909. // 去除空数组,并重新组合有数据的数组
  4910. $filteredData = array_filter($child_nums, function($array) {
  4911. return !empty($array); // 如果数组不为空,则保留
  4912. });
  4913. // 合并所有非空数组
  4914. foreach ($filteredData as $array) {
  4915. $result_big_team_arr = array_merge($result_big_team_arr, $array);
  4916. }
  4917. // var_dump($result_big_team_arr);
  4918. // 获取当前用户下面在2.0中的下级所有PV
  4919. //$get_teams_comm_pv = $this->getteampv($result_big_team_arr);
  4920. $t_pv = $this->getteampv_getcon($result_big_team_arr);
  4921. $get_teams_comm_pv = $t_pv;
  4922. // var_dump($get_teams_comm_pv);echo "ttt";
  4923. // 用户伞下小部门所有在2.0系统下面的业绩和人数 end
  4924. }else{
  4925. // 当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
  4926. $child_nums = $this->getChildren_getcon($user_id);
  4927. // 获取父级子级下面的个人
  4928. $num_teams = $this->getTeamSize_getcon($child_nums);
  4929. // var_dump($num_teams);
  4930. foreach($child_nums as $v){
  4931. $get_teams_comm_datas[] = $this->getTeamPv11_getcon($v);// 如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
  4932. }
  4933. //$s = $this->getparents_child_pv($user_id);
  4934. // var_dump($get_teams_comm_datas);
  4935. // 如果只有一个部门,就是默认大部门
  4936. if( count($get_teams_comm_datas) ==1 ){
  4937. $get_teams_comm_pv =$get_teams_comm_datas[0];
  4938. $get_teams_comm_num = $num_teams[0]['total_count'];
  4939. }else if(count($get_teams_comm_datas) >1){
  4940. // var_dump( $get_teams_comm_datas);
  4941. // 获取一个最大值,设为大部门,其他的加载一块是小部门
  4942. $getss = $this->processArray_getcon($get_teams_comm_datas);
  4943. // var_dump($getss);
  4944. $max_value_count = $num_teams[$getss['max_index']]['total_count'];
  4945. unset($num_teams[$getss['max_index']]);
  4946. // 获取小部门的人数
  4947. $per_num = 0;
  4948. foreach($num_teams as $k=>$v){
  4949. $per_num +=$v['total_count'];
  4950. }
  4951. // 找到最大值的(大部门)
  4952. //$get_teams_comm_num = $max_value_count;
  4953. // 小部门的数量
  4954. // $get_teams_per_num = $per_num;
  4955. // var_dump($getss['max_value']);
  4956. $person_amount = $getss['remaining_sum'];
  4957. $get_teams_comm_pv = $getss['max_value'];
  4958. }
  4959. }
  4960. // var_dump($get_teams_comm_pv);
  4961. // 合并业绩和人数
  4962. $team_amount += $get_teams_comm_pv;
  4963. // var_dump($team_amount);
  4964. // 1.0获取小区业绩
  4965. $person_nums = $this->getPersonageNums_getcon($user_id);
  4966. // var_dump($person_nums);
  4967. $result_small_team_arr = [];
  4968. // 1.0系统中有下级,需要在2.0中再加下级数据
  4969. // 用户三峡所有在2.0系统下面的业绩和人数 start
  4970. $child_nums_mix = [];
  4971. // 获取当前用户
  4972. foreach($person_nums as $v){
  4973. $child_nums_mix[] = $this->getRecursiveChildren_getcon($v);
  4974. }
  4975. // 去除空数组,并重新组合有数据的数组
  4976. $filteredData_1 = array_filter($child_nums_mix, function($array) {
  4977. return !empty($array); // 如果数组不为空,则保留
  4978. });
  4979. // 合并所有非空数组
  4980. $result_small_team_arr = [];
  4981. foreach ($filteredData_1 as $array) {
  4982. $result_small_team_arr = array_merge($result_small_team_arr, $array);
  4983. }
  4984. // var_dump($result_small_team_arr);
  4985. // 获取当前用户下面在2.0中的下级所有PV
  4986. // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
  4987. $t_pv = $this->getteampv_getcon($result_small_team_arr);
  4988. $get_teams_per_pv =$t_pv;
  4989. // var_dump( $get_teams_per_pv);
  4990. // 获取当前用户下面在2.0中的下级所有人数
  4991. // $get_teams_per_num += count($result_small_team_arr);
  4992. // 合并业绩和人数
  4993. $person_amount += $get_teams_per_pv;
  4994. // 当前会员直属的业绩(1.0大部门)
  4995. $t_pv = $this->getteampv_getcon($common_nums);
  4996. $team_amount += $t_pv;
  4997. // 当前会员直属的业绩(1.0大部门)
  4998. $p_pv = $this->getteampv_getcon($person_nums);
  4999. $person_amount += $p_pv;
  5000. // var_dump($team_amount,$person_amount);
  5001. // 如果当前用户是1.0用户,找到其直推所有的业绩,根据业绩找到大小部门的同时,还要比对1.0中大小部门的业绩,摘出一个最大业绩的部门是大部门,其余都是小部门()
  5002. if($user_id < 611){
  5003. // 获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
  5004. // 例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
  5005. $b_s = $this->getparents_child_pv11_getcon($user_id,$team_amount,$person_amount);
  5006. $team_amount = $b_s[0];
  5007. $person_amount = $b_s[1];
  5008. }
  5009. $return_data = [
  5010. 'common_nums_pv'=> $team_amount,
  5011. 'person_nums_pv'=> $person_amount,
  5012. ];
  5013. return $return_data;
  5014. }
  5015. /**
  5016. * 获取该用户共建联盟
  5017. */
  5018. public function getCommonNums_getcon($user_id){
  5019. // 先获取共建联盟下用户的id
  5020. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->select()->toArray();
  5021. $new_array_ids =[];
  5022. foreach ($son_ids as $key => $value) {
  5023. # code...
  5024. $son_id = $value['id'];
  5025. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  5026. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  5027. if(count($son_value_ids) > 0) {
  5028. $son_value_ids = array_column($son_value_ids,"id");
  5029. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  5030. }
  5031. }
  5032. return $new_array_ids;
  5033. }
  5034. /**
  5035. * 获取该用户个人联盟
  5036. */
  5037. public function getPersonageNums_getcon($user_id){
  5038. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("id")->select();
  5039. $new_array_ids =[];
  5040. // return 3343;
  5041. foreach ($son_ids as $key => $value) {
  5042. # code...
  5043. $son_id = $value['id'];
  5044. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  5045. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  5046. if(count($son_value_ids) > 0) {
  5047. $son_value_ids = array_column($son_value_ids,"id");
  5048. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  5049. }
  5050. }
  5051. return $new_array_ids;
  5052. }
  5053. // 根据父级uid,递归获取所有子级UID数组
  5054. public function getRecursiveChildren_getcon($parentUid) {
  5055. $result = []; // 用于存储所有子级的 uid
  5056. // 定义递归函数
  5057. $recursion = function ($parentUid) use (&$result, &$recursion) {
  5058. // 查询当前父级的所有直接子级
  5059. $children = Db::name("user")
  5060. ->where("spread_uid", $parentUid)
  5061. ->column("uid"); // 获取子级的 uid 列表
  5062. // 如果没有子级,直接返回
  5063. if (empty($children)) {
  5064. return;
  5065. }
  5066. // 遍历每个子级
  5067. foreach ($children as $childUid) {
  5068. $result[] = $childUid; // 将子级的 uid 添加到结果数组
  5069. $recursion($childUid); // 递归查询子级的子级
  5070. }
  5071. };
  5072. // 从初始父级开始递归查询
  5073. $recursion($parentUid);
  5074. return array_unique($result); // 返回结果数组,并去重
  5075. }
  5076. // 只获取数组中的业绩
  5077. public function getteampv_getcon($common_nums) {
  5078. // // 查询当前用户及其子级的所有订单
  5079. $orders_gongxian = Db::name("user_sign_gongxian")
  5080. ->whereIn('status', [1])
  5081. ->whereIn("uid", $common_nums)
  5082. ->select();
  5083. // var_dump( $common_nums);
  5084. $total_gongxian = 0;
  5085. // // 遍历订单计算业绩
  5086. foreach ($orders_gongxian as $order) {
  5087. if (strpos($order['mark'], "购买") !== false) {
  5088. $total_gongxian += $order['number'];
  5089. }
  5090. }
  5091. return $total_gongxian;
  5092. // // // 查询当前用户及其子级的所有订单
  5093. // $orders = Db::name("store_order")
  5094. // ->whereIn('status', [0, 1, 2, 3])
  5095. // ->whereIn("uid", $common_nums)
  5096. // ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  5097. // ->select();
  5098. // // 初始化业绩和人数
  5099. // $totalPv = 0;
  5100. // $totalUsers = count($common_nums); // 初始化人数为子级总数
  5101. // // 遍历订单计算业绩
  5102. // foreach ($orders as $order) {
  5103. // if ($order['total_price'] == 1180) {
  5104. // $totalPv += 700;
  5105. // } else if ($order['total_price'] == 11800) {
  5106. // $totalPv += 7000;
  5107. // } else if ($order['total_price'] == 10620) {
  5108. // $totalPv += 6300;
  5109. // } else if ($order['total_price'] == 2360) {
  5110. // $totalPv += 1400;
  5111. // } else if ($order['total_price'] == 9440) {
  5112. // $totalPv += 5600;
  5113. // }
  5114. // }
  5115. // // 返回业绩和人数
  5116. // return [
  5117. // 'totalPv' => $totalPv,
  5118. // 'totalUsers' => $totalUsers
  5119. // ];
  5120. }
  5121. // 2.0 根据父级uid,找到当前用户下面的UID
  5122. public function getChildren_getcon($parentUid) {
  5123. $result = []; // 用于存储所有子级的 uid
  5124. $children = Db::name("user")
  5125. ->where("spread_uid", $parentUid)
  5126. ->column("uid"); // 获取子级的 uid 列表
  5127. return $children; // 返回结果数组,并去重
  5128. }
  5129. // 递归获取所有子级 UID 的业绩
  5130. public function getTeamPv11_getcon($parentUid) {
  5131. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  5132. $children = Db::name("user")
  5133. ->where("spread_uid", $parentUid)
  5134. ->column("uid");
  5135. $allChildren = [];
  5136. foreach ($children as $childUid) {
  5137. $allChildren[] = $childUid;
  5138. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  5139. }
  5140. return $allChildren;
  5141. };
  5142. // 获取当前用户及其所有子级的 UID
  5143. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  5144. $orders_gongxian = Db::name("user_sign_gongxian")
  5145. ->whereIn('status', [1])
  5146. ->whereIn("uid", $allUids)
  5147. ->select();
  5148. $total_gongxian = 0;
  5149. // // 遍历订单计算业绩
  5150. foreach ($orders_gongxian as $order) {
  5151. if (strpos($order['mark'], "购买") !== false) {
  5152. $total_gongxian += $order['number'];
  5153. }
  5154. }
  5155. return $total_gongxian;
  5156. // // 查询当前用户及其子级的所有订单
  5157. // $orders = Db::name("store_order")
  5158. // ->whereIn('status', [0, 1, 2, 3])
  5159. // ->whereIn("uid", $allUids)
  5160. // ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  5161. // ->select();
  5162. // // 计算总业绩
  5163. // $totalPv = 0;
  5164. // foreach ($orders as $order) {
  5165. // switch ($order['total_price']) {
  5166. // case 1180:
  5167. // $totalPv += 700;
  5168. // break;
  5169. // case 11800:
  5170. // $totalPv += 7000;
  5171. // break;
  5172. // case 10620:
  5173. // $totalPv += 6300;
  5174. // break;
  5175. // case 2360:
  5176. // $totalPv += 1400;
  5177. // break;
  5178. // case 9440:
  5179. // $totalPv += 5600;
  5180. // break;
  5181. // }
  5182. // }
  5183. // return $totalPv;
  5184. }
  5185. // 根据传递的父级数组,返回他的对应子级的个数
  5186. public function getTeamSize_getcon($parentUids) {
  5187. // 初始化结果数组
  5188. $result = [];
  5189. // 遍历每个父级ID
  5190. foreach ($parentUids as $parentUid) {
  5191. // 递归获取所有子级 UID
  5192. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  5193. $children = Db::name("user")
  5194. ->where("spread_uid", $parentUid)
  5195. ->column("uid");
  5196. // 确保返回的是数组
  5197. if (!is_array($children)) {
  5198. return [];
  5199. }
  5200. $allChildren = [];
  5201. foreach ($children as $childUid) {
  5202. $allChildren[] = $childUid;
  5203. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  5204. }
  5205. return $allChildren;
  5206. };
  5207. // 获取当前父级及其所有子级的 UID
  5208. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  5209. // 计算总个数(包括父级自身)
  5210. $totalUids = count($allUids);
  5211. // 将结果存入数组
  5212. $result[] = [
  5213. 'parent_uid' => $parentUid,
  5214. 'total_count' => $totalUids
  5215. ];
  5216. }
  5217. return $result;
  5218. }
  5219. public function processArray_getcon($array) {
  5220. // 初始化结果数组
  5221. $result = [
  5222. 'max_value' => null, // 最大值
  5223. 'max_index' => null, // 最大值的下标
  5224. 'remaining_sum' => 0 // 剩余值的总和
  5225. ];
  5226. // 检查数组是否为空
  5227. if (empty($array)) {
  5228. return $result;
  5229. }
  5230. // 找出最大值及其下标
  5231. $maxValue = $array[0];
  5232. $maxIndex = 0;
  5233. for ($i = 1; $i < count($array); $i++) {
  5234. if ($array[$i] > $maxValue) {
  5235. $maxValue = $array[$i];
  5236. $maxIndex = $i;
  5237. }
  5238. }
  5239. // 计算剩余值的总和
  5240. $remainingSum = 0;
  5241. for ($i = 0; $i < count($array); $i++) {
  5242. if ($i != $maxIndex) {
  5243. $remainingSum += $array[$i];
  5244. }
  5245. }
  5246. // 将结果存入数组
  5247. $result['max_value'] = $maxValue;
  5248. $result['max_index'] = $maxIndex;
  5249. $result['remaining_sum'] = $remainingSum;
  5250. return $result;
  5251. }
  5252. /**
  5253. * 获取流水信息
  5254. */
  5255. public function getPerformance1_getcon($user_id) {
  5256. // $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money");
  5257. // $amount = isset($amount) ? round($amount*0.7,2) : 0;
  5258. // return $amount;
  5259. $money1180Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",1180)->where("status",1)->select();
  5260. $money1180Sum = 0;
  5261. foreach ($money1180Records as $record) {
  5262. $money1180Sum += $record['money'] - 300 - 180;
  5263. }
  5264. // var_dump($money1180Sum);
  5265. $money11800Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",11800)->where("status",1)->select();
  5266. // var_dump($person_nums);
  5267. // 计算个人的11800单价的业绩 集合
  5268. $money11800Sum = 0;
  5269. foreach ($money11800Records as $record) {
  5270. $money11800Sum += $record['money'] - 3000 - 1800;
  5271. }
  5272. $money10620Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",10620)->where("status",1)->select();
  5273. // var_dump($person_nums);
  5274. // 计算个人的11800单价的业绩 集合
  5275. $money10620Sum = 0;
  5276. foreach ($money10620Records as $record) {
  5277. $money10620Sum += $record['money'] - 2700 - 1620;
  5278. }
  5279. // 计算除去特定值后的总和
  5280. $otherMoneyRecords = Db::name("old_user_of_goods")->where("node_id",$user_id)->where('status', 1)->whereNotIn('money', [1180, 11800 ,10620])->select();
  5281. $otherMoneySum = 0;
  5282. foreach ($otherMoneyRecords as $record) {
  5283. $otherMoneySum += $record['money'];
  5284. }
  5285. // 分别处理特定值的情况并加上其他值的总和
  5286. $user_person_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  5287. return $user_person_amount;
  5288. }
  5289. // 1.0用户直属的部门和2.0直属的部门,进行比较,获取大部门和小部门数据
  5290. public function getparents_child_pv11_getcon($user_id, $bigamount, $smallamount) {
  5291. // 获取直接下级的 UID 列表
  5292. $get_childs = Db::name("user")
  5293. ->where("spread_uid", $user_id)
  5294. ->column("uid");
  5295. // 初始化变量
  5296. $all_departments = []; // 用于存储所有直属下级的业绩
  5297. // 遍历每个直属下级
  5298. foreach ($get_childs as $child) {
  5299. // 获取当前下级及其子级
  5300. $child_group = [$child];
  5301. $recursive_children = $this->getRecursiveChildren_getcon($child);
  5302. $child_group = array_merge($child_group, $recursive_children);
  5303. // 获取当前分组的业绩
  5304. $result = $this->getteampv_getcon($child_group);
  5305. // 将直属下级的业绩加入数组
  5306. $all_departments[] = $result;
  5307. }
  5308. // 将传入的 $bigamount 和 $smallamount 加入数组
  5309. $all_departments[] = $bigamount;
  5310. $all_departments[] = $smallamount;
  5311. // 检查是否所有业绩都是 0
  5312. if (count(array_filter($all_departments, function($value) { return $value != 0; })) == 0) {
  5313. return [0, 0];
  5314. }
  5315. // 初始化最大部门和小部门
  5316. $max_department = 0;
  5317. $small_department = 0;
  5318. // 遍历 $all_departments,找出最大值并累加小部门的值
  5319. foreach ($all_departments as $department) {
  5320. if ($department > $max_department) {
  5321. // 如果当前部门的业绩大于最大部门的业绩,更新最大部门
  5322. if ($max_department != 0) {
  5323. $small_department += $max_department; // 将旧的最大值累加到小部门
  5324. }
  5325. $max_department = $department; // 更新最大部门
  5326. } else {
  5327. // 如果当前部门的业绩小于或等于最大部门的业绩,累加到小部门
  5328. $small_department += $department;
  5329. }
  5330. }
  5331. // 返回结果
  5332. return [
  5333. $max_department, // 大部门业绩
  5334. $small_department // 小部门业绩
  5335. ];
  5336. // 拿$bigamount, $smallamount业绩和get_childs产生的result业绩去对比。如果都是0.说明没有大小部门了,直接返回0,0如果只有一个数组有数据,
  5337. // 说明只有大部门,默认返回大部门数据,小部门返回0,如果有多条数组数据是一样的,那么就是选一个,设为大部门。剩下的数据叠加设为小部门
  5338. }
  5339. // 获取当前uesr_id下面在2.0中是否还有直接下级,并计算她的大部门和小部门
  5340. public function getparents_child_pv_getcon($user_id){
  5341. // 获取直接下级的 UID 列表
  5342. //$user_id = 593;
  5343. // $get_childs = $this->getRecursiveChildren($user_id);
  5344. $get_childs = Db::name("user")
  5345. ->where("spread_uid", $user_id)
  5346. ->column("uid"); // 获取子级的 uid 列表
  5347. // 根据获得的直接推荐下级2.0,来获取他们和她伞下的子级PV。对比拿一个最大的值,设为大部门,其余的是小部门
  5348. // 获取直接下级
  5349. $children_group = []; // 用于存储每个直接下级及其子级的分组
  5350. // 遍历每个直接下级
  5351. foreach ($get_childs as $child) {
  5352. $child_group = [$child]; // 将直接下级加入分组
  5353. $recursive_children = $this->getRecursiveChildren($child); // 获取直接下级的所有子级
  5354. $child_group = array_merge($child_group, $recursive_children); // 将子级加入分组
  5355. $children_group[] = $child_group; // 将分组加入最终结果
  5356. }
  5357. $get_teams_comm_datas = [];
  5358. foreach($children_group as $v){
  5359. $get_teams_comm_datas[] = $this->getteampv($v);// 如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
  5360. }
  5361. if(count($get_teams_comm_datas) > 0){
  5362. // 找到最大值作为大部门
  5363. $max_value = max($get_teams_comm_datas);
  5364. $total_sum = array_sum($get_teams_comm_datas); // 计算数组的总和
  5365. // 小部门为总和减去最大值
  5366. $small_department = $total_sum - $max_value;
  5367. // 返回大部门和小部门
  5368. return [
  5369. $max_value,
  5370. $small_department
  5371. ];
  5372. }else{
  5373. return [
  5374. 0,
  5375. 0
  5376. ];
  5377. }
  5378. }
  5379. /**
  5380. * 解绑微信或支付宝
  5381. * @return void
  5382. */
  5383. public function unBindVxOrAli()
  5384. {
  5385. $uid = $this->request->uid();
  5386. $type = request()->param('type','');
  5387. if(!$type) return app('json')->fail('请选择解绑类型');
  5388. if(!$uid) return app('json')->fail('请登录');
  5389. // 1 = 微信 2 = 支付宝 3 = 全部
  5390. if($type == 1){
  5391. Db::name('user')->where('uid',$uid)->update(['wechat_user_id' => 0]);
  5392. }else if ($type == 2){
  5393. Db::name('user')->where('uid',$uid)->update(['ali_user_id' => 0]);
  5394. }else{
  5395. Db::name('user')->where('uid',$uid)->update(['wechat_user_id' => 0,'ali_user_id' => 0]);
  5396. }
  5397. Db::name('log')->insert(['data' => '用户uid:' . $uid . '进行解绑操作type类型为' . $type]);
  5398. return app('json')->success('解绑成功');
  5399. }
  5400. }