User.php 196 KB

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