User.php 252 KB

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