User.php 236 KB

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