User.php 251 KB

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