User.php 194 KB

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