| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340 |
- <?php
- /**
- * @package merchant
- *
- * @author xaboy
- * @day 2020/6/18
- *
- *
- */
- namespace app\controller\api\user;
- use app\common\repositories\article\AgreementRepository;
- use app\common\repositories\merchant\order\OrderGzcRepository;
- use app\common\repositories\merchant\order\OrderMerchantRepository;
- use app\common\repositories\store\product\ProductRepository;
- use app\common\repositories\user\UnionUsersRepository;
- use app\controller\api\merchant\sxy\Access;
- use app\controller\api\store\product\DaTaoKe;
- use app\controller\api\store\product\Jd;
- use app\controller\api\store\product\TaoBao;
- use app\controller\api\store\product\TaoKe;
- use app\controller\api\store\product\Vip;
- use app\model\common\UserThirdModel;
- use app\traits\GzcApiRequest;
- use app\traits\HuiPay;
- use crmeb\basic\BaseController;
- use app\common\repositories\user\UserBillRepository;
- use app\common\repositories\user\UserRepository;
- use app\common\repositories\user\UserVisitRepository;
- use crmeb\services\QrcodeService;
- use crmeb\services\WechatService;
- use Symfony\Component\HttpFoundation\Request;
- use think\App;
- use think\facade\Db;
- use think\Exception;
- use think\exception\ValidateException;
- use think\facade\Cache;
- use BaiduAi\controller\Ocr;
- use think\facade\Log;
- use think\facade\Request as r;
- use app\common\common;
- use phpseclib3\Math\BigInteger\Engines\BCMath;
- class User extends BaseController
- {
- use HuiPay;
- public $repository;
- private $merId;
- private $source;
- public function __construct(App $app, UserRepository $repository)
- {
- parent::__construct($app);
- $this->repository = $repository;
- $this->source = $this->request->header('source');
- $this->merId = $this->request->header('merId');
- }
- /**
- * 创建环信账户
- * @return mixed
- */
- public function hxim_create()
- {
- $uid = $this->request->uid();
- try {
- $im = new Im();
- $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();
- if (isset($user['im_uuid']) && $user['im_user_id']) {
- return app('json')->success($user);
- }
- $im_user_id = 'user' . $user['uid'];
- $data = [];
- $data['im_pass'] = mt_rand(100000, 999999);
- $data['im_user_id'] = $im_user_id;
- // 获取用户是否存在
- $imUser = $im->getImUser('user' . $uid);
- if (isset($imUser['activated']) && $imUser['activated'] == true) {
- $data['im_uuid'] = $imUser['uuid'];
- } else {
- $data['im_uuid'] = $im->createImUser($im_user_id, $user['nickname'], $data['im_pass']);
- }
- Db::name('User')->where(['uid' => $uid])->update([
- 'im' => 1,
- 'im_uuid' => $data['im_uuid'],
- 'im_userid' => $im_user_id,
- 'im_password' => $data['im_pass']
- ]);
- return app('json')->success($data);
- } catch (\Exception $e) {
- Db::name('log')->insert(['data' => '注册异常' . $e->getFile() . $e->getMessage() . $e->getLine()]);
- }
- return app('json')->fail('注册失败');
- }
- /**
- * @return mixed
- * @author xaboy
- * @day 2020/6/22
- */
- public function we_com()
- {
- $where2['mer_id'] = $this->merId;
- $user = Db::name('enterprise')->field('we_com,we_com_url')->where($where2)->find();
- return app('json')->success($user);
- }
- public function spread_image()
- {
- $type = $this->request->param('type');
- $res = $type == 'routine'
- ? $this->repository->routineSpreadImage($this->request->userInfo())
- : $this->repository->wxSpreadImage($this->request->userInfo());
- return app('json')->success($res);
- }
- /**
- * @return mixed
- * 分享每日海报
- */
- public function share_day()
- {
- /**
- * 1242
- * 2208
- */
- $user = $this->request->userInfo();
- $name = $user['uid'] . '_' . $user['is_promoter'] . '_user_wap.jpg';
- $siteUrl = systemConfig('site_url');
- $codeUrl = set_http_type($siteUrl . '/share?spread=' . $user['uid'], request()->isSsl() ? 0 : 1);//二维码链接
- $imageInfo = app()->make(QrcodeService::class)->getQRCodePath($codeUrl, $name, $user['avatar']);
- if (is_string($imageInfo)) throw new ValidateException('二维码生成失败');
- $filename = 'https://88yx.xyz/qqh/uploads/20211101074257444.jpg';
- $qrcode = $imageInfo['dir'];
- dump($qrcode);
- $config = array(
- 'image' => array(
- array(
- 'url' => $qrcode,//二维码资源
- 'stream' => 0,
- 'left' => 533,
- 'top' => 1941,
- 'right' => 0,
- 'bottom' => 0,
- 'width' => 184,
- 'height' => 182,
- 'opacity' => 100
- )
- ),
- 'background' => $filename
- );
- $data = setSharePoster($config, 'routine/spread/poster');
- dump($data);
- return app('json')->success($data);
- }
- public function spread_info()
- {
- $user = $this->request->userInfo();
- $user->append(['one_level_count', 'lock_brokerage', 'two_level_count', 'spread_total', 'yesterday_brokerage', 'total_extract', 'total_brokerage']);
- $data = [
- 'lock_brokerage' => $user->lock_brokerage,
- 'one_level_count' => $user->one_level_count,
- 'two_level_count' => $user->two_level_count,
- 'spread_total' => $user->spread_total,
- 'yesterday_brokerage' => $user->yesterday_brokerage,
- 'total_extract' => $user->total_extract,
- 'total_brokerage' => $user->total_brokerage,
- 'brokerage_price' => $user->brokerage_price,
- 'member_brokerage_price' => $user->member_brokerage_price,
- 'now_money' => $user->now_money,
- 'broken_day' => (int)systemConfig('lock_brokerage_timer')
- ];
- return app('json')->success($data);
- }
- //红包
- public function hongbao_info(){
- log::info("============hongbao");
- $user = $this->request->userInfo();
- if($user->uid>0){
- //已经入账红包
- $data['total_source']=$user->hongbao;
- //为生效红包
- $data['no_total_source']=Db::name('user_sign_hongbao')->where('status', -1)->where('uid', $user->uid)->sum('number');;
- log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
- return app('json')->success($data);
- }
- }
- public function vr_name()
- {
- $uid = $this->request->uid();
- $data = [
- "name"=>"VR",
- "url"=>'https://show.hxxfb.com/?uid=' .$uid,
- ];
- return app('json')->success($data);
- }
- public function hongbao_list(){
- $pm = $this->request->param('pm');
- [$page, $limit] = $this->getPage();
- $uid = $this->request->uid();
- log::info("hongbao_list==={$uid}");
- $where['uid'] = $uid;
- if ($pm==0){
- $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();
- }
- if($pm==1){
- $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();
- }
- if($pm==2){
- $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();
- if($data){
- $data = $data->toArray();
- foreach ($data as $k=>$v){
- if($v['status'] == 0){
- $data[$k]['mark'] = '(失效)' . $v['mark'];
- }
- }
- }
- }
- return app("json")->success($data);
- }
- public function buildTreeContribute($users, $parentId = 0) {
- $branch = array();
- foreach ($users as $user) {
- if ($user['spread_uid'] == $parentId) {
- $children = $this->buildTreeContribute($users, $user['uid']); // 递归查找子节点
- if ($children) {
- $user['children'] = $children; // 如果有子节点,添加到当前节点
- }else{
- $user['children'] = [];
- }
- $user['total_contribute'] = $user['contribute_sum']; // 初始化当前节点的总余额为自身余额
- if ($children) { // 如果存在子节点,计算总余额
- foreach ($children as $child) {
- $user['total_contribute'] += $child['total_contribute']; // 累加子节点的总余额
- }
- }
- $branch[] = $user; // 将当前节点添加到树中
- }
- }
- return $branch; // 返回当前分支的所有节点
- }
- // 根据父级uid,递归获取所有子级UID数组 默认深度10级
- public function getRecursiveChildrenChengji($parentUid, $number = 10) {
- $user = Db::name('user')->where('uid', $parentUid)->field('uid,spread_uid,contribute,per_contribute')->find();
- $user['contribute_sum'] = bcadd($user['contribute'], $user['per_contribute'], 2);
- $user['contribute_sum'] = 0;
- $uids = [];// 用于存储符合条件的子级 uid
- $result = [$user]; // 用于存储符合条件的子级数据
- // 定义递归函数
- $num = 0;//当前层级
- $recursion = function ($parentUid, $number, $num) use (&$uids, &$result, &$recursion) {
- if($num >= $number){
- return;
- }
- // 查询当前父级的所有直接子级
- $children = Db::name('user')->field('uid,spread_uid,contribute,per_contribute')->where("spread_uid", $parentUid)->select()->toArray();
- // 如果没有子级,直接返回
- if (!count($children) && count($children) < 1) {
- return;
- }else{
- $num = $num + 1;
- }
- // 遍历每个子级
- foreach ($children as $childUid) {
- //如果有重复的就跳过 防止死循环
- if(in_array($childUid['uid'], $uids)){
- continue;
- }
- // 将符合条件的子级 uid 添加到结果数组
- $uids[] = $childUid['uid'];
- // 将符合条件的子级 uid 添加到结果数组
- $childUid['contribute_sum'] = bcadd($childUid['contribute'], $childUid['per_contribute'], 2);
- $result[] = $childUid;
- // 递归查询子级的子级
- $recursion($childUid['uid'], $number, $num);
- }
- };
- // 从初始父级开始递归查询
- $recursion($parentUid, $number, $num);
- return $result; // 返回结果数组,并去重
- }
- //贡献值
- public function gongxian_info(){
- log::info("============gongxianinfo");
- $user = $this->request->userInfo();
- if($user->uid>0){
- // 先去更新一下用户身份
- $number = Db::name("system_config_value")->where(["config_key" => "team_commission_recursion_depth"])->value("value");
- $this->repository->setUserIdentity($user->uid);
- $result = $this->repository->getUserContributeInfoByDepth($user->uid, 0);
- $con = DB::name('user')->where('uid', $user->uid)->find();
- $isNormalUser = false;
- if ($con['user_group'] == 1) {
- $isNormalUser = true;
- }
- $data = [
- 'no_total_source' => Db::name('user_sign_gongxian')->where('status', -1)->where('uid', $user->uid)->sum('number'),
- 'team_gongxian_num' => $result['arriveNumTeam'],
- 'zhitui' => $result['perContribute'],
- 'total_source' => $result['contribute'],
- 'largeContribute' => $result['largeContribute'],
- 'subordinate' => $result['subordinate'],
- 'isNormalUser' => $isNormalUser
- ];
- return app('json')->success($data);
- // $dateObj=DB::name('user_sign_gongxian')->where('uid', $user->uid)->where("status",1)->select();
- $con = DB::name('user')->where('uid', $user->uid)->find();
- // $totalcon = 0;
- // foreach($dateObj as $k=>$v){
- // $totalcon += $v['number'];
- // }
- //已经入账贡献值
- // if( $con['user_group'] <= 2 ){
- // $data['total_source'] = $con['contribute'] + $con['per_contribute'];
- // }else{
- $data['total_source'] = $con['contribute'];
- $data['zhitui'] = $con['per_contribute'];
- // }
- // $getteamscon = $this->getPerformance($user->uid);
- //$getcon = $this->getPerformance_getcon( $user->uid);
- // $team_userinfo_old_jbp22 = $this->getPerformance22($user->uid);
- $user_id = $con['uid'];
- $user_group = $con['user_group'];
- $number = 10;
- if($user_group <= 1){
- $number = 1;
- }
- //如果下级团队只有一个人 那就不用再查了 为0
- //如果用户等级为用户身份 只查一级直推
- //去除掉贡献值最大的下级
- $child_nums = $this->getRecursiveChildrenChengji($user_id, $number);
- $child_nums_Tree = $this->buildTreeContribute($child_nums, $con['spread_uid']);
- if (empty($child_nums_Tree)){
- $child_nums_Tree = $child_nums;
- $total_contribute = $child_nums_Tree[0]['per_contribute'];
- }else{
- // 找到贡献值最大的用户的索引
- if(count($child_nums_Tree[0]['children'])){
- $maxBalanceIndex = array_search(max(array_column($child_nums_Tree[0]['children'], 'total_contribute')), array_column($child_nums_Tree, 'total_contribute'));
- // 减去该用户的贡献值
- $total_contribute = bcsub($child_nums_Tree[0]['total_contribute'], $child_nums_Tree[0]['children'][$maxBalanceIndex]['total_contribute'], 2);
- }else{
- $total_contribute = $child_nums_Tree[0]['total_contribute'];
- }
- }
- $data['team_gongxian_num'] = $total_contribute;
- //我的团队贡献值
- // if( $con['user_group'] <= 2 ){
- // $data['team_gongxian_num'] = $team_userinfo_old_jbp22['person_nums_pv'] - $con['per_contribute'];
- // }else{
- // $data['team_gongxian_num'] = $team_userinfo_old_jbp22['person_nums_pv'];
- // }
- //未生效贡献值
- $data['no_total_source']=Db::name('user_sign_gongxian')->where('status', -1)->where('uid', $user->uid)->sum('number');
- log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
- return app('json')->success($data);
- }
- }
- //获取团队贡献值
- public function gettemasconvalue($user_id) {
- //$user_id = 17;
- $children = Db::name("user")
- ->where("spread_uid", $user_id)
- ->select(); // 获取子级的 uid 列表
- $total_pv = 0;
- foreach($children as $k=>$v){
- //$children_pv = Db::name("store_order")->where("uid", $v['uid'])->whereIn("status",[0,1,2,3])->select();
- $children_pv = Db::name("user_sign_gongxian")->where("uid", $v['uid'])->where("status",1)->select();
- foreach($children_pv as $k1=>$v1){
- $total_pv += $v1['number'];
- }
- }
- }
- public function gongxian_list(){
- $pm = $this->request->param('pm');
- [$page, $limit] = $this->getPage();
- $uid = $this->request->uid();
- log::info("green_integral_list==={$uid}");
- $where['uid'] = $uid;
- if ($pm==0){
- $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();
- }
- // if($pm==1){
- // $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();
- //
- // }
- if($pm==2){
- $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();
- if($data){
- $data = $data->toArray();
- foreach ($data as $k=>$v){
- if($v['status'] == 0){
- $data[$k]['mark'] = '(失效)' . $v['mark'];
- }
- }
- }
- }
- return app("json")->success($data);
- }
- //京豆
- public function jingdou_info(){
- log::info("============hongbao");
- $user = $this->request->userInfo();
- if($user->uid>0){
- //已经入账京豆
- //$data['total_source']=$user->vr;//原件
- $data['total_source'] = $user->jingdou;//临时使用
- //为生效京豆
- $data['no_total_source']=Db::name('user_sign_jingdou')->where('status', -1)->where('uid', $user->uid)->sum('number');;
- log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
- return app('json')->success($data);
- }
- }
- public function jingdou_list(){
- $pm = $this->request->param('pm');
- [$page, $limit] = $this->getPage();
- $uid = $this->request->uid();
- log::info("jingdou_list==={$uid}");
- $where['uid'] = $uid;
- if ($pm==0){
- $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();
- }
- if($pm==1){
- $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();
- }
- if($pm==2){
- $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();
- if($data){
- $data = $data->toArray();
- foreach ($data as $k=>$v){
- if($v['status'] == 0){
- $data[$k]['mark'] = '(失效)' . $v['mark'];
- }
- }
- }
- }
- // $data['total'] =111;
- return app("json")->success($data);
- }
- //复购金
- public function fugou_info(){
- log::info("============fugou");
- $user = $this->request->userInfo();
- if($user->uid>0){
- //已经入账京豆
- $data['total_source']=$user->fugou;
- //为生效京豆
- $data['no_total_source']=Db::name('user_sign_fugou')->where('status', -1)->where('uid', $user->uid)->sum('number');;
- log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
- return app('json')->success($data);
- }
- }
- public function fugou_list(){
- $pm = $this->request->param('pm');
- [$page, $limit] = $this->getPage();
- $uid = $this->request->uid();
- log::info("fugou_list==={$uid}");
- $where['uid'] = $uid;
- if ($pm==0){
- $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();
- }
- if($pm==1){
- $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();
- }
- if($pm==2){
- $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();
- if($data){
- $data = $data->toArray();
- foreach ($data as $k=>$v){
- if($v['status'] == 0){
- $data[$k]['mark'] = '(失效)' . $v['mark'];
- }
- }
- }
- }
- return app("json")->success($data);
- }
- //VR 购物金
- public function vr_info(){
- log::info("============vr");
- $user = $this->request->userInfo();
- if($user->uid>0){
- //已经入账京豆
- $data['total_source'] = $user->vr;
- //为生效京豆
- $data['no_total_source']=0;
- //$data['no_total_source']=Db::name('user_sign_vr')->where('status', -1)->where('uid', $user->uid)->sum('number');;
- log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
- return app('json')->success($data);
- }
- }
- public function vr_list(){
- $pm = $this->request->param('pm');
- [$page, $limit] = $this->getPage();
- $uid = $this->request->uid();
- log::info("vr_list==={$uid}");
- $where['uid'] = $uid;
- $data = DB::name('user_sign_vr')->page($page, $limit)->order("id desc")->select();
- if ($pm==0){
- $data = DB::name('user_sign_vr')->where($where)->where('type', 1)->page($page, $limit)->order("id desc")->select();
- }
- if($pm==2){
- $data = DB::name('user_sign_vr')->where($where)->where('type', 2)->page($page, $limit)->order("id desc")->select();
- }
- // if($pm==2){
- // $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();
- //
- // }
- log::info("=======date==={$data}");
- return app("json")->success($data);
- }
- public function spread_info_yhc()
- {
- log::info("============ddddddddd");
- $user = $this->request->userInfo();
- if($user->uid>0){
- //已经入账积分
- $data['total_source']=$user->score;
- //为生效积分
- $data['no_total_source']=Db::name('user_sign_score')->where('status', -1)->where('uid', $user->uid)->sum('reward_socre');;
- log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
- return app('json')->success($data);
- }
- // if ($this->source == 'yhc' && $this->merId) {
- // $where['mer_id'] = $this->merId;
- // $where['uid'] = $user->uid;
- // $enterprise_user = Db::name('enterprise_user')->where($where)->find();
- // if ($enterprise_user) {
- // $data['current_balance'] = set_price_rtrim($enterprise_user['commission']);//收益余额
- // $data['unsettled_balance'] = 0;//未结算
- // $extract_price = Db::name('user_extract')->where($where)->whereIn('status', [0, 1])->sum('extract_price');
- // $data['withdrawn_balance'] = set_price_rtrim($extract_price); //已提现
- // $data['total_balance'] = set_price_rtrim($enterprise_user['commission'] + $data['withdrawn_balance']);//总收益=收益余额+已提现
- // $data['identity'] = $enterprise_user['identity'];
- // $data['level'] = $enterprise_user['level'];
- // $data['partnership'] = $enterprise_user['partnership'];
- // $data['green_integral'] = $enterprise_user['green_integral'];
- // $data['green_integral_is'] = $enterprise_user['green_integral_is'];
- // $data['operate'] = $enterprise_user['operate'];
- // $data['operate_icon'] = '';
- // $data['operate_text'] = '';
- // $member_settings = merchantConfig($this->merId, 'member_settings');
- // if ($data['operate'] == 101) {
- // $data['operate_icon'] = $member_settings['yy_one_img'];
- // $data['operate_text'] = $member_settings['yy_one_text'];
- // }
- // if ($data['operate'] == 102) {
- // $data['operate_icon'] = $member_settings['yy_two_img'];
- // $data['operate_text'] = $member_settings['yy_two_text'];
- // }
- //
- //
- // $data['nickname'] = $user->nickname;
- // $data['avatar'] = $enterprise_user['avatar'];
- //
- // $arr = $this->jisuan_fans($user->uid);
- // $data['fans_num'] = count($arr);//粉丝总数
- //
- // $yanglao = 0;
- // $offLinewhere = ['mer_id' => $this->merId, 'uid' => $user->uid, 'commission_type' => '5', 'type_shop' => 0];
- // $offLine1 = Db::name('user_bill')->where($offLinewhere)->where('source', 1)->where('status', 1)->sum('number');
- // $yanglao += $offLine1;
- // $offLine2 = Db::name('user_bill')->where($offLinewhere)->where('source', 0)->whereIn('status', [0, 1])->sum('number');
- // $yanglao += $offLine2;
- //
- //
- // $data['ylj'] = set_price_rtrim($yanglao);
- //
- // $data['yhc_withdrawal_money'] = merchantConfig($this->merId, 'yhc_withdrawal_money');
- //
- //
- // $data['uid'] = $enterprise_user['uid'];
- // if ($enterprise_user['identity'] > 100) {
- // $data['identity_data'] = Db::name('enterprise_performance_divvy')->field('name,img,content')->where('state', 1)->where('id', $enterprise_user['identity'])->find();
- // if (!$data['identity_data']) {
- // $data['identity_data'] = null;
- // $data['identity'] = '100';
- // }
- // } else {
- // $data['identity_data'] = null;
- // }
- //
- // $data['level_data'] = Db::name('enterprise_agent_divvy')->field('name,img,content')->where('state', 1)->where('id', $enterprise_user['level'])->find();
- //
- //
- // return app('json')->success($data);
- // }
- // }
- return app('json')->fail('用户不存在');
- }
- /**
- * @param UserBillRepository $billRepository
- * @return mixed
- * @author xaboy
- * @day 2020/6/22
- */
- public function bill(UserBillRepository $billRepository)
- {
- [$page, $limit] = $this->getPage();
- $where = [
- // 'now_money' => $this->request->param('type', 0),
- 'status' => $this->request->param('status'),
- ];
- if ($this->request->param('is_red') == true) {
- $where['is_red_brokerage'] = 1;
- }
- return app('json')->success($billRepository->userList($where, $this->request->uid(), $page, $limit));
- }
- /**
- * @param UserBillRepository $billRepository
- * @return mixed
- * @author xaboy
- * @day 2020/6/22
- */
- public function brokerage_list(UserBillRepository $billRepository)
- {
- [$page, $limit] = $this->getPage();
- return app('json')->success($billRepository->userList([
- 'category' => 'brokerage',
- ], $this->request->uid(), $page, $limit));
- }
- /**
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author xaboy
- * @day 2020/6/22
- */
- public function spread_order()
- {
- [$page, $limit] = $this->getPage();
- return app('json')->success($this->repository->subOrder($this->request->uid(), $page, $limit));
- }
- /**
- * TODO
- * @return mixed
- * @author Qinii
- * @day 2020-06-18
- */
- public function binding()
- {
- $data = $this->request->params(['phone', 'sms_code']);
- if (!$data['sms_code'] || !$this->checkSmsCode($data['phone'], $data['sms_code'])) return app('json')->fail('验证码不正确');
- $user = $this->repository->accountByUser($data['phone']);
- if ($user) {
- $data = ['phone' => $data['phone']];
- } else {
- $data = ['account' => $data['phone'], 'phone' => $data['phone']];
- }
- $this->repository->update($this->request->uid(), $data);
- return app('json')->success('绑定成功');
- }
- /**
- * TODO
- * @return mixed
- * @author Qinii
- * @day 2020-06-18
- */
- public function binding_verify()
- {
- $data = $this->request->params(['user_id', 'captcha']);
- $data['phone'] = \think\facade\Db::name("user")->where(["uid" => $data['user_id']])->value("phone");
- $data['sms_code'] = $data['captcha'];
- if (!$data['sms_code'] || !$this->checkSmsCode($data['phone'], $data['sms_code'])) return app('json')->fail('验证码不正确');
- return app('json')->success('验证成功');
- }
- public function checkSmsCode($phone, $code)
- {
- $sms_key = 'api.auth.sms.' . $phone;
- if (!$cache_code = Cache::get($sms_key)) return false;
- if ($code != $cache_code) return false;
- Cache::delete($sms_key);
- return true;
- }
- /**
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author xaboy
- * @day 2020/6/22
- */
- public function spread_list()
- {
- [$level, $sort, $nickname] = $this->request->params(['level', 'sort', 'keyword'], true);
- $uid = $this->request->uid();
- [$page, $limit] = $this->getPage();
- return app('json')->success($level == 2
- ? $this->repository->getTwoLevelList($uid, $nickname, $sort, $page, $limit)
- : $this->repository->getOneLevelList($uid, $nickname, $sort, $page, $limit));
- }
- /**
- * @return mixed
- * @author xaboy
- * @day 2020/6/22
- */
- public function spread_top()
- {
- [$page, $limit] = $this->getPage();
- $type = $this->request->param('type', 0);
- return app('json')->success($type == 1
- ? $this->repository->spreadMonthTop($page, $limit)
- : $this->repository->spreadWeekTop($page, $limit));
- }
- /**
- * @return mixed
- * @author xaboy
- * @day 2020/6/22
- */
- public function brokerage_top()
- {
- [$page, $limit] = $this->getPage();
- $type = $this->request->param('type', 0);
- return app('json')->success($type == 1
- ? $this->repository->brokerageMonthTop($page, $limit)
- : $this->repository->brokerageWeekTop($page, $limit));
- }
- public function history(UserVisitRepository $repository)
- {
- $uid = $this->request->uid();
- [$page, $limit] = $this->getPage();
- return app('json')->success($repository->getHistory($uid, $page, $limit));
- }
- public function deleteHistory($id, UserVisitRepository $repository)
- {
- $uid = $this->request->uid();
- if (!$repository->getWhereCount(['user_visit_id' => $id, 'uid' => $uid]))
- return app('json')->fail('数据不存在');
- $repository->delete($id);
- return app('json')->success('删除成功');
- }
- public function account()
- {
- $user = $this->request->userInfo();
- if (!$user->phone) return app('json')->fail('请绑定手机号');
- return app('json')->success($this->repository->selfUserList($user->phone));
- }
- public function switchUser()
- {
- $uid = (int)$this->request->param('uid');
- if (!$uid) return app('json')->fail('用户不存在');
- $userInfo = $this->request->userInfo();
- if (!$userInfo->phone) return app('json')->fail('请绑定手机号');
- $user = $this->repository->switchUser($userInfo, $uid);
- $tokenInfo = $this->repository->createToken($user);
- $this->repository->loginAfter($user);
- return app('json')->success($this->repository->returnToken($user, $tokenInfo));
- }
- /**
- * 签到 获取积分
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function sub_signin()
- {
- $member_id = $this->request->uid();
- if (!$member_id) return app('json')->fail('用户不存在');
- $res = $this->repository->sub_signin($member_id);
- return app('json')->success($res);
- }
- /**
- * 获取用户签到记录
- * data1 开始时间
- * data2 结束时间
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function get_signin()
- {
- $member_id = $this->request->uid();
- if (!$member_id) return app('json')->fail('用户不存在');
- $where = [];
- $data1 = input('data1');
- $data2 = input('data2');
- if ($data1 && $data2) {
- $where["data1"] = $data1;
- $where["data2"] = $data2;
- }
- $res = $this->repository->get_signin($member_id, $where);
- return app('json')->success($res);
- }
- /**
- * 提交实名认证
- *
- * @return void
- */
- public function add_certification()
- {
- $member_id = $this->request->uid();
- $type = input("type", 0);
- if ($type == 1) {
- $data = $this->repository->get_cer(["uid" => $member_id]);
- return app('json')->success($data);
- }
- if (!$member_id) return app('json')->fail('用户不存在');
- $params = $this->request->params([
- 'user_name',
- 'mobile',
- 'user_card',
- 'card_positive',
- 'card_reverse',
- ]);
- $params['create_time'] = time();
- $params['uid'] = $member_id;
- $baidu = new Ocr();
- $image = file_get_contents($params['card_positive']);
- $idCardSide = "front";
- $result = $baidu->idcard($image, $idCardSide);
- $real_user_name = $result['words_result']['姓名']['words'] ?? '';
- $real_user_card = $result['words_result']['公民身份号码']['words'] ?? '';
- if ($real_user_name != $params['user_name']) {
- return app('json')->fail('姓名或身份证号输入有误~');
- }
- if ($real_user_card != $params['user_card']) {
- return app('json')->fail('姓名或身份证号输入有误~');
- }
- if ($result['image_status'] == "normal" && $result['idcard_number_type'] == 1) {
- $params['status'] = 1;
- $res = $this->repository->add_cer($params, $member_id);
- if ($res) {
- $userRepository = app()->make(UserRepository::class);
- //赠送积分 完善实名送90个积分,同时送邀请人50个积分
- $userRepository->sign_add($member_id, 90,1,'完善实名系统赠送90个积分','','', '', 1, '', 1);
- $member_info = Db::name('user')->where( array('uid' => $member_id) )->find();
- Db::name('user')
- ->where('uid', $member_id)
- ->update(['real_name' => $params['user_name'], 'nickname' => $params['user_name']]);
- if($member_info['spread_uid']){
- //好友完善实名系统赠送50个积分
- $spreadUid = $member_info['spread_uid'];
- $userRepository->sign_add($spreadUid, 50,1,'好友完善实名系统赠送50个积分','','', '', 1, '', 1);
- }
- return app('json')->success($res);
- } else {
- return app('json')->fail('认证失败');
- }
- } else {
- return app('json')->fail('认证失败,请重新认证');
- }
- }
- /**
- * 申请代理
- * name:公司名称
- * identity:身份
- * license:营业执照
- */
- public function apply_agent()
- {
- $name = input("name", "");
- $identity = input("identity", 1);
- $license = input("license", "");
- $province_id = input("province_id", "");
- $city_id = input("city_id", "");
- $area_id = input("area_id", "");
- $street_id = input("street_id", "");
- $spread_account = input("spread_account", "");
- $member_id = $this->request->uid();
- if ($identity != 6 && (!$name || !$identity || !$license)) {
- return app('json')->fail('请检查参数');
- }
- if ($identity == 6 && (!$name || !$identity)) {
- return app('json')->fail('请检查参数');
- }
- $data = [
- "name" => $name,
- "identity" => $identity,
- "license" => $license,
- "user_id" => $member_id,
- "province_id" => $province_id,
- "city_id" => $city_id,
- "area_id" => $area_id,
- "street_id" => $street_id,
- 'spread_account' => $spread_account,
- "add_time" => time(),
- "update_time" => time()
- ];
- $res = $this->repository->agent($data);
- if ($res['code'] == 400) {
- return app('json')->fail($res['msg']);
- }
- return app('json')->success("申请成功", $res);
- }
- /*查询是否有已申请或者审核中的代理信息*/
- public function isAgent()
- {
- $uid = $this->request->uid();
- $data = $this->repository->isAgent($uid);
- return app("json")->success($data);
- }
- /*查询是否有审核成功的未支付或支付失败的订单*/
- public function AgentPayDetail()
- {
- $uid = $this->request->uid();
- if (!$uid) {
- return app('json')->fail('请检查参数');
- }
- $where = ['status' => 1, 'pay_status' => ['0', '2'], 'user_id' => $uid];
- $data = $this->repository->getAgentPayDetail($where);
- return app('json')->success("成功", $data);
- }
- /**
- * 获取信息 全民营销首页
- * @return mixed
- */
- public function get_agent_info()
- {
- $member_id = $this->request->uid();
- $res = $this->repository->get_agent_info($member_id);
- if ($res) {
- return app('json')->success($res);
- } else {
- return app('json')->fail('获取失败');
- }
- }
- /**
- * 推广统计
- * search 搜索
- * @return mixed
- */
- public function get_extension_info()
- {
- $search = input("search", "");
- $where = $this->request->params(["identity"]);
- $member_id = $this->request->uid();
- $res = $this->repository->get_extension_info($member_id, $search, $where);
- if ($res) {
- return app('json')->success($res);
- } else {
- return app('json')->fail('获取失败');
- }
- }
- /**
- * 收益统计
- * type 搜索
- * @return mixed
- */
- public function get_profit_info()
- {
- $where = $this->request->params([
- 'commission_type',
- 'date_on',
- 'date_off',
- 'order'
- ]);
- $member_id = $this->request->uid();
- $res = $this->repository->get_profit_info($member_id, $where);
- if ($res) {
- return app('json')->success($res);
- } else {
- return app('json')->fail('获取失败');
- }
- }
- /**
- * 订单统计
- * search 搜索
- * @return mixed
- */
- public function get_tuiguang_order()
- {
- $member_id = $this->request->uid();
- $res = $this->repository->get_tuiguang_order($member_id);
- if ($res) {
- return app('json')->success($res);
- } else {
- return app('json')->fail('获取失败');
- }
- }
- /*
- * 攒金明细统计
- * */
- public function get_commission_all()
- {
- $uid = $this->request->uid();
- $where['date_on'] = 1;
- $where['date_off'] = 0;
- // $where['commission_type'] = '';
- $date = $this->request->params(['date']);//"today","yesterday","week","month","year"
- $where['order'] = $date['date'];
- $res = $this->repository->get_profit_info($uid, $where);
- return app('json')->success($res);
- }
- /*
- * 攒金明细列表
- * */
- public function get_commission_list()
- {
- $uid = $this->request->uid();
- [$where['page'], $where['limit']] = $this->getPage();
- $data = $this->request->params(['type', 'date']);//"today","yesterday","week","month","year"
- $where['type'] = $data['type'];//0线上;1线下
- $where['order'] = $data['date'];//"today","yesterday","week","month","year"
- $res = $this->repository->get_tuiguang_list($uid, $where);
- return app('json')->success($res);
- }
- /*
- * 越攒越多佣金
- * */
- public function get_com_list()
- {
- $uid = $this->request->uid();
- [$where['page'], $where['limit']] = $this->getPage();
- $data = $this->request->params(['date']);//"today","yesterday","week","month","year"
- $where['order'] = $data['date'];//"today","yesterday","week","month","year"
- $res = $this->repository->get_com_list($uid, $where);
- return app('json')->success($res);
- }
- /*
- * 越攒越多统计
- * */
- public function get_com_all()
- {
- $uid = $this->request->uid();
- $data = $this->request->params(['date']);//"today","yesterday","week","month","year"
- $where['order'] = $data['date'];//"today","yesterday","week","month","year"
- $res = $this->repository->get_com_all($uid, $where);
- return app('json')->success($res);
- }
- /**
- * 养老金详情
- * @return mixed
- */
- public function get_yanglao()
- {
- $member_id = $this->request->uid();
- $res = $this->repository->get_yanglao($member_id);
- if ($res) {
- return app('json')->success($res);
- } else {
- return app('json')->fail('获取失败');
- }
- }
- /**
- * 养老金明细
- */
- public function yanglaolog()
- {
- $member_id = $this->request->uid();
- [$page, $limit] = $this->getPage();
- $where = ["uid" => $member_id, "type" => "commission", "commission_type" => 5, "type_shop" => 0];
- if ($this->source == 'yhc' && $this->merId) {
- $where['mer_id'] = $this->merId;
- }
- $month = $this->request->param('month', '');//年月搜索
- $status = $this->request->param('status', 1);
- //1-全部 2-已结算 3-未结算 4-已取消
- if ($status == 2) {
- $where['status'] = 1;
- } else if ($status == 3) {
- // $where['gzc']=0;
- $where['status'] = 0;
- } else if ($status == 4) {
- $where['status'] = -1;
- }
- $source = $this->request->param('source', -1);
- if ($source > -1) {
- $where['source'] = $source;
- }
- $res = $this->repository->yanglaolog($where, $page, $limit, $month,1);
- if ($res) {
- $res['list'] = $res['list']->toArray();
- if($res['list']){
- foreach ($res['list'] as $k=>$v){
- if($v['status'] == -1){
- $res['list'][$k]['mer_name'] = $v['mer_name'] . '(失效)';
- }
- }
- }
- return app('json')->success($res);
- } else {
- return app('json')->fail('获取失败');
- }
- }
- /*养老金详情*/
- public function YangLaoDetail($id)
- {
- $member_id = $this->request->uid();
- $data = $this->request->params([
- 'type',
- ]);
- $where = ["uid" => $member_id, "type" => "commission", "commission_type" => $data['type'], 'bill_id' => $id];
- $res = $this->repository->yanglaoDetail($where);
- return app('json')->success($res);
- }
- /**
- * 消费明细
- * @return mixed
- */
- public function tripartite()
- {
- $member_id = $this->request->uid();
- $where = ["uid" => $member_id, "type" => "commission", "commission_type" => 5, "tripartite" => ["<>", 0]];
- $res = $this->repository->yanglaolog($where);
- if ($res) {
- return app('json')->success($res);
- } else {
- return app('json')->fail('获取失败');
- }
- }
- /**
- * 提现明细
- * @return mixed
- */
- public function withdrawal()
- {
- $member_id = $this->request->uid();
- $data = $this->request->params([
- 'type',
- ]);
- $where = ["uid" => $member_id, "type" => $data['type'] ? $data['type'] : 2];
- if ($this->source == 'yhc') {
- $where['mer_id'] = $this->merId;
- }
- $res = $this->repository->withdrawal_user($where);
- if ($res) {
- return app('json')->success($res);
- } else {
- return app('json')->fail('获取失败');
- }
- }
- /**
- * 提现详情
- * @return mixed
- * @author cabbage
- * @day 2020/10/31
- */
- public function withdrawalDetail()
- {
- $member_id = $this->request->uid();
- $extract_id = input("extract_id", 0);
- return app('json')->success($this->repository->withdrawalDetail($extract_id, $member_id));
- }
- /*
- * 修改个人信息*/
- public function updateUser()
- {
- $data['nickname'] = $this->request->param('nickname', null);
- $data['avatar'] = $this->request->param('avatar', null);
- $data['sex'] = $this->request->param('sex', null);
- $data['birthday'] = $this->request->param('birthday', null);
- $data['addres'] = $this->request->param('addres', null);
- $data['mark'] = $this->request->param('mark', null);
- $data['phone'] = $this->request->param('phone', null);
- // $data['phone'] = $this->request->param('phone', null);
- if (!empty($data['phone'])) {
- $data['account'] = $data['phone'];
- }
- $data = array_filter($data, function($value) {
- return $value !== null;
- });
- $uid = $this->request->uid();
- $res = '';
- if ($this->source == 'yhc') {
- $res = Db::name('enterprise_user')->where('mer_id', $this->merId)->where('uid', $uid)->update(['avatar' => $data['avatar']]);
- unset($data['avatar']);
- }
- $data = $this->repository->updateUser($uid, $data);
- if ($data || $res) {
- return app("json")->success("修改成功", $data);
- }
- return app("json")->fail("未做任何修改");
- }
- /*积分记录*/
- public function socreList()
- {
- [$page, $limit] = $this->getPage();
- $uid = $this->request->uid();
- $data = $this->repository->socreList($uid, $page, $limit);
- return app("json")->success($data);
- }
- function jisuan_fans($uid)
- {
- $where22['node_uid'] = $uid;
- $where22['mer_id'] = $this->merId;
- $arr = $this->jisuantuandui($where22);
- $where['puid'] = $uid;
- $where['mer_id'] = $this->merId;
- $direct_fans = Db::name('enterprise_user')->where($where)->column('uid');//直属粉丝数量
- $result = array_unique(array_merge($arr, $direct_fans));
- return $result;
- }
- function jisuantuandui($where, $data = [])
- {
- $enterprise_user_team = DB::name('enterprise_user')->where($where)->column('uid');
- $arr = array_merge($data, $enterprise_user_team);
- foreach ($enterprise_user_team as $v) {
- $where['node_uid'] = $v;
- $arr = $this->jisuantuandui($where, $arr);
- }
- return $arr;
- }
- /**
- * 一壶茶-团队列表
- */
- public function team_list_1()
- {
- $teamid = $this->request->uid();
- //$teamid = $this->request->param('teamid');//测试ID
- $teamid = 17;
- $datas_jbp = Db::name('old_user_jbp')->where("id",$teamid)->find();//查询旧系统是否有当前会员
- $type = $this->request->param('type',0);//1:大部门,0:小部门,2:直推
- if(!empty($datas_jbp)){
- $team_userinfo_old_jbp1 = $this->getPerformance($teamid);
- //判断大小团队(业绩多的是大部门,业绩小的是小部门)
- $tes = $this->teamPeople($teamid,$type);//1:团队,2:个人
- // 获取分页参数
- $data1= [
- "total"=>100,
- "per_page"=> 10,
- "current_page"=> 1,
- "last_page"=> 1,
- ];
- if($type != 2){
- //小部门和大部门列表数据
- foreach($tes as $k=>$v){
- $curr_pv = '';
- if($v['curr_type']==0){
- $curr_pv = $team_userinfo_old_jbp1['person_nums_pv'];
- }else if($v['curr_type']==1){
- $curr_pv = $team_userinfo_old_jbp1['common_nums_pv'];
- }else{
- $curr_pv = 0;
- }
- $data1['data'][$k] = [
- "uid"=>$v["id"],
- "nickname"=> $v['user_name'] . $curr_pv,
- "phone"=> "137****3315",
- "avatar"=>"https://cdn.bjtdba.com/vod/image/2025-01-20/20250120125206881.png",
- "create_time"=>"2025-01-25 11:00:18",
- "identity"=>"11",
- "level"=> "40002",
- "partnership"=>"22",
- "total_performance"=> $curr_pv,//$v["performance"]['sum_nums_pv'],//总业绩
- "new_performance"=> 0,//新增业绩
- "team_count"=> $v["performance"]['common_nums'] + $v["performance"]['person_nums'] + 1,//团购人数(加的这个1 是当前用户的数)
- ];
- }
- }else{
- //直推列表
- foreach($tes as $k=>$v){
- $data1['data'][$k] = [
- "uid"=>$v["uid"],
- "nickname"=> $v['nickname'],
- "avatar"=>$v['avatar'],
- "create_time"=>"2025-01-25 11:00:18",
- ];
- }
- }
- $data['team_list'] = $data1;
- $data['fans_num'] = $team_userinfo_old_jbp1['person_nums'] + $team_userinfo_old_jbp1['common_nums'] ;//粉丝数
- $data['new_performance'] = 0;//新增业绩
- $data['total_performance']= $team_userinfo_old_jbp1['sum_nums_pv'];//总业绩
- $data['person_nums'] = $team_userinfo_old_jbp1['person_nums'];//个人联盟
- $data['common_nums'] = $team_userinfo_old_jbp1['common_nums'];//共建联盟
- $data['common_nums_pv'] =max( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);//公共联盟PV
- $data['person_nums_pv'] = min( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);//个人联盟PV
- // $data['effective_fans_num'] = DB::name('enterprise_user')
- }
- //var_dump($data);
- //把新表中的新增邀请用户加到数组中
- //$spread_usersdata = Db::name('user')->where("spread_uid",$teamid)->select();//查询旗下会员
- // 查询当前会员旗下的会员数据
- // 获取分页参数
- [$page, $limit] = $this->getPage();
- // 查询当前会员旗下的会员数据(分页)
- $subordinate_members = Db::name('user')
- ->alias('u')
- ->join('store_order so', 'u.uid = so.uid', 'LEFT')
- ->where("u.spread_uid", $teamid) // 查询旗下会员
- ->where("so.mer_id", 496)
- // ->where("so.douhuomall", 1)
- // ->where("so.douhuomall_status", 9)
- // ->where("so.status", 0)
- ->group('u.uid') // 确保每个用户只出现一次
- ->page($page, $limit) // 分页查询
- ->select(); // 获取分页数据
- //计算团队总业绩
- // $total_amount=0;
- // foreach($subordinate_members as $k=>$v){
- // }
- // 获取总会员数
- $total_members = Db::name('user') ->alias('u')
- ->join('store_order so', 'u.uid = so.uid', 'LEFT')
- ->where("u.spread_uid", $teamid) // 查询旗下会员
- ->where("so.mer_id", 496)
- // ->where("so.douhuomall", 1)
- // ->where("so.douhuomall_status", 9)
- // ->where("so.status", 0)
- ->group('u.uid') // 确保每个用户只出现一次
- ->page($page, $limit) // 分页查询
- ->count(); // 获取分页数据
- // 构造分页信息
- $data1 = [
- "total" => $total_members,
- "per_page" => $limit,
- "current_page" => $page,
- "last_page" => ceil($total_members / $limit),
- "data" => []
- ];
- $total_amount_pv_team = 0;//计算总业绩
- //获取团队总数量
- $team_count_total = 0;
- $small_count = 0;//小部门人数
- //var_dump($this->calculatePerformance($subordinate_members));
- //获取大小部门数据(新表)
- $get_big_small_datas = $this->getbig_samll_datas($subordinate_members);//下标0是大部门
- //var_dump( $get_big_small_datas);
- //判断大小部门的人数(根据业绩多的就是大部门,业绩小的就是小部门来计算展示的部门人数);
- $big_team_count = $get_big_small_datas[0]['team_count'];
- $smallteam_count = $get_big_small_datas[1]['team_count'];
- //end
- // 遍历分页数据,构造每个会员的详细信息
- foreach ($subordinate_members as $k => $v) {
- //计算自己和旗下的业绩
- $t_teams_pv = $this->calculatePerformance($v['uid']);
- $total_amount_pv_team += $t_teams_pv['total_performance'];
- $data1['data'][$k] = [
- "uid" => $v["uid"],
- "nickname" => $v['nickname'], // 假设昵称字段为 nickname
- "phone" => substr_replace($v['phone'], '****', 3, 4), // 隐藏手机号中间四位
- "avatar" => $v['avatar'], // 假设头像字段为 avatar
- "create_time" => $v['create_time'], // 假设创建时间为 create_time
- "total_performance" => $t_teams_pv['total_performance'], // 假设总业绩字段需要额外计算
- "new_performance" => $t_teams_pv['total_performance'], // 假设新增业绩字段需要额外计算
- "team_count" => $t_teams_pv['team_count'], // 假设团购人数需要额外计算
- ];
- }
- // 根据 type 参数处理数据
- if ($type == 1) {
- // 大部门:取 total_performance 最大的一个数组
- usort($data1['data'], function ($a, $b) {
- return $b['total_performance'] <=> $a['total_performance'];
- });
- $data1['data'] = array_slice($data1['data'], 0, 1); // 只保留最大的一个
- } elseif ($type == 0) {
- // 小部门:去掉 total_performance 最大的一个数组
- usort($data1['data'], function ($a, $b) {
- return $b['total_performance'] <=> $a['total_performance'];
- });
- $data1['data'] = array_slice($data1['data'], 1); // 去掉第一个
- } elseif ($type == 2) {
- // 直推:不做任何处理
- }
- // 构造最终返回的数据
- $data = [
- 'team_list' => $data1,
- 'fans_num' => $get_big_small_datas[0]['team_count'] + $get_big_small_datas[1]['team_count'], // 粉丝数
- 'new_performance' => $get_big_small_datas[0]['total_performance'] + $get_big_small_datas[1]['total_performance'], // 新增业绩
- 'total_performance' => $get_big_small_datas[0]['total_performance'] + $get_big_small_datas[1]['total_performance'], // 总业绩
- 'person_nums' => $big_team_count, // 大部门人数
- 'common_nums' => $smallteam_count, // 小部门人数
- 'common_nums_pv' => $get_big_small_datas[0]['total_performance'], // 公共联盟PV
- 'person_nums_pv' => $get_big_small_datas[1]['total_performance'], // 个人联盟PV
- ];
- return app("json")->success($data);
- }
- public function buildTreePv($users, $parentId = 0, $keyword = 'level_id' , $is_b = 1) {
- $branch = array();
- foreach ($users as $user) {
- if ($user[$keyword] == $parentId) {
- if($keyword == 'spread_uid' && $is_b == 1) {
- $children = $this->buildTreePv($users, $user['uid'], 'spread_uid', $is_b+1); // 递归查找子节点
- } else {
- $children = $this->buildTreePv($users, $user['uid'], 'level_id', $is_b+1); // 递归查找子节点
- }
- if ($children) {
- $user['children'] = $children; // 如果有子节点,添加到当前节点
- }else{
- $user['children'] = [];
- }
- $user['team_count'] = count($children);
- $user['total_pv'] = $user['pv']; // 初始化当前节点的总余额为自身余额
- if ($children) { // 如果存在子节点,计算总余额
- foreach ($children as $child) {
- $user['total_pv'] += $child['total_pv']; // 累加子节点的总余额
- $user['team_count'] += $child['team_count'];
- }
- }
- $branch[] = $user; // 将当前节点添加到树中
- }
- }
- return $branch; // 返回当前分支的所有节点
- }
- // 根据父级uid,递归获取所有子级UID数组 默认深度10级
- public function getdepartmentStatistics($parentUid, $keyword = 'level_id') {
- $user = Db::name('user')->where('uid', $parentUid)->field('uid,nickname,avatar,spread_uid,pv,create_time,level_id')->find();
- $user['pv'] = 0;
- $uids = [];// 用于存储符合条件的子级 uid
- $result = [$user]; // 用于存储符合条件的子级数据
- // 定义递归函数
- $is_a = true;
- $recursion = function ($parentUid) use (&$uids, &$result, &$recursion, &$keyword, &$is_a) {
- if ($keyword == 'spread_uid' && $is_a) {
- $children = Db::name('user')->field('uid,nickname,avatar,spread_uid,pv,create_time,level_id')->where($keyword, $parentUid)->select()->toArray();
- $is_a = false;
- } else {
- $children = Db::name('user')->field('uid,nickname,avatar,spread_uid,pv,create_time,level_id')->where('level_id', $parentUid)->select()->toArray();
- }
- // 查询当前父级的所有直接子级
- // 如果没有子级,直接返回
- if (!count($children) && count($children) < 1) {
- return;
- }
- // 遍历每个子级
- foreach ($children as $childUid) {
- //如果有重复的就跳过 防止死循环
- if(in_array($childUid['uid'], $uids)){
- continue;
- }
- // 将符合条件的子级 uid 添加到结果数组
- $uids[] = $childUid['uid'];
- $result[] = $childUid;
- // 递归查询子级的子级
- $recursion($childUid['uid']);
- }
- };
- // 从初始父级开始递归查询
- $recursion($parentUid);
- return $result; // 返回结果数组,并去重
- }
- /**
- * 一壶茶-团队列表
- */
- public function team_list()
- {
- $teamid = $this->request->uid();
- [$page, $limit] = $this->getPage();
- //小夏重写部分
- $user_id = $teamid;
- //如果下级团队只有一个人 那就不用再查了 为0
- //如果用户等级为用户身份 只查一级直推
- //去除掉贡献值最大的下级
- $user = Db::name('user')->where('uid', $user_id)->field('uid,nickname,avatar,spread_uid,pv,create_time,level_id')->find();
- $child_nums = $this->getdepartmentStatistics($user_id, 'level_id');
- $child_nums_Tree = $this->buildTreePv($child_nums, $user['level_id'], 'level_id');
- $new_performance = 0; //一周内新增总业绩
- // 这周的时间区间
- // $end_time = date('Y-m-d ' . '00:00:00', strtotime('-7 days'));
- $now = time();
- $startTime = date('Y-m-d 00:00:00', strtotime('monday this week', $now)); // 这周星期一的开始时间
- $endTime = date('Y-m-d 23:59:59', strtotime('sunday this week', $now)); // 这周星期日的结束时间
- $person_nums_pv = 0;//大部门业绩
- $common_nums_pv = 0;//小部门业绩
- $aLL_list = [];//直推数据
- $person_list = [];//大部门数据
- $common_list = [];//小部门数据
- if (count($child_nums_Tree) && isset($child_nums_Tree[0]['children']) && count($child_nums_Tree[0]['children'])) {
- // 计算总新增业绩
- $uid_list = array_column($child_nums, 'uid');
- $uid_list = array_diff($uid_list, [$user_id]);
- $new_performance = Db::name("user_pv_log")
- ->whereIn('uid', $uid_list)
- ->whereBetween('settlement_time', [$startTime, $endTime])
- ->sum('pv');
- //获取大部门的key
- $maxBalanceIndex = array_search(max(array_column($child_nums_Tree[0]['children'], 'total_pv')), array_column($child_nums_Tree[0]['children'], 'total_pv'));
- foreach ($child_nums_Tree[0]['children'] as $k => $v) {
- $child_nums = $this->getdepartmentStatistics($v['uid'], 'level_id');
- $uid_list = array_column($child_nums, 'uid');
- array_push($uid_list, $v['uid']);
- $new_performance_child = Db::name("user_pv_log")
- ->whereIn('uid', $uid_list)
- ->whereBetween('settlement_time', [$startTime, $endTime])
- ->sum('pv');
- if ($k == $maxBalanceIndex) {
- $person_list[] = [
- "uid" => $v["uid"],
- "spread_uid" => $v['spread_uid'],
- "level_id" => $v['level_id'],
- "nickname" => $v['nickname'],
- "avatar" => $v['avatar'],
- "pv" =>round( $v['pv'],2),
- "total_performance" => round($v['total_pv'],2),
- "create_time" => $v['create_time'],
- 'team_count' => $v['team_count'],
- 'new_performance' => $new_performance_child
- ];
- $person_nums_pv = bcadd($person_nums_pv, $v['total_pv'],2);
- } else {
- $common_list[] = [
- "uid" => $v["uid"],
- "spread_uid" => $v['spread_uid'],
- "level_id" => $v['level_id'],
- "nickname" => $v['nickname'],
- "avatar" => $v['avatar'],
- "pv" => round($v['pv'],2),
- "total_performance" => round($v['total_pv'],2),
- "create_time" => $v['create_time'],
- 'team_count' => $v['team_count'],
- 'new_performance' => $new_performance_child
- ];
- $common_nums_pv = bcadd($common_nums_pv, $v['total_pv'],2);
- }
- // 我的直推 不是大小团队 加起来
- // $aLL_list[] = [
- // "uid" => $v["uid"],
- // "spread_uid" => $v['spread_uid'],
- // "nickname" => $v['nickname'],
- // "avatar" => $v['avatar'],
- // "pv" => $v['pv'],
- // "total_performance" => (int)$v['total_pv'],
- // "create_time" => $v['create_time'],
- // 'team_count'=> $v['team_count'],
- // 'new_performance' => $new_performance_child
- // ];
- }
- }
- $type = $this->request->param('type', 0);//1:大部门,0:小部门,2:直推
- // 初始化最终返回的数据
- $data = [
- 'team_list' => [],
- 'fans_num' => 0, // 粉丝数
- 'new_performance' => 0, // 新增业绩
- 'total_performance' => 0, // 总业绩
- 'person_nums' => 0, // 个人联盟人数
- 'common_nums' => 0, // 公共联盟人数
- 'common_nums_pv' => 0, // 公共联盟PV
- 'person_nums_pv' => 0, // 个人联盟PV
- ];
- if ($type != 2) {
- if ($type == 1) {
- $data1 = [
- "total" => count($person_list),
- "per_page" => (int)$limit,
- "current_page" => $page,
- "last_page" => ceil(count($person_list) / $limit),
- "data" => array_slice($person_list, ($page - 1) * $limit, $limit)
- ];
- } else {
- $data1 = [
- "total" => count($common_list),
- "per_page" => (int)$limit,
- "current_page" => $page,
- "last_page" => ceil(count($common_list) / $limit),
- "data" => array_slice($common_list, ($page - 1) * $limit, $limit)
- ];
- }
- } else {
- $child_nums = $this->getdepartmentStatistics($user_id, 'spread_uid');
- $child_nums_Tree_spread = $this->buildTreePv($child_nums, $user['spread_uid'], 'spread_uid');
- if (count($child_nums_Tree_spread) && isset($child_nums_Tree_spread[0]['children']) && count($child_nums_Tree_spread[0]['children'])) {
- // 计算总新增业绩
- $uid_list = array_column($child_nums, 'uid');
- $uid_list = array_diff($uid_list, [$user_id]);
- foreach ($child_nums_Tree_spread[0]['children'] as $k => $v) {
- $child_nums = $this->getdepartmentStatistics($v['uid']);
- $uid_list = array_column($child_nums, 'uid');
- array_push($uid_list, $v['uid']);
- $new_performance_child = Db::name("user_pv_log")
- ->whereIn('uid', $uid_list)
- ->whereBetween('settlement_time', [$startTime, $endTime])
- ->sum('pv');
- $aLL_list[] = [
- "uid" => $v["uid"],
- "spread_uid" => $v['spread_uid'],
- "level_id" => $v['level_id'],
- "nickname" => $v['nickname'],
- "avatar" => $v['avatar'],
- "pv" => round($v['pv'],2),
- "total_performance" => round($v['total_pv'], 2),
- "create_time" => $v['create_time'],
- 'team_count'=> $v['team_count'],
- 'new_performance' => $new_performance_child
- ];
- }
- }
- $data1 = [
- "total" => count($aLL_list),
- "per_page" => (int)$limit,
- "current_page" => $page,
- "last_page" => ceil(count($aLL_list) / $limit),
- "data" => array_slice($aLL_list, ($page - 1) * $limit, $limit)
- ];
- }
- // 旧系统中的公共部分数据
- $data['teamid'] = $teamid;
- $data['team_list'] = $data1;
- $data['fans_num'] = $child_nums_Tree[0]['team_count'];//总人数
- $data['new_performance'] = $new_performance;//新增总业绩
- $data['total_performance'] = bcadd($child_nums_Tree[0]['total_pv'] ?? 0, 0, 2);//总业绩
- $data['person_nums'] = count($person_list);//大部门人数
- $data['common_nums'] = count($common_list);//小部门人数
- $data['common_nums_pv'] = $person_nums_pv;//大部门业绩
- $data['person_nums_pv'] = $common_nums_pv;//小部门业绩
- return app("json")->success($data);
- // // 查询当前会员旗下的会员数据(分页)
- // [$page, $limit] = $this->getPage();
- // $subordinate_members = Db::name('user')
- // // ->alias('u')
- // // ->join('store_order so', 'u.uid = so.uid', 'LEFT')
- // ->where("spread_uid", $teamid)
- // // ->where("so.mer_id", 496)
- // // ->group('u.uid')
- // ->page($page, $limit)
- // ->select();
- // $total_members = Db::name('user')
- // // ->alias('u')
- // // ->join('store_order so', 'u.uid = so.uid', 'LEFT')
- // ->where("spread_uid", $teamid)
- // // ->where("so.mer_id", 496)
- // // ->group('u.uid')
- // ->count();
- // $data1 = [
- // "total" => $total_members,
- // "per_page" => $limit,
- // "current_page" => $page,
- // "last_page" => ceil($total_members / $limit),
- // "data" => []
- // ];
- // $total_amount_pv_team = 0;
- // $team_count_total = 0;
- // foreach ($subordinate_members as $k => $v) {
- // $t_teams_pv = $this->calculatePerformance($v['uid']);
- // $total_amount_pv_team += $t_teams_pv['total_performance'];
- // $team_count_total += $t_teams_pv['team_count'];
- // $data1['data'][$k] = [
- // "uid" => $v["uid"],
- // "nickname" => $v['nickname'],
- // "phone" => substr_replace($v['phone'], '****', 3, 4),
- // "avatar" => $v['avatar'],
- // "create_time" => $v['create_time'],
- // "total_performance" => $t_teams_pv['total_performance'],
- // "new_performance" => $t_teams_pv['total_performance'],
- // "team_count" => $t_teams_pv['team_count'],
- // ];
- // }
- // // 获取大小部门数据
- // $get_big_small_datas = $this->getbig_samll_datas($subordinate_members);
- // // 判断大小部门的人数
- // $big_team_count = $get_big_small_datas[0]['team_count'];
- // $small_team_count = $get_big_small_datas[1]['team_count'];
- // // 根据 type 参数处理数据
- // if ($type == 1) {
- // usort($data1['data'], function ($a, $b) {
- // return $b['total_performance'] <=> $a['total_performance'];
- // });
- // $data1['data'] = array_slice($data1['data'], 0, 1);
- // } elseif ($type == 0) {
- // usort($data1['data'], function ($a, $b) {
- // return $b['total_performance'] <=> $a['total_performance'];
- // });
- // $data1['data'] = array_slice($data1['data'], 1);
- // }
- // // 合并数据
- // if (!empty($datas_jbp)) {
- // // 如果旧系统中有数据,合并新旧数据
- // $data['team_list']['data'] = array_merge($data['team_list']['data'], $data1['data']);
- // $data['fans_num'] += $team_count_total;
- // $data['new_performance'] += $total_amount_pv_team;
- // $data['total_performance'] += $total_amount_pv_team;
- // $data['person_nums'] += $big_team_count;
- // $data['common_nums'] += $small_team_count;
- // $data['common_nums_pv'] += $get_big_small_datas[0]['total_performance'];
- // $data['person_nums_pv'] += $get_big_small_datas[1]['total_performance'];
- // } else {
- // // 如果旧系统中没有数据,直接使用新数据
- // $data['team_list'] = $data1;
- // $data['fans_num'] = $team_count_total;
- // $data['new_performance'] = $total_amount_pv_team;
- // $data['total_performance'] = $total_amount_pv_team;
- // $data['person_nums'] = $big_team_count;
- // $data['common_nums'] = $small_team_count;
- // $data['common_nums_pv'] = $get_big_small_datas[0]['total_performance'];
- // $data['person_nums_pv'] = $get_big_small_datas[1]['total_performance'];
- // }
- // return app("json")->success($data);
- }
- //计算自己和自己团队下面的业绩。新表
- //计算自己和自己团队下面的业绩。新表
- public function calculatePerformance($uid)
- {
- // 初始化业绩数组
- $performance = [
- 'personal_performance' => 0, // 个人业绩
- 'team_performance' => 0, // 团队业绩
- 'total_performance' => 0, // 总业绩
- 'team_count' => 0, // 加上自己的团队数量
- ];
- // 定义业绩换算规则
- $performanceMapping = [
- 1180 => 700,
- 10620 => 6300,
- 11800 => 7000
- ];
- // 计算个人业绩
- $personalOrder = Db::name('store_order')->where("uid", $uid)->find();
- if ($personalOrder) {
- // 将浮点数转换为整数
- $totalPrice = (int)$personalOrder['total_price'];
- if (isset($performanceMapping[$totalPrice])) {
- $performance['personal_performance'] = $performanceMapping[$totalPrice];
- }
- }
- if($uid <= 611){
- // 计算旗下团队成员的业绩
- $teamOrders = Db::name('user')
- ->alias('u')
- ->join('store_order so', 'u.uid = so.uid', 'LEFT')
- ->where("u.spread_uid", $uid) // 查询旗下会员
- ->where("so.mer_id", 496)
- // ->where("so.douhuomall", 1)
- // ->where("so.douhuomall_status", 9)
- // ->where("so.status", 0)
- ->select();
- $teamOrders_count = Db::name('user')
- ->alias('u')
- ->join('store_order so', 'u.uid = so.uid', 'LEFT')
- ->where("u.spread_uid", $uid) // 查询旗下会员
- ->where("so.mer_id", 496)
- // ->where("so.douhuomall", 1)
- // ->where("so.douhuomall_status", 9)
- // ->where("so.status", 0)
- ->count();
- $performance['team_count'] = $teamOrders_count + 1; // 赋值团队数量
- foreach ($teamOrders as $order) {
- if ($order['total_price']) {
- // 将浮点数转换为整数
- $totalPrice = (int)$order['total_price'];
- if (isset($performanceMapping[$totalPrice])) {
- $performance['team_performance'] += $performanceMapping[$totalPrice];
- }
- }
- }
- // 计算总业绩
- $performance['total_performance'] = $performance['personal_performance'] + $performance['team_performance'];
- // 假设总业绩最大值需要通过后续逻辑判断,这里暂时设置为 false
- return $performance;
- }
- }
- //获取大小部门业绩(新表)
- public function getbig_samll_datas($subordinate_members){
- //单独写一个方法获取大小部门的数据
- $arr_team = [];
- foreach ($subordinate_members as $k => $v) {
- //计算自己和旗下的业绩
- $arr_team[] = $this->calculatePerformance($v['uid']);
- }
- // 初始化变量
- $maxPerformance = 0;
- $maxIndex = -1;
- // 找出 total_performance 最高的记录
- foreach ($arr_team as $index => $item) {
- if ($item['total_performance'] > $maxPerformance) {
- $maxPerformance = $item['total_performance'];
- $maxIndex = $index;
- }
- }
- // 如果找到了最高记录
- if ($maxIndex !== -1) {
- // 提取最高记录
- $maxRecord = $arr_team[$maxIndex];
- // 从原数组中移除该记录
- unset($arr_team[$maxIndex]);
- // 重新索引数组
- $arr_team = array_values($arr_team);
- } else {
- // 如果没有找到记录,可以设置一个默认值
- $maxRecord = null;
- }
- // 计算大部门和小部门的汇总信息
- $majorDepartmentSummary = [
- "total_person_performance" => $maxRecord ? $maxRecord['personal_performance'] : 0,
- "total_team_performance" => $maxRecord ? $maxRecord['team_performance'] : 0,
- "total_performance" => $maxRecord ? $maxRecord['total_performance'] : 0,
- "team_count" => $maxRecord ? $maxRecord['team_count'] : 0,
- "data" => $maxRecord ? [$maxRecord] : []
- ];
- $minorDepartmentSummary = [
- "total_person_performance" => array_sum(array_column($arr_team, 'personal_performance')),
- "total_team_performance" => array_sum(array_column($arr_team, 'team_performance')),
- "total_performance" => array_sum(array_column($arr_team, 'total_performance')),
- "team_count" => array_sum(array_column($arr_team, 'team_count')),
- "data" => $arr_team
- ];
- // 输出结果
- // echo "大部门汇总信息:\n";
- // print_r($majorDepartmentSummary);
- // echo "小部门汇总信息:\n";
- // print_r($minorDepartmentSummary);
- return array($majorDepartmentSummary,$minorDepartmentSummary);
- }
- //计算自己和自己团队下面的业绩。新表
- public function calculatePerformance_copy($uid)
- {
- // 初始化业绩数组
- $performance = [
- 'personal_performance' => 0, // 个人业绩
- 'team_performance' => 0, // 团队业绩
- 'total_performance' => 0, // 总业绩
- 'team_count' =>0, //加上自己的团队数量
- //'team_count_pr'=>0,//实际团队数量(没有加上自己)
- ];
- // 定义业绩换算规则
- $performanceMapping = [
- 1180 => 700,
- 10620 => 6300,
- 11800 => 7000
- ];
- // 计算个人业绩
- $personalOrder = Db::name('store_order')->where("uid", $uid)->find();
- if ($personalOrder) {
- // 将浮点数转换为整数
- $totalPrice = (int)$personalOrder['total_price'];
- if (isset($performanceMapping[$totalPrice])) {
- $performance['personal_performance'] = $performanceMapping[$totalPrice];
- }
- }
- // 计算旗下团队成员的业绩
- $teamOrders = Db::name('user')
- ->alias('u')
- ->join('store_order so', 'u.uid = so.uid', 'LEFT')
- ->where("u.spread_uid", $uid) // 查询旗下会员
- ->where("so.mer_id", 496)
- // ->where("so.douhuomall", 1)
- // ->where("so.douhuomall_status", 9)
- // ->where("so.status", 0)
- ->select();
- $teamOrders_count = Db::name('user')
- ->alias('u')
- ->join('store_order so', 'u.uid = so.uid', 'LEFT')
- ->where("u.spread_uid", $uid) // 查询旗下会员
- ->where("so.mer_id", 496)
- // ->where("so.douhuomall", 1)
- // ->where("so.douhuomall_status", 9)
- // ->where("so.status", 0)
- ->count();
- $performance['team_count'] = $teamOrders_count+1;//赋值团队数量
- //$performance['team_count_pr'] = $teamOrders_count;//没有加上父级赋值团队数量
- foreach ($teamOrders as $order) {
- if ($order['total_price']) {
- // 将浮点数转换为整数
- $totalPrice = (int)$order['total_price'];
- if (isset($performanceMapping[$totalPrice])) {
- $performance['team_performance'] += $performanceMapping[$totalPrice];
- }
- }
- }
- // 计算总业绩
- $performance['total_performance'] = $performance['personal_performance'] + $performance['team_performance'];
- return $performance;
- }
- public function team_list_copy旧表使用()
- {
- $teamid = $this->request->uid();
- //$teamid = $this->request->param('teamid');//测试ID
- $teamid = 17;
- $type = $this->request->param('type',0);//1:大部门,0:小部门,2:直推
- $team_userinfo_old_jbp1= $this->getPerformance($teamid);
- //判断大小团队(业绩多的是大部门,业绩小的是小部门)
- $tes = $this->teamPeople($teamid,$type);//1:团队,2:个人
- $data1= [
- "total"=>100,
- "per_page"=> 10,
- "current_page"=> 1,
- "last_page"=> 1,
- ];
- if($type != 2){
- //小部门和大部门列表数据
- foreach($tes as $k=>$v){
- $curr_pv = '';
- if($v['curr_type']==0){
- $curr_pv = $team_userinfo_old_jbp1['person_nums_pv'];
- }else if($v['curr_type']==1){
- $curr_pv = $team_userinfo_old_jbp1['common_nums_pv'];
- }else{
- $curr_pv = 0;
- }
- $data1['data'][$k] = [
- "uid"=>$v["id"],
- "nickname"=> $v['user_name'] . $curr_pv,
- "phone"=> "137****3315",
- "avatar"=>"https://cdn.bjtdba.com/vod/image/2025-01-20/20250120125206881.png",
- "create_time"=>"2025-01-25 11:00:18",
- "identity"=>"11",
- "level"=> "40002",
- "partnership"=>"22",
- "total_performance"=> $curr_pv,//$v["performance"]['sum_nums_pv'],//总业绩
- "new_performance"=> 0,//新增业绩
- "team_count"=> $v["performance"]['common_nums'] + $v["performance"]['person_nums'] + 1,//团购人数(加的这个1 是当前用户的数)
- ];
- }
- }else{
- //直推列表
- foreach($tes as $k=>$v){
- $data1['data'][$k] = [
- "uid"=>$v["uid"],
- "nickname"=> $v['nickname'],
- "avatar"=>$v['avatar'],
- "create_time"=>"2025-01-25 11:00:18",
- ];
- }
- }
- $data['team_list'] = $data1;
- $data['fans_num'] = $team_userinfo_old_jbp1['person_nums'] + $team_userinfo_old_jbp1['common_nums'] ;//粉丝数
- $data['new_performance'] = 0;//新增业绩
- $data['total_performance']= $team_userinfo_old_jbp1['sum_nums_pv'];//总业绩
- $data['person_nums'] = $team_userinfo_old_jbp1['person_nums'];//个人联盟
- $data['common_nums'] = $team_userinfo_old_jbp1['common_nums'];//共建联盟
- $data['common_nums_pv'] =max( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);//公共联盟PV
- $data['person_nums_pv'] = min( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);//个人联盟PV
- // $data['effective_fans_num'] = DB::name('enterprise_user')
- //把新表中的新增邀请用户加到数组中
- return app("json")->success($data);
- }
- /**
- * 一壶茶-团队列表
- */
- public function team_list_copy()
- {
- $uid = $this->request->uid();
- $where['puid'] = $uid;
- $where['mer_id'] = $this->merId;
- $data['direct_fans_num'] = Db::name('enterprise_user')->where($where)->count();//直属粉丝数量
- //var_dump($uid);
- $arr = $this->jisuan_fans($uid);
- $data['fans_num'] = count($arr);//粉丝总数
- $data['total_performance'] = 12555;//总业绩
- $data['new_performance'] = 15;//新增业绩
- [$page, $limit] = $this->getPage();
- $where2['eu.mer_id'] = $this->merId;
- $type = $this->request->param('type', 0);//1:大部门,0:小部门
- // var_dump($where2);
- $enterprise_user_team = DB::name('enterprise_user')
- ->alias('eu')
- ->join('user u', 'eu.uid=u.uid')
- ->where($where2)
- ->when($type < 1 || $type == 2, function ($q) use ($arr) {
- $q->whereIn('eu.uid', $arr);
- })
- ->when($type == 1, function ($q) use ($uid) {
- $q->whereIn('eu.puid', $uid);
- })
- ->when($type == 2, function ($q) use ($uid) {
- $q->whereIn('eu.identity', [100, 101, 102, 103, 104, 105]);
- })
- ->field('eu.uid,u.nickname,u.phone,eu.avatar,eu.create_time,eu.identity,eu.level,eu.partnership')
- ->order('eu.enterprise_user_id desc')
- ->paginate($limit)
- ->each(function ($item) {
- $item['phone'] = substr_replace($item['phone'], '****', 3, 4);
- return $item;
- });
- //var_dump($enterprise_user_team);
- $data['team_list'] = $enterprise_user_team;
- $data['effective_fans_num'] = DB::name('enterprise_user')
- ->alias('eu')
- ->join('user u', 'eu.uid=u.uid')
- ->where($where2)
- ->whereIn('eu.uid', $arr)
- ->whereIn('eu.identity', [100, 101, 102, 103, 104, 105])
- ->count();//有效粉丝数量
- return app("json")->success($data);
- }
- public function team_details()
- {
- $uid = $this->request->param('uid', 0);
- $where2['eu.uid'] = $uid;
- $where2['eu.mer_id'] = $this->merId;
- $enterprise_user_team = DB::name('enterprise_user')
- ->alias('eu')
- ->join('user u', 'eu.uid=u.uid')
- ->where($where2)
- ->field('eu.uid,u.nickname,u.phone,u.avatar,eu.create_time,eu.identity,eu.level,eu.partnership,eu.puid')
- ->find();;
- if ($enterprise_user_team) {
- $enterprise_user_team['phone'] = substr_replace($enterprise_user_team['phone'], '****', 3, 4);
- $enterprise_user_team['p_nickname'] = '';
- $enterprise_user_team['p_phone'] = '';
- $yanglao = 0;
- $offLinewhere = ['mer_id' => $this->merId, 'uid' => $uid, 'commission_type' => '5', 'type_shop' => 0];
- $offLine1 = Db::name('user_bill')->where($offLinewhere)->where('source', 1)->where('status', 1)->sum('number');
- $yanglao += $offLine1;
- $offLine2 = Db::name('user_bill')->where($offLinewhere)->where('source', 0)->whereIn('status', [0, 1])->sum('number');
- $yanglao += $offLine2;
- $enterprise_user_team['ylj'] = set_price_rtrim($yanglao);
- if ($enterprise_user_team['puid'] > 0) {
- $user = Db::name('user')->where('uid', $enterprise_user_team['puid'])->find();
- if ($user) {
- $enterprise_user_team['p_nickname'] = $user['nickname'];
- $enterprise_user_team['p_phone'] = substr_replace($user['phone'], '****', 3, 4);
- }
- }
- }
- return app("json")->success($enterprise_user_team);
- }
- /**
- * 率积分明细
- */
- public function green_integral_list()
- {
- $pm = $this->request->param('pm');
- $status = $this->request->param('status');
- [$page, $limit] = $this->getPage();
- $uid = $this->request->uid();
- log::info("green_integral_list==={$uid}");
- $where['uid'] = $uid;
- // $where['mer_id'] = $this->merId;
- // if ($pm == 1) {
- // $pm_arr = [1, 3];
- // } else {
- // $pm_arr = [2, 4];
- // }
- if ($pm==0){
- $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();
- }
- if($pm==1){
- $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();
- }
- if($pm==2){
- $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();
- if($data){
- $data = $data->toArray();
- foreach ($data as $k=>$v){
- if($v['status'] == 0){
- $data[$k]['mark'] = '(失效)' . $v['mark'];
- }
- }
- }
- }
- return app("json")->success($data);
- }
- public function user_invite_profit_list()
- {
- $uid = $this->request->uid();
- [$page, $limit] = $this->getPage();
- $commission_type = $this->request->param('commission_type', 0);
- if ($commission_type) {
- $where['commission_type'] = $commission_type;
- }
- $month = $this->request->param('month', '') ?: date('Y-m');
- $startMonth = date('Y-m-01 00:00:00', strtotime($month));
- $endMonth = date("Y-m-d 00:00:00", strtotime("first day of next month", strtotime($month)));
- $data['yanglao_clear_all'] = Db::name('user_bill')
- ->where('uid', $uid)
- ->whereBetween('create_time', [$startMonth, $endMonth])
- ->where('commission_type', 5)
- ->where('pm', 1)
- ->where('status', 1)
- ->sum('number');
- $data['yanglao_nclear_all'] = Db::name('user_bill')
- ->where('uid', $uid)
- ->whereBetween('create_time', [$startMonth, $endMonth])
- ->where('commission_type', 5)
- ->where('pm', 1)
- ->where('status', 0)
- ->sum('number');
- $data['yanglao_yugu_all'] = $data['yanglao_clear_all'] + $data['yanglao_nclear_all'];
- $where['uid'] = $uid;
- $data['totel_money'] = Db::name('user_bill')->where($where)
- ->whereNotIn('commission_type', [0, 5, 17, 19])
- ->when($commission_type == 5, function ($query) use ($where, $startMonth, $endMonth) {
- $query->whereBetween('create_time', [$startMonth, $endMonth]);
- }, function ($query) use ($where, $month, $startMonth, $endMonth) {
- $query->where('commission_type', '<>', 5)
- ->whereBetween('create_time', [$startMonth, $endMonth]);
- })
- ->sum('number');
- $pageInfo = Db::name('user_bill')
- ->where($where)
- ->whereNotIn('commission_type', [0, 5, 17, 19])
- ->when($commission_type == 5, function ($query) use ($where, $startMonth, $endMonth) {
- $query->whereBetween('create_time', [$startMonth, $endMonth]);
- }, function ($query) use ($where, $month, $startMonth, $endMonth) {
- $query->where('commission_type', '<>', 5)
- ->whereBetween('create_time', [$startMonth, $endMonth]);
- })
- ->order('bill_id desc')
- ->paginate($limit);
- $data_arr = [];
- foreach ($pageInfo->items() as $k => $v) {
- $v['money'] = set_price_rtrim($v['number']);
- $v['order_money'] = set_price_rtrim(0);
- $v['commission_rate'] = set_price_rtrim(0);
- $order = Db::name('store_order')->where('order_sn', $v['order_sn'])->find();
- if (!empty($order)) {
- $v['order_money'] = set_price_rtrim($order['total_price']);
- $v['commission_rate'] = set_price_rtrim(bcdiv($v['money'], $v['order_money'], 2));
- }
- if ($v['status'] == 0) {
- // $v['create_time'] = '--';
- }
- if ($v['status'] == 1) {
- // $v['create_time'] = $v['take_time'];
- }
- if ($v['status'] == -1) {
- $v['mark'] = '(失效)' . $v['mark'];
- // $v['status'] = 0;
- }
- $data_arr[] = $v;
- }
- $data['pageInfo']['current_page'] = $pageInfo->currentPage();
- $data['pageInfo']['data'] = $data_arr;
- $data['pageInfo']['last_page'] = $pageInfo->lastPage();
- return app("json")->success($data);
- }
- /*导航转链-用于用户下单绑定*/
- public function changeLink()
- {
- $uid = $this->request->uid();
- if (!$uid) {
- return app("json")->error("请登录");
- }
- $data = $data = $this->request->params([
- 'url',
- 'name'
- ]);
- $data['url'] = urldecode($data['url']);
- $data['name'] = urldecode($data['name']);
- if (in_array($data['name'], ['京东', '苏宁易购', '饿了么', '唯品会', '拼多多'])) {
- if ($data['name'] == '京东') {
- $url = app()->make(Jd::class)->linkChange($data['url'], $uid);
- }
- if ($data['name'] == '拼多多') {
- $url = app()->make(TaoKe::class)->changeLink($data['url'], $uid);
- }
- if ($data['name'] == '唯品会') {
- $url = app()->make(Vip::class)->changeLink($data['url'], $uid);
- }
- if ($data['name'] == '苏宁易购') {
- $url = $data['url'];
- //$url = app()->make(Su::class)->changeLink($data['url'],$uid);
- }
- if ($data['name'] == '饿了么') {//获取饿了么官方活动链接
- //如果用户没有拉取relation_id,
- $where = ['uid' => $uid, 'type' => 5];
- $isRelation = UserThirdModel::where($where)->find();
- if ($isRelation) {
- $result = DaTaoKe::activityChangeLink('20150318020002597', $uid);
- if ($result['code'] == 0) {
- return \app('json')->fail("获取饿了么链接出错", $result['raw']);
- }
- $url = $result['link'];
- } else {//如果还没有获取用户的relation_id还需要拉淘宝授权
- $state = "{$uid}_h5";
- $url = \app()->make(TaoBao::class)->getAuthUrl($state);
- }
- }
- }
- return app("json")->success($url);
- }
- /*获取协议*/
- public function xieyi()
- {
- $data = $this->request->params([
- 'type'
- ]);
- $data = app()->make(\app\common\repositories\agreement\AgreementRepository::class)->getTypeDetail($data['type']);
- return app("json")->success($data);
- }
- /*获取规则文章*/
- public function guize()
- {
- $id = $this->request->param('id');
- $data = app()->make(\app\common\repositories\agreement\AgreementRepository::class)->getTypeDetail($id);
- if(!$data){
- $data['title']='';
- $data['content']='';
- }
- $html='<!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>'.$data['title'].'</title>
- <style>
- body {
- font-family: Arial, sans-serif;
- margin: 0;
- padding: 0;
- }
- .container {
- margin: 0 auto;
- padding: 20px;
- }
- </style>
- </head>
- <body>
- <div class="container">
- '.$data['content'].'
- </div>
- </body>
- </html';
- return $html;
- }
- /**
- * 支付宝获取授权
- * @return mixed
- * @author php迷途小书童
- * @created 2021/1/16 17:03
- */
- public function alipayAuthorization(UserRepository $userRepository)
- {
- $authorization_code = $this->request->param('code');
- $type = $this->request->param('type', 'h5');
- $paramStr = $userRepository->getTokenByCode($authorization_code, false, $type);
- return app("json")->success($paramStr);
- }
- /**
- * 微信获取授权
- * @return mixed
- * @author php迷途小书童
- * @created 2021/1/16 19:08
- */
- public function wechatAuthorization()
- {
- $request = $this->request;
- $wxConfig = [
- "appid" => "wx66f5f8def2b755da",
- "appsecret" => "891572d83222105a635cf9f502363ff8"
- ];
- $oauth = WechatService::create()->getApplication()->oauth;
- // dump($oauth);
- $oauth->setRequest(new Request($request->get(), $request->post(), [], [], [], $request->server(), $request->getContent()));
- try {
- $wechatInfo = $oauth->user()->getOriginal();
- } catch (\Exception $e) {
- return app('json')->fail('授权失败[001]', ['message' => $e->getMessage()]);
- }
- if (!isset($wechatInfo['nickname'])) {
- return app('json')->fail('授权失败[002]');
- }
- return app("json")->success($wechatInfo);
- }
- /**
- * 更新绑定微信支付宝账号
- * type=1 微信 2 支付宝
- * openid openid
- */
- public function updateAccount(UserRepository $userRepository)
- {
- $type = $this->request->param('type');
- $openid = $this->request->param('openid');//前端传的是unionid
- $nickname = $this->request->param('nickname');
- $avater = $this->request->param('avater');
- $alinfo = $this->request->param('alinfo');
- $uid = $this->request->uid();
- $user = $this->request->userInfo();
- if (!$type) {
- return app("json")->fail("失败");
- }
- makeLock()->lock();
- try {
- if ($type == 1) {
- $data = ["wechat_user_id" => $openid];
- $unionId = $openid;
- $check = Db::name('user_extract_openid')->where('uid',$uid)->value('openid');
- if ($check) throw new \Exception("此微信号已被绑定");
- } else {
- $alinfo = json_decode($alinfo, true);
- if (!$alinfo) throw new \Exception("参数异常");
- $data = ["ali_user_id" => $alinfo["userId"]];
- $unionId = $alinfo["userId"];
- $check = Db::name("user")->where("ali_user_id", $unionId)->find();
- if ($check) throw new \Exception("此支付宝号已被绑定");
- $paramStr = $userRepository->getTokenByCode($alinfo["authCode"], true);
- $userRepository->getTokenByCodeWithCert($alinfo["authCode"], true);
- // \think\facade\Db::name('log')->insert(['data'=>'支付宝授权信息'.json_encode($paramStr)]);
- $nickname = empty($paramStr["nick_name"]) ? "al" . $alinfo["userId"] : $paramStr["nick_name"];
- $avater = empty($paramStr["avatar"]) ? "https://cdn.bjtdba.com/vod/image/2025-01-21/20250121180855764.png" : $paramStr["avatar"];
- }
- $data2 = [
- "type" => $type,
- "uid" => $uid,
- "nickname" => $nickname,
- "avater" => $avater,
- ];
- $result = $this->repository->updateUser($uid, $data, $data2);
- if (!$result) throw new \Exception("修改失败");
- $userRepository = app()->make(UserRepository::class);
- $userInfo = $userRepository->getOne(['uid' => $uid]);
- //绑定线下充值金额
- $unionUsersRepository = app()->make(UnionUsersRepository::class);
- $orderMerchantRepository = app()->make(OrderMerchantRepository::class);
- $notBind = $unionUsersRepository->getAllNotBind($unionId);
- if ($notBind) {
- $orderMerchantRepository->doBindUser($userInfo, $type);
- }
- } catch (\Throwable $e) {
- makeLock()->unlock();
- return app("json")->fail("失败" . $e->getMessage());
- }
- makeLock()->unlock();
- return app("json")->success("修改成功", $data);
- }
- /**
- * 获取账号绑定信息
- * @return mixed
- */
- public function getAccount()
- {
- $uid = $this->request->uid();
- // $data = $this->repository->getUser($uid, "wechat_user_id,ali_user_id");
- $data = $this->repository->getAccount($uid);
- if ($data) {
- return app("json")->success("查询成功", $data);
- }
- return app("json")->fail("未绑定");
- }
- // /*
- // * 养老金统计
- // * */
- // public function get_yanglao_statistics()
- // {
- // $uid = $this->request->uid();
- // //线下数量
- // // 查询未结算
- //
- // $gzc_order_list = Db::name('gzc_logs')->where('uid', $uid)->column('out_trade_no');
- //
- // $onlineYanglaoUserBill = Db::name('user_bill')->where('commission_type', 5)->whereNotIn('order_sn',$gzc_order_list)->where('status', 0)->where('uid', $uid)->sum('number');
- // $onlineYanglaoGzc = Db::name('gzc_logs')->where('success', 0)->where('uid', $uid)->sum('pension');
- // $clearYanglao = Db::name('gzc_logs')->where('success', 1)->where('uid', $uid)->sum('pension');
- //
- // $userInfo = Db::name('UserCertification')->where('uid', $uid)->field('user_name,user_card')->find();
- // $res = GzcApiRequest::checkAmount($userInfo);
- // $gzc = $res['extendData']['amount'] * 0.01;
- // // PCPC-中信公证处
- // $data['all_gzc'] = set_price_rtrim(sprintf("%01.2f", $gzc));
- // // 总养老金
- // $data['all_yanglao'] = set_price_rtrim($onlineYanglaoUserBill + $onlineYanglaoGzc + $clearYanglao + $gzc);
- // // 平台养老金
- // $data['all_yanglao_yhc'] = set_price_rtrim($onlineYanglaoUserBill + $onlineYanglaoGzc + $clearYanglao);
- // // 未结算养老金=预估养老金,不能包含进入公证处未成功的记录(这部分是已结算的)
- // $data['all_yanglao_yugu'] = set_price_rtrim(round($onlineYanglaoUserBill, 2));
- // // 已结算养老金 已入账
- // $data['all_yanglao_clear'] = set_price_rtrim(round($onlineYanglaoGzc+$clearYanglao, 2));
- // // 已入账养老金
- // $data['all_yanglao_in'] = set_price_rtrim(round($clearYanglao, 2));
- // // 平台未入账养老金
- // $data['all_yanglao_nclear'] = set_price_rtrim(round($onlineYanglaoGzc + $onlineYanglaoUserBill, 2));
- // // 待发起
- // $data['all_yanglao_wait'] = set_price_rtrim(round($onlineYanglaoGzc, 2));
- //
- // return app("json")->success("查询成功", $data);
- // }
- /*
- * 养老金统计
- * */
- public function get_yanglao_statistics()
- {
- $uid = $this->request->uid();
- //线下数量
- $offLine = \think\facade\Db::name('order_merchant')->where('uid', $uid)->where('status', 1)->field('pension yanglao')->select()->toArray();
- $data['offLine'] = array(
- 'num' => count($offLine),
- 'yanglao' => round($this->num($offLine, 'yanglao'), 2)
- );
- $offLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>1,'type_shop'=>0];
- if($this->source=='yhc' && $this->merId){
- $offLinewhere['mer_id']=$this->merId;
- }
- $offLine= \think\facade\Db::name('user_bill')->where($offLinewhere)->select()->toArray();
- $data['offLine'] = array(
- 'num' => count($offLine),
- 'yanglao' => round($this->num($offLine, 'number'), 2)
- );
- // $offLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>0,'type_shop'=>0];
- // $offLine= \think\facade\Db::name('user_bill')->where($offLinewhere)->select()->toArray();
- // $data['offLine'] = array(
- // 'num' => count($offLine),
- // 'yanglao' => round($this->num($offLine, 'number'), 2)
- // );
- //线上已确认收货
- // $onLine = \think\facade\Db::name('store_order')->where('uid', $uid)->where('paid', 1)->where('status', 'in', '2,3')->select()
- // ->each(function ($item) {
- // //查询养老金金额
- // $UserBillRepository = app()->make(UserBillRepository::class);
- // $bill = $UserBillRepository->getWhere(['uid' => $item['uid'], 'link_id' => $item['order_id'], 'order_sn' => $item['order_sn'], 'title' => '养老金']);
- // $pension = $bill->number ?? 0;
- // $item['yanglao'] = $pension;
- // return $item;
- // })
- // ->toArray();
- $onLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>0,'type_shop'=>0];
- if($this->source=='yhc' && $this->merId){
- $onLinewhere['mer_id']=$this->merId;
- }
- $onLine= \think\facade\Db::name('user_bill')->where($onLinewhere)->select()->toArray();
- $data['onLine'] = array(
- 'num' => count($onLine),
- 'yanglao' => round($this->num($onLine, 'number'), 2)
- );
- //线上未确认收货
- // $onLine = \think\facade\Db::name('store_order')->where('uid', $uid)->where('paid', 1)->where('status', 'in', '0,1')->select()
- // ->each(function ($item) {
- // //查询养老金金额
- // $UserBillRepository = app()->make(UserBillRepository::class);
- // $bill = $UserBillRepository->getWhere(['uid' => $item['uid'], 'link_id' => $item['order_id'], 'order_sn' => $item['order_sn'], 'title' => '养老金']);
- // $pension = $bill->number ?? 0;
- // $item['yanglao'] = $pension;
- // return $item;
- // })
- // ->toArray();
- $onLine_take_nowhere=['uid'=>$uid,'status'=>'0','commission_type' => '5','source'=>0,'type_shop'=>0];
- if($this->source=='yhc' && $this->merId){
- $onLine_take_nowhere['mer_id']=$this->merId;
- }
- $onLine_take_no=\think\facade\Db::name('user_bill')->where($onLine_take_nowhere)->select()->toArray();
- $data['onLine_take_no'] = array(
- 'num' => count($onLine_take_no),
- 'yanglao' => round($this->num($onLine_take_no, 'number'), 2)
- );
- if($this->source=='yhc' && $this->merId){
- $data['all_num'] = $data['offLine']['num'] +$data['onLine_take_no']['num'] + $data['onLine']['num'];
- $data['all_yanglao_yhc'] = set_price_rtrim(round($data['offLine']['yanglao']+$data['onLine']['yanglao'] + $data['onLine_take_no']['yanglao'] , 2));//总养老金
- $data['all_yanglao_a'] = set_price_rtrim(round($data['offLine']['yanglao'] + $data['onLine']['yanglao'], 2));//已结算养老金
- $data['all_yanglao_yugu'] = set_price_rtrim(round($data['all_yanglao_yhc']-$data['all_yanglao_a'],2));//预估养老金
- $userInfo = Db::name('UserCertification') -> where('uid',$uid) -> field('user_name,user_card') -> find();
- $res = GzcApiRequest::checkAmount($userInfo);
- $data['all_gzc']=set_price_rtrim(sprintf("%01.2f", $res['extendData']['amount'] * 0.01));
- $data['all_yanglao']=set_price_rtrim( $data['all_yanglao_yhc'] + $data['all_gzc']);
- return app("json")->success("查询成功", $data);
- }
- //淘宝
- $tb_a = 0;
- $tb_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>5];
- $tb = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($tb_where)->where('status','<>','-1')->select()->each(function ($value) use (&$tb_a) {
- $value['yanglao'] = 0;
- $value['yanglao'] = $value['number'];
- $value['yanglao_a'] = 0;
- if ($value['status'] == 1) {
- $value['yanglao_a'] = $value['yanglao'];
- $tb_a++;
- }
- return $value;
- })->toArray();
- $data['tb'] = array(
- 'num' => count($tb),
- 'num_a' => $tb_a,
- 'yanglao' => round($this->num($tb, 'yanglao'), 2),
- 'yanglao_a' => round($this->num($tb, 'yanglao_a'), 2),
- );
- //京东
- $jd_a = 0;
- $jd_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>6];
- $jd = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($jd_where)->where('status','<>','-1')->select()->each(function ($value) use (&$jd_a) {
- $value['yanglao'] = 0;
- $value['yanglao'] = $value['number'];
- $value['yanglao_a'] = 0;
- if ($value['status'] == 1) {
- $value['yanglao_a'] = $value['yanglao'];
- $jd_a++;
- }
- return $value;
- })->toArray();
- $data['jd'] = array(
- 'num' => count($jd),
- 'num_a' => $jd_a,
- 'yanglao' => round($this->num($jd, 'yanglao'), 2),
- 'yanglao_a' => round($this->num($jd, 'yanglao_a'), 2),
- );
- //苏宁
- $su_a = 0;
- $su_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>3];
- $su = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($su_where)->where('status','<>','-1')->select()->each(function ($value) use (&$su_a) {
- $value['yanglao'] = 0;
- $value['yanglao'] = $value['number'];
- $value['yanglao_a'] = 0;
- if ($value['status'] == 1) {
- $value['yanglao_a'] = $value['yanglao'];
- $su_a++;
- }
- return $value;
- })->toArray();
- $data['su'] = array(
- 'num' => count($su),
- 'num_a' => $su_a,
- 'yanglao' => round($this->num($su, 'yanglao'), 2),
- 'yanglao_a' => round($this->num($su, 'yanglao_a'), 2),
- );
- //拼多多
- $pdd_a = 0;
- $pdd_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>1];
- $pdd = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($pdd_where)->where('status','<>','-1')->select()->each(function ($value) use (&$pdd_a) {
- $value['yanglao'] = 0;
- $value['yanglao'] = $value['number'];
- $value['yanglao_a'] = 0;
- if ($value['status'] == 1) {
- $value['yanglao_a'] = $value['yanglao'];
- $pdd_a++;
- }
- return $value;
- })->toArray();
- $data['pdd'] = array(
- 'num' => count($pdd),
- 'num_a' => $pdd_a,
- 'yanglao' => round($this->num($pdd, 'yanglao'), 2),
- 'yanglao_a' => round($this->num($pdd, 'yanglao_a'), 2),
- );
- //唯品会
- $vip_a = 0;
- $vip_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>2];
- $vip = \think\facade\Db::name('user_bill')->where($vip_where)->where('uid', $uid)->where('status','<>','-1')->select()->each(function ($value) use (&$vip_a) {
- $value['yanglao'] = 0;
- $value['yanglao'] = $value['number'];
- $value['yanglao_a'] = 0;
- if ($value['status'] == 1) {
- $value['yanglao_a'] = $value['yanglao'];
- $vip_a++;
- }
- return $value;
- })->toArray();
- $data['vip'] = array(
- 'num' => count($vip),
- 'num_a' => $vip_a,
- 'yanglao' => round($this->num($vip, 'yanglao'), 2),
- 'yanglao_a' => round($this->num($vip, 'yanglao_a'), 2),
- );
- // 抖音
- $dy_a = 0;
- $dy_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>9];
- $dy = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($dy_where)->where('status','<>','-1')->select()->each(function ($value) use (&$dy_a) {
- $value['yanglao'] = 0;
- $value['yanglao'] = $value['number'];
- $value['yanglao_a'] = 0;
- if ($value['status'] == 1) {
- $value['yanglao_a'] = $value['yanglao'];
- $dy_a++;
- }
- return $value;
- })->toArray();
- $data['dy'] = array(
- 'num' => count($dy),
- 'num_a' => $dy_a,
- 'yanglao' => round($this->num($dy, 'yanglao'), 2),
- 'yanglao_a' => round($this->num($dy, 'yanglao_a'), 2),
- );
- $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'];
- $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);
- $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);
- $data['third_party_num']=['all_num'=>$data['tb']['num']+$data['jd']['num']+$data['su']['num']+ $data['pdd']['num'] + $data['vip']['num']+ $data['dy']['num']];
- $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']];
- $data['third_party_num_n']=['all_num_n'=>$data['third_party_num']['all_num']-$data['third_party_num_a']['all_num_a']];
- return app("json")->success("查询成功", $data);
- }
- public function num($data, $field)
- {
- $sum = 0;
- foreach ($data as $item) {
- $sum += $item[$field];
- }
- return $sum;
- }
- //志愿者升级
- public function changeVolunteer()
- {
- $uid = $this->request->uid();
- //志愿者条件
- $volunteer_achievement = systemConfig("volunteer_achievement");//volunteer_achievement:用户本人满足养老金要求可升级为志愿者
- $volunteer_class = new Volunteer();
- $volunteer = $volunteer_class->volunteer($uid);
- if ($volunteer['self_yanglao'] < $volunteer_achievement) {
- $data['grade'] = 0;
- $data['self_yanglao'] = $volunteer['self_yanglao'];
- $data['condition_one'] = systemConfig("volunteer_achievement");//用户本人满足养老金要求可升级为志愿者
- return app('json')->success($data);
- }
- $volunteer_class->grade($uid, 1, $volunteer);
- return app('json')->success('申请成功');
- }
- public function GZC($uid)
- {
- $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
- $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
- $OrderGzcRepository = app()->make(OrderGzcRepository::class);
- $where = [
- 'uid' => $uid,
- 'pm' => 1,
- 'status' => 1,
- 'type' => 'commission'
- ];
- $user_data = \think\facade\Db::name('user')->where('uid', $uid)->find();
- $certification = ['user_name' => $user_data['real_name'], 'mobile' => $user_data['account'], 'user_card' => $user_data['card_id']];
- $user_data['real_name'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('user_name');
- $user_data['account'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('mobile');
- $user_data['card_id'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('user_card');
- Db::name('user_bill')->where($where)->select()->each(function ($item) use ($uid, $orderId, $OrderGzcRepository, $user_data, $certification) {
- $is_implement = 1;
- if ($item['source'] == 0) {
- $order_data = \think\facade\Db::name('store_order')->where('order_sn', $item['order_sn'])->value('uid');
- if ($order_data['uid'] == $item['uid']) {
- $is_implement = 0;
- } else {
- $is_implement = 1;
- }
- } else {
- $order_data = \think\facade\Db::name('order_merchant')->where('out_trade_no', $item['order_sn'])->value('uid');
- if ($order_data['uid'] == $item['uid']) {
- $is_implement = 0;
- } else {
- $is_implement = 1;
- }
- }
- if ($is_implement == 1) {
- $online = ['uid' => $uid, 'pay_type' => '1', 'order_sn' => $item['order_sn'], 'order_id' => $item['link_id']];
- $create = [
- 'uid' => $online['uid'],
- 'platform_no' => $orderId,
- 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
- 'user_name' => $certification['user_name'],
- 'mobile' => $certification['mobile'],
- 'user_card' => $certification['user_card'],
- 'pension' => $item['number'],
- 'order_type' => 2,
- 'out_trade_no' => $online['order_sn']
- ];
- $OrderGzcRepository->create($create);
- }
- });
- }
- //20220712版签到
- public function new_sign()
- {
- // return app('json')->fail('不允许签到');
- $uid = $this->request->uid();//签到用户
- $user = Db::name('user')->where('uid', $uid)->field("spread_uid,first_sign")->find();//上级用户
- //第一天签到获得2积分,第二天获得4积分,第三天获得6积分,第四天获得 10 积分,第五天获得 14积分第六天获得 20积分,
- //连续签到从第七天开始,每日签到获得3积分,第七天连续签到额外奖励 38积分,第 14 天连续签到额外奖励 68 积分,第 21天连续签到额外奖励 128 积分第 30 天连续签到额外奖励 188 积分
- //前6天积分
- $score = [
- 2,//1
- 4,//2
- 6,//3
- 10,//4
- 14,//5
- 20//6
- ];
- //7-30天积分
- $scoreS = 3;
- //额外积分
- $scoreExtra = [
- 7 => 38,
- 14 => 68,
- 21 => 128,
- 30 => 188
- ];
- $today_signintime = strtotime(date('Y-m-d', time()));
- $today_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid))->whereDay('signin_time')->find();
- if (!empty($today_signin_info)) {
- return app('json')->fail('今天已经签到过了');
- } else {
- //查询昨天是否已经签到了
- $yes_signintime = strtotime(date('Y-m-d')) - 86400;
- $yes_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid, 'signin_time' => $yes_signintime))->find();
- $has_qian = 1;
- if (!empty($yes_signin_info)) {
- $has_qian = $yes_signin_info['continuity_day'] + 1;
- $has_qian = $has_qian > 30 ? 1 : $has_qian;
- }
- $get_score = 0;
- $get_gw_score = 0;
- if ($has_qian <= 6) {
- $get_score = $score[$has_qian - 1];
- } else {
- $get_score = $scoreS;
- if (isset($scoreExtra[$has_qian])) {
- $get_gw_score = $scoreExtra[$has_qian];
- }
- }
- $userRepository = app()->make(UserRepository::class);
- $userRepository->sign_add($uid, $get_score, 1, '签到赠送积分', $has_qian, $today_signintime, '', 1, '', 1);
- if($get_gw_score > 0){
- $userRepository->sign_add($uid, $get_gw_score,1,'连续签到赠送额外奖励积分', $has_qian, $today_signintime, '', 1, '', 1);
- }
- //首次签到
- if ($user['first_sign'] == 0) {
- // //首次签到送30积分,同时赠送邀请人30积分
- // $userRepository->sign_add($uid, 30,1,'首次签到送30积分','','', '', 1, '', 1);
- // $member_info = Db::name('user')->where( array('uid' => $uid) )->find();
- // if($member_info['spread_uid']){
- // $spreadUid = $member_info['spread_uid'];
- // $userRepository->sign_add($spreadUid, 30,1,'邀请人首次签到送30积分','','', '', 1, '', 1);
- // }
- Db::name('user')->where('uid', $uid)->update(['first_sign' => 1]);
- } elseif ($user['first_sign'] == 1 && $has_qian == 1) {
- Db::name('user')->where('uid', $uid)->update(['first_sign' => 2]);
- }
- // //非首次签到,第一天,断签
- // //好友连续签到3天 奖励50
- // //好友连续签到14天 奖励100
- // //好友联系签到30天 奖励300
- // if ($user['first_sign'] < 2) {
- // if ($has_qian == 3) {
- // $userRepository->sign_add($user['spread_uid'], 50, 1, '好友签到赠送积分', '', $today_signintime, '');
- // } elseif ($has_qian == 14) {
- // $userRepository->sign_add($user['spread_uid'], 100, 1, '好友签到赠送积分', '', $today_signintime, '');
- // } elseif ($has_qian == 30) {
- // $userRepository->sign_add($user['spread_uid'], 300, 1, '好友签到赠送积分', '', $today_signintime, '');
- // Db::name('user')->where('uid', $uid)->update(['first_sign' => 3]);
- // }
- // }
- return app('json')->success('签到成功', ['score' => $get_score]);
- }
- }
- public function new_sign_info()
- {
- $uid = $this->request->uid();
- //查询今天是否已经签到
- $today_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid))->whereDay('signin_time')->find();
- //查询昨天是否已经签到了
- $yes_signintime = strtotime(date('Y-m-d')) - 86400;
- $yes_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid, 'signin_time' => $yes_signintime))->find();
- $data = [
- 'today' => 0,
- 'day' => 0
- ];
- if ($yes_signin_info) $data['day'] = (int)$yes_signin_info['continuity_day'];
- if ($yes_signin_info['continuity_day'] >= 30) $data['day'] = 0;
- if ($today_signin_info) {
- $data['today'] = 1;
- $data['day'] = $data['day'] + 1;
- }
- return app('json')->success($data);
- }
- /**
- * 积分列表
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function sign_list()
- {
- [$page, $limit] = $this->getPage();
- $uid = $this->request->uid();
- $month = $this->request->param('month', '') ?: date('Y-m');
- $status = $this->request->param('status');
- $pm = $this->request->param('pm');
- $startMonth = strtotime(date('Y-m-01 00:00:00', strtotime($month)));
- $endMonth = strtotime(date("Y-m-d 00:00:00", strtotime("first day of next month", strtotime($month))));
- $count = Db::name('user_sign_score')
- ->whereBetween('addtime', [$startMonth, $endMonth])
- ->when(isset($status) && $status !== '', function ($query) use ($status) {
- $query->where('status', $status);
- })
- ->when(isset($pm) && $pm !== '', function ($query) use ($pm) {
- $query->where('pm', $pm);
- })
- ->where('uid', $uid)->count();
- $list = Db::name('user_sign_score')
- ->whereBetween('addtime', [$startMonth, $endMonth])
- ->where('uid', $uid)
- ->when(isset($status) && $status !== '', function ($query) use ($status) {
- $query->where('status', $status);
- })
- ->when(isset($pm) && $pm !== '', function ($query) use ($pm) {
- $query->where('pm', $pm);
- })
- ->page($page, $limit)->order('id DESC')->select()->each(function ($item) {
- $item['signin_time'] = date('Y-m-d', $item['signin_time']);
- $item['addtime'] = date('Y-m-d H:i:s', $item['addtime']);
- if (!empty($item['order_id'])) {
- //线上订单
- if ($item['order_type'] == 'store_order' || $item['order_type'] == 'store_order_beishengtang') {
- $item['order_sn'] = Db::name("store_order")->where("order_id", $item['order_id'])->value("order_sn");
- } elseif ($item['order_type'] == 'order_merchant') {
- $item['order_sn'] = Db::name("order_merchant")->where("id", $item['order_id'])->value("out_trade_no");
- } elseif ($item['order_type'] == 'extract') {
- $item['order_sn'] = Db::name("user_extract")->where("extract_id", $item['order_id'])->value("order_sn");
- } else {
- $item['order_sn'] = '';
- }
- } else {
- $item['order_sn'] = '';
- }
- return $item;
- });
- $data['list'] = $list;
- $data['count'] = $count;
- return app('json')->success($data);
- }
- public function getAmountFromGzc()
- {
- $uid = $this->request->uid();
- $userInfo = Db::name('UserCertification')->where('uid', $uid)->field('user_name,user_card')->find();
- $res = GzcApiRequest::checkAmount($userInfo);
- return app('json')->success(['amount' => sprintf("%01.2f", $res['extendData']['amount'] * 0.01)]);
- }
- public function check_user_annual_fee()
- {
- //INSERT INTO rrx_user_pension_account (uid) SELECT uid FROM rrx_user;
- //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;
- $uid = $this->request->uid();
- $check = Db::name("user_pension_account")->where("uid", $uid)->find();
- $data = [
- "status" => 3,//0:未交年费,1:年费到期。2:未实名认证,3:正常
- ];
- // //未交年费
- // if (!$check || $check["status"] == 0) {
- // $data["status"] = 0;
- // return app('json')->success($data);
- // }
- // //到期时间小于当前时间。年费到期
- // if (strtotime($check['end_time']) < time()){
- // $data["status"] = 1;
- // return app('json')->success($data);
- // }
- // $data["start_time"] = $check['start_time'];
- // $data["end_time"] = $check['end_time'];
- //
- // //检查实名认证
- // $checkCertification = Db::name("user_certification") -> where("uid",$uid) -> find();
- // if (!$checkCertification){
- // $data["status"] = 2;
- // return app('json')->success($data);
- // }
- return app('json')->success($data);
- }
- /**
- *
- * @remarks 创建年费订单
- * @author 小菜菜
- * @created 2023/04/10 14:37
- */
- public function create_annual_order()
- {
- $uid = $this->request->uid();
- $type = $this->request->param('type', 1);
- $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
- if ($type == 1) $price = "12.00";
- elseif ($type == 2) $price = systemConfig('offline_a');
- elseif ($type == 3) $price = systemConfig('offline_b');
- elseif ($type == 4) $price = systemConfig('offline_c');
- else return app('json')->fail("参数错误");
- $check = Db::name("user_pension_account")->where("uid", $uid)->find();
- //到期时间小于当前时间。年费到期
- if (strtotime($check['end_time']) > time() && $check['status'] == 1) {
- return app('json')->fail("账户已开通,不可重复开通账户");
- }
- $insertData = [
- 'pay_price' => $price,
- 'status' => 0,
- 'order_no' => $OrderMerchantRepository->getNewOrderId("mt"),
- 'uid' => $uid,
- 'type' => $type,
- ];
- $order_id = Db::name('user_pension_account_order')->insertGetId($insertData);
- try {
- return app('json')->success(['order_id' => $order_id]);
- } catch (\Exception $e) {
- return app('json')->status('error', $e->getMessage(), ['order_id' => $order_id]);
- }
- }
- /**
- * @remarks 会员支付
- * @author Tang
- * @created 2021/8/27 9:18
- */
- public function pay_user_annual()
- {
- try {
- $oid = r::param('oid', '');
- $code = r::param('code', '');
- $payType = r::param('type', '');//wx.ALI
- if ($oid == '') return app('json')->fail("请检查参数是否正确");
- $groupOrder = Db::name('user_pension_account_order')->where('id', $oid)->where('status', 0)->find();
- if (!$groupOrder) return app('json')->fail('订单不存在或已支付');
- $access = new Access();
- $res = $access->pay_huifu($payType, $code, $groupOrder, "年费", env('APP_URL') . "/api/hf_notify/pay_user_annual");
- Db::name('log')->insert(['data' => '汇付用户年费支付---' . json_encode($res)]);
- Db::name('user_pension_account_order')->where('id', $oid)->update(['hf_pay_id' => $res['id']]);
- return app('json')->success($res);
- } catch (\Exception $exception) {
- return app('json')->fail();
- }
- }
- /**
- * @remarks 会员支付 线下
- * @author Tang
- * @created 2021/8/27 9:18
- */
- public function pay_user_annual_offline()
- {
- try {
- $oid = r::param('oid', '');
- $payType = r::param('type', '');//WX.ALI
- $pay_user_id = r::param('pay_user_id', '');//如果是微信。传open_id 如果是支付宝。传user_id
- if ($oid == '') return app('json')->fail("请检查参数是否正确");
- if ($pay_user_id == '') return app('json')->fail("请检查参数是否正确");
- $order = Db::name('user_pension_account_order')->where('id', $oid)->where('status', 0)->find();
- if (!$order) return app('json')->fail('订单不存在或已支付');
- if ($order['type'] == 1) {
- $title = "开通账户";
- } elseif ($order['type'] == 2) {
- $title = "大礼包1";
- } elseif ($order['type'] == 3) {
- $title = "大礼包2";
- } elseif ($order['type'] == 4) {
- $title = "大礼包3";
- } else {
- return app('json')->fail('订单异常');
- }
- if ($order['type'] > 1) {
- //本人给养老金10%
- $ylj = sprintf("%01.2f", bcmul($order['pay_price'], '0.1', 5));//10%的养老金
- $commission = 0;
- //上级给佣金10%
- $order_user = Db::name("user")->where("uid", $order["uid"])->field("spread_uid")->find();
- //推广员id
- $spread_uid = $order_user["spread_uid"];
- if (!empty($spread_uid)) {
- $commission = sprintf("%01.2f", bcmul($order['pay_price'], '0.1', 5));//10%的佣金
- }
- $pt = sprintf("%01.2f", 12 + $ylj + $commission);
- $merchant_money = sprintf("%01.2f", $order['pay_price'] - $pt);
- } else {
- $pt = "12.00";
- $merchant_money = "0.00";
- }
- if ($payType == 'WX') {
- $pay_wx = systemConfig('pay_wx');
- //微信
- if ($pay_wx == 3) {
- $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 3)->value('member_id');
- $key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
- $app_id = 'app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0';
- } else {
- $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 2)->value('member_id');
- $key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
- $app_id = 'app_0827b960-b932-45ec-b800-4e850091b419';
- }
- $type = '2';
- $pay_channel = 'wx_pub';
- $expend = [
- 'open_id' => $pay_user_id
- ];
- } elseif ($payType == 'ALI') {
- $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 1)->value('member_id');
- $app_id = 'app_44108546-d27a-48ee-88c1-84b45b75114f';
- $type = '1';
- $pay_channel = 'alipay_pub';
- $expend = [
- 'buyer_id' => $pay_user_id
- ];
- $key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
- }
- if ($merchant_money == '0.00') {
- $div_members = [
- [
- 'member_id' => 0,
- 'amount' => $pt,
- 'fee_flag' => 'Y'
- ]
- ];
- } else {
- $div_members = [
- [
- 'member_id' => $member_id,
- 'amount' => $merchant_money,
- 'fee_flag' => 'Y'
- ],
- [
- 'member_id' => 0,
- 'amount' => $pt,
- 'fee_flag' => 'N'
- ]
- ];
- }
- $params = [
- 'order_no' => $order['order_no'] . '_' . rand(000, 999),
- 'app_id' => $app_id,
- 'pay_channel' => $pay_channel,
- 'pay_amt' => (string)$order['pay_price'],
- 'goods_title' => "幸福宝",
- 'goods_desc' => $title,
- 'device_info' => [
- 'device_ip' => app('request')->ip()
- // 'device_ip'=>'115.171.134.68'
- ],
- 'expend' => json_encode($expend),
- 'div_members' => json_encode($div_members),
- 'fee_mode' => 'I',
- 'notify_url' => env('APP_URL') . "/api/jsapiPay/notify/HF_pay_user_annual"
- ];
- $res = $this->Payment_create_traits($params, $type, $key);
- if (!empty($res['error_code'])) {
- return app('json')->fail($res['return_msg']);
- } else {
- Db::name('user_pension_account_order')->where('id', $oid)->update(['hf_pay_id' => $res['id']]);
- return app('json')->success($res);
- }
- } catch (\Exception $exception) {
- Db::name('log')->insert(['data' => '大礼包支付error:' . $exception->getFile() . ':' . $exception->getLine() . '【' . $exception->getMessage() . '】']);
- return app('json')->fail();
- }
- }
- public function red_log()
- {
- $uid = $this->request->uid();
- [$page, $limit] = $this->getPage();
- $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) {
- $item['create_time'] = date('Y-m-d H:i:s', $item['time']);
- $item['red'] = set_price_rtrim($item['red']);
- return $item;
- });
- return app('json')->success($user_rich_log);
- }
- public function apply_bang_fu()
- {
- $uid = $this->request->uid();
- $check = Db::name('user_rich')->where('uid', $uid)->find();
- if ($check['type'] < 3) {
- return app('json')->fail("不满足申请条件");
- }
- $check = Db::name('user_bangfu')->where('uid', $uid)->value('status');
- if ($check == 0) {
- return app('json')->fail("审核中");
- }
- if ($check == 1) {
- return app('json')->fail("已是帮扶中心");
- }
- if ($check == 2) {
- return app('json')->fail("审核被拒绝");
- }
- $bang_fu_number = systemConfig("bang_fu_number");
- //检测用户是否满足条件
- $number = $this->getNumber($uid, $bang_fu_number) - 1;//满足条件人数 减去自己
- //条件
- if ($number >= $bang_fu_number) {
- // echo '满足';
- Db::name('user_bangfu')->insert([
- 'uid' => $uid,
- 'time' => time(),
- 'status' => 0
- ]);
- return app('json')->success("提交申请成功");
- }
- return app('json')->fail("不满足申请条件");
- // echo '不满足';
- }
- //获得满足 1+5 的下级数量
- public function getNumber($uid, $bang_fu_number): int
- {
- $number = 0;
- $getUid = Db::name('user')->where('level_id', $uid)->field('uid')->select();
- $count = count($getUid);
- if ($count >= 5) {
- $number = 1;
- foreach ($getUid as $value) {
- $number += $this->getNumber($value['uid'], $bang_fu_number);
- if ($number >= $bang_fu_number) {
- break;
- }
- }
- }
- return $number;
- }
- /**
- * 积分明细
- * @return mixed
- */
- public function score_info()
- {
- $uid = $this->request->uid();;
- $data['score'] = decimal2(Db::name('user_sign_score')
- ->where('uid', $uid)
- ->where('status', 1)
- ->where('pm', 1)
- ->sum('reward_socre'));;
- $data['no_clear_score'] = decimal2(Db::name('user_sign_score')
- ->where('uid', $uid)
- ->where('status', -1)
- ->where('pm', 1)
- ->sum('reward_socre'));
- $data['lose_score'] = decimal2(Db::name('user_sign_score')
- ->where('uid', $uid)
- ->where('pm', 2)
- ->sum('reward_socre'));
- $data['clear_score'] = $score = decimal2($data['score'] - $data['lose_score']);
- $data['score'] = $data['clear_score'] + $data['no_clear_score'] + $data['lose_score'];
- $data['score'] = decimal2($data['score']);
- Db::name('user')->where('uid', $uid)->update([
- 'score' => $score
- ]);
- //clear_score 可用积分,score 积分总数 lose_score 已使用积分 no_clear_score 未结算积分
- return app('json')->success($data);
- }
- /**
- * 新版我的团队
- */
- public function get_team_list()
- {
- $data = [];
- [$page, $limit] = $this->getPage();
- $uid = $this->request->uid();
- $type = intval($this->request->param('type'));
- //查询团队列表
- $userRepository = app()->make(UserRepository::class);
- $chilid_userids = $userRepository->getSpreadUidBreak($uid);
- $data['fans_count'] = count($chilid_userids);
- $direct_uid_list = Db::name('user')->where('spread_uid', $uid)->where('is_del', 0)->column('uid');
- $data['direct_count'] = count($direct_uid_list);
- $valid_uid_list = Db::name('store_order')
- ->whereIn('uid', $chilid_userids)
- ->where('paid', 1)
- ->group('uid')
- ->column('uid');
- $data['valid_count'] = count($valid_uid_list);
- $data['count'] = Db::name('user')
- ->whereIn('uid', $chilid_userids)
- ->count();
- $data['list'] = Db::name('user')
- ->field('uid,phone,nickname,user_group,create_time,avatar as picture')
- ->page($page, $limit)
- ->whereIn('uid', $chilid_userids)
- ->when($type == 1, function ($query) use ($direct_uid_list) {
- return $query->whereIn('uid', $direct_uid_list);
- })
- ->when($type == 2, function ($query) use ($valid_uid_list) {
- return $query->whereIn('uid', $valid_uid_list);
- })
- ->order('uid DESC')
- ->select()
- ->toArray();
- foreach ($data['list'] as &$user) {
- $user ['phone'] = substr_replace($user['phone'], '****', 3, 4);
- }
- return app('json')->success($data);
- }
- /**
- * 我的粉丝详情
- */
- public function get_team_info()
- {
- $uid = $this->request->param('uid', '');
- if (!$uid)
- return app('json')->fail("uid不正确");
- $userRepository = app()->make(UserRepository::class);
- $chilid_userids = $userRepository->getSpreadUidBreak($this->request->uid());
- if (!in_array($uid, $chilid_userids))
- return app('json')->fail("该用户不在所属团队内");
- $data = Db::name('user')
- ->field('uid,phone,nickname,spread_uid,user_group,create_time,manage_address')
- ->where('uid', $uid)
- ->find();
- $data['regimental_commander_count'] = Db::name('user')
- ->where('spread_uid', $uid)
- ->where('user_group', 2)
- ->count();
- $data['clear_order_amount'] = Db::name('store_order')
- ->where('uid', $uid)
- ->where('is_settlement', 1)
- ->sum('pay_price');
- $data['mybuy_order_amount'] = Db::name('store_order')
- ->where('uid', $uid)
- ->where('paid', 1)
- ->sum('pay_price');
- $spread_user = Db::name('user')
- ->field('nickname as spread_nickname,phone as spread_phone')
- ->where('uid', $data['spread_uid'])
- ->find();
- $spread_user ['spread_phone'] = substr_replace($spread_user['spread_phone'], '****', 3, 4);
- $spread_user ['spread_nick_name'] = $spread_user['spread_nickname'] ?? '';
- $data ['phone'] = substr_replace($data['phone'], '****', 3, 4);
- $data = array_merge($data, $spread_user);
- if (in_array($data['user_group'], [5, 6])) {
- $data['area_name'] = Db::name('regions')->field('type,code_list')->where('id', 'in', $data['manage_address'])->cache('code:' . $data['manage_address'], 7200)->column('name');
- $data['area_name'] = join($data['area_name']);
- $data['area_bonus_money'] = Db::name('user_bill')
- ->where('uid', $uid)
- ->sum('number');
- }
- unset($data['manage_address']);
- if (in_array($data['user_group'], [4])) {
- $merchant = Db::name('merchant')->where('uid', $uid)->field('mer_id,mer_name')->find();
- $data['mer_id'] = $merchant['mer_id'] ?? 0;
- $data['mer_name'] = $merchant['mer_name'] ?? '';
- }
- return app('json')->success($data);
- }
- /**
- * 我的佣金
- */
- public function get_brokerage_info()
- {
- $uid = $this->request->uid();
- //佣金余额
- $data['brokerage_price'] = Db::name('user')->where('uid', $uid)->value('brokerage_price');
- //总收益
- $data['sum_amount'] = Db::name('user_bill')
- ->where('uid', $uid)
- ->where('commission_type', '<>', 5)
- ->where('commission_type', '<>', 0)
- ->where('pm', 1)
- ->sum('number');
- //未结算
- $data['no_clear_amount'] = Db::name('user_bill')
- ->where('uid', $uid)
- ->where('commission_type', '<>', 5)
- ->where('commission_type', '<>', 0)
- ->where('pm', 1)
- ->where('status', 0)
- ->sum('number');
- //已提现
- $data['withdraw_amount'] = Db::name('user_extract')
- ->where('uid', $uid)
- ->whereIn('status', [0, 1])
- ->sum('extract_price');
- //转VR
- $data['transition_vr_amount'] = Db::name('user_transition_vr')
- ->where('uid', $uid)
- ->where('type', 1)
- ->sum('number');
- //最终 总收益是 = 佣金余额 + 已提现 + 已转VR
- // $data['sum_amount'] = $data['sum_amount'] + $data['transition_vr_amount'];
- $data['sum_amount'] = set_price_rtrim($data['sum_amount']);
- return app('json')->success($data);
- }
- public function get_token_by_phone(UserRepository $repository){
- $user = $repository->accountByUser($this->request->param('phone'));
- $tokenInfo = $repository->createToken($user);
- return app('json')->success($repository->returnToken($user, $tokenInfo));
- }
- /**
- * 转VR
- */
- public function transition_vr()
- {
- $uid = $this->request->uid();
- $user = $this->request->userInfo();
- $type = $this->request->param('type', 'brokerage');
- $extract_amount = $this->request->param('extract_amount', 0);
- if ($type == 'brokerage') {
- $brokerage_price = Db::name('user')->where('uid', $uid)->value('brokerage_price');
- // 参考结算任务中的代码片段, 余额中 应不包含未结算余额
- // $no_clear_amount = Db::name('user_bill')
- // ->where('uid', $uid)
- // ->where('commission_type', '<>', 5)
- // ->where('pm', 1)
- // ->where('status', 0)
- // ->sum('number');
- // $clear_amount = $brokerage_price - $no_clear_amount;
- $clear_amount = $brokerage_price;
- // if ($user['brokerage_price'] < (systemConfig('withdrawal_money'))){
- // return app('json')->fail('未到达提现最低额度');
- // }
- if($extract_amount > $clear_amount){
- return app('json')->fail("可用金额不足提现");
- }
- $brokerage_price = bcsub($user['brokerage_price'], $extract_amount,2);
- $user->brokerage_price = $brokerage_price;
- $vr = bcadd($user['vr'], $extract_amount, 2);
- $user->vr = $vr;
- $res = $user->save();
- if ($res){
- //加入转VR记录
- $insertdata = [
- 'uid'=> $uid,
- 'number' => $extract_amount,
- 'surplus' => $vr,
- 'mark' => '佣金转VR',
- 'type' => 1,
- 'create_time' => time(),
- ];
- Db::name('user_transition_vr')->insertGetId($insertdata);
- //VR入账
- $insertdata = [
- 'uid'=> $uid,
- 'number' => $extract_amount,
- 'surplus' => $vr,
- 'mark' => '佣金转VR',
- 'order_id'=> 0,
- 'type' => 1,
- 'addtime' => time(),
- 'settlement_time'=> date('Y-m-d H:i:s', time())
- ];
- Db::name('user_sign_vr')->insertGetId($insertdata);
- return app('json')->success('转VR成功');
- }else{
- return app('json')->fail('转VR失败');
- }
- }
- if ($type == 'hongbao') {
- $hongbao = Db::name('user')->where('uid', $uid)->value('hongbao');
- $no_clear_amount = Db::name('user_sign_hongbao')
- ->where('uid', $uid)
- ->where('type', 1)
- ->where('status', -1)
- ->sum('number');
- $clear_amount = $hongbao - $no_clear_amount;
- if ($user['hongbao'] < (systemConfig('withdrawal_money'))){
- return app('json')->fail('未到达提现最低额度');
- }
- if($extract_amount > $clear_amount){
- return app('json')->fail("可用金额不足提现");
- }
- $hongbao = bcsub($user['hongbao'], $extract_amount,2);
- $user->hongbao = $hongbao;
- $vr = bcadd($user['vr'], $extract_amount, 2);
- $user->vr = $vr;
- $res = $user->save();
- if ($res){
- //加入转VR记录
- $insertdata = [
- 'uid'=> $uid,
- 'number' => $extract_amount,
- 'surplus' => $vr,
- 'mark' => '红包转VR',
- 'type' => 2,
- 'status' => 1,
- 'addtime' => time(),
- ];
- Db::name('user_sign_hongbao')->insertGetId($insertdata);
- //VR入账
- $insertdata = [
- 'uid'=> $uid,
- 'number' => $extract_amount,
- 'surplus' => $vr,
- 'mark' => '红包转VR',
- 'order_id'=> 0,
- 'type' => 1,
- 'addtime' => time(),
- 'settlement_time'=> date('Y-m-d H:i:s', time())
- ];
- Db::name('user_sign_vr')->insertGetId($insertdata);
- return app('json')->success('转VR成功');
- }else{
- return app('json')->fail('转VR失败');
- }
- }
- return app('json')->fail('转VR失败');
- }
- /**
- * 转VR记录
- */
- public function transition_vr_log()
- {
- $uid = $this->request->uid();
- $type = $this->request->param('type', 1);
- [$page, $limit] = $this->getPage();
- $where = [];
- $where[] = ['uid', '=', $uid];
- $where[] = ['type', '=', $type];
- $query = Db::name("user_transition_vr");
- $count = $query->where($where)->count();
- $list = $query->page($page, $limit)->where($where)->select()->each(function ($item){
- $item['create_time'] = date("Y-m-d H:i:s", $item['create_time']);
- return $item;
- });
- return app('json')->success('获取转VR记录成功', ['list'=>$list, 'count'=>$count]);
- }
- // 根据父级uid,递归获取所有子级UID数组
- public function getRecursiveChildren($parentUid) {
- $result = []; // 用于存储符合条件的子级 uid
- // 定义递归函数
- $recursion = function ($parentUid) use (&$result, &$recursion) {
- // 查询当前父级的所有直接子级
- $children = Db::name("user")
- ->where("spread_uid", $parentUid)
- ->column("uid"); // 获取子级的 uid 列表
- // 如果没有子级,直接返回
- if (empty($children)) {
- return;
- }
- // 遍历每个子级
- foreach ($children as $childUid) {
- // 如果子级的 uid 小于或等于 611,跳过该子级及其所有子级
- if ($childUid <= 611) {
- continue;
- }
- // 将符合条件的子级 uid 添加到结果数组
- $result[] = $childUid;
- // 递归查询子级的子级
- $recursion($childUid);
- }
- };
- // 从初始父级开始递归查询
- $recursion($parentUid);
- return array_unique($result); // 返回结果数组,并去重
- }
- // 2.0 根据父级uid,找到当前用户下面的UID
- public function getChildren($parentUid) {
- $result = []; // 用于存储所有子级的 uid
- $children = Db::name("user")
- ->where("spread_uid", $parentUid)
- ->column("uid"); // 获取子级的 uid 列表
- return $children; // 返回结果数组,并去重
- }
- public function getNewTeamPv($common_nums) {
- // 初始化结果数组
- $result = [
- 'max_value' => null,
- 'max_uid' => null,
- 'remaining_values' => 0, // 剩余值的总和
- 'remaining_uids' => [] // 剩余值对应的 UID
- ];
- // 递归获取所有子级 UID 的函数
- $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
- $children = Db::name("user")
- ->where("spread_uid", $parentUid)
- ->column("uid");
- $allChildren = [];
- foreach ($children as $childUid) {
- $allChildren[] = $childUid;
- $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
- }
- return $allChildren;
- };
- // 获取每个用户的总业绩,包括子级的业绩
- $userTotalPv = [];
- foreach ($common_nums as $uid) {
- // 获取当前用户及其所有子级的 UID
- $allUids = array_merge([$uid], $getRecursiveChildren($uid));
- // 查询当前用户及其子级的所有订单
- $orders = Db::name("store_order")
- ->whereIn('status', [0, 1, 2, 3])
- ->whereIn("uid", $allUids)
- ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
- ->select();
- // 计算总业绩
- $totalPv = 0;
- foreach ($orders as $order) {
- if ($order['total_price'] == 1180) {
- $totalPv += 700;
- } else if ($order['total_price'] == 11800) {
- $totalPv += 7000;
- } else if ($order['total_price'] == 10620) {
- $totalPv += 6300;
- } else if ($order['total_price'] == 2360) {
- $totalPv += 1400;
- } else if ($order['total_price'] == 9440) {
- $totalPv += 5600;
- }
- }
- // 将当前用户的总业绩和 UID 存入数组
- $userTotalPv[] = ['uid' => $uid, 'totalPv' => $totalPv];
- }
- // 如果没有符合条件的订单,直接返回空数组
- if (empty($userTotalPv)) {
- return [];
- }
- // 找到最大值及其对应的 UID
- usort($userTotalPv, function($a, $b) {
- return $b['totalPv'] <=> $a['totalPv']; // 按 totalPv 降序排序
- });
- // 获取最大值及其 UID
- $result['max_value'] = $userTotalPv[0]['totalPv'];
- $result['max_uid'] = $userTotalPv[0]['uid'];
- // 计算剩余值的总和和对应的 UID
- foreach ($userTotalPv as $index => $user) {
- if ($index > 0) { // 跳过第一个(最大值)
- $result['remaining_values'] += $user['totalPv'];
- $result['remaining_uids'][] = $user['uid'];
- }
- }
- return $result;
- }
- //只获取数组中的业绩
- public function getteampv($common_nums) {
- // 查询当前用户及其子级的所有订单
- $orders = Db::name("store_order")
- ->whereIn('status', [0, 1, 2, 3])
- ->whereIn("uid", $common_nums)
- ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
- ->select();
- // 初始化业绩和人数
- $totalPv = 0;
- $totalUsers = count($common_nums); // 初始化人数为子级总数
- // 遍历订单计算业绩
- foreach ($orders as $order) {
- if ($order['total_price'] == 1180) {
- $totalPv += 700;
- } else if ($order['total_price'] == 11800) {
- $totalPv += 7000;
- } else if ($order['total_price'] == 10620) {
- $totalPv += 6300;
- } else if ($order['total_price'] == 2360) {
- $totalPv += 1400;
- } else if ($order['total_price'] == 9440) {
- $totalPv += 5600;
- }
- }
- // 返回业绩和人数
- return [
- 'totalPv' => $totalPv,
- 'totalUsers' => $totalUsers
- ];
- }
- // 递归获取所有子级 UID 的业绩
- public function getTeamPv11($parentUid) {
- $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
- $children = Db::name("user")
- ->where("spread_uid", $parentUid)
- ->column("uid");
- $allChildren = [];
- foreach ($children as $childUid) {
- $allChildren[] = $childUid;
- $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
- }
- return $allChildren;
- };
- // 获取当前用户及其所有子级的 UID
- $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
- // 查询当前用户及其子级的所有订单
- $orders = Db::name("store_order")
- ->whereIn('status', [0, 1, 2, 3])
- ->whereIn("uid", $allUids)
- ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
- ->select();
- // 计算总业绩
- $totalPv = 0;
- foreach ($orders as $order) {
- switch ($order['total_price']) {
- case 1180:
- $totalPv += 700;
- break;
- case 11800:
- $totalPv += 7000;
- break;
- case 10620:
- $totalPv += 6300;
- break;
- case 2360:
- $totalPv += 1400;
- break;
- case 9440:
- $totalPv += 5600;
- break;
- }
- }
- return $totalPv;
- }
- //根据传递的父级数组,返回他的对应子级的个数
- public function getTeamSize($parentUids) {
- // 初始化结果数组
- $result = [];
- // 遍历每个父级ID
- foreach ($parentUids as $parentUid) {
- // 递归获取所有子级 UID
- $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
- $children = Db::name("user")
- ->where("spread_uid", $parentUid)
- ->column("uid");
- // 确保返回的是数组
- if (!is_array($children)) {
- return [];
- }
- $allChildren = [];
- foreach ($children as $childUid) {
- $allChildren[] = $childUid;
- $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
- }
- return $allChildren;
- };
- // 获取当前父级及其所有子级的 UID
- $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
- // 计算总个数(包括父级自身)
- $totalUids = count($allUids);
- // 将结果存入数组
- $result[] = [
- 'parent_uid' => $parentUid,
- 'total_count' => $totalUids
- ];
- }
- return $result;
- }
- public function processArray($array) {
- // 初始化结果数组
- $result = [
- 'max_value' => null, // 最大值
- 'max_index' => null, // 最大值的下标
- 'remaining_sum' => 0 // 剩余值的总和
- ];
- // 检查数组是否为空
- if (empty($array)) {
- return $result;
- }
- // 找出最大值及其下标
- $maxValue = $array[0];
- $maxIndex = 0;
- for ($i = 1; $i < count($array); $i++) {
- if ($array[$i] > $maxValue) {
- $maxValue = $array[$i];
- $maxIndex = $i;
- }
- }
- // 计算剩余值的总和
- $remainingSum = 0;
- for ($i = 0; $i < count($array); $i++) {
- if ($i != $maxIndex) {
- $remainingSum += $array[$i];
- }
- }
- // 将结果存入数组
- $result['max_value'] = $maxValue;
- $result['max_index'] = $maxIndex;
- $result['remaining_sum'] = $remainingSum;
- return $result;
- }
- //获取当前uesr_id下面在2.0中是否还有直接下级,并计算她的大部门和小部门
- public function getparents_child_pv($user_id){
- // 获取直接下级的 UID 列表
- $get_childs = Db::name("user")
- ->where("spread_uid", $user_id)
- ->column("uid");
- //var_dump($get_childs);
- // 初始化总业绩和总人数
- $total_value = 0;
- $total_count = 0;
- $max_value = 0;
- $max_count = 0;
- // 遍历每个直接下级
- foreach ($get_childs as $child) {
- //echo $child;
- // 获取当前下级及其子级
- $child_group = [$child];
- $recursive_children = $this->getRecursiveChildren($child);
- $child_group = array_merge($child_group, $recursive_children);
- //var_dump($child_group );
- // 获取当前分组的业绩和人数
- $result = $this->getteampv($child_group);
- //var_dump($result);
- $group_pv = $result['totalPv'];
- $group_count = $result['totalUsers'];
- // 累加总业绩和总人数
- $total_value += $group_pv;
- $total_count += $group_count;
- // 更新最大业绩及其对应的人数
- if ($group_pv > $max_value) {
- $max_value = $group_pv;
- $max_count = $group_count;
- }
- }
- // 计算小部门的业绩和人数
- $small_department_value = $total_value - $max_value;
- $small_department_count = $total_count - $max_count;
- // 返回结果
- return [
- 'team_pv' => $max_value,
- 'team_num' => $max_count,
- 'per_pv' => $small_department_value,
- 'per_num' => $small_department_count
- ];
- }
- //1.0用户直属的部门和2.0直属的部门,进行比较,获取大部门和小部门数据
- public function getparents_child_pv11($user_id, $bigamount, $smallamount, $common_nums, $person_nums) {
- // 获取直接下级的 UID 列表
- $get_childs = Db::name("user")
- ->where("spread_uid", $user_id)
- ->column("uid");
- // 初始化变量
- $all_departments = []; // 用于存储所有直属下级的业绩和人数
- // 遍历每个直属下级
- foreach ($get_childs as $child) {
- // 获取当前下级及其子级
- $child_group = [$child];
- $recursive_children = $this->getRecursiveChildren($child);
- $child_group = array_merge($child_group, $recursive_children);
- // 获取当前分组的业绩和人数
- $result = $this->getteampv($child_group);
- // if($user_id == 593){
- // var_dump($result);
- // }
- // 将直属下级的业绩和人数加入数组
- $all_departments[] = [
- 'value' => $result['totalPv'],
- 'count' => $result['totalUsers']
- ];
- }
- // 将传入的 $bigamount 和 $smallamount 以及对应的人数加入数组
- $all_departments[] = [
- 'value' => $bigamount,
- 'count' => $common_nums // 大部门的人数
- ];
- $all_departments[] = [
- 'value' => $smallamount,
- 'count' => $person_nums // 小部门的人数
- ];
- // 初始化最大部门和小部门
- $max_department = null;
- $small_department = [
- 'value' => 0,
- 'count' => 0
- ];
- // 遍历 $all_departments,找出最大值并累加小部门的值
- foreach ($all_departments as $department) {
- if ($max_department === null || $department['value'] > $max_department['value']) {
- // 如果当前部门的业绩大于最大部门的业绩,更新最大部门
- $small_department['value'] += $max_department['value'] ?? 0; // 将旧的最大值累加到小部门
- $small_department['count'] += $max_department['count'] ?? 0;
- $max_department = $department; // 更新最大部门
- } else {
- // 如果当前部门的业绩小于或等于最大部门的业绩,累加到小部门
- $small_department['value'] += $department['value'];
- $small_department['count'] += $department['count'];
- }
- }
- // 返回结果
- return [
- 'big_department' => $max_department,
- 'small_department' => $small_department
- ];
- }
- //根据父级IDS获取伞下的所有子级ID
- public function getRecursiveChildren_s($parentUid) {
- $result = []; // 用于存储所有子级的 uid
- // 定义递归函数
- $recursion = function ($currentUid) use (&$result, &$recursion) {
- // 查询当前父级的所有直接子级
- $children = Db::name("user")
- ->where("spread_uid", $currentUid)
- ->column("uid"); // 获取子级的 uid 列表
- // 如果没有子级,直接返回
- if (empty($children)) {
- return;
- }
- // 遍历每个子级
- foreach ($children as $childUid) {
- $result[] = $childUid; // 将子级的 uid 添加到结果数组
- $recursion($childUid); // 递归查询子级的子级
- }
- };
- // 从初始父级开始递归查询
- $recursion($parentUid);
- return array_unique($result); // 返回结果数组,并去重
- }
- /**
- * 获取当前用户业绩
- */
- public function userupdates($user_id) {
- //$user_id = 17;
- $children = Db::name("user")
- ->where("spread_uid", $user_id)
- ->select(); // 获取子级的 uid 列表
- $total_pv = 0;
- foreach($children as $k=>$v){
- //$children_pv = Db::name("store_order")->where("uid", $v['uid'])->whereIn("status",[0,1,2,3])->select();
- $children_pv = Db::name("user_sign_gongxian")->where("uid", $v['uid'])->where("status",1)->select();
- foreach($children_pv as $k1=>$v1){
- $total_pv += $v1['number'];
- }
- }
- return $total_pv;
- $userdatas = Db::name("user")->where("uid", $user_id)->find();
- // var_dump($userdatas['user_group']);
- //如果当前用户是普通消费者的情况下
- if($userdatas['user_group'] == 1){
- if($total_pv != 0){
- if($total_pv >= 1180 && $total_pv < 11800){
- Db::name("user")->where("uid", $user_id)->update(['user_group',2]);
- }
- }
- }
- //如果当前用户是业务员消费者的情况下
- if($userdatas['user_group'] <= 2){
- if($total_pv != 0){
- if(11800 <= $total_pv){
- Db::name("user")->where("uid", $user_id)->update(['user_group',3]);
- }
- }
- }
- }
- /**
- * 获取当前用户业绩
- */
- public function getPerformance22($user_id) {
- $team_amount = 0;
- $person_amount = 0;
- // $user_id = 17; //598 523 536
- $result_big_team_arr = [];
- $get_teams_comm_datas = [];//在2.0中获取父级下面的所有团队数据
- //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
- $common_nums = $this->getCommonNums($user_id);
- // var_dump( $common_nums);
- $get_teams_comm_num = 0;
- $get_teams_comm_pv = 0;
- $get_teams_per_num = 0;//小部门人数
- //1.0系统中有下级,需要在2.0中再加下级数据
- if($user_id < 611){
- //梅红在2.0中的ID是780
- //用户三峡所有在2.0系统下面的业绩和人数 start
- $child_nums = [];
- //获取当前用户
- foreach($common_nums as $v){
- $child_nums[] = $this->getRecursiveChildren($v);
- }
- //var_dump($child_nums);
- //去除空数组,并重新组合有数据的数组
- $filteredData = array_filter($child_nums, function($array) {
- return !empty($array); // 如果数组不为空,则保留
- });
- // 合并所有非空数组
- foreach ($filteredData as $array) {
- $result_big_team_arr = array_merge($result_big_team_arr, $array);
- }
- //var_dump($result_big_team_arr);
- //获取当前用户下面在2.0中的下级所有PV
- //$get_teams_comm_pv = $this->getteampv($result_big_team_arr);
- $t_pv = $this->getteampv($result_big_team_arr);
- $get_teams_comm_pv =$t_pv['totalPv'];
- //var_dump($t_pv);echo "ttt";
- //获取当前用户下面在2.0中的下级所有人数
- $get_teams_comm_num = count($result_big_team_arr);
- //用户伞下小部门所有在2.0系统下面的业绩和人数 end
- }else{
- //当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
- $child_nums = $this->getChildren($user_id);
- //获取父级子级下面的个人
- $num_teams = $this->getTeamSize($child_nums);
- //var_dump($num_teams);
- foreach($child_nums as $v){
- $get_teams_comm_datas[] = $this->getTeamPv11($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
- }
- //$s = $this->getparents_child_pv($user_id);
- // var_dump($get_teams_comm_datas);
- //如果只有一个部门,就是默认大部门
- if( count($get_teams_comm_datas) ==1 ){
- $get_teams_comm_pv =$get_teams_comm_datas[0];
- $get_teams_comm_num = $num_teams[0]['total_count'];
- }else if(count($get_teams_comm_datas) >1){
- // var_dump( $get_teams_comm_datas);
- //获取一个最大值,设为大部门,其他的加载一块是小部门
- $getss = $this->processArray($get_teams_comm_datas);
- $max_value_count = $num_teams[$getss['max_index']]['total_count'];
- unset($num_teams[$getss['max_index']]);
- //获取小部门的人数
- $per_num = 0;
- foreach($num_teams as $k=>$v){
- $per_num +=$v['total_count'];
- }
- //找到最大值的(大部门)
- $get_teams_comm_num = $max_value_count;
- //小部门的数量
- $get_teams_per_num = $per_num;
- //var_dump($getss['max_value']);
- $person_amount = $getss['remaining_sum'];
- $get_teams_comm_pv = $getss['max_value'];
- }
- }
- //var_dump($get_teams_comm_pv);
- //合并业绩和人数
- $team_amount += $get_teams_comm_pv;
- //var_dump($team_amount);
- //1.0获取小区业绩
- $person_nums = $this->getPersonageNums($user_id);
- //var_dump($person_nums);
- $result_small_team_arr = [];
- //1.0系统中有下级,需要在2.0中再加下级数据
- //用户三峡所有在2.0系统下面的业绩和人数 start
- $child_nums_mix = [];
- //获取当前用户
- foreach($person_nums as $v){
- $child_nums_mix[] = $this->getRecursiveChildren($v);
- }
- //去除空数组,并重新组合有数据的数组
- $filteredData_1 = array_filter($child_nums_mix, function($array) {
- return !empty($array); // 如果数组不为空,则保留
- });
- // 合并所有非空数组
- $result_small_team_arr = [];
- foreach ($filteredData_1 as $array) {
- $result_small_team_arr = array_merge($result_small_team_arr, $array);
- }
- //var_dump($result_small_team_arr);
- //获取当前用户下面在2.0中的下级所有PV
- // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
- $t_pv = $this->getteampv($result_small_team_arr);
- $get_teams_per_pv =$t_pv['totalPv'];
- //var_dump( $get_teams_per_pv);
- //获取当前用户下面在2.0中的下级所有人数
- $get_teams_per_num += count($result_small_team_arr);
- //合并业绩和人数
- $person_amount += $get_teams_per_pv;
- // if($user_id == 593){
- // $person_amount = 2800;
- // }
- //var_dump($person_amount);
- //用户小部门所有在2.0系统下面的业绩和人数 end
- //var_dump($team_amount);
- // $common_nums[] = $user_id;
- foreach ($common_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $team_amount += $amount;
- }
- foreach ($person_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $person_amount += $amount;
- }
- // var_dump($team_amount);
- // var_dump($person_amount);
- //
- //var_dump($team_amount);
- $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
- //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
- // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
- $money1180Sum = 0;
- foreach ($user_team_amount as $record) {
- $money1180Sum += $record['money'] - 300 - 180;
- }
- //var_dump($money1180Sum );
- // 获取 status 为 1 且 money 为 11800 的记录集合
- $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
- // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
- $money11800Sum = 0;
- foreach ($money11800Records as $record) {
- $money11800Sum += $record['money'] - 3000 - 1800;
- }
- //var_dump($money11800Sum );
- $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
- // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
- $money10620Sum = 0;
- foreach ($money10620Records as $record) {
- $money10620Sum += $record['money'] - 2700 - 1620;
- }
- // var_dump($money10620Sum );
- // 计算除去特定值后的总和
- //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
- $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
- $otherMoneySum = 0;
- foreach ($otherMoneyRecords as $record) {
- $otherMoneySum += $record['money'];
- }
- // 分别处理特定值的情况并加上其他值的总和
- $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
- //var_dump($all_record_nums);
- $team_amount += $all_record_nums;
- //var_dump($team_amount);
- //计算自己的个人联盟总流水
- // // //计算自己的个人联盟总流水
- // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
- // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
- // $person_amount += $user_person_amount;
- //计算个人的1180单价的业绩 集合
- $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
- $money1180Sum = 0;
- foreach ($money1180Records as $record) {
- $money1180Sum += $record['money'] - 300 - 180;
- }
- $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
- //var_dump($person_nums);
- //计算个人的11800单价的业绩 集合
- $money11800Sum = 0;
- foreach ($money11800Records as $record) {
- $money11800Sum += $record['money'] - 3000 - 1800;
- }
- $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
- //var_dump($person_nums);
- //计算个人的10620单价的业绩 集合
- $money10620Sum = 0;
- foreach ($money10620Records as $record) {
- $money10620Sum += $record['money'] - 2700 - 1620;
- }
- // 计算除去特定值后的总和
- $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
- $otherMoneySum = 0;
- foreach ($otherMoneyRecords as $record) {
- $otherMoneySum += $record['money'];
- }
- // 分别处理特定值的情况并加上其他值的总和
- $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
- $person_amount += $user_person_amount;
- //大部门人数
- $teams_num = count($common_nums) + $get_teams_comm_num;
- //小部门人数
- $per_num = count($person_nums) + $get_teams_per_num;
- // var_dump($team_amount);
- // var_dump($person_amount);
- //如果当前用户是1.0用户,找到其直推所有的业绩,根据业绩找到大小部门的同时,还要比对1.0中大小部门的业绩,摘出一个最大业绩的部门是大部门,其余都是小部门()
- if($user_id < 611){
- // var_dump($team_amount);
- // var_dump($person_amount);
- //获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
- //例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
- $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);
- //var_dump($b_s);
- // var_dump($team_amount,$person_amount);
- // var_dump(count($common_nums)+ $get_teams_comm_num,count($person_nums)+ $get_teams_per_num);
- //var_dump( $b_s);echo "yyyyyyyyyyyyy";
- $team_amount = $b_s['big_department']['value'];
- $teams_num = $b_s['big_department']['count'];
- // var_dump($b_s['team_pv']);
- // var_dump($b_s['per_pv']);
- $person_amount = $b_s['small_department']['value'];
- $per_num = $b_s['small_department']['count'];//小部门人数
- //var_dump( $b_s['team_num'],$b_s['per_num']);
- }
- //级别信息
- $userInfo = Db::name("user")->find($user_id);//
- $zk_level = 4;
- $is_zk = false;
- if($userInfo['user_level_id_old'] == $zk_level) {
- $is_zk = true;
- $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
- $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
- } else{
- $sales_incentive = 0;
- }
- $return_data = [
- 'common_nums'=>$teams_num,
- 'person_nums'=>$per_num,
- 'common_nums_pv'=> $team_amount,
- 'person_nums_pv'=> $person_amount,
- 'sum_nums_pv' =>$team_amount + $person_amount,
- 'sales_incentive' => $sales_incentive,
- "is_zk"=>$is_zk
- ];
- return $return_data;
- }
- /**
- * 获取当前用户业绩
- */
- public function getPerformance($user_id) {
- $team_amount = 0;
- $person_amount = 0;
- $result_big_team_arr = [];
- $get_teams_comm_datas = [];//在2.0中获取父级下面的所有团队数据
- //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
- $common_nums = $this->getCommonNums($user_id);
- //var_dump($user_id);
- $get_teams_comm_num = 0;
- $get_teams_comm_pv = 0;
- $get_teams_per_num = 0;//小部门人数
- //1.0系统中有下级,需要在2.0中再加下级数据
- if($user_id < 611){
- //梅红在2.0中的ID是780
- // if($user_id == 593){
- // $common_nums[] = 780;
- // unset($common_nums[0]);
- // }
- //var_dump($common_nums);
- //用户三峡所有在2.0系统下面的业绩和人数 start
- $child_nums = [];
- //再加上当前用户直属的子级
- $common_ns = $common_nums;
- $common_ns[] = $user_id;
- //var_dump($common_ns);return;
- //获取当前用户
- foreach($common_nums as $v){
- $child_nums[] = $this->getRecursiveChildren($v);
- }
- //梅红在2.0中的ID是780
- // if($user_id == 593){
- // $child_nums[0][] = 780;
- // }
- //去除空数组,并重新组合有数据的数组
- $filteredData = array_filter($child_nums, function($array) {
- return !empty($array); // 如果数组不为空,则保留
- });
- // 合并所有非空数组
- foreach ($filteredData as $array) {
- $result_big_team_arr = array_merge($result_big_team_arr, $array);
- }
- //var_dump($result_big_team_arr);echo "ppppppppppppppppp";
- //获取当前用户下面在2.0中的下级所有PV
- $t_pv = $this->getteampv($result_big_team_arr);
- $get_teams_comm_pv =$t_pv['totalPv'];
- // if($user_id == 593){
- // $get_teams_comm_pv = 7000;
- // }
- //var_dump($get_teams_comm_pv);
- //获取当前用户下面在2.0中的下级所有人数
- $get_teams_comm_num = count($result_big_team_arr);
- //用户伞下小部门所有在2.0系统下面的业绩和人数 end
- }else{
- //当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
- $child_nums = $this->getChildren($user_id);
- //获取父级子级下面的个人
- $num_teams = $this->getTeamSize($child_nums);
- foreach($child_nums as $v){
- $get_teams_comm_datas[] = $this->getTeamPv11($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
- }
- if( count($get_teams_comm_datas) ==1 ){
- $get_teams_comm_pv =$get_teams_comm_datas[0];
- $get_teams_comm_num = $num_teams[0]['total_count'];
- }else if(count($get_teams_comm_datas) >1){
- // $getss = $this->processArray($get_teams_comm_datas);
- // $team_datas = $num_teams[$getss['max_index']];
- // var_dump( $get_teams_comm_datas);
- //获取一个最大值,设为大部门,其他的加载一块是小部门
- $getss = $this->processArray($get_teams_comm_datas);
- $max_value_count = $num_teams[$getss['max_index']]['total_count'];
- unset($num_teams[$getss['max_index']]);
- //获取小部门的人数
- $per_num = 0;
- foreach($num_teams as $k=>$v){
- $per_num +=$v['total_count'];
- }
- //找到最大值的(大部门)
- $get_teams_comm_num = $max_value_count;
- //小部门的数量
- $get_teams_per_num = $per_num;
- //var_dump($getss['max_value']);
- $person_amount = $getss['remaining_sum'];
- $get_teams_comm_pv = $getss['max_value'];
- }
- }
- //合并业绩和人数
- $team_amount += $get_teams_comm_pv;
- //var_dump($team_amount);
- //1.0获取小区业绩
- $person_nums = $this->getPersonageNums($user_id);
- //var_dump($person_nums);
- $result_small_team_arr = [];
- //1.0系统中有下级,需要在2.0中再加下级数据
- //用户三峡所有在2.0系统下面的业绩和人数 start
- $child_nums_mix = [];
- //再加上当前用户直属的子级
- $common_ns1 = $person_nums;
- $common_ns1[] = $user_id;
- //获取当前用户
- foreach($person_nums as $v){
- $child_nums_mix[] = $this->getRecursiveChildren($v);
- }
- //去除空数组,并重新组合有数据的数组
- $filteredData_1 = array_filter($child_nums_mix, function($array) {
- return !empty($array); // 如果数组不为空,则保留
- });
- // 合并所有非空数组
- $result_small_team_arr = [];
- foreach ($filteredData_1 as $array) {
- $result_small_team_arr = array_merge($result_small_team_arr, $array);
- }
- //获取当前用户下面在2.0中的下级所有PV
- // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
- $t_pv = $this->getteampv($result_small_team_arr);
- $get_teams_per_pv =$t_pv['totalPv'];
- //获取当前用户下面在2.0中的下级所有人数
- $get_teams_per_num += count($result_small_team_arr);
- //合并业绩和人数
- $person_amount += $get_teams_per_pv;
- // if($user_id == 593){
- // $person_amount = 2800;
- // }
- //var_dump($person_amount);
- //用户小部门所有在2.0系统下面的业绩和人数 end
- // $common_nums[] = $user_id;
- foreach ($common_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $team_amount += $amount;
- }
- foreach ($person_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $person_amount += $amount;
- }
- //var_dump($team_amount);
- // if($user_id < 611){
- // //获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
- // //例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
- // $b_s = $this->getparents_child_pv($user_id);
- // //var_dump( $b_s);echo "yyyyyyyyyyyyy";
- // $team_amount += $b_s['team_pv'];
- // $get_teams_comm_num += $b_s['team_num'];
- // $person_amount += $b_s['per_pv'];
- // $get_teams_per_num += $b_s['per_num'];//小部门人数
- // //var_dump($team_amount,$person_amount );
- // }
- $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
- //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
- // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
- $money1180Sum = 0;
- foreach ($user_team_amount as $record) {
- $money1180Sum += $record['money'] - 300 - 180;
- }
- if($user_id == 593){
- $money1180Sum -= 700;
- }
- // 获取 status 为 1 且 money 为 11800 的记录集合
- $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
- // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
- $money11800Sum = 0;
- foreach ($money11800Records as $record) {
- $money11800Sum += $record['money'] - 3000 - 1800;
- }
- $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
- // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
- $money10620Sum = 0;
- foreach ($money10620Records as $record) {
- $money10620Sum += $record['money'] - 2700 - 1620;
- }
- // 计算除去特定值后的总和
- //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
- $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
- $otherMoneySum = 0;
- foreach ($otherMoneyRecords as $record) {
- $otherMoneySum += $record['money'];
- }
- // 分别处理特定值的情况并加上其他值的总和
- $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
- // var_dump($all_record_nums);
- $team_amount += $all_record_nums;
- // var_dump($user_team_amount);
- //计算自己的个人联盟总流水
- // // //计算自己的个人联盟总流水
- // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
- // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
- // $person_amount += $user_person_amount;
- //计算个人的1180单价的业绩 集合
- $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
- $money1180Sum = 0;
- foreach ($money1180Records as $record) {
- $money1180Sum += $record['money'] - 300 - 180;
- }
- $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
- //var_dump($person_nums);
- //计算个人的11800单价的业绩 集合
- $money11800Sum = 0;
- foreach ($money11800Records as $record) {
- $money11800Sum += $record['money'] - 3000 - 1800;
- }
- $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
- //var_dump($person_nums);
- //计算个人的10620单价的业绩 集合
- $money10620Sum = 0;
- foreach ($money10620Records as $record) {
- $money10620Sum += $record['money'] - 2700 - 1620;
- }
- // 计算除去特定值后的总和
- $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
- $otherMoneySum = 0;
- foreach ($otherMoneyRecords as $record) {
- $otherMoneySum += $record['money'];
- }
- // 分别处理特定值的情况并加上其他值的总和
- $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
- $person_amount += $user_person_amount;
- // //临时设置
- // if($user_id == 536){
- // $person_amount = 2800;
- // $team_amount = 7000;
- // }
- // //临时设置
- // if($user_id == 222){
- // $person_amount = 2800;
- // $team_amount = 11900;
- // }
- //大部门人数
- $teams_num = count($common_nums) + $get_teams_comm_num;
- //小部门人数
- $per_num = count($person_nums) + $get_teams_per_num;
- //如果当前用户是1.0用户,找到其直推所有的业绩,根据业绩找到大小部门的同时,还要比对1.0中大小部门的业绩,摘出一个最大业绩的部门是大部门,其余都是小部门()
- if($user_id < 611){
- // var_dump($team_amount);
- // var_dump($person_amount);
- //获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
- //例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
- $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);
- //var_dump($b_s);
- // var_dump($team_amount,$person_amount);
- // var_dump(count($common_nums)+ $get_teams_comm_num,count($person_nums)+ $get_teams_per_num);
- //var_dump( $b_s);echo "yyyyyyyyyyyyy";
- $team_amount = $b_s['big_department']['value'];
- $teams_num = $b_s['big_department']['count'];
- // var_dump($b_s['team_pv']);
- // var_dump($b_s['per_pv']);
- $person_amount = $b_s['small_department']['value'];
- $per_num = $b_s['small_department']['count'];//小部门人数
- //var_dump( $b_s['team_num'],$b_s['per_num']);
- }
- //级别信息
- $userInfo = Db::name("user")->find($user_id);//
- $zk_level = 4;
- $is_zk = false;
- if($userInfo['user_level_id_old'] == $zk_level) {
- $is_zk = true;
- $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
- $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
- } else{
- $sales_incentive = 0;
- }
- $return_data = [
- 'common_nums' => $teams_num,
- 'person_nums' => $per_num,
- 'common_nums_pv'=> $team_amount,
- 'person_nums_pv'=> $person_amount,
- 'sum_nums_pv' =>$team_amount + $person_amount,
- 'sales_incentive' => $sales_incentive,
- "is_zk"=>$is_zk
- ];
- return $return_data;
- }
- /**
- * 获取当前用户业绩
- */
- public function getPerformance_copy($user_id) {
- // $user_id = $this->request->post("user_id");
- //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
- $common_nums = $this->getCommonNums($user_id);
- //1.0获取小区业绩
- $person_nums = $this->getPersonageNums($user_id);
- //return $person_nums;
- // var_dump( $common_nums);
- $team_amount = 0;
- $person_amount = 0;
- // $common_nums[] = $user_id;
- foreach ($common_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $team_amount += $amount;
- }
- foreach ($person_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $person_amount += $amount;
- }
- //var_dump($team_amount);
- $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
- //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
- // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
- $money1180Sum = 0;
- foreach ($user_team_amount as $record) {
- $money1180Sum += $record['money'] - 300 - 180;
- }
- // 获取 status 为 1 且 money 为 11800 的记录集合
- $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
- // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
- $money11800Sum = 0;
- foreach ($money11800Records as $record) {
- $money11800Sum += $record['money'] - 3000 - 1800;
- }
- $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
- // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
- $money10620Sum = 0;
- foreach ($money10620Records as $record) {
- $money10620Sum += $record['money'] - 2700 - 1620;
- }
- // 计算除去特定值后的总和
- //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
- $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
- $otherMoneySum = 0;
- foreach ($otherMoneyRecords as $record) {
- $otherMoneySum += $record['money'];
- }
- // 分别处理特定值的情况并加上其他值的总和
- $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
- // var_dump($all_record_nums);
- $team_amount += $all_record_nums;
- //计算自己的个人联盟总流水
- // // //计算自己的个人联盟总流水
- // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
- // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
- // $person_amount += $user_person_amount;
- //计算个人的1180单价的业绩 集合
- $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
- $money1180Sum = 0;
- foreach ($money1180Records as $record) {
- $money1180Sum += $record['money'] - 300 - 180;
- }
- $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
- //var_dump($person_nums);
- //计算个人的11800单价的业绩 集合
- $money11800Sum = 0;
- foreach ($money11800Records as $record) {
- $money11800Sum += $record['money'] - 3000 - 1800;
- }
- $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
- //var_dump($person_nums);
- //计算个人的10620单价的业绩 集合
- $money10620Sum = 0;
- foreach ($money10620Records as $record) {
- $money10620Sum += $record['money'] - 2700 - 1620;
- }
- // 计算除去特定值后的总和
- $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
- $otherMoneySum = 0;
- foreach ($otherMoneyRecords as $record) {
- $otherMoneySum += $record['money'];
- }
- // 分别处理特定值的情况并加上其他值的总和
- $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
- $person_amount += $user_person_amount;
- //级别信息
- $userInfo = Db::name("user")->find($user_id);//
- $zk_level = 4;
- $is_zk = false;
- if($userInfo['user_level_id_old'] == $zk_level) {
- $is_zk = true;
- $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
- $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
- } else{
- $sales_incentive = 0;
- }
- $return_data = [
- 'common_nums'=>count($common_nums),
- 'person_nums'=>count($person_nums),
- 'common_nums_pv'=> $team_amount,
- 'person_nums_pv'=> $person_amount,
- 'sum_nums_pv' =>$team_amount + $person_amount,
- 'sales_incentive' => $sales_incentive,
- "is_zk"=>$is_zk
- ];
- return $return_data;
- }
- /**
- * 获取指定用户业绩
- */
- public function getPerformanceOf($user_id) {
- //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
- $common_nums = $this->getCommonNums($user_id);
- $person_nums = $this->getPersonageNums($user_id);
- $team_amount = 0;
- $person_amount = 0;
- // $common_nums[] = $user_id;
- foreach ($common_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $team_amount += $amount;
- }
- foreach ($person_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $person_amount += $amount;
- }
- // return $person_nums;
- //添加自己共建联盟的流水
- $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("spread_id",$user_id)->sum("money");
- $user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
- $team_amount += $user_team_amount;
- // //计算自己的个人联盟总流水
- $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("spread_id",$user_id)->sum("money");
- $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
- $person_amount += $user_person_amount;
- $sum_nums_pv = $team_amount + $person_amount;
- $sum_nums_pv = isset($sum_nums_pv) ? $sum_nums_pv :0;
- return $sum_nums_pv;
- }
- /**
- * 获取用户星级
- */
- public function getStarLevel($user_id,$team_money=0,$person_money=0) {
- if(empty($team_money)) {
- $common_nums = $this->getCommonNums($user_id);
- $team_money = 0;
- foreach ($common_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $team_money += $amount;
- }
- //计算自己的共建联盟流水
- $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->sum("money");
- $user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
- $team_money += $user_team_amount;
- }else{
- $common_nums = $this->getCommonNums($user_id);
- }
- if(empty($person_money)) {
- $person_nums = $this->getPersonageNums($user_id);
- $person_amount = 0;
- foreach ($person_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $person_amount += $amount;
- }
- $person_money = $person_amount;
- //计算自己的个人联盟总流水
- $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->sum("money");
- $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
- $person_money += $user_person_amount;
- }else{
- $person_nums = $this->getPersonageNums($user_id);
- }
- $slow = $person_money;
- if($team_money < $person_money) {
- $slow = $team_money;
- }
- $sum_money = $team_money + $person_money;
- // $data = ['sum_money'=>$sum_money,"team_money"=>$team_money,"person_money"=>$person_money];
- // $this->error(0,$data);
- $star_list = Db::name("old_user_star")->order("statement_all_num desc")->select();
- $start_level = "";
- foreach ($star_list as $key => $value) {
- # code...
- if( $sum_money>=$value['statement_all_num'] && $slow >= $value['person_statement']) {
- return $value;
- }
- }
- return $start_level;
- }
- /**
- * 获取流水信息
- */
- public function getPerformance1($user_id) {
- // $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money");
- // $amount = isset($amount) ? round($amount*0.7,2) : 0;
- // return $amount;
- $money1180Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",1180)->where("status",1)->select();
- $money1180Sum = 0;
- foreach ($money1180Records as $record) {
- $money1180Sum += $record['money'] - 300 - 180;
- }
- // var_dump($money1180Sum);
- $money11800Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",11800)->where("status",1)->select();
- //var_dump($person_nums);
- //计算个人的11800单价的业绩 集合
- $money11800Sum = 0;
- foreach ($money11800Records as $record) {
- $money11800Sum += $record['money'] - 3000 - 1800;
- }
- $money10620Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",10620)->where("status",1)->select();
- //var_dump($person_nums);
- //计算个人的11800单价的业绩 集合
- $money10620Sum = 0;
- foreach ($money10620Records as $record) {
- $money10620Sum += $record['money'] - 2700 - 1620;
- }
- // 计算除去特定值后的总和
- $otherMoneyRecords = Db::name("old_user_of_goods")->where("node_id",$user_id)->where('status', 1)->whereNotIn('money', [1180, 11800 ,10620])->select();
- $otherMoneySum = 0;
- foreach ($otherMoneyRecords as $record) {
- $otherMoneySum += $record['money'];
- }
- // 分别处理特定值的情况并加上其他值的总和
- $user_person_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
- return $user_person_amount;
- }
- /**
- * 获取个人业绩统计信息
- */
- public function getPerformanceOfId($user_id)
- {
- //var_dump($user_id);
- //联盟总人数 共建联盟人数 个人联盟人数 总流水 共建联盟流水 个人联盟流水 所属星级(钻卡专属)
- $common_nums = $this->getCommonNums($user_id);
- $person_nums = $this->getPersonageNums($user_id);
- //联盟业绩 查询 共建联盟业绩 个人联盟业绩
- $team_amount = 0;
- $person_amount = 0;
- // $common_nums[] = $user_id;
- foreach ($common_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $team_amount += $amount;
- }
- //计算自己的共建联盟流水
- //$user_team_amount = Db::name("user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where("status",1)->sum("money");
- // $this->error(0,$team_amount);
- //$user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
- $money1180Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 1180)->select();
- // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
- $money1180Sum = 0;
- foreach ($money1180Records as $record) {
- $money1180Sum += $record['money'] - 300 - 180;
- }
- // 获取 status 为 1 且 money 为 11800 的记录集合
- $money11800Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 11800)->select();
- // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
- $money11800Sum = 0;
- foreach ($money11800Records as $record) {
- $money11800Sum += $record['money'] - 3000 - 1800;
- }
- // 获取 status 为 1 且 money 为 11800 的记录集合
- $money10620Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 10620)->select();
- // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
- $money10620Sum = 0;
- foreach ($money10620Records as $record) {
- $money10620Sum += $record['money'] - 2700 - 1620;
- }
- // 计算除去特定值后的总和
- $otherMoneyRecords = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->whereNotIn('money', [1180, 11800,10620])->select();
- $otherMoneySum = 0;
- foreach ($otherMoneyRecords as $record) {
- $otherMoneySum += $record['money'];
- }
- // 分别处理特定值的情况并加上其他值的总和
- $user_team_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
- $team_amount += $user_team_amount;
- foreach ($person_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $person_amount += $amount;
- }
- // //计算自己的个人联盟总流水
- $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("status",1)->sum("money");
- $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
- $person_amount += $user_person_amount;
- // $this->error(0,$common_nums);
- return $team_amount + $person_amount;
- }
- /**
- * 获取该用户共建联盟
- */
- public function getCommonNums($user_id){
- //先获取共建联盟下用户的id
- $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->select()->toArray();
- $new_array_ids =[];
- foreach ($son_ids as $key => $value) {
- # code...
- $son_id = $value['id'];
- $new_array_ids = array_merge($new_array_ids,[$son_id]);
- $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
- if(count($son_value_ids) > 0) {
- $son_value_ids = array_column($son_value_ids,"id");
- $new_array_ids = array_merge($new_array_ids,$son_value_ids);
- }
- }
- return $new_array_ids;
- }
- /**
- * 获取该用户个人联盟
- */
- public function getPersonageNums($user_id){
- $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("id")->select();
- $new_array_ids =[];
- // return 3343;
- foreach ($son_ids as $key => $value) {
- # code...
- $son_id = $value['id'];
- $new_array_ids = array_merge($new_array_ids,[$son_id]);
- $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
- if(count($son_value_ids) > 0) {
- $son_value_ids = array_column($son_value_ids,"id");
- $new_array_ids = array_merge($new_array_ids,$son_value_ids);
- }
- }
- return $new_array_ids;
- }
- //获取团队递归聚宝盆1
- public function teamPeople( $user_id,$type){
- //var_dump($type);
- //$ftype = 1:大部门,0:小部门
- //业绩小是小部门,业绩大是大部门
- if($type == 1) {
- $list = Db::name("old_user_jbp")
- ->where("spread", $user_id)
- ->where("is_team", 1)
- ->field("user_name, id")
- ->select()
- ->toArray();
- $list = $this->get_yj_amount($list,1);
- $list1 = Db::name("old_user_jbp")
- ->where("spread", $user_id)
- ->where("is_team", 0)
- ->field("user_name, id")
- ->select()
- ->toArray();
- $list1 = $this->get_yj_amount($list1, 0);
- // 检查数组和字段是否存在
- if (isset($list[0]['performance']['common_nums_pv']) && isset($list1[0]['performance']['common_nums_pv'])) {
- // 如果$list的值小于或等于$list1的值,选择$list
- if ($list[0]['performance']['common_nums_pv'] <= $list1[0]['performance']['common_nums_pv']) {
- return $list1;
- } else {
- return $list;
- }
- } elseif (isset($list[0]['performance']['common_nums_pv'])) {
- // 如果只有$list有值,返回$list
- return $list;
- } elseif (isset($list1[0]['performance']['common_nums_pv'])) {
- // 如果只有$list1有值,返回$list1
- return $list1;
- } else {
- // 如果两个数组都没有该字段,返回空数组
- return [];
- }
- }else if($type == 0) {
- $list = Db::name("old_user_jbp")
- ->where("spread", $user_id)
- ->where("is_team", 1)
- ->field("user_name, id")
- ->select()
- ->toArray();
- $list = $this->get_yj_amount($list,1);
- $list1 = Db::name("old_user_jbp")
- ->where("spread", $user_id)
- ->where("is_team", 0)
- ->field("user_name, id")
- ->select()
- ->toArray();
- $list1 = $this->get_yj_amount($list1, 0);
- // 检查数组和字段是否存在
- if (isset($list[0]['performance']['common_nums_pv']) && isset($list1[0]['performance']['common_nums_pv'])) {
- // 如果$list的值小于或等于$list1的值,选择$list
- if ($list[0]['performance']['common_nums_pv'] <= $list1[0]['performance']['common_nums_pv']) {
- return $list;
- } else {
- return $list1;
- }
- } elseif (isset($list[0]['performance']['common_nums_pv'])) {
- // 如果只有$list有值,返回$list
- return $list;
- } elseif (isset($list1[0]['performance']['common_nums_pv'])) {
- // 如果只有$list1有值,返回$list1
- return $list1;
- } else {
- // 如果两个数组都没有该字段,返回空数组
- return [];
- }
- }else if($type == 2){
- $list = Db::name("user")->where("spread_uid",$user_id)->field("nickname,uid,avatar")->select()->toArray();
- return $list;
- }
- // foreach ($list as $key => $value) {
- // $list[$key]['user_name'] = $value['user_name'] . "业绩";
- // $list[$key]['performance'] = $this->getPerformance($value['id']);
- // //辨别当前是大部门还是小部门。用于显示大小业绩展示
- // $list[$key]['curr_type'] = '';
- // if($type == 1){
- // $list[$key]['curr_type'] = 1;
- // }else if($type == 0){
- // $list[$key]['curr_type'] = 0;
- // }else{
- // $list[$key]['curr_type'] = '';
- // }
- // }
- return $list;
- }
- public function get_yj_amount($list,$type){
- foreach ($list as $key => $value) {
- # code...
- // $amount = $this->getPerformanceOfId($value['id']);
- $list[$key]['user_name'] = $value['user_name'] . "业绩";
- //$list[$key]['total_performance'] = $amount;
- //$performance = $this->getPerformanceOfId($search_name['id']);
- $list[$key]['performance'] = $this->getPerformance($value['id']);
- //辨别当前是大部门还是小部门。用于显示大小业绩展示
- $list[$key]['curr_type'] = '';
- if($type == 1){
- $list[$key]['curr_type'] = 1;
- }else if($type == 0){
- $list[$key]['curr_type'] = 0;
- }else{
- $list[$key]['curr_type'] = '';
- }
- }
- return $list;
- }
- //获取团队递归聚宝盆1
- public function teamPeople_copy( $user_id,$type){
- //var_dump($type);
- //$ftype = 1:大部门,0:小部门
- //$user_id = $this->request->post("user_id");
- //$type = $this->request->post("type",0);
- //查找当前用户id下节点
- if($type == 1) {
- // echo 33;
- $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->field("user_name,id")->select()->toArray();
- }else if($type == 0) {
- // echo 44;
- $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("user_name,id")->select()->toArray();
- }else if($type == 2){
- $list = Db::name("user")->where("spread_uid",$user_id)->field("nickname,uid")->select()->toArray();
- return $list;
- }else {
- // echo 55;
- $list = Db::name("old_user_jbp")->where("spread",$user_id)->field("user_name,id")->select()->toArray();
- }
- foreach ($list as $key => $value) {
- # code...
- // $amount = $this->getPerformanceOfId($value['id']);
- $list[$key]['user_name'] = $value['user_name'] . "业绩";
- //$list[$key]['total_performance'] = $amount;
- //$performance = $this->getPerformanceOfId($search_name['id']);
- $list[$key]['performance'] = $this->getPerformance($value['id']);
- //辨别当前是大部门还是小部门。用于显示大小业绩展示
- $list[$key]['curr_type'] = '';
- if($type == 1){
- $list[$key]['curr_type'] = 1;
- }else if($type == 0){
- $list[$key]['curr_type'] = 0;
- }else{
- $list[$key]['curr_type'] = '';
- }
- }
- return $list;
- }
- // //获取团队递归聚宝盆1
- // public function teamPeople( $user_id,$type){
- // //$user_id = $this->request->post("user_id");
- // //$type = $this->request->post("type",0);
- // //查找当前用户id下节点
- // if($type == 1) {
- // $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->field("user_name,id")->select()->toArray();
- // }else if($type == 2) {
- // $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("user_name,id")->select()->toArray();
- // }else {
- // $list = Db::name("old_user_jbp")->where("spread",$user_id)->field("user_name,id")->select()->toArray();
- // }
- // foreach ($list as $key => $value) {
- // # code...
- // $amount = $this->getPerformanceOfId($value['id']);
- // $list[$key]['user_name'] = $value['user_name'] . "-----业绩" . $amount;
- // }
- // return $list;
- // }
- //获取大小部门贡献值
- /**
- * 获取当前用户大小部门贡献值
- */
- public function getPerformance_getcon($user_id) {
- $team_amount = 0;
- $person_amount = 0;
- // $user_id = 593; //598 523 536
- $result_big_team_arr = [];
- $get_teams_comm_datas = [];//在2.0中获取父级下面的所有团队数据
- //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
- $common_nums = $this->getCommonNums_getcon($user_id);
- //var_dump($common_nums);
- $get_teams_comm_num = 0;
- $get_teams_comm_pv = 0;
- $get_teams_per_num = 0;//小部门人数
- //1.0系统中有下级,需要在2.0中再加下级数据
- if($user_id < 611){
- //梅红在2.0中的ID是780
- //var_dump( $common_nums);
- //用户三峡所有在2.0系统下面的业绩和人数 start
- $child_nums = [];
- //获取当前用户
- foreach($common_nums as $v){
- $child_nums[] = $this->getRecursiveChildren_getcon($v);
- }
- //去除空数组,并重新组合有数据的数组
- $filteredData = array_filter($child_nums, function($array) {
- return !empty($array); // 如果数组不为空,则保留
- });
- // 合并所有非空数组
- foreach ($filteredData as $array) {
- $result_big_team_arr = array_merge($result_big_team_arr, $array);
- }
- //var_dump($result_big_team_arr);
- //获取当前用户下面在2.0中的下级所有PV
- //$get_teams_comm_pv = $this->getteampv($result_big_team_arr);
- $t_pv = $this->getteampv_getcon($result_big_team_arr);
- $get_teams_comm_pv = $t_pv;
- //var_dump($get_teams_comm_pv);echo "ttt";
- //用户伞下小部门所有在2.0系统下面的业绩和人数 end
- }else{
- //当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
- $child_nums = $this->getChildren_getcon($user_id);
- //获取父级子级下面的个人
- $num_teams = $this->getTeamSize_getcon($child_nums);
- //var_dump($num_teams);
- foreach($child_nums as $v){
- $get_teams_comm_datas[] = $this->getTeamPv11_getcon($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
- }
- //$s = $this->getparents_child_pv($user_id);
- //var_dump($get_teams_comm_datas);
- //如果只有一个部门,就是默认大部门
- if( count($get_teams_comm_datas) ==1 ){
- $get_teams_comm_pv =$get_teams_comm_datas[0];
- $get_teams_comm_num = $num_teams[0]['total_count'];
- }else if(count($get_teams_comm_datas) >1){
- // var_dump( $get_teams_comm_datas);
- //获取一个最大值,设为大部门,其他的加载一块是小部门
- $getss = $this->processArray_getcon($get_teams_comm_datas);
- //var_dump($getss);
- $max_value_count = $num_teams[$getss['max_index']]['total_count'];
- unset($num_teams[$getss['max_index']]);
- //获取小部门的人数
- $per_num = 0;
- foreach($num_teams as $k=>$v){
- $per_num +=$v['total_count'];
- }
- //找到最大值的(大部门)
- //$get_teams_comm_num = $max_value_count;
- //小部门的数量
- // $get_teams_per_num = $per_num;
- //var_dump($getss['max_value']);
- $person_amount = $getss['remaining_sum'];
- $get_teams_comm_pv = $getss['max_value'];
- }
- }
- //var_dump($get_teams_comm_pv);
- //合并业绩和人数
- $team_amount += $get_teams_comm_pv;
- //var_dump($team_amount);
- //1.0获取小区业绩
- $person_nums = $this->getPersonageNums_getcon($user_id);
- //var_dump($person_nums);
- $result_small_team_arr = [];
- //1.0系统中有下级,需要在2.0中再加下级数据
- //用户三峡所有在2.0系统下面的业绩和人数 start
- $child_nums_mix = [];
- //获取当前用户
- foreach($person_nums as $v){
- $child_nums_mix[] = $this->getRecursiveChildren_getcon($v);
- }
- //去除空数组,并重新组合有数据的数组
- $filteredData_1 = array_filter($child_nums_mix, function($array) {
- return !empty($array); // 如果数组不为空,则保留
- });
- // 合并所有非空数组
- $result_small_team_arr = [];
- foreach ($filteredData_1 as $array) {
- $result_small_team_arr = array_merge($result_small_team_arr, $array);
- }
- //var_dump($result_small_team_arr);
- //获取当前用户下面在2.0中的下级所有PV
- // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
- $t_pv = $this->getteampv_getcon($result_small_team_arr);
- $get_teams_per_pv =$t_pv;
- //var_dump( $get_teams_per_pv);
- //获取当前用户下面在2.0中的下级所有人数
- // $get_teams_per_num += count($result_small_team_arr);
- //合并业绩和人数
- $person_amount += $get_teams_per_pv;
- //当前会员直属的业绩(1.0大部门)
- $t_pv = $this->getteampv_getcon($common_nums);
- $team_amount += $t_pv;
- //当前会员直属的业绩(1.0大部门)
- $p_pv = $this->getteampv_getcon($person_nums);
- $person_amount += $p_pv;
- //var_dump($team_amount,$person_amount);
- //如果当前用户是1.0用户,找到其直推所有的业绩,根据业绩找到大小部门的同时,还要比对1.0中大小部门的业绩,摘出一个最大业绩的部门是大部门,其余都是小部门()
- if($user_id < 611){
- //获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
- //例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
- $b_s = $this->getparents_child_pv11_getcon($user_id,$team_amount,$person_amount);
- $team_amount = $b_s[0];
- $person_amount = $b_s[1];
- }
- $return_data = [
- 'common_nums_pv'=> $team_amount,
- 'person_nums_pv'=> $person_amount,
- ];
- return $return_data;
- }
- /**
- * 获取该用户共建联盟
- */
- public function getCommonNums_getcon($user_id){
- //先获取共建联盟下用户的id
- $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->select()->toArray();
- $new_array_ids =[];
- foreach ($son_ids as $key => $value) {
- # code...
- $son_id = $value['id'];
- $new_array_ids = array_merge($new_array_ids,[$son_id]);
- $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
- if(count($son_value_ids) > 0) {
- $son_value_ids = array_column($son_value_ids,"id");
- $new_array_ids = array_merge($new_array_ids,$son_value_ids);
- }
- }
- return $new_array_ids;
- }
- /**
- * 获取该用户个人联盟
- */
- public function getPersonageNums_getcon($user_id){
- $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("id")->select();
- $new_array_ids =[];
- // return 3343;
- foreach ($son_ids as $key => $value) {
- # code...
- $son_id = $value['id'];
- $new_array_ids = array_merge($new_array_ids,[$son_id]);
- $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
- if(count($son_value_ids) > 0) {
- $son_value_ids = array_column($son_value_ids,"id");
- $new_array_ids = array_merge($new_array_ids,$son_value_ids);
- }
- }
- return $new_array_ids;
- }
- // 根据父级uid,递归获取所有子级UID数组
- public function getRecursiveChildren_getcon($parentUid) {
- $result = []; // 用于存储所有子级的 uid
- // 定义递归函数
- $recursion = function ($parentUid) use (&$result, &$recursion) {
- // 查询当前父级的所有直接子级
- $children = Db::name("user")
- ->where("spread_uid", $parentUid)
- ->column("uid"); // 获取子级的 uid 列表
- // 如果没有子级,直接返回
- if (empty($children)) {
- return;
- }
- // 遍历每个子级
- foreach ($children as $childUid) {
- $result[] = $childUid; // 将子级的 uid 添加到结果数组
- $recursion($childUid); // 递归查询子级的子级
- }
- };
- // 从初始父级开始递归查询
- $recursion($parentUid);
- return array_unique($result); // 返回结果数组,并去重
- }
- //只获取数组中的业绩
- public function getteampv_getcon($common_nums) {
- // // 查询当前用户及其子级的所有订单
- $orders_gongxian = Db::name("user_sign_gongxian")
- ->whereIn('status', [1])
- ->whereIn("uid", $common_nums)
- ->select();
- //var_dump( $common_nums);
- $total_gongxian = 0;
- // // 遍历订单计算业绩
- foreach ($orders_gongxian as $order) {
- if (strpos($order['mark'], "购买") !== false) {
- $total_gongxian += $order['number'];
- }
- }
- return $total_gongxian;
- // // // 查询当前用户及其子级的所有订单
- // $orders = Db::name("store_order")
- // ->whereIn('status', [0, 1, 2, 3])
- // ->whereIn("uid", $common_nums)
- // ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
- // ->select();
- // // 初始化业绩和人数
- // $totalPv = 0;
- // $totalUsers = count($common_nums); // 初始化人数为子级总数
- // // 遍历订单计算业绩
- // foreach ($orders as $order) {
- // if ($order['total_price'] == 1180) {
- // $totalPv += 700;
- // } else if ($order['total_price'] == 11800) {
- // $totalPv += 7000;
- // } else if ($order['total_price'] == 10620) {
- // $totalPv += 6300;
- // } else if ($order['total_price'] == 2360) {
- // $totalPv += 1400;
- // } else if ($order['total_price'] == 9440) {
- // $totalPv += 5600;
- // }
- // }
- // // 返回业绩和人数
- // return [
- // 'totalPv' => $totalPv,
- // 'totalUsers' => $totalUsers
- // ];
- }
- // 2.0 根据父级uid,找到当前用户下面的UID
- public function getChildren_getcon($parentUid) {
- $result = []; // 用于存储所有子级的 uid
- $children = Db::name("user")
- ->where("spread_uid", $parentUid)
- ->column("uid"); // 获取子级的 uid 列表
- return $children; // 返回结果数组,并去重
- }
- // 递归获取所有子级 UID 的业绩
- public function getTeamPv11_getcon($parentUid) {
- $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
- $children = Db::name("user")
- ->where("spread_uid", $parentUid)
- ->column("uid");
- $allChildren = [];
- foreach ($children as $childUid) {
- $allChildren[] = $childUid;
- $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
- }
- return $allChildren;
- };
- // 获取当前用户及其所有子级的 UID
- $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
- $orders_gongxian = Db::name("user_sign_gongxian")
- ->whereIn('status', [1])
- ->whereIn("uid", $allUids)
- ->select();
- $total_gongxian = 0;
- // // 遍历订单计算业绩
- foreach ($orders_gongxian as $order) {
- if (strpos($order['mark'], "购买") !== false) {
- $total_gongxian += $order['number'];
- }
- }
- return $total_gongxian;
- // // 查询当前用户及其子级的所有订单
- // $orders = Db::name("store_order")
- // ->whereIn('status', [0, 1, 2, 3])
- // ->whereIn("uid", $allUids)
- // ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
- // ->select();
- // // 计算总业绩
- // $totalPv = 0;
- // foreach ($orders as $order) {
- // switch ($order['total_price']) {
- // case 1180:
- // $totalPv += 700;
- // break;
- // case 11800:
- // $totalPv += 7000;
- // break;
- // case 10620:
- // $totalPv += 6300;
- // break;
- // case 2360:
- // $totalPv += 1400;
- // break;
- // case 9440:
- // $totalPv += 5600;
- // break;
- // }
- // }
- // return $totalPv;
- }
- //根据传递的父级数组,返回他的对应子级的个数
- public function getTeamSize_getcon($parentUids) {
- // 初始化结果数组
- $result = [];
- // 遍历每个父级ID
- foreach ($parentUids as $parentUid) {
- // 递归获取所有子级 UID
- $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
- $children = Db::name("user")
- ->where("spread_uid", $parentUid)
- ->column("uid");
- // 确保返回的是数组
- if (!is_array($children)) {
- return [];
- }
- $allChildren = [];
- foreach ($children as $childUid) {
- $allChildren[] = $childUid;
- $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
- }
- return $allChildren;
- };
- // 获取当前父级及其所有子级的 UID
- $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
- // 计算总个数(包括父级自身)
- $totalUids = count($allUids);
- // 将结果存入数组
- $result[] = [
- 'parent_uid' => $parentUid,
- 'total_count' => $totalUids
- ];
- }
- return $result;
- }
- public function processArray_getcon($array) {
- // 初始化结果数组
- $result = [
- 'max_value' => null, // 最大值
- 'max_index' => null, // 最大值的下标
- 'remaining_sum' => 0 // 剩余值的总和
- ];
- // 检查数组是否为空
- if (empty($array)) {
- return $result;
- }
- // 找出最大值及其下标
- $maxValue = $array[0];
- $maxIndex = 0;
- for ($i = 1; $i < count($array); $i++) {
- if ($array[$i] > $maxValue) {
- $maxValue = $array[$i];
- $maxIndex = $i;
- }
- }
- // 计算剩余值的总和
- $remainingSum = 0;
- for ($i = 0; $i < count($array); $i++) {
- if ($i != $maxIndex) {
- $remainingSum += $array[$i];
- }
- }
- // 将结果存入数组
- $result['max_value'] = $maxValue;
- $result['max_index'] = $maxIndex;
- $result['remaining_sum'] = $remainingSum;
- return $result;
- }
- /**
- * 获取流水信息
- */
- public function getPerformance1_getcon($user_id) {
- // $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money");
- // $amount = isset($amount) ? round($amount*0.7,2) : 0;
- // return $amount;
- $money1180Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",1180)->where("status",1)->select();
- $money1180Sum = 0;
- foreach ($money1180Records as $record) {
- $money1180Sum += $record['money'] - 300 - 180;
- }
- // var_dump($money1180Sum);
- $money11800Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",11800)->where("status",1)->select();
- //var_dump($person_nums);
- //计算个人的11800单价的业绩 集合
- $money11800Sum = 0;
- foreach ($money11800Records as $record) {
- $money11800Sum += $record['money'] - 3000 - 1800;
- }
- $money10620Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",10620)->where("status",1)->select();
- //var_dump($person_nums);
- //计算个人的11800单价的业绩 集合
- $money10620Sum = 0;
- foreach ($money10620Records as $record) {
- $money10620Sum += $record['money'] - 2700 - 1620;
- }
- // 计算除去特定值后的总和
- $otherMoneyRecords = Db::name("old_user_of_goods")->where("node_id",$user_id)->where('status', 1)->whereNotIn('money', [1180, 11800 ,10620])->select();
- $otherMoneySum = 0;
- foreach ($otherMoneyRecords as $record) {
- $otherMoneySum += $record['money'];
- }
- // 分别处理特定值的情况并加上其他值的总和
- $user_person_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
- return $user_person_amount;
- }
- //1.0用户直属的部门和2.0直属的部门,进行比较,获取大部门和小部门数据
- public function getparents_child_pv11_getcon($user_id, $bigamount, $smallamount) {
- // 获取直接下级的 UID 列表
- $get_childs = Db::name("user")
- ->where("spread_uid", $user_id)
- ->column("uid");
- // 初始化变量
- $all_departments = []; // 用于存储所有直属下级的业绩
- // 遍历每个直属下级
- foreach ($get_childs as $child) {
- // 获取当前下级及其子级
- $child_group = [$child];
- $recursive_children = $this->getRecursiveChildren_getcon($child);
- $child_group = array_merge($child_group, $recursive_children);
- // 获取当前分组的业绩
- $result = $this->getteampv_getcon($child_group);
- // 将直属下级的业绩加入数组
- $all_departments[] = $result;
- }
- // 将传入的 $bigamount 和 $smallamount 加入数组
- $all_departments[] = $bigamount;
- $all_departments[] = $smallamount;
- // 检查是否所有业绩都是 0
- if (count(array_filter($all_departments, function($value) { return $value != 0; })) == 0) {
- return [0, 0];
- }
- // 初始化最大部门和小部门
- $max_department = 0;
- $small_department = 0;
- // 遍历 $all_departments,找出最大值并累加小部门的值
- foreach ($all_departments as $department) {
- if ($department > $max_department) {
- // 如果当前部门的业绩大于最大部门的业绩,更新最大部门
- if ($max_department != 0) {
- $small_department += $max_department; // 将旧的最大值累加到小部门
- }
- $max_department = $department; // 更新最大部门
- } else {
- // 如果当前部门的业绩小于或等于最大部门的业绩,累加到小部门
- $small_department += $department;
- }
- }
- // 返回结果
- return [
- $max_department, // 大部门业绩
- $small_department // 小部门业绩
- ];
- //拿$bigamount, $smallamount业绩和get_childs产生的result业绩去对比。如果都是0.说明没有大小部门了,直接返回0,0如果只有一个数组有数据,
- // 说明只有大部门,默认返回大部门数据,小部门返回0,如果有多条数组数据是一样的,那么就是选一个,设为大部门。剩下的数据叠加设为小部门
- }
- //获取当前uesr_id下面在2.0中是否还有直接下级,并计算她的大部门和小部门
- public function getparents_child_pv_getcon($user_id){
- // 获取直接下级的 UID 列表
- //$user_id = 593;
- // $get_childs = $this->getRecursiveChildren($user_id);
- $get_childs = Db::name("user")
- ->where("spread_uid", $user_id)
- ->column("uid"); // 获取子级的 uid 列表
- //根据获得的直接推荐下级2.0,来获取他们和她伞下的子级PV。对比拿一个最大的值,设为大部门,其余的是小部门
- //获取直接下级
- $children_group = []; // 用于存储每个直接下级及其子级的分组
- // 遍历每个直接下级
- foreach ($get_childs as $child) {
- $child_group = [$child]; // 将直接下级加入分组
- $recursive_children = $this->getRecursiveChildren($child); // 获取直接下级的所有子级
- $child_group = array_merge($child_group, $recursive_children); // 将子级加入分组
- $children_group[] = $child_group; // 将分组加入最终结果
- }
- $get_teams_comm_datas = [];
- foreach($children_group as $v){
- $get_teams_comm_datas[] = $this->getteampv($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
- }
- if(count($get_teams_comm_datas) > 0){
- // 找到最大值作为大部门
- $max_value = max($get_teams_comm_datas);
- $total_sum = array_sum($get_teams_comm_datas); // 计算数组的总和
- // 小部门为总和减去最大值
- $small_department = $total_sum - $max_value;
- //返回大部门和小部门
- return [
- $max_value,
- $small_department
- ];
- }else{
- return [
- 0,
- 0
- ];
- }
- }
- /**
- * 解绑微信或支付宝
- * @return void
- */
- public function unBindVxOrAli()
- {
- $uid = $this->request->uid();
- $type = request()->param('type','');
- if(!$type) return app('json')->fail('请选择解绑类型');
- if(!$uid) return app('json')->fail('请登录');
- // 1 = 微信 2 = 支付宝 3 = 全部
- if($type == 1){
- Db::name('user')->where('uid',$uid)->update(['wechat_user_id' => 0]);
- }else if ($type == 2){
- Db::name('user')->where('uid',$uid)->update(['ali_user_id' => 0]);
- }else{
- Db::name('user')->where('uid',$uid)->update(['wechat_user_id' => 0,'ali_user_id' => 0]);
- }
- Db::name('log')->insert(['data' => '用户uid:' . $uid . '进行解绑操作type类型为' . $type]);
- return app('json')->success('解绑成功');
- }
- }
|