User.php 237 KB

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