Merge branch 'star' of git.kingsome.cn:server/game2006api into star
This commit is contained in:
commit
1066e64c23
@ -64,8 +64,8 @@ class BlockChain(object):
|
||||
'group': 'BlockChain',
|
||||
'url': 'webapp/index.php?c=BlockChain&a=active721Nft',
|
||||
'params': [
|
||||
['type', 0, '1:英雄 2:枪械'],
|
||||
['uniid', 0, '唯一id'],
|
||||
['type', 0, '1:英雄 2:枪械 3:芯片'],
|
||||
['uniid', '', '唯一id'],
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
@ -73,99 +73,4 @@ class BlockChain(object):
|
||||
['!params', [''], '合约参数列表'],
|
||||
]
|
||||
},
|
||||
{
|
||||
'name': 'evolve721Nft',
|
||||
'desc': 'nft进阶(英雄,武器)',
|
||||
'group': 'BlockChain',
|
||||
'url': 'webapp/index.php?c=BlockChain&a=evolve721Nft',
|
||||
'params': [
|
||||
['type', 0, '1:英雄 2:枪械'],
|
||||
['token_id1', 0, 'tokenid1'],
|
||||
['token_id2', 0, 'tokenid2'],
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
['trans_id', '', '事务id'],
|
||||
['!params', [''], '合约参数列表'],
|
||||
]
|
||||
},
|
||||
{
|
||||
'name': 'evolveChip',
|
||||
'desc': '芯片进阶',
|
||||
'group': 'BlockChain',
|
||||
'url': 'webapp/index.php?c=BlockChain&a=evolveChip',
|
||||
'params': [
|
||||
['token_id1', 0, 'tokenid1'],
|
||||
['token_ids', '', 'tokenids材料id(|分割)'],
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
['trans_id', '', '事务id'],
|
||||
['!params', [''], '合约参数列表'],
|
||||
]
|
||||
},
|
||||
{
|
||||
'name': 'mintShardBatchUser',
|
||||
'desc': '碎片生成',
|
||||
'group': 'BlockChain',
|
||||
'url': 'webapp/index.php?c=BlockChain&a=mintShardBatchUser',
|
||||
'params': [
|
||||
['item_uniid', 0, '道具唯一id'],
|
||||
['num', 0, '使用数量'],
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
['trans_id', '', '事务id'],
|
||||
['!params', [''], '合约参数列表'],
|
||||
]
|
||||
},
|
||||
{
|
||||
'name': 'shardMixByUser',
|
||||
'desc': '碎片合成',
|
||||
'group': 'BlockChain',
|
||||
'url': 'webapp/index.php?c=BlockChain&a=shardMixByUser',
|
||||
'params': [
|
||||
['item_id', '', '指定的英雄id或者武器id'],
|
||||
['token_ids', '', 'token_ids多个用|分割'],
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
['trans_id', '', '事务id'],
|
||||
['!params', [''], '合约参数列表'],
|
||||
]
|
||||
},
|
||||
{
|
||||
'name': 'pluginChipBatch',
|
||||
'desc': '批量装上芯片',
|
||||
'group': 'BlockChain',
|
||||
'url': 'webapp/index.php?c=BlockChain&a=pluginChipBatch',
|
||||
'params': [
|
||||
['type', 0, '1:英雄 2:枪械'],
|
||||
['token_id', '', 'token_id'],
|
||||
['chip_ids', '', '需要卸下的chip token_ids多个用|分割'],
|
||||
['slot_ids', '', '槽位0-3多个用|分割'],
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
['trans_id', '', '事务id'],
|
||||
['!params', [''], '合约参数列表'],
|
||||
]
|
||||
},
|
||||
{
|
||||
'name': 'unplugChip',
|
||||
'desc': '卸下芯片',
|
||||
'group': 'BlockChain',
|
||||
'url': 'webapp/index.php?c=BlockChain&a=unplugChip',
|
||||
'params': [
|
||||
['type', 0, '1:英雄 2:枪械'],
|
||||
['token_id', '', 'token_id'],
|
||||
['chip_ids', '', '需要卸下的chip token_ids多个用|分割'],
|
||||
['slot_ids', '', '槽位0-3多个用|分割'],
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
['trans_id', '', '事务id'],
|
||||
['!params', [''], '合约参数列表'],
|
||||
]
|
||||
}
|
||||
]
|
||||
|
47
doc/Shop.py
47
doc/Shop.py
@ -96,5 +96,50 @@ class Shop(object):
|
||||
['goods_chg', _common.NewGoods(), '购买后更新商品的最新信息(可能为null客户端需要做容错处理)'],
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
'name': 'buyGoodsDirect',
|
||||
'desc': '直接购买(充值,gold)',
|
||||
'group': 'Shop',
|
||||
'url': 'webapp/index.php?c=Shop&a=buyGoodsDirect',
|
||||
'params': [
|
||||
['account_id', '', '账号id'],
|
||||
['order_id', '', '订单id'],
|
||||
['id', 0, '商品唯一id,参见shopGoods表'],
|
||||
['token_type', '', "选用币种"],
|
||||
['goods_num', 0, '商品数量'],
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
]
|
||||
},
|
||||
{
|
||||
'name': 'startGoodsDirect',
|
||||
'desc': '发起一个 直接购买(充值,gold)',
|
||||
'group': 'Shop',
|
||||
'url': 'webapp/index.php?c=Shop&a=startGoodsDirect',
|
||||
'params': [
|
||||
_common.ReqHead(),
|
||||
['id', 0, '商品唯一id,参见shopGoods表'],
|
||||
['token_type', '', "选用币种"],
|
||||
['goods_num', 0, '商品数量'],
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
['order_id', '', '订单id'],
|
||||
]
|
||||
},
|
||||
{
|
||||
'name': 'statusGoodsDirect',
|
||||
'desc': '查询 直接购买(充值,gold) 状态',
|
||||
'group': 'Shop',
|
||||
'url': 'webapp/index.php?c=Shop&a=statusGoodsDirect',
|
||||
'params': [
|
||||
_common.ReqHead(),
|
||||
['order_id', '', '订单id'],
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
['status', 0, '订单状态 0:未支付 1:已支付 2:支付失败'],
|
||||
]
|
||||
},
|
||||
]
|
||||
|
@ -205,6 +205,8 @@ class User(object):
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
['is_retry', 0, '是否重试 0:不用重试 1:重试'],
|
||||
['retry_time', 0, '重试时间(单位秒)'],
|
||||
]
|
||||
},
|
||||
]
|
||||
|
@ -246,6 +246,8 @@ CREATE TABLE `t_chip` (
|
||||
`state` int(11) NOT NULL DEFAULT '0' COMMENT '0:已购买 1:免费(GIFT标签)',
|
||||
`inlay_state` varchar(60) COMMENT '所镶嵌的芯片页id:1|2|3',
|
||||
`rand_attr` mediumblob COMMENT '随机属性',
|
||||
`active_token_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'active_token_id',
|
||||
`active_count` int(11) NOT NULL DEFAULT '0' COMMENT 'active_count',
|
||||
`activate` int(11) NOT NULL DEFAULT '0' COMMENT '是否激活 1:已初始激活',
|
||||
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
||||
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
|
||||
@ -845,6 +847,7 @@ DROP TABLE IF EXISTS `t_transaction`;
|
||||
CREATE TABLE `t_transaction` (
|
||||
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
|
||||
`account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)',
|
||||
`address` varchar(60) NOT NULL DEFAULT '' COMMENT 'address',
|
||||
`trans_id` varchar(255) NOT NULL DEFAULT '' COMMENT '事务id',
|
||||
`action` int(11) NOT NULL DEFAULT '0' COMMENT 'action',
|
||||
`token_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'token_id',
|
||||
@ -859,7 +862,8 @@ CREATE TABLE `t_transaction` (
|
||||
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
|
||||
PRIMARY KEY (`idx`),
|
||||
UNIQUE KEY `trans_id` (`trans_id`),
|
||||
KEY `account_id` (`account_id`)
|
||||
KEY `account_id` (`account_id`),
|
||||
KEY `address` (`address`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
begin;
|
||||
|
||||
alter table t_user add column `address` varchar(60) COMMENT 'address';
|
||||
alter table t_user add KEY `address` (`address`);
|
||||
alter table t_user add UNIQUE KEY `address` (`address`);
|
||||
|
||||
insert into version (version) values(2023060501);
|
||||
|
||||
|
11
sql/migrate_230607_01.sql
Normal file
11
sql/migrate_230607_01.sql
Normal file
@ -0,0 +1,11 @@
|
||||
begin;
|
||||
|
||||
alter table t_chip add column `active_token_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'active_token_id';
|
||||
alter table t_chip add column `active_count` int(11) NOT NULL DEFAULT '0' COMMENT 'active_count';
|
||||
|
||||
alter table t_transaction add column `address` varchar(60) NOT NULL DEFAULT '' COMMENT 'address';
|
||||
alter table t_transaction add KEY `address` (`address`);
|
||||
|
||||
insert into version (version) values(2023060701);
|
||||
|
||||
commit;
|
@ -35,7 +35,7 @@ use models\Chip;
|
||||
|
||||
class BaseAuthedController extends BaseController {
|
||||
|
||||
private $accountId = '';
|
||||
protected $accountId = '';
|
||||
private $sessionId = '';
|
||||
private $mysqlConn = null;
|
||||
private $address = null;
|
||||
@ -106,7 +106,7 @@ class BaseAuthedController extends BaseController {
|
||||
}*/
|
||||
}
|
||||
|
||||
private function _userLvRestriction(){
|
||||
protected function _userLvRestriction(){
|
||||
$userDb = $this->_getOrmUserInfo();
|
||||
$controller = getReqVal('c', '');
|
||||
switch ($controller){
|
||||
@ -165,10 +165,17 @@ class BaseAuthedController extends BaseController {
|
||||
return phpcommon\extractChannel($this->_getAccountId());
|
||||
}
|
||||
|
||||
public function _getAddress(){
|
||||
public function _getAddress()
|
||||
{
|
||||
return $this->_getOpenId();
|
||||
}
|
||||
|
||||
public function _isValidAddress()
|
||||
{
|
||||
$address = $this->_getAddress();
|
||||
return !empty($address);
|
||||
}
|
||||
|
||||
public function _getSessionId()
|
||||
{
|
||||
return $this->sessionId;
|
||||
|
@ -36,8 +36,7 @@ class BlockChainController extends BaseAuthedController {
|
||||
public function _handlePre()
|
||||
{
|
||||
parent::_handlePre();
|
||||
if (getReqVal('a', '') != 'getTransactionList' &&
|
||||
myself()->_getChannel() != BC_CHANNEL) {
|
||||
if (getReqVal('a', '') != 'getTransactionList' && !myself()->_isValidAddress()) {
|
||||
die(json_encode(array(
|
||||
'errcode' => 501,
|
||||
'errmsg' => 'you are not a wallet user'
|
||||
@ -69,6 +68,50 @@ class BlockChainController extends BaseAuthedController {
|
||||
));
|
||||
}
|
||||
|
||||
public function reportResult()
|
||||
{
|
||||
$transId = getReqVal('trans_id', '');
|
||||
$result = getReqVal('result', '');
|
||||
error_log($result);
|
||||
Transaction::reportResult($transId, $result);
|
||||
myself()->_rspOk();
|
||||
}
|
||||
|
||||
public function getJumpInfo()
|
||||
{
|
||||
$transId = getReqVal('trans_id', '');
|
||||
if (!$transId){
|
||||
myself()->_rspErr(101, 'trans_id paramater error');
|
||||
return;
|
||||
}
|
||||
$tranDb= Transaction::find($transId);
|
||||
if (!$tranDb){
|
||||
myself()->_rspErr(101, 'trans_id paramater error');
|
||||
return;
|
||||
}
|
||||
$data = Transaction::getJumpInfo($tranDb);
|
||||
myself()->_rspData($data);
|
||||
}
|
||||
|
||||
public function getTransactionInfo()
|
||||
{
|
||||
$transId = getReqVal('trans_id', '');
|
||||
if (!$transId){
|
||||
myself()->_rspErr(101, 'trans_id paramater error');
|
||||
return;
|
||||
}
|
||||
$tranDb= Transaction::find($transId);
|
||||
myself()->_rspData(array(
|
||||
'data' => array(
|
||||
'trans_id' => $tranDb['trans_id'],
|
||||
'item_id' => $tranDb['item_id'],
|
||||
'action' => Transaction::getActionDesc($tranDb),
|
||||
'status' => Transaction::getStatusDesc($tranDb),
|
||||
'time' => $tranDb['createtime'],
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public function active721Nft()
|
||||
{
|
||||
$type = getReqVal('type', 0);
|
||||
@ -92,7 +135,7 @@ class BlockChainController extends BaseAuthedController {
|
||||
2006,
|
||||
phpcommon\BC_FUNC_CREATION,
|
||||
myself()->_getNowTime(),
|
||||
myself()->_getOpenId()
|
||||
myself()->_getAddress()
|
||||
);
|
||||
Hero::Update($heroDb['hero_uniid'],
|
||||
array(
|
||||
@ -123,7 +166,7 @@ class BlockChainController extends BaseAuthedController {
|
||||
2006,
|
||||
phpcommon\BC_FUNC_CREATION,
|
||||
myself()->_getNowTime(),
|
||||
myself()->_getOpenId()
|
||||
myself()->_getAddress()
|
||||
);
|
||||
Gun::Update($gunDb['gun_uniid'],
|
||||
array(
|
||||
@ -136,177 +179,35 @@ class BlockChainController extends BaseAuthedController {
|
||||
$this->internalActivate721Nft($tokenId, Nft::EQUIP_TYPE, $gunDb['gun_uniid'], $gunDb['gun_id']);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
case 3:
|
||||
{
|
||||
myself()->_rspErr(1, 'type param error');
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function reportResult()
|
||||
{
|
||||
$transId = getReqVal('trans_id', '');
|
||||
$result = getReqVal('result', '');
|
||||
error_log($result);
|
||||
Transaction::reportResult($transId, $result);
|
||||
myself()->_rspOk();
|
||||
}
|
||||
|
||||
public function evolve721Nft()
|
||||
{
|
||||
error_log(json_encode($_REQUEST));
|
||||
$type = getReqVal('type', '');
|
||||
$tokenId1 = getReqVal('token_id1', '');
|
||||
$tokenId2 = getReqVal('token_id2', '');
|
||||
switch ($type) {
|
||||
case 1:
|
||||
{
|
||||
$nft1 = Hero::findByTokenId($tokenId1);
|
||||
$nft2 = Hero::findByTokenId($tokenId2);
|
||||
if (!$nft1 || !$nft2) {
|
||||
myself()->_rspErr(1, 'token paramater error');
|
||||
$chipDb = Chip::find($uniid);
|
||||
if (!$chipDb) {
|
||||
myself()->_rspErr(1, 'chip not found');
|
||||
return;
|
||||
}
|
||||
//CEG扣除
|
||||
{
|
||||
$costItems = array(
|
||||
array(
|
||||
'item_id' => V_ITEM_GOLD,
|
||||
'item_num' => \services\FormulaService::Hero_Advanced_CEG_Expend($nft1['quality']+1)
|
||||
),
|
||||
array(
|
||||
'item_id' => V_ITEM_DIAMOND,
|
||||
'item_num' => \services\FormulaService::Hero_Advanced_CEC_Expend($nft1['quality']+1)
|
||||
)
|
||||
);
|
||||
$lackItem = null;
|
||||
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
||||
return;
|
||||
}
|
||||
$decFeeCb = function ($transId) use ($costItems){
|
||||
myself()->_decItems($costItems);
|
||||
foreach ($costItems as $costItem){
|
||||
TransactionPrefee::add($transId,$costItem);
|
||||
}
|
||||
};
|
||||
}
|
||||
//英雄进阶概率
|
||||
$rnd = rand(1, 100);
|
||||
$probability = \services\FormulaService::Hero_Advanced_Probability($nft1['quality'] + 1)*100;
|
||||
if ($rnd > $probability) {
|
||||
$result = 0;
|
||||
}else{
|
||||
$result = 1;
|
||||
}
|
||||
error_log(
|
||||
json_encode(
|
||||
array(
|
||||
'NftEvent'=> 'Hero',
|
||||
'nft' => $nft1,
|
||||
'probability' => $probability,
|
||||
'result' => $result
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->internalBcCall(
|
||||
array(
|
||||
'c' => 'BcService',
|
||||
'a' => 'evolve721Nft',
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'session_id' => myself()->_getSessionId(),
|
||||
'account' => myself()->_getOpenId(),
|
||||
'type' => $type,
|
||||
'token_id1' => $tokenId1,
|
||||
'token_id2' => $tokenId2
|
||||
),
|
||||
array(
|
||||
'action' => Transaction::EVOLVE_721_ACTION_TYPE,
|
||||
'tokenId' => $nft1['token_id'],
|
||||
'tokenType' => Nft::HERO_TYPE,
|
||||
'itemUniId' => $nft1['hero_uniid'],
|
||||
'itemId' => $nft1['hero_id'],
|
||||
'result' => $result,
|
||||
),
|
||||
$decFeeCb
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
$nft1 = Gun::findByTokenId($tokenId1);
|
||||
$nft2 = Gun::findByTokenId($tokenId2);
|
||||
if (!$nft1 || !$nft2) {
|
||||
myself()->_rspErr(1, 'token paramater error');
|
||||
if ($chipDb['token_id']) {
|
||||
myself()->_rspErr(1, 'already activated');
|
||||
return;
|
||||
}
|
||||
//CEG扣除
|
||||
{
|
||||
$costItems = array(
|
||||
array(
|
||||
'item_id' => V_ITEM_GOLD,
|
||||
'item_num' => \services\FormulaService::Weapon_Advanced_CEG_Expend($nft1['quality']+1)
|
||||
),
|
||||
array(
|
||||
'item_id' => V_ITEM_DIAMOND,
|
||||
'item_num' => \services\FormulaService::Weapon_Advanced_CEC_Expend($nft1['quality']+1)
|
||||
)
|
||||
);
|
||||
|
||||
$lackItem = null;
|
||||
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
||||
return;
|
||||
}
|
||||
$decFeeCb = function ($transId) use ($costItems){
|
||||
myself()->_decItems($costItems);
|
||||
foreach ($costItems as $costItem){
|
||||
TransactionPrefee::add($transId,$costItem);
|
||||
}
|
||||
};
|
||||
$tokenId = $chipDb['active_token_id'];
|
||||
if (!$tokenId) {
|
||||
$tokenId = BuyRecord::genOrderId
|
||||
(
|
||||
2006,
|
||||
phpcommon\BC_FUNC_CREATION,
|
||||
myself()->_getNowTime(),
|
||||
myself()->_getAddress()
|
||||
);
|
||||
Chip::Update($chipDb['chip_uniid'],
|
||||
array(
|
||||
'active_token_id' => $tokenId,
|
||||
'active_count' => function () {
|
||||
return 'active_count + 1';
|
||||
}
|
||||
));
|
||||
}
|
||||
//武器进阶概率
|
||||
$rnd = rand(1, 100);
|
||||
$probability = \services\FormulaService::Weapon_Advanced_Probability($nft1['quality'] + 1)*100;
|
||||
if ($rnd > $probability) {
|
||||
$result = 0;
|
||||
}else{
|
||||
$result = 1;
|
||||
}
|
||||
error_log(
|
||||
json_encode(
|
||||
array(
|
||||
'NftEvent'=> 'Gun',
|
||||
'nft' => $nft1,
|
||||
'probability' => $probability,
|
||||
'result' => $result
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->internalBcCall(
|
||||
array(
|
||||
'c' => 'BcService',
|
||||
'a' => 'evolve721Nft',
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'session_id' => myself()->_getSessionId(),
|
||||
'account' => myself()->_getOpenId(),
|
||||
'type' => $type,
|
||||
'token_id1' => $tokenId1,
|
||||
'token_id2' => $tokenId2
|
||||
),
|
||||
array(
|
||||
'action' => Transaction::EVOLVE_721_ACTION_TYPE,
|
||||
'tokenId' => $nft1['token_id'],
|
||||
'tokenType' => Nft::EQUIP_TYPE,
|
||||
'itemUniId' => $nft1['gun_uniid'],
|
||||
'itemId' => $nft1['gun_id'],
|
||||
'result' => $result,
|
||||
),
|
||||
$decFeeCb
|
||||
);
|
||||
$this->internalActivate721Nft($tokenId, Nft::CHIP_TYPE, $chipDb['chip_uniid'], $chipDb['item_id']);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -314,538 +215,10 @@ class BlockChainController extends BaseAuthedController {
|
||||
myself()->_rspErr(1, 'type param error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function evolveChip()
|
||||
{
|
||||
$tokenId1 = getReqVal('token_id1', '');
|
||||
$tokenIds = explode('|', getReqVal('token_ids', ''));
|
||||
|
||||
if (in_array($tokenId1, $tokenIds) || count($tokenIds) <= 0) {
|
||||
myself()->_rspErr(1, 'token_ids paramater error');
|
||||
return;
|
||||
}
|
||||
|
||||
$nftDb = Chip::findByTokenId($tokenId1);
|
||||
if (!$nftDb) {
|
||||
myself()->_rspErr(1, 'token_id1 paramater error');
|
||||
return;
|
||||
}
|
||||
//芯片进阶概率
|
||||
$upgrade_cost = \services\FormulaService::getChipUpgradeCost($nftDb['chip_grade']+1);
|
||||
if ($upgrade_cost==0){
|
||||
$this->_rspErr(1, 'token_id1 Error in calculation formula');
|
||||
return;
|
||||
}
|
||||
$cumulative_cost = 0;
|
||||
foreach ($tokenIds as $val){
|
||||
$chip_param = Chip::findByTokenId($val);
|
||||
$cumulative_cost += \services\FormulaService::getChipCumulativeCost($chip_param['chip_grade']);
|
||||
}
|
||||
$rnd = rand(1,100);
|
||||
$probability = $cumulative_cost/$upgrade_cost * 100;
|
||||
if ($rnd > $probability) {
|
||||
$result = 0;
|
||||
}else{
|
||||
$result = 1;
|
||||
}
|
||||
error_log(
|
||||
json_encode(
|
||||
array(
|
||||
'NftEvent'=> 'Chip',
|
||||
'nft' => $nftDb,
|
||||
'upgrade_cost' => $upgrade_cost,
|
||||
'cumulative_cost' => $cumulative_cost,
|
||||
'probability' => $probability,
|
||||
'result' => $result
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->internalBcCall(
|
||||
array(
|
||||
'c' => 'BcService',
|
||||
'a' => 'evolveChip',
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'session_id' => myself()->_getSessionId(),
|
||||
'account' => myself()->_getOpenId(),
|
||||
'token_id' => $tokenId1,
|
||||
'token_ids' => implode('|', $tokenIds)
|
||||
),
|
||||
array(
|
||||
'action' => Transaction::EVOLVE_CHIP_ACTION_TYPE,
|
||||
'tokenId' => $tokenId1,
|
||||
'tokenType' => 0,
|
||||
'itemUniId' => $nftDb['chip_uniid'],
|
||||
'itemId' => $nftDb['item_id'],
|
||||
'result' => $result,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function mintShardBatchUser()
|
||||
{
|
||||
$itemUniId = getReqVal('item_uniid', 0);
|
||||
$num = getReqVal('num', 0);
|
||||
$itemDb = Bag::findByUniId($itemUniId);
|
||||
if ($num <= 0) {
|
||||
myself()->_rspErr(1, 'num paramater error');
|
||||
return;
|
||||
}
|
||||
error_log(json_encode(
|
||||
$_REQUEST
|
||||
));
|
||||
if (!$itemDb || $itemDb['item_num'] < $num) {
|
||||
myself()->_rspErr(1, 'item not enough');
|
||||
return;
|
||||
}
|
||||
$itemMeta = mt\Item::get($itemDb['item_id']);
|
||||
switch ($itemMeta['type']) {
|
||||
case mt\Item::FRAGMENT_BOX_TYPE:
|
||||
{
|
||||
$this->internalOpenFragmentBox($itemDb, $itemMeta, $num);
|
||||
}
|
||||
break;
|
||||
case mt\Item::CHIP_BOX_TYPE:
|
||||
{
|
||||
$this->internalOpenChipBox($itemDb, $itemMeta, $num);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
myself()->_rspErr(1, 'item type error');
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function shardMixByUser()
|
||||
{
|
||||
$tokenIds = explode('|', getReqVal('token_ids', ''));
|
||||
$itemId = getReqVal('item_id', '');
|
||||
|
||||
$tokenId = '';
|
||||
$tokenType = '';
|
||||
|
||||
{
|
||||
$heros = array();
|
||||
$guns = array();
|
||||
$specHeros = array();
|
||||
$specGuns = array();
|
||||
mt\Item::groupFragment($tokenIds, $heros, $guns, $specHeros, $specGuns);
|
||||
error_log(json_encode(array(
|
||||
$tokenIds,
|
||||
$heros,
|
||||
$guns,
|
||||
$specHeros,
|
||||
$specGuns,
|
||||
json_encode($_REQUEST)
|
||||
)));
|
||||
if (count($tokenIds) != (
|
||||
count($heros) + count($guns) + count($specHeros) + count($specGuns)
|
||||
)) {
|
||||
myself()->_rspErr(101, 'token_ids paramater error');
|
||||
return;
|
||||
}
|
||||
if (count($specHeros) + count($specGuns) > 1) {
|
||||
myself()->_rspErr(101, 'token_ids paramater error');
|
||||
return;
|
||||
}
|
||||
if (count($heros) > 0 && count($guns) > 0) {
|
||||
myself()->_rspErr(101, 'token_ids paramater error');
|
||||
return;
|
||||
}
|
||||
if (count($heros) > 0) {
|
||||
if (count($heros) != 8 || count($specGuns) > 0) {
|
||||
myself()->_rspErr(101, 'token_ids paramater error');
|
||||
return;
|
||||
}
|
||||
$tokenType = Nft::HERO_TYPE;
|
||||
} else if (count($guns) > 0) {
|
||||
if (count($guns) != 8 || count($specHeros) > 0) {
|
||||
myself()->_rspErr(101, 'token_ids paramater error');
|
||||
return;
|
||||
}
|
||||
$tokenType = Nft::EQUIP_TYPE;
|
||||
} else {
|
||||
myself()->_rspErr(101, 'token_ids paramater error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$tokenId = BuyRecord::genOrderId
|
||||
(
|
||||
2006,
|
||||
phpcommon\BC_FUNC_CREATION,
|
||||
myself()->_getNowTime(),
|
||||
myself()->_getOpenId()
|
||||
);
|
||||
//CEG扣除
|
||||
{
|
||||
if ($tokenType == Nft::HERO_TYPE){
|
||||
$costItems = array(
|
||||
array(
|
||||
'item_id' => V_ITEM_GOLD,
|
||||
'item_num' => 100
|
||||
),
|
||||
);
|
||||
$lackItem = null;
|
||||
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
||||
return;
|
||||
}
|
||||
$decFeeCb = function ($transId) use ($costItems){
|
||||
myself()->_decItems($costItems);
|
||||
foreach ($costItems as $costItem){
|
||||
TransactionPrefee::add($transId,$costItem);
|
||||
}
|
||||
};
|
||||
// $this->_decItems($costItems);
|
||||
}
|
||||
if ($tokenType == Nft::EQUIP_TYPE){
|
||||
$costItems = array(
|
||||
array(
|
||||
'item_id' => V_ITEM_GOLD,
|
||||
'item_num' => 30
|
||||
),
|
||||
);
|
||||
$lackItem = null;
|
||||
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
||||
return;
|
||||
}
|
||||
$decFeeCb = function ($transId) use ($costItems){
|
||||
myself()->_decItems($costItems);
|
||||
foreach ($costItems as $costItem){
|
||||
TransactionPrefee::add($transId,$costItem);
|
||||
}
|
||||
};
|
||||
// $this->_decItems($costItems);
|
||||
}
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'c' => 'BcService',
|
||||
'a' => 'shardMixByUser',
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'session_id' => myself()->_getSessionId(),
|
||||
'account' => myself()->_getOpenId(),
|
||||
'token_id' => $tokenId,
|
||||
'token_type' => $tokenType,
|
||||
'item_id' => $itemId,
|
||||
'token_ids' => implode('|', $tokenIds)
|
||||
);
|
||||
{
|
||||
error_log(3333333);
|
||||
$url = self::getWeb3ServiceUrl();
|
||||
$response = '';
|
||||
if (!phpcommon\HttpClient::get
|
||||
($url,
|
||||
$params,
|
||||
$response)) {
|
||||
error_log(444444);
|
||||
myself()->_rspErr(500, 'server internal error');
|
||||
return;
|
||||
}
|
||||
error_log($response);
|
||||
$rspObj = json_decode($response, true);
|
||||
if ($rspObj['errcode'] == 0) {
|
||||
$transId = $rspObj['trans_id'];
|
||||
Transaction::add(
|
||||
$transId,
|
||||
Transaction::SHARD_MIX_BY_USER_ACTION_TYPE,
|
||||
$tokenId,
|
||||
$tokenType,
|
||||
0,
|
||||
$itemId,
|
||||
1
|
||||
);
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
$propertyChgService->addUserChg();
|
||||
$decFeeCb($transId);
|
||||
myself()->_rspData(array(
|
||||
'trans_id' => $transId,
|
||||
'params' => $rspObj['params'],
|
||||
'property_chg' => $propertyChgService->toDto(),
|
||||
));
|
||||
error_log(5555555555);
|
||||
} else {
|
||||
error_log(22222222222222);
|
||||
myself()->_rspErr(500, 'server internal error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function pluginChipBatch()
|
||||
{
|
||||
$type = getReqVal('type', '');
|
||||
$tokenId = getReqVal('token_id', '');
|
||||
$chipIds = explode('|', getReqVal('chip_ids', ''));
|
||||
$slotIds = explode('|', getReqVal('slot_ids', ''));
|
||||
|
||||
error_log(json_encode($_REQUEST));
|
||||
if (count($chipIds) != count($slotIds) ||
|
||||
count($chipIds) < 0) {
|
||||
myself()->_rspErr(101, 'chip_ids paramater error');
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case 1:
|
||||
{
|
||||
$heroDb = Hero::findByTokenId($tokenId);
|
||||
foreach ($chipIds as $chipId) {
|
||||
$chipDb = Chip::findByTokenId($chipId);
|
||||
if (!$chipDb) {
|
||||
myself()->_rspErr(101, 'chip_ids paramater error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!$heroDb) {
|
||||
myself()->_rspErr(101, 'token_id paramater error');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->internalBcCall(
|
||||
array(
|
||||
'c' => 'BcService',
|
||||
'a' => 'pluginChip',
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'session_id' => myself()->_getSessionId(),
|
||||
'account' => myself()->_getOpenId(),
|
||||
'token_id' => $tokenId,
|
||||
'token_type' => Nft::HERO_TYPE,
|
||||
'chip_ids' => implode('|', $chipIds),
|
||||
'slot_ids' => implode('|', $slotIds),
|
||||
),
|
||||
array(
|
||||
'action' => Transaction::PLUGIN_CHIP_ACTION_TYPE,
|
||||
'tokenId' => $tokenId,
|
||||
'tokenType' => Nft::HERO_TYPE,
|
||||
'itemUniId' => $heroDb['hero_uniid'],
|
||||
'itemId' => $heroDb['hero_id'],
|
||||
'result' => 1,
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
$gunDb = Gun::findByTokenId($tokenId);
|
||||
foreach ($chipIds as $chipId) {
|
||||
$chipDb = Chip::findByTokenId($chipId);
|
||||
if (!$chipDb) {
|
||||
myself()->_rspErr(101, 'chip_ids paramater error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!$gunDb) {
|
||||
myself()->_rspErr(101, 'token_id paramater error');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->internalBcCall(
|
||||
array(
|
||||
'c' => 'BcService',
|
||||
'a' => 'pluginChip',
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'session_id' => myself()->_getSessionId(),
|
||||
'account' => myself()->_getOpenId(),
|
||||
'token_id' => $tokenId,
|
||||
'token_type' => Nft::EQUIP_TYPE,
|
||||
'chip_ids' => implode('|', $chipIds),
|
||||
'slot_ids' => implode('|', $slotIds),
|
||||
),
|
||||
array(
|
||||
'action' => Transaction::PLUGIN_CHIP_ACTION_TYPE,
|
||||
'tokenId' => $tokenId,
|
||||
'tokenType' => Nft::EQUIP_TYPE,
|
||||
'itemUniId' => $gunDb['gun_uniid'],
|
||||
'itemId' => $gunDb['gun_id'],
|
||||
'result' => 1,
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function unplugChip()
|
||||
{
|
||||
$type = getReqVal('type', '');
|
||||
$tokenId = getReqVal('token_id', '');
|
||||
$chipIds = explode('|', getReqVal('chip_ids', ''));
|
||||
$slotIds = explode('|', getReqVal('slot_ids', ''));
|
||||
|
||||
if (count($chipIds) != count($slotIds) ||
|
||||
count($chipIds) < 0) {
|
||||
myself()->_rspErr(101, 'chip_ids paramater error');
|
||||
return;
|
||||
}
|
||||
|
||||
//CEG扣除
|
||||
{
|
||||
$costSum = 0;
|
||||
foreach ($chipIds as $chipId){
|
||||
$chipDb = Chip::getChipByTokenId($chipId);
|
||||
if ($chipDb){
|
||||
$tiliDiff = $chipDb['strength_max'] - $chipDb['strength'];
|
||||
$costSum += \services\FormulaService::Chip_Demount_Mint($tiliDiff);
|
||||
}
|
||||
}
|
||||
$decFeeCb = null;
|
||||
if ($costSum > 0){
|
||||
$costItems = array(
|
||||
array(
|
||||
'item_id' => V_ITEM_GOLD,
|
||||
'item_num' => $costSum
|
||||
),
|
||||
);
|
||||
$lackItem = null;
|
||||
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
||||
return;
|
||||
}
|
||||
$decFeeCb = function ($transId) use ($costItems, $chipIds){
|
||||
myself()->_decItems($costItems);
|
||||
error_log(json_encode($costItems));
|
||||
foreach ($costItems as $costItem){
|
||||
TransactionPrefee::add($transId,$costItem);
|
||||
}
|
||||
|
||||
foreach ($chipIds as $chipId){
|
||||
$chipDb = Chip::getChipByTokenId($chipId);
|
||||
$items = array(
|
||||
'token_id' => $chipDb['token_id'],
|
||||
'token_type' => $chipDb['chip_type'],
|
||||
'item_id' => self::TEST_ITEM_ID,
|
||||
'item_num' => $chipDb['strength_max'] - $chipDb['strength']
|
||||
);
|
||||
Chip::update($chipId,array(
|
||||
'strength'=>$chipDb['strength_max']
|
||||
));
|
||||
TransactionPrefee::add($transId,$items);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case 1:
|
||||
{
|
||||
$heroDb = Hero::findByTokenId($tokenId);
|
||||
if (!$heroDb) {
|
||||
myself()->_rspErr(101, 'token_id paramater error');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->internalBcCall(
|
||||
array(
|
||||
'c' => 'BcService',
|
||||
'a' => 'unplugChip',
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'session_id' => myself()->_getSessionId(),
|
||||
'account' => myself()->_getOpenId(),
|
||||
'token_id' => $tokenId,
|
||||
'token_type' => Nft::HERO_TYPE,
|
||||
'chip_ids' => implode('|', $chipIds),
|
||||
'slot_ids' => implode('|', $slotIds),
|
||||
),
|
||||
array(
|
||||
'action' => Transaction::UNPLUG_CHIP_ACTION_TYPE,
|
||||
'tokenId' => $tokenId,
|
||||
'tokenType' => Nft::HERO_TYPE,
|
||||
'itemUniId' => $heroDb['hero_uniid'],
|
||||
'itemId' => $heroDb['hero_id'],
|
||||
'result' => 1,
|
||||
),
|
||||
$decFeeCb
|
||||
);
|
||||
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
$gunDb = Gun::findByTokenId($tokenId);
|
||||
if (!$gunDb) {
|
||||
myself()->_rspErr(101, 'token_id paramater error');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->internalBcCall(
|
||||
array(
|
||||
'c' => 'BcService',
|
||||
'a' => 'unplugChip',
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'session_id' => myself()->_getSessionId(),
|
||||
'account' => myself()->_getOpenId(),
|
||||
'token_id' => $tokenId,
|
||||
'token_type' => Nft::EQUIP_TYPE,
|
||||
'chip_ids' => implode('|', $chipIds),
|
||||
'slot_ids' => implode('|', $slotIds),
|
||||
),
|
||||
array(
|
||||
'action' => Transaction::UNPLUG_CHIP_ACTION_TYPE,
|
||||
'tokenId' => $tokenId,
|
||||
'tokenType' => Nft::EQUIP_TYPE,
|
||||
'itemUniId' => $gunDb['gun_uniid'],
|
||||
'itemId' => $gunDb['gun_id'],
|
||||
'result' => 1,
|
||||
),
|
||||
$decFeeCb
|
||||
);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
myself()->_rspErr(101, 'type paramater error');
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function getJumpInfo(){
|
||||
$transId = getReqVal('trans_id', '');
|
||||
if (!$transId){
|
||||
myself()->_rspErr(101, 'trans_id paramater error');
|
||||
return;
|
||||
}
|
||||
$tranDb= Transaction::find($transId);
|
||||
if (!$tranDb){
|
||||
myself()->_rspErr(101, 'trans_id paramater error');
|
||||
return;
|
||||
}
|
||||
$data = Transaction::getJumpInfo($tranDb);
|
||||
myself()->_rspData($data);
|
||||
}
|
||||
|
||||
public function getTransactionInfo(){
|
||||
$transId = getReqVal('trans_id', '');
|
||||
if (!$transId){
|
||||
myself()->_rspErr(101, 'trans_id paramater error');
|
||||
return;
|
||||
}
|
||||
$tranDb= Transaction::find($transId);
|
||||
myself()->_rspData(array(
|
||||
'data' => array(
|
||||
'trans_id' => $tranDb['trans_id'],
|
||||
'item_id' => $tranDb['item_id'],
|
||||
'action' => Transaction::getActionDesc($tranDb),
|
||||
'status' => Transaction::getStatusDesc($tranDb),
|
||||
'time' => $tranDb['createtime'],
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
private function internalActivate721Nft($tokenId, $tokenType, $itemUniId, $itemId)
|
||||
{
|
||||
$params = array(
|
||||
@ -853,7 +226,7 @@ class BlockChainController extends BaseAuthedController {
|
||||
'a' => 'activate721Nft',
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'session_id' => myself()->_getSessionId(),
|
||||
'account' => myself()->_getOpenId(),
|
||||
'account' => myself()->_getAddress(),
|
||||
'token_id' => $tokenId,
|
||||
'token_type' => $tokenType,
|
||||
'item_uniid' => $itemUniId,
|
||||
@ -894,170 +267,6 @@ class BlockChainController extends BaseAuthedController {
|
||||
}
|
||||
}
|
||||
|
||||
private function internalOpenChipBox($itemDb, $itemMeta, $num) {
|
||||
$tokenId = BuyRecord::genOrderId
|
||||
(
|
||||
2006,
|
||||
phpcommon\BC_FUNC_CREATION,
|
||||
myself()->_getNowTime(),
|
||||
myself()->_getOpenId()
|
||||
);
|
||||
$params = array(
|
||||
'c' => 'BcService',
|
||||
'a' => 'activate1155Nft',
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'session_id' => myself()->_getSessionId(),
|
||||
'account' => myself()->_getOpenId(),
|
||||
'token_id' => $tokenId,
|
||||
'item_uniid' => $itemDb['item_uniid'],
|
||||
'item_id' => $itemDb['item_id'],
|
||||
'num' => $num,
|
||||
);
|
||||
{
|
||||
$url = self::getWeb3ServiceUrl();
|
||||
$response = '';
|
||||
if (!phpcommon\HttpClient::get
|
||||
($url,
|
||||
$params,
|
||||
$response)) {
|
||||
myself()->_rspErr(500, 'server internal error');
|
||||
die();
|
||||
return;
|
||||
}
|
||||
error_log($response);
|
||||
$tokenType = Nft::CHIP_TYPE;
|
||||
$rspObj = json_decode($response, true);
|
||||
if ($rspObj['errcode'] == 0) {
|
||||
$transId = $rspObj['trans_id'];
|
||||
Transaction::add(
|
||||
$transId,
|
||||
Transaction::MINT_1155_ACTION_TYPE,
|
||||
$tokenId,
|
||||
Nft::CHIP_TYPE,
|
||||
$itemDb['item_uniid'],
|
||||
$itemDb['item_id'],
|
||||
1
|
||||
);
|
||||
Bag::decItemByUnIid($itemDb['item_uniid'], $num);
|
||||
TransactionPrefee::add($transId, array(
|
||||
'item_uniid' => $itemDb['item_uniid'],
|
||||
'item_id' => $itemDb['item_id'],
|
||||
'item_num' => $num,
|
||||
));
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
$propertyChgService->addBagChg();
|
||||
myself()->_rspData(array(
|
||||
'trans_id' => $transId,
|
||||
'params' => $rspObj['params'],
|
||||
'property_chg' => $propertyChgService->toDto()
|
||||
));
|
||||
} else {
|
||||
myself()->_rspErr(500, 'server internal error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function internalOpenFragmentBox($itemDb, $itemMeta, $num) {
|
||||
$tokenId = $itemMeta['include_item_id'];
|
||||
$itemId = $itemMeta['include_item_id'];
|
||||
$params = array(
|
||||
'c' => 'BcService',
|
||||
'a' => 'mintShardBatchUser',
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'session_id' => myself()->_getSessionId(),
|
||||
'account' => myself()->_getOpenId(),
|
||||
'token_id' => $tokenId,
|
||||
'item_uniid' => $itemDb['item_uniid'],
|
||||
'item_id' => $itemId,
|
||||
'num' => $num
|
||||
);
|
||||
{
|
||||
$url = self::getWeb3ServiceUrl();
|
||||
$response = '';
|
||||
if (!phpcommon\HttpClient::get
|
||||
($url,
|
||||
$params,
|
||||
$response)) {
|
||||
myself()->_rspErr(500, 'server internal error');
|
||||
die();
|
||||
return;
|
||||
}
|
||||
error_log($response);
|
||||
$tokenType = Nft::FRAGMENT_TYPE;
|
||||
$rspObj = json_decode($response, true);
|
||||
if ($rspObj['errcode'] == 0) {
|
||||
$transId = $rspObj['trans_id'];
|
||||
Transaction::add(
|
||||
$transId,
|
||||
Transaction::MINT_SHARD_BATCH_ACTION_TYPE,
|
||||
$tokenId,
|
||||
$tokenType,
|
||||
$itemDb['item_uniid'],
|
||||
$itemId,
|
||||
1
|
||||
);
|
||||
Bag::decItemByUnIid($itemDb['item_uniid'], $num);
|
||||
TransactionPrefee::add($transId, array(
|
||||
'item_uniid' => $itemDb['item_uniid'],
|
||||
'item_id' => $itemDb['item_id'],
|
||||
'item_num' => $num,
|
||||
));
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
$propertyChgService->addBagChg();
|
||||
myself()->_rspData(array(
|
||||
'trans_id' => $transId,
|
||||
'params' => $rspObj['params'],
|
||||
'property_chg' => $propertyChgService->toDto()
|
||||
));
|
||||
} else {
|
||||
myself()->_rspErr(500, 'server internal error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function internalBcCall($params, $transParams, $cb = null) {
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
$propertyChgService->addUserChg();
|
||||
$url = self::getWeb3ServiceUrl();
|
||||
$response = '';
|
||||
if (!phpcommon\HttpClient::get
|
||||
($url,
|
||||
$params,
|
||||
$response)) {
|
||||
myself()->_rspErr(500, 'server internal error');
|
||||
die();
|
||||
return;
|
||||
}
|
||||
error_log($response);
|
||||
$rspObj = json_decode($response, true);
|
||||
if ($rspObj['errcode'] == 0) {
|
||||
$transId = $rspObj['trans_id'];
|
||||
Transaction::add(
|
||||
$transId,
|
||||
$transParams['action'],
|
||||
$transParams['tokenId'],
|
||||
$transParams['tokenType'],
|
||||
$transParams['itemUniId'],
|
||||
$transParams['itemId'],
|
||||
$transParams['result']
|
||||
);
|
||||
if ($cb) {
|
||||
$cb($transId);
|
||||
}
|
||||
myself()->_rspData(array(
|
||||
'trans_id' => $transId,
|
||||
'params' => $rspObj['params'],
|
||||
'property_chg' => $propertyChgService->toDto(),
|
||||
));
|
||||
} else {
|
||||
myself()->_rspErr(500, 'server internal error');
|
||||
die();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static function getWeb3ServiceUrl()
|
||||
{
|
||||
if (SERVER_ENV == _TEST) {
|
||||
|
@ -39,7 +39,7 @@ class FirstTopupController extends BaseAuthedController
|
||||
);
|
||||
}
|
||||
|
||||
private function begin()
|
||||
public function begin()
|
||||
{
|
||||
$conn = myself()->_getMysql('');
|
||||
|
||||
@ -113,7 +113,7 @@ class FirstTopupController extends BaseAuthedController
|
||||
if ($complete == 1) {
|
||||
$this->_setV(TN_FIRST_TUPOP_STATUS, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
$this->_rspData(
|
||||
array(
|
||||
'group' => $group,
|
||||
@ -152,14 +152,18 @@ class FirstTopupController extends BaseAuthedController
|
||||
array('account_id' => myself()->_getAccountId())
|
||||
);
|
||||
|
||||
// 0 未领取 1 可领取 2 已领取
|
||||
$status = [(int)$row['status1'], (int)$row['status2'], (int)$row['status3']];
|
||||
$time = $row['createtime'];
|
||||
$status = [0, 0, 0];
|
||||
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
if ($status[$i] < 2) {
|
||||
// 检测是否到了可以领取的时间
|
||||
$status[$i] = $this->getStatus($i, $time);
|
||||
if ($row) {
|
||||
// 0 未领取 1 可领取 2 已领取
|
||||
$status = [(int)$row['status1'], (int)$row['status2'], (int)$row['status3']];
|
||||
$time = $row['createtime'];
|
||||
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
if ($status[$i] < 2) {
|
||||
// 检测是否到了可以领取的时间
|
||||
$status[$i] = $this->getStatus($i, $time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,11 +43,29 @@ class ShopController extends BaseAuthedController
|
||||
const TOKEN_TYPE_MATIC = '101';
|
||||
const TOKEN_TYPE_BNB = '102';
|
||||
|
||||
const TOKEN_TYPE_DSD = '99';
|
||||
|
||||
// 限购类型
|
||||
const DAILY_BUY_LIMIT = 1;
|
||||
const WEEKLY_BUY_LIMIT = 2;
|
||||
const TOTAL_BUY_LIMIT = 3;
|
||||
|
||||
public function _handlePre()
|
||||
{
|
||||
// if (SERVER_ENV == _ONLINE) {
|
||||
// if (getReqVal('client_uuid', '') != '499af8a0-a1bc-0b0e-dc79-a42cb3f103dc') {
|
||||
// if ((getReqVal('c', '') != 'Battle')) {
|
||||
// phpcommon\sendError(1001, 'session expiration');
|
||||
// die();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
if(getReqVal('a', '') != 'buyGoodsDirect'){
|
||||
parent::_handlePre();
|
||||
}
|
||||
}
|
||||
|
||||
public function getGoodsList()
|
||||
{
|
||||
$goodsList = mt\ShopGoods::all();
|
||||
@ -248,6 +266,265 @@ class ShopController extends BaseAuthedController
|
||||
}
|
||||
}
|
||||
|
||||
public function buyGoodsDirect()
|
||||
{
|
||||
// let repdata = {
|
||||
// account_id: string
|
||||
// order_id: string
|
||||
// status: string
|
||||
// id: string
|
||||
// txhash: string
|
||||
// }
|
||||
// 我返回给你这些数据和一个sign字段,
|
||||
// sign使用上面 repdata 按key 顺序排后, 组成key1=val1&key2=val2后, 使用hmac_sha256 hash, key是 iG4Rpsa)6U31$H#^T85$^^3
|
||||
|
||||
|
||||
$token_type = getReqVal('token_type', '');
|
||||
$goods_num = getReqVal('goods_num', 0);
|
||||
|
||||
$order_id = 28;
|
||||
error_log("buyGoodsDirect");
|
||||
|
||||
$conn = myself()->_getMysql('');
|
||||
|
||||
$order = SqlHelper::selectOne($conn, 't_shop_buy_order', array('account_id', 'item_id', 'goods_num', 'status'), array('idx' => $order_id));
|
||||
|
||||
$id = $order['item_id'];
|
||||
$goods_num = $order['goods_num'];
|
||||
$status = $order['status'];
|
||||
|
||||
$row = mt\ShopGoods::get($id);
|
||||
|
||||
$desired_token_type = $row['token_type'];
|
||||
$check_token_type = splitStr1($desired_token_type);
|
||||
$token_pos = array_search($token_type, $check_token_type, true);
|
||||
if (!in_array($token_type, $check_token_type)) {
|
||||
$this->_rspErr(1, "token_type parameter error, desired_token_type: {$desired_token_type}");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($goods_num > $row['max_amount']) {
|
||||
$this->_rspErr(1, "goods_num parameter error, max_amount: {$row['max_amount']}");
|
||||
return;
|
||||
}
|
||||
|
||||
// 这里命名混乱了, 购买个数,一捆个数命名冲突
|
||||
$goods_count = $row['goods_num'];
|
||||
|
||||
$buyRecordHash = ShopBuyRecord::allToHash();
|
||||
$boughtTimes = 1;
|
||||
switch ($row['limit_type']) {
|
||||
case ShopController::DAILY_BUY_LIMIT: {
|
||||
$buyRecord = getXVal($buyRecordHash, $id);
|
||||
$boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1 : 1;
|
||||
if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $row['limit_num']) {
|
||||
$this->_rspErr(2, 'Has reached the maximum number of purchase restrictions today');
|
||||
return;
|
||||
}
|
||||
if ($row['limit_num'] <= 0) {
|
||||
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ShopController::WEEKLY_BUY_LIMIT: {
|
||||
$buyRecord = getXVal($buyRecordHash, $id);
|
||||
$boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1;
|
||||
if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $row['limit_num']) {
|
||||
$this->_rspErr(2, 'The maximum number of purchase restrictions this week has been reached');
|
||||
return;
|
||||
}
|
||||
if ($row['limit_num'] <= 0) {
|
||||
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ShopController::TOTAL_BUY_LIMIT: {
|
||||
$buyRecord = getXVal($buyRecordHash, $id);
|
||||
$boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1;
|
||||
if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $row['limit_num']) {
|
||||
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
|
||||
return;
|
||||
}
|
||||
if ($row['limit_num'] <= 0) {
|
||||
$this->_rspErr(2, 'he maximum number of purchase restrictions has been reached');
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$price_array = splitStr1($row['price']);
|
||||
$discount_array = splitStr1($row['discount']);
|
||||
|
||||
$need_price = $price_array[$token_pos];
|
||||
$discount = $discount_array[$token_pos];
|
||||
|
||||
$discount_begin = strtotime($row['discount_begin'] . ' UTC');
|
||||
$discount_end = strtotime($row['discount_end'] . ' UTC');
|
||||
$nowTime = $this->_getNowTime();
|
||||
|
||||
if ($nowTime >= $discount_begin && $nowTime < $discount_end) {
|
||||
|
||||
$need_price = ceil($need_price * ($discount / 100.0));
|
||||
}
|
||||
|
||||
$costItemId = $this->getCostItemIdByTokenType($token_type);
|
||||
|
||||
switch ($token_type) {
|
||||
case ShopController::TOKEN_TYPE_CEG:
|
||||
case ShopController::TOKEN_TYPE_CEC:
|
||||
$costItems = $this->makeCostItems($costItemId, $goods_num * $need_price);
|
||||
$lackItem = null;
|
||||
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
|
||||
return;
|
||||
}
|
||||
|
||||
$itemMeta = mt\Item::get($row['goods_id']);
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
for ($i = 0; $i < $goods_num; $i++) {
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count);
|
||||
}
|
||||
$awardService = new services\AwardService();
|
||||
$awardService->addItem($row['goods_id'], $goods_num);
|
||||
ShopBuyRecord::add($id, $goods_num);
|
||||
$this->_decItems($costItems);
|
||||
$goodsDto = array(
|
||||
'goods_id' => $id,
|
||||
'item_id' => $row['goods_id'],
|
||||
'price_info' => array(
|
||||
'item_id' => $row['goods_id'],
|
||||
'cost_list' => array(),
|
||||
'discount_begin_time' => phpcommon\datetimeToTimestamp($row['discount_begin']),
|
||||
'discount_end_time' => phpcommon\datetimeToTimestamp($row['discount_end'])
|
||||
),
|
||||
'flag_icon' => $row['tag'],
|
||||
'limit_type' => $row['limit_type'],
|
||||
'bought_times' => $boughtTimes,
|
||||
'total_buy_times' => $row['limit_num'],
|
||||
); {
|
||||
$priceInfo = mt\Item::getPriceInfo($itemMeta);
|
||||
if (!empty($priceInfo)) {
|
||||
$goodsDto['price_info'] = $priceInfo['price_info'];
|
||||
}
|
||||
}
|
||||
$propertyChgService->addUserChg();
|
||||
$this->_rspData(
|
||||
array(
|
||||
'award' => $awardService->toDto(),
|
||||
'property_chg' => $propertyChgService->toDto(),
|
||||
'goods_chg' => $goodsDto
|
||||
)
|
||||
);
|
||||
break;
|
||||
|
||||
case ShopController::TOKEN_TYPE_BCEG:
|
||||
break;
|
||||
|
||||
case ShopController::TOKEN_TYPE_USDT:
|
||||
case ShopController::TOKEN_TYPE_USDC:
|
||||
|
||||
$itemMeta = mt\Item::get($row['goods_id']);
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
for ($i = 0; $i < $goods_num; $i++) {
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count);
|
||||
}
|
||||
$awardService = new services\AwardService();
|
||||
$awardService->addItem($row['goods_id'], $goods_num);
|
||||
ShopBuyRecord::add($id, $goods_num);
|
||||
|
||||
// $goodsDto = array(
|
||||
// 'goods_id' => $id,
|
||||
// 'item_id' => $row['goods_id'],
|
||||
// 'price_info' => array(
|
||||
// 'item_id' => $row['goods_id'],
|
||||
// 'cost_list' => array(),
|
||||
// 'discount_begin_time' => phpcommon\datetimeToTimestamp($row['discount_begin']),
|
||||
// 'discount_end_time' => phpcommon\datetimeToTimestamp($row['discount_end'])
|
||||
// ),
|
||||
// 'flag_icon' => $row['tag'],
|
||||
// 'limit_type' => $row['limit_type'],
|
||||
// 'bought_times' => $boughtTimes,
|
||||
// 'total_buy_times' => $row['limit_num'],
|
||||
// ); {
|
||||
// $priceInfo = mt\Item::getPriceInfo($itemMeta);
|
||||
// if (!empty($priceInfo)) {
|
||||
// $goodsDto['price_info'] = $priceInfo['price_info'];
|
||||
// }
|
||||
// }
|
||||
// $propertyChgService->addUserChg();
|
||||
|
||||
$this->_rspOk();
|
||||
break;
|
||||
case ShopController::TOKEN_TYPE_BUSD:
|
||||
case ShopController::TOKEN_TYPE_MATIC:
|
||||
case ShopController::TOKEN_TYPE_BNB:
|
||||
default:
|
||||
$this->_rspErr(1, "token_type is unsupport, {$token_type}");
|
||||
}
|
||||
}
|
||||
|
||||
public function startGoodsDirect() {
|
||||
$id = getReqVal('id', 0);
|
||||
$token_type = getReqVal('token_type', '');
|
||||
$goods_num = getReqVal('goods_num', 0);
|
||||
|
||||
$conn = myself()->_getMysql('');
|
||||
|
||||
$chk = SqlHelper::insert(
|
||||
$conn,
|
||||
't_shop_buy_order',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
'item_id' => $id,
|
||||
'goods_num' => $goods_num,
|
||||
'status' => 0, // 0-客户端申请了订单 1-订单完成 2-订单失败
|
||||
)
|
||||
);
|
||||
if ($chk) {
|
||||
$lastId = $this->lastInsertId($conn);
|
||||
$this->_rspData(
|
||||
array(
|
||||
'order_id' => $lastId,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function statusGoodsDirect() {
|
||||
$order_id = getReqVal('order_id', '');
|
||||
|
||||
$conn = myself()->_getMysql('');
|
||||
|
||||
$row = SqlHelper::selectOne(
|
||||
$conn,
|
||||
't_shop_buy_order',
|
||||
array('status'),
|
||||
array(
|
||||
'idx' => $order_id,
|
||||
)
|
||||
);
|
||||
if ($row) {
|
||||
$this->_rspData(
|
||||
array(
|
||||
'status' => $row['status'],
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->_rspData(
|
||||
array(
|
||||
'status' => 0,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function getCostItemIdByTokenType($token_type)
|
||||
{
|
||||
switch ($token_type) {
|
||||
@ -730,11 +1007,16 @@ class ShopController extends BaseAuthedController
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
Bag::addItem($itemMeta['id'], $count);
|
||||
$propertyChgService->addBagChg();
|
||||
// 充值就尝试开启首充活动
|
||||
if ($itemMeta['id'] == 10001) {
|
||||
$this->beginFirstTupop();
|
||||
if ($this->_isVirtualItem($itemMeta['id'])) {
|
||||
$this->_addVirtualItem($itemMeta['id'], $count, null, $propertyChgService);
|
||||
$propertyChgService->addUserChg();
|
||||
// 充值就尝试开启首充活动
|
||||
if ($itemMeta['id'] == 10001) {
|
||||
$this->beginFirstTupop();
|
||||
}
|
||||
} else {
|
||||
Bag::addItem($itemMeta['id'], $count);
|
||||
$propertyChgService->addBagChg();
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -811,4 +1093,11 @@ class ShopController extends BaseAuthedController
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private function lastInsertId($conn)
|
||||
{
|
||||
$row = $conn->execQueryOne('SELECT LAST_INSERT_ID() as lastId;', array());
|
||||
return $row['lastId'];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -805,8 +805,43 @@ class UserController extends BaseAuthedController {
|
||||
|
||||
public function updateAddressBind()
|
||||
{
|
||||
$hero_uniid = getReqVal('jwt', '');
|
||||
$this->_rspOk();
|
||||
error_log(json_encode($_REQUEST));
|
||||
$jwt = getReqVal('jwt', '');
|
||||
|
||||
$arr = explode('.', $jwt);
|
||||
if (count($arr) < 3) {
|
||||
phpcommon\sendError(1, 'token error');
|
||||
die();
|
||||
return;
|
||||
}
|
||||
$header = base64_decode($arr[0]);
|
||||
$payload = base64_decode($arr[1]);
|
||||
$sign = base64_decode($arr[2]);
|
||||
$data = json_decode($payload, true);
|
||||
|
||||
$url = 'https://pay.cebggame.com/wallet/info?';
|
||||
$params = array(
|
||||
'token' => $jwt
|
||||
);
|
||||
$response = '';
|
||||
if (!phpcommon\HttpClient::get
|
||||
($url,
|
||||
$params,
|
||||
$response)) {
|
||||
myself()->_rspErr(500, 'server internal error');
|
||||
die();
|
||||
return;
|
||||
}
|
||||
error_log($response);
|
||||
$rspObj = json_decode($response, true);
|
||||
User::Update(array(
|
||||
'address' => $rspObj['data']['address']
|
||||
));
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
$propertyChgService->addUserChg();
|
||||
$this->_rspData(array(
|
||||
'property_chg' => $propertyChgService->toDto(),
|
||||
));
|
||||
}
|
||||
|
||||
private function dampingElo($userInfo){
|
||||
|
@ -26,7 +26,7 @@ class Transaction extends BaseModel {
|
||||
myself()->_getSelfMysql(),
|
||||
't_transaction',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'address' => myself()->_getAddress(),
|
||||
'client_confirmed' => 1
|
||||
)
|
||||
);
|
||||
@ -39,7 +39,7 @@ class Transaction extends BaseModel {
|
||||
myself()->_getSelfMysql(),
|
||||
't_transaction',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'address' => myself()->_getAddress(),
|
||||
'trans_id' => $transId,
|
||||
)
|
||||
);
|
||||
@ -65,6 +65,7 @@ class Transaction extends BaseModel {
|
||||
't_transaction',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'address' => myself()->_getAddress(),
|
||||
'trans_id' => $transId,
|
||||
'action' => $action,
|
||||
'token_id' => $tokenId,
|
||||
@ -152,6 +153,16 @@ class Transaction extends BaseModel {
|
||||
);
|
||||
}
|
||||
break;
|
||||
case Nft::EQUIP_CHIP:
|
||||
{
|
||||
$jumpInfo = array(
|
||||
'action' => 3,//武器激活(武器详情)
|
||||
'params' => array(
|
||||
$transDb['token_id']
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
@ -325,7 +336,7 @@ class Transaction extends BaseModel {
|
||||
myself()->_getSelfMysql(),
|
||||
't_transaction',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'address' => myself()->_getAddress(),
|
||||
'trans_id' => $transId
|
||||
),
|
||||
array(
|
||||
|
Loading…
x
Reference in New Issue
Block a user