User.php 251 KB

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