User.php 250 KB

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