User.php 253 KB

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