User.php 237 KB

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