User.php 252 KB

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