User.php 253 KB

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