User.php 251 KB

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