Merge branch 'hjb' of git.kingsome.cn:server/game2006api into hjb
This commit is contained in:
commit
668fd3fff5
25
doc/AccountVerify.py
Normal file
25
doc/AccountVerify.py
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import _common
|
||||
|
||||
class AccountVerify(object):
|
||||
|
||||
def __init__(self):
|
||||
self.apis = [
|
||||
{
|
||||
'method': 'GET',
|
||||
'name': 'canBind',
|
||||
'desc': '是否可绑定',
|
||||
'group': 'AccountVerify',
|
||||
'url': 'webapp/index.php?c=AccountVerify&a=canBind',
|
||||
'params': [
|
||||
_common.ReqHead(),
|
||||
['guest_account', '', 'guest账号'],
|
||||
['target_plat', '', '绑定的目标账号渠道'],
|
||||
['target_account', '', '绑定的目标账号'],
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
]
|
||||
},
|
||||
]
|
@ -81,15 +81,15 @@ CREATE TABLE `t_staking` (
|
||||
`stacked_num` varchar(60) NOT NULL DEFAULT '' COMMENT 'stacked_num',
|
||||
`start_time` bigint NOT NULL DEFAULT '0' COMMENT '质押开始时间',
|
||||
`stake_time` bigint NOT NULL DEFAULT '0' COMMENT '质押结束时间',
|
||||
`unstake_time` bigint NOT NULL DEFAULT '0' COMMENT '解押结束时间',
|
||||
`redeem_time` bigint NOT NULL DEFAULT '0' COMMENT '赎回时间',
|
||||
`status` int(11) NOT NULL COMMENT '0:质押中 1:已解押',
|
||||
`txhash` varchar(255) NOT NULL DEFAULT '' COMMENT 'txhash',
|
||||
`ceg_value` double NOT NULL DEFAULT '0' COMMENT 'ceg价值',
|
||||
`ceg_reward` double NOT NULL DEFAULT '0' COMMENT '利息',
|
||||
`nft_type` int(11) NOT NULL COMMENT '',
|
||||
`nft_reward` double NOT NULL DEFAULT '0' COMMENT '利息',
|
||||
`createtime` int(11) NOT NULL COMMENT '创建时间',
|
||||
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
|
||||
PRIMARY KEY (`idx`),
|
||||
UNIQUE KEY `unikey` (`token_id`, `contract_address`, `net_id`, `start_time`)
|
||||
UNIQUE KEY `unikey` (`token_id`, `contract_address`, `net_id`, `start_time`),
|
||||
KEY `address` (`address`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8;
|
||||
|
||||
|
38
webapp/controller/AccountVerifyController.class.php
Normal file
38
webapp/controller/AccountVerifyController.class.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use phpcommon\SqlHelper;
|
||||
|
||||
class AccountVerify extends BaseController {
|
||||
|
||||
public function canBind()
|
||||
{
|
||||
$guestAccount = getReqVal('guest_account', '');
|
||||
$targetPlat = getReqVal('target_plat', '');
|
||||
$targetAccount = getReqVal('target_account', '');
|
||||
{
|
||||
$row = SqlHelper::ormSelectOne(
|
||||
myself()->_getMysql(''),
|
||||
't_user',
|
||||
array(
|
||||
'account_id' => TAPTAP_CHANNEL . '_2006_' . $guestAccount
|
||||
));
|
||||
if (!$row) {
|
||||
myself()->_rspErr(1, 'guest_account not found');
|
||||
return;
|
||||
}
|
||||
}
|
||||
{
|
||||
$row = SqlHelper::ormSelectOne(
|
||||
myself()->_getMysql(''),
|
||||
't_user',
|
||||
array(
|
||||
'account_id' => BC_POLY_CHANNEL . '_2006_' . $targetPlat . '_' . $targetAccount
|
||||
));
|
||||
if ($row) {
|
||||
myself()->_rspErr(1, 'cannot bind');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
require_once("mt/Stacking.php");
|
||||
|
||||
require_once("models/Stacking.php");
|
||||
|
||||
use models\Statcking;
|
||||
@ -62,7 +64,10 @@ class StackingController extends BaseAuthedController {
|
||||
} else {
|
||||
$info['maturity_quant'] += $row['stacked_num'];
|
||||
}
|
||||
$info['staking_value'] += $row['ceg_value'];
|
||||
$stakingMeta = mt\Staking::get($row['item_id']);
|
||||
if ($stakingMeta) {
|
||||
$info['staking_value'] += $stakingMeta['stake_value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -74,7 +79,9 @@ class StackingController extends BaseAuthedController {
|
||||
} else {
|
||||
$info['maturity_quant'] += $row['stacked_num'];
|
||||
}
|
||||
$info['staking_value'] += $row['ceg_value'];
|
||||
if ($stakingMeta) {
|
||||
$info['staking_value'] += $stakingMeta['stake_value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -104,6 +111,10 @@ class StackingController extends BaseAuthedController {
|
||||
$info['stake_time'] = $row['stake_time'];
|
||||
$info['txhash'] = $row['txhash'];
|
||||
$info['item_id'] = $row['item_id'];
|
||||
$info['stacked_days'] = intval((myself()->_getNowDaySeconds() -
|
||||
myself()->_getDaySeconds($row['start_time'])) / 3600 / 24);
|
||||
$info['remain_days'] = max(0, intval($row['stake_time'] / 3600 / 24) - $info['stacked_days']);
|
||||
|
||||
|
||||
array_push($items, $info);
|
||||
}
|
||||
@ -122,7 +133,7 @@ class StackingController extends BaseAuthedController {
|
||||
$toTime = getReqVal('to_time', '');
|
||||
$rows = Stacking::all(myself()->_getAddress());
|
||||
foreach ($rows as $row) {
|
||||
if ($row['status'] == Stacking::UNSTAKE_STATUS) {
|
||||
if ($row['status'] == Stacking::REDEEM_STATUS) {
|
||||
$info = array();
|
||||
$info['token_id'] = $row['token_id'];
|
||||
$info['token_type'] = $row['token_type'];
|
||||
@ -132,7 +143,12 @@ class StackingController extends BaseAuthedController {
|
||||
$info['stake_time'] = $row['stake_time'];
|
||||
$info['txhash'] = $row['txhash'];
|
||||
$info['item_id'] = $row['item_id'];
|
||||
$info['stacked_days'] = intval(
|
||||
(myself()->_getNowDaySeconds() -
|
||||
myself()->_getDaySeconds($row['start_time']) + 3600 *24) / 3600 / 24);
|
||||
$info['remain_days'] = max(0, intval($row['stake_time'] / 3600 / 24) - $info['stacked_days']);
|
||||
|
||||
$info['total_rewards'] = $row['stacked_days'] *$info['daily_rewards'];
|
||||
array_push($items, $info);
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,20 @@
|
||||
|
||||
namespace models;
|
||||
|
||||
require_once("mt/Staking.php");
|
||||
|
||||
use phpcommon\SqlHelper;
|
||||
|
||||
class Staking extends BaseModel {
|
||||
|
||||
const STAKING_STATUS = 0;
|
||||
const UNSTAKE_STATUS = 1;
|
||||
const REDEEM_STATUS = 1;
|
||||
|
||||
const NFT721 = 1;
|
||||
|
||||
public static function all($address)
|
||||
{
|
||||
$result = array();
|
||||
$rows = SqlHelper::ormSelect(
|
||||
myself()->_getMysql(''),
|
||||
't_staking',
|
||||
@ -16,7 +23,154 @@ class Staking extends BaseModel {
|
||||
'address' => $address
|
||||
)
|
||||
);
|
||||
return $rows;
|
||||
foreach ($rows as $row) {
|
||||
if ($row['nft_type'] == self::NFT721) {
|
||||
if (!$row['item_id']) {
|
||||
$itemId = 0;
|
||||
$tokenType = 0;
|
||||
if (!self::repair721NftInfo($row['token_id'], $row['contract_address'], $row['net_id'],
|
||||
$row['start_time'], $itemId, $tokenType)) {
|
||||
continue;
|
||||
}
|
||||
$row['item_id'] = $itemId;
|
||||
$row['token_type'] = $tokenType;
|
||||
}
|
||||
}
|
||||
array_push($result, $row);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function staked721($data, $netId)
|
||||
{
|
||||
foreach ($data['infos'] as $info) {
|
||||
$address = strtolower($info[0]);
|
||||
$nftAddress = strtolower($info[1]);
|
||||
$tokenId = $info[2];
|
||||
$startTime = $info[3];
|
||||
$stakeTime = $info[4];
|
||||
SqlHelper::upsert(
|
||||
myself()->_getMysql(''),
|
||||
't_staking',
|
||||
array(
|
||||
'token_id' => $tokenId,
|
||||
'contract_address' => $nftAddress,
|
||||
'net_id' => $netId,
|
||||
'start_time' => $nftAddress,
|
||||
),
|
||||
array(
|
||||
|
||||
),
|
||||
array(
|
||||
'address' => $address,
|
||||
'token_id' => $tokenId,
|
||||
'token_type' => '0',
|
||||
'net_id' => $netId,
|
||||
'contract_address' => $nftAddress,
|
||||
'stacked_num' => 1,
|
||||
'start_time' => $startTime,
|
||||
'stake_time' => $stakeTime,
|
||||
'status' => self::STAKING_STATUS,
|
||||
'nft_type' => self::NFT721,
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
'modifytime' => myself()->_getNowTime(),
|
||||
)
|
||||
);
|
||||
$itemId = 0;
|
||||
$tokenType = 0;
|
||||
self::repair721NftInfo($tokenId, $nftAddress, $netId, $startTime,
|
||||
$itemId, $tokenId);
|
||||
}
|
||||
}
|
||||
|
||||
public static function repair721NftInfo($tokenId, $contractAddress, $netId, $startTime,
|
||||
&$itemId, &$tokenType)
|
||||
{
|
||||
$row = SqlHelper::ormSelect(
|
||||
myself()->_getMarketMysql(),
|
||||
't_nft',
|
||||
array(
|
||||
'token_id' => $tokenId,
|
||||
'contract_address' => $contractAddress,
|
||||
'net_id' => $netId,
|
||||
)
|
||||
);
|
||||
if (!$row) {
|
||||
return false;
|
||||
}
|
||||
$itemId = $row['item_id'];
|
||||
$tokenType = $row['token_type'];
|
||||
SqlHelper::update(
|
||||
myself()->_getMysql(''),
|
||||
't_staking',
|
||||
array(
|
||||
'token_id' => $tokenId,
|
||||
'contract_address' => $contractAddress,
|
||||
'net_id' => $netId,
|
||||
'start_time' => $startTime,
|
||||
'nft_type' => self::NFT721,
|
||||
),
|
||||
array(
|
||||
'item_id' => $itemId,
|
||||
'token_type' => $tokenType
|
||||
)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function redeem721($data, $netId, $redeemTime, $txHash)
|
||||
{
|
||||
foreach ($data['infos'] as $info) {
|
||||
$address = strtolower($info[0]);
|
||||
$nftAddress = strtolower($info[1]);
|
||||
$tokenId = $info[2];
|
||||
$startTime = $info[3];
|
||||
$stakeTime = $info[4];
|
||||
SqlHelper::upsert(
|
||||
myself()->_getMysql(''),
|
||||
't_staking',
|
||||
array(
|
||||
'token_id' => $tokenId,
|
||||
'contract_address' => $nftAddress,
|
||||
'net_id' => $netId,
|
||||
'start_time' => $startTime,
|
||||
),
|
||||
array(
|
||||
'txhash' => $txHash,
|
||||
'redeem_time' => $redeemTime,
|
||||
'status' => self::REDEEM_STATUS,
|
||||
),
|
||||
array(
|
||||
'address' => $address,
|
||||
'token_id' => $tokenId,
|
||||
'token_type' => '0',
|
||||
'net_id' => $netId,
|
||||
'contract_address' => $nftAddress,
|
||||
'stacked_num' => 1,
|
||||
'start_time' => $startTime,
|
||||
'stake_time' => $stakeTime,
|
||||
'txhash' => $txHash,
|
||||
'redeem_time' => $redeemTime,
|
||||
'status' => self::REDEEM_STATUS,
|
||||
'nft_type' => self::NFT721,
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
'modifytime' => myself()->_getNowTime(),
|
||||
)
|
||||
);
|
||||
$itemId = 0;
|
||||
$tokenType = 0;
|
||||
self::repair721NftInfo($tokenId, $nftAddress, $netId, $startTime,
|
||||
$itemId, $tokenId);
|
||||
}
|
||||
}
|
||||
|
||||
public static function calcReward($row, &$reward)
|
||||
{
|
||||
$stakingMeta = mt\Staking::get($row['item_id']);
|
||||
if (!$stakingMeta) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
24
webapp/mt/Staking.php
Normal file
24
webapp/mt/Staking.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace mt;
|
||||
|
||||
use phpcommon;
|
||||
|
||||
class Staking {
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return array_key_exists($id, self::getMetaList()) ? self::getMetaList()[$id] : null;
|
||||
}
|
||||
|
||||
protected static function getMetaList()
|
||||
{
|
||||
if (!self::$metaList) {
|
||||
self::$metaList = getMetaTable('staking@staking.php');
|
||||
}
|
||||
return self::$metaList;
|
||||
}
|
||||
|
||||
protected static $metaList;
|
||||
|
||||
}
|
@ -14,6 +14,8 @@ class CallBackService extends BaseService {
|
||||
'MarketPriceUpdateOrderOk' => 'MarketPriceUpdateOrderOk',
|
||||
'inappPurchase' => 'InAppPurchase',
|
||||
'outappPurchase' => 'OutAppPurchase',
|
||||
'staked721' => 'Staked721',
|
||||
'redeem721' => 'Redeem721',
|
||||
);
|
||||
|
||||
public function dispatch($action)
|
||||
|
35
webapp/services/callback/Redeem721.php
Normal file
35
webapp/services/callback/Redeem721.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace services;
|
||||
|
||||
require_once('mt/Item.php');
|
||||
require_once('mt/Hero.php');
|
||||
require_once('mt/Parameter.php');
|
||||
|
||||
require_once ('models/Staking.php');
|
||||
|
||||
require_once ('services/callback/common/SignatureService.php');
|
||||
|
||||
use phpcommon\SqlHelper;
|
||||
|
||||
use mt\Item;
|
||||
use mt\Hero;
|
||||
use mt\Parameter;
|
||||
|
||||
use models\Staking;
|
||||
|
||||
class Redeem721
|
||||
{
|
||||
|
||||
public function process()
|
||||
{
|
||||
SignatureService::web3ServiceCheck();
|
||||
$data = json_decode(getReqVal('data', ''), true);
|
||||
$netId = getReqVal('net_id', '');
|
||||
$redeemTime = getReqVal('redeem_time', '');
|
||||
$txHash = getReqVal('txhash', '');
|
||||
Staking::redeem721($data, $netId, $redeemTime, $txHash);
|
||||
myself()->_rspOk();
|
||||
}
|
||||
|
||||
}
|
33
webapp/services/callback/Staked721.php
Normal file
33
webapp/services/callback/Staked721.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace services;
|
||||
|
||||
require_once('mt/Item.php');
|
||||
require_once('mt/Hero.php');
|
||||
require_once('mt/Parameter.php');
|
||||
|
||||
require_once ('models/Staking.php');
|
||||
|
||||
require_once ('services/callback/common/SignatureService.php');
|
||||
|
||||
use phpcommon\SqlHelper;
|
||||
|
||||
use mt\Item;
|
||||
use mt\Hero;
|
||||
use mt\Parameter;
|
||||
|
||||
use models\Staking;
|
||||
|
||||
class Staked721
|
||||
{
|
||||
|
||||
public function process()
|
||||
{
|
||||
SignatureService::web3ServiceCheck();
|
||||
$data = json_decode(getReqVal('data', ''), true);
|
||||
$netId = getReqVal('net_id', '');
|
||||
Staking::staked721($data, $netId);
|
||||
myself()->_rspOk();
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user