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