User.php 250 KB

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