User.php 251 KB

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