User.php 252 KB

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