Merge branch 'yd' into hjb
This commit is contained in:
commit
c00f2c099a
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
78
webapp/services/StakingVipService.php
Normal file
78
webapp/services/StakingVipService.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace services;
|
||||
|
||||
require_once('mt/StakingVip.php');
|
||||
require_once('phpcommon/bignumber.php');
|
||||
|
||||
use mt;
|
||||
use phpcommon;
|
||||
|
||||
class StakingVipService extends BaseService
|
||||
{
|
||||
public static function getDetails($accountAddr)
|
||||
{
|
||||
if (empty($accountAddr) || !is_string($accountAddr)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$row = phpcommon\SqlHelper::ormSelectOne(
|
||||
myself()->_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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user