diff --git a/webapp/controller/UnitTestController.class.php b/webapp/controller/UnitTestController.class.php index 4e8adda5..f78faaae 100644 --- a/webapp/controller/UnitTestController.class.php +++ b/webapp/controller/UnitTestController.class.php @@ -17,10 +17,10 @@ class UnitTestController extends BaseAuthedController { $marqueeType= getReqVal('type', 1); $loop = getReqVal('loop', 1); $interval = getReqVal('interval', 10); - + $contents= file_get_contents('php://input'); $postdata = json_decode($contents, true); - + $content = ''; if ($marqueeType == 1) { $elements = $postdata["elements"]; @@ -48,4 +48,13 @@ class UnitTestController extends BaseAuthedController { )); } + public function testVip() + { + try { + $addr = getReqVal('addr', ''); + echo json_encode(myself()->_callServiceStatic('StakingVipService', 'getDetails', $addr)); + } catch (Exception $e) { + error_log('testVip:' . $e); + } + } } diff --git a/webapp/services/StakingVipService.php b/webapp/services/StakingVipService.php new file mode 100644 index 00000000..56915cf2 --- /dev/null +++ b/webapp/services/StakingVipService.php @@ -0,0 +1,78 @@ +_getMarketMysql(), + 't_vip_user', + array( + 'account_address' => $accountAddr, + ) + ); + + $details = array( + 'lv' => 0, + 'cur' => 0, + 'target' => 0, + ); + + if ($row) { + $lv = $row['vip_lv']; + $cfg = mt\StakingVip::find($lv); + $details['lv'] = $lv; + + if ($cfg) { + $details['target'] = $cfg['thisPoint']; + $balance = phpcommon\bnInit($row['escec_balance']); + $staking = phpcommon\bnInit($row['escec_stacking']); + $convert = phpcommon\bnInit($row['escec_convert']); + + $diff = time() - $row["last_convert_time"]; + if ($diff < 0) { + $diff = 0; + } + + $eclapse = phpcommon\bnInit($diff); + $depositExec = phpcommon\bnDiv(phpcommon\bnMul($convert, $eclapse), phpcommon\bnInit(365 * 24 * 3600)); + if (phpcommon\bnCmp($depositExec, $convert) < 0) { + $depositExec = phpcommon\bnSub($convert, $depositExec); + } else { + $depositExec = phpcommon\bnInit(0); + } + + $curExec = phpcommon\bnAdd(phpcommon\bnAdd($staking, $balance), $depositExec); + + $convercurExec = intval(phpcommon\bnDiv($curExec, phpcommon\bnInit(1000 * 1000 * 1000 * 1000 * 1000 * 1000))); + + $nextlvcfg = mt\StakingVip::find($lv + 1); + $upgraderequire = $cfg['require']; + if ($nextlvcfg && $convercurExec >= $upgraderequire) { + $details['cur'] = intval($cfg['thisPoint'] * ($convercurExec - $upgraderequire) / ($nextlvcfg['require'] - $upgraderequire)); + } else if (!$nextlvcfg) { + $details['cur'] = $details['target']; + } + } + } else { + $cfg = mt\StakingVip::find(0); + if ($cfg) { + $details['target'] = $cfg['thisPoint']; + } + } + + return $details; + } +}