User.php 174 KB

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