User.php 253 KB

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