This commit is contained in:
aozhiwei 2022-01-27 14:43:08 +08:00
parent d702a908cd
commit bae8c2dd35
4 changed files with 81 additions and 5 deletions

View File

@ -80,6 +80,23 @@ CREATE TABLE `t_nft` (
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `t_buy_record`
--
DROP TABLE IF EXISTS `t_buy_record`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_buy_record` (
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
`blobdata` mediumblob COMMENT 'blobdata',
`buyer_address` mediumblob COMMENT 'buyer_address',
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `t_log`
--

@ -1 +1 @@
Subproject commit 80d7222a4a31e295fffbf09fc1880940b4eb630b
Subproject commit e42a7b732c806c4cc8060a101f9a13ae579039e3

View File

@ -9,10 +9,14 @@ require_once('mt/Hero.php');
require_once('models/BoxOrder.php');
require_once('models/Nft.php');
require_once('models/BuyRecord.php');
require_once('phpcommon/bchelper.php');
use phpcommon\SqlHelper;
use models\BoxOrder;
use models\Nft;
use models\BuyRecord;
class MarketController extends BaseController {
@ -120,6 +124,7 @@ class MarketController extends BaseController {
$nonce = getReqVal('nonce', '');
$signature = getReqVal('signature', '');
$gameId = 2006;
$funcId = 1;
if (empty($type) ||
empty($buyerAddress) ||
@ -137,14 +142,29 @@ class MarketController extends BaseController {
return;
}
if (!phpcommon\isValidBcGameId($gameId)) {
myself()->_rspErr(500, 'server internal error');
return;
}
if (!phpcommon\isValidBcTime(myself()->_getNowTime())) {
myself()->_rspErr(500, 'server internal error');
return;
}
if (!phpcommon\isValidBcFunc($funcId)) {
myself()->_rspErr(500, 'server internal error');
return;
}
/*if (!$this->isTestMode() && BoxOrder::isBuyed($buyerAddress, $currBatchMeta['batch_id'])) {
myself()->_rspErr(1, 'account can only choose 1 hero to purchase');
return;
}*/
$orderId = BuyRecord::genOrderId($gameId, $funcId, myself()->_getNowTime(), $buyerAddress);
$tokenId = $orderId;
if ($this->isTestMode()) {
$orderId = myself()->_getNowTime();
$tokenId = $orderId;
$itemId = $type;
SqlHelper::insert
(myself()->_getMarketMysql(),
@ -181,8 +201,6 @@ class MarketController extends BaseController {
)
);
} else {
$orderId = myself()->_getNowTime();
$tokenId = $orderId;
$itemId = $type;
SqlHelper::insert
(myself()->_getMarketMysql(),

View File

@ -0,0 +1,41 @@
<?php
namespace models;
require_once('phpcommon/bchelper.php');
use mt;
use phpcommon\SqlHelper;
class BuyRecord extends BaseModel {
public static function genOrderId($gameId, $funcId, $time, $buyerAddress)
{
SqlHelper::insert
(myself()->_getMarketMysql(),
't_buy_record',
array(
'blobdata' => json_encode($_REQUEST),
'buyer_address' => $buyerAddress,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
$lastIdx = SqlHelper::getLastInsertId(myself()->_getMarketMysql());
if (empty($lastIdx)) {
die(json_encode(array(
'errcode' => 500,
'errmsg' => 'server internal error'
)));
}
$orderId = phpcommon\genOrderId($gameId, $funcId, $time, $lastIdx);
if (!phpcommon\isValidOrderId($orderId)) {
die(json_encode(array(
'errcode' => 500,
'errmsg' => 'server internal error'
)));
}
return $orderId;
}
}