Merge branch 'james' of git.kingsome.cn:server/game2006api into james

This commit is contained in:
hujiabin 2022-11-02 10:52:19 +08:00
commit 7bd90cf9cb
7 changed files with 184 additions and 15 deletions

View File

@ -39,7 +39,7 @@ class BlockChain(object):
'group': 'BlockChain',
'url': 'webapp/index.php?c=BlockChain&a=active1155Nft',
'params': [
['trans_id', '', '事务id'],
['uniid', '', '芯片唯一id'],
],
'response': [
_common.RspHead(),

View File

@ -791,6 +791,7 @@ CREATE TABLE `t_transaction` (
`account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)',
`trans_id` varchar(255) NOT NULL DEFAULT '' COMMENT '事务id',
`action` int(11) NOT NULL DEFAULT '0' COMMENT 'action',
`item_uniid` int(11) NOT NULL DEFAULT '0' COMMENT '道具uniid',
`item_id` int(11) NOT NULL DEFAULT '0' COMMENT '道具id',
`status` int(11) NOT NULL DEFAULT '0' COMMENT 'status',
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
@ -840,4 +841,4 @@ CREATE TABLE `t_shop_goods` (
`buy_gift` varchar(255) DEFAULT NULL,
`normal_gift` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

2
third_party/j7 vendored

@ -1 +1 @@
Subproject commit 7533a5e7ed287378d33cb1bc3244487d33de7951
Subproject commit f98d9e8dfb0575f3c42795163bfbaa5c807a5935

@ -1 +1 @@
Subproject commit 848e05c01f44622e52996bb04dfb6b344acce1b8
Subproject commit 571b6c46137597d3bede13989e284130a070bea0

View File

@ -10,6 +10,7 @@ require_once('models/Hero.php');
require_once('models/Gun.php');
require_once('models/Nft.php');
require_once('models/Transaction.php');
require_once('models/BuyRecord.php');
require_once('services/AwardService.php');
require_once('services/PropertyChgService.php');
@ -22,6 +23,7 @@ use models\Hero;
use models\Gun;
use models\Nft;
use models\Transaction;
use models\BuyRecord;
class BlockChainController extends BaseAuthedController {
@ -47,7 +49,56 @@ class BlockChainController extends BaseAuthedController {
public function active721Nft()
{
$type = getReqVal('type', 0);
$uniid = getReqVal('uniid', 0);
switch ($type) {
case 1:
{
$heroDb = Hero::find($uuid);
if (!$heroDb) {
myself()->_rspErr(1, 'hero not found');
return;
}
if ($heroDb['token_id']) {
myself()->_rspErr(1, 'already activated');
return;
}
$tokenId = $heroDb['active_token_id'];
if (!$tokenId) {
$tokenId = BuyRecord::genOrderId
(
2006,
phpcommon\BC_FUNC_CREATION,
myself()->_getNowTime(),
myself()->_getOpenId()
);
Hero::Update($heroDb['hero_uniid'],
array(
'active_token_id' => $tokenId,
'active_count' => function () {
return 'active_count + 1';
}
));
}
$this->internalActivate721Nft($tokenId, Nft::HERO_TYPE, $heroDb['hero_uniid'], $heroDb['hero_id']);
}
break;
case 2:
{
$gunDb = Gun::find($uuid);
if (!$gunDb) {
myself()->_rspErr(1, 'gun not found');
return;
}
}
break;
default:
{
myself()->_rspErr(1, 'type param error');
return;
}
break;
}
}
public function active1155Nft()
@ -100,4 +151,47 @@ class BlockChainController extends BaseAuthedController {
}
private function internalActivate721Nft($tokenId, $tokenType, $itemUniId, $itemId)
{
$params = array(
'account_id' => myself()->_getAccountId(),
'session_id' => myself()->_getSessionId(),
'token_id' => $tokenId,
'token_type' => $tokenType,
'item_uniid' => $itemUniId,
'item_id' => $itemId
);
{
$url = self::getWeb3ServiceUrl();
$response = '';
if (!phpcommon\HttpClient::get
($url,
$params,
$response)) {
phpcommon\sendError(500, 'server internal error');
die();
return;
}
$rspObj = json_decode($response, true);
if ($rspObj['errcode'] == 0) {
$transId = $rspObj['trans_id'];
Transaction::add(
$transId,
Transaction::MINT_721_ACTION_TYPE,
$tokenId,
$tokenType,
$itemUniId,
$itemId
);
myself()->_rspData(array(
'trans_id' => $transId,
'params' => $rspObj['params']
));
} else {
phpcommon\sendError(500, 'server internal error');
return;
}
}
}
}

View File

@ -38,6 +38,11 @@ class ShopController extends BaseAuthedController {
const TOKEN_TYPE_MATIC = '101';
const TOKEN_TYPE_BNB = '102';
// 限购类型
const DAILY_BUY_LIMIT = 1;
const WEEKLY_BUY_LIMIT = 2;
const TOTAL_BUY_LIMIT = 3;
public function getGoodsList()
{
$row = SqlHelper::ormSelect(
@ -89,6 +94,59 @@ class ShopController extends BaseAuthedController {
return;
}
$buyRecordHash = ShopBuyRecord::allToHash();
$boughtTimes = 1;
switch ($row['limit_type']) {
case ShopController::DAILY_BUY_LIMIT:
{
$buyRecord = getXVal($buyRecordHash, $id);
echo "===========".json_encode($buyRecord)."-------".$row['limit_num']."..".getXVal($buyRecord, 'this_day_buy_times', 0);
$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']);
@ -111,21 +169,21 @@ class ShopController extends BaseAuthedController {
$this->internalAddItem($propertyChgService, $itemMeta);
$awardService = new services\AwardService();
$awardService->addItem($row['goods_id'], $goods_num);
ShopBuyRecord::add($row['goods_id'], $itemNum);
ShopBuyRecord::add($id, $goods_num);
$this->_decItems($costItems);
$goodsDto = array(
'goods_id' => $itemMeta['id'],
'item_id' => $itemMeta['id'],
'goods_id' => $id,
'item_id' => $row['goods_id'],
'price_info' => array(
'item_id' => $itemMeta['id'],
'item_id' => $row['goods_id'],
'cost_list' => array(),
'discount_begin_time' => phpcommon\datetimeToTimestamp($itemMeta['discount_begin']),
'discount_end_time' => phpcommon\datetimeToTimestamp($itemMeta['discount_end'])
'discount_begin_time' => phpcommon\datetimeToTimestamp($row['discount_begin']),
'discount_end_time' => phpcommon\datetimeToTimestamp($row['discount_end'])
),
'flag_icon' => $goodsMeta['tag'],
'limit_type' => $itemMeta['limit_type'],
'flag_icon' => $row['tag'],
'limit_type' => $row['limit_type'],
'bought_times' => $boughtTimes,
'total_buy_times' => $itemMeta['limit_num'],
'total_buy_times' => $row['limit_num'],
);
{
$priceInfo = mt\Item::getPriceInfo($itemMeta);

View File

@ -5,7 +5,7 @@ namespace models;
use mt;
use phpcommon\SqlHelper;
class Transaction extends BaseModel {
class Transactionxo extends BaseModel {
const MINT_721_ACTION_TYPE = 1;
const MINT_1155_ACTION_TYPE = 2;
@ -43,6 +43,22 @@ class Transaction extends BaseModel {
return $row;
}
public static function add($transId, $action, $tokenId, $tokenType, $itemUniId, $itemId)
{
SqlHelper::insert(
't_transaction',
array(
'account_id' => myself()->_getAccountId(),
'trans_id' => $transId,
'action' => $action,
'token_id' => $tokenId,
'token_type' => $tokenType,
'item_uniid' => $itemUniId,
'item_id' => $itemId,
)
);
}
public static function getActionDesc($transDb)
{
switch ($transDb['action']) {