User.php 253 KB

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