User.php 248 KB

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