User.php 251 KB

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