User.php 192 KB

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