User.php 238 KB

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