1
This commit is contained in:
parent
5cc75ff718
commit
2e93e6e384
@ -455,6 +455,7 @@ class Nft(object):
|
||||
['type', 0, '类型 0:英雄 1:枪支 2:芯片'],
|
||||
['token_id', '', '代币id?'],
|
||||
['status', 0, '状态'],
|
||||
['inventory', 0, '库存(剩余数量)'],
|
||||
['owner_address', '', '所有者地址'],
|
||||
['owner_id', '', '所有者'],
|
||||
['image_avatar', '', '图片'],
|
||||
|
@ -19,23 +19,6 @@ CREATE TABLE `version` (
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `t_boxes`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `t_boxes`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `t_boxes` (
|
||||
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
|
||||
`box_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'box_id',
|
||||
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
||||
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
|
||||
PRIMARY KEY (`idx`),
|
||||
UNIQUE KEY `box_id` (`box_id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `t_goods`
|
||||
--
|
||||
@ -45,12 +28,38 @@ DROP TABLE IF EXISTS `t_goods`;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `t_goods` (
|
||||
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
|
||||
`goods_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'goods_id',
|
||||
`goods_num` int(11) NOT NULL DEFAULT '0' COMMENT 'goods数量',
|
||||
`goods_id` int(11) NOT NULL DEFAULT '0' COMMENT 'goods id',
|
||||
`goods_idx` int(11) NOT NULL DEFAULT '0' COMMENT 'goods idx',
|
||||
`item_id` int(11) NOT NULL DEFAULT '0' COMMENT '道具id',
|
||||
`state` int(11) NOT NULL DEFAULT '0' COMMENT 'state 0:待支付 1:支付成功',
|
||||
`buy_count` int(11) NOT NULL DEFAULT '0' COMMENT 'buy count',
|
||||
`last_buyer` varchar(60) NOT NULL DEFAULT '' COMMENT '最后购买者',
|
||||
`last_buy_time` int(11) NOT NULL DEFAULT '0' COMMENT '最后一次购买时间',
|
||||
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
||||
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
|
||||
PRIMARY KEY (`idx`),
|
||||
UNIQUE KEY `box_id` (`box_id`)
|
||||
UNIQUE KEY `goods_id_goods_idx` (`goods_id`, `goods_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_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',
|
||||
`buyer` varchar(60) NOT NULL DEFAULT '' COMMENT 'buyer',
|
||||
`goods_id` int(11) NOT NULL DEFAULT '0' COMMENT 'goods id',
|
||||
`goods_idx` int(11) NOT NULL DEFAULT '0' COMMENT 'goods idx',
|
||||
`item_id` int(11) NOT NULL DEFAULT '0' COMMENT '道具id',
|
||||
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
||||
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
|
||||
PRIMARY KEY (`idx`),
|
||||
KEY `goods_id_goods_idx` (`goods_id`, `goods_idx`),
|
||||
KEY `buyer` (`buyer`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
$g_conf_market_mysql_cluster = require('../config/game2006market.mysql.cluster.php');
|
||||
$g_conf_mysql_cluster = require('../config/game2006api.mysql.cluster.php');
|
||||
$g_conf_redis_cluster = require('../config/game2006api.redis.cluster.php');
|
||||
$g_metatables = array();
|
||||
@ -41,6 +42,17 @@ function getMysqlConfig($hash_value)
|
||||
return $g_conf_mysql_cluster[$idx];
|
||||
}
|
||||
|
||||
function getMarketMysqlConfig($hash_value)
|
||||
{
|
||||
if ($hash_value < 0) {
|
||||
error_log('callstack:' . json_encode(debug_backtrace(), JSON_PRETTY_PRINT));
|
||||
die('hash_value < 0 ' . $hash_value);
|
||||
}
|
||||
global $g_conf_market_mysql_cluster;
|
||||
$idx = $hash_value % count($g_conf_market_mysql_cluster);
|
||||
return $g_conf_market_mysql_cluster[$idx];
|
||||
}
|
||||
|
||||
function getRedisConfig($hash_value)
|
||||
{
|
||||
if ($hash_value < 0) {
|
||||
|
@ -87,6 +87,19 @@ class BaseController {
|
||||
return $conn;
|
||||
}
|
||||
|
||||
public function _getMarketMysql()
|
||||
{
|
||||
$mysql_conf = getMarketMysqlConfig(crc32(''));
|
||||
$conn = new phpcommon\Mysql(array(
|
||||
'host' => $mysql_conf['host'],
|
||||
'port' => $mysql_conf['port'],
|
||||
'user' => $mysql_conf['user'],
|
||||
'passwd' => $mysql_conf['passwd'],
|
||||
'dbname' => 'marketdb2006'
|
||||
));
|
||||
return $conn;
|
||||
}
|
||||
|
||||
public function _getRedis($data)
|
||||
{
|
||||
$redis_conf = getRedisConfig(crc32($data));
|
||||
|
@ -5,7 +5,10 @@ require_once('mt/Item.php');
|
||||
require_once('mt/WhiteList.php');
|
||||
require_once('mt/Currency.php');
|
||||
|
||||
require_once('models/Goods.php');
|
||||
|
||||
use phpcommon\SqlHelper;
|
||||
use models\Goods;
|
||||
|
||||
class MarketController extends BaseController {
|
||||
|
||||
@ -49,16 +52,56 @@ class MarketController extends BaseController {
|
||||
$page = getReqVal('page', 1);
|
||||
$type = getReqVal('type', 0);
|
||||
$sort = getReqVal('sort', '');
|
||||
|
||||
$rows = array();
|
||||
$pageInfo = array(
|
||||
'total' => 0,
|
||||
'count' => 0,
|
||||
'per_page' => 10,
|
||||
'current_page' => $page,
|
||||
'total_pages' => 0
|
||||
);
|
||||
mt\Market::traverseMeta(function ($meta) use(&$rows, &$pageInfo) {
|
||||
$remainBuyableNum = Goods::getRemainBuyableNum($meta);
|
||||
if ($remainBuyableNum > 0) {
|
||||
++$pageInfo['total'];
|
||||
if ($pageInfo['total'] >= $pageInfo['per_page'] * $pageInfo['current_page'] &&
|
||||
count($rows) < $pageInfo['per_page']) {
|
||||
array_push($rows, $this->wrapNft($meta, $remainBuyableNum));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$pageInfo['count'] = count($rows);
|
||||
$pageInfo['total_pages'] = ceil($pageInfo['total'] / $pageInfo['per_page']);
|
||||
$this->_rspData(array(
|
||||
'rows' => array(),
|
||||
'page' => array(
|
||||
'total' => 0,
|
||||
'count' => 0,
|
||||
'per_page' => 10,
|
||||
'current_page' => 1,
|
||||
'total_pages' => 0
|
||||
)
|
||||
'rows' => $rows,
|
||||
'page' => $pageInfo
|
||||
));
|
||||
}
|
||||
|
||||
private function wrapNft($meta, $inventory)
|
||||
{
|
||||
$nft = array();
|
||||
$nft['goods_id'] = 0;
|
||||
$nft['nft_id'] = '';
|
||||
$nft['type'] = 0;
|
||||
$nft['token_id'] = '';
|
||||
$nft['status'] = 0;
|
||||
$nft['inventory'] = 0;
|
||||
$nft['owner_address'] = '';
|
||||
$nft['owner_id'] = '';
|
||||
$nft['image_avatar'] = '';
|
||||
$nft['image_full'] = '';
|
||||
$nft['price'] = array(
|
||||
'type' => 0,
|
||||
'name' => '',
|
||||
'value' => 0,
|
||||
'decimals' => 0
|
||||
);
|
||||
$nft['created_at'] = 0;
|
||||
$nft['last_modified_at'] = 0;
|
||||
return $nft;
|
||||
}
|
||||
|
||||
}
|
||||
|
38
webapp/models/Goods.php
Normal file
38
webapp/models/Goods.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace models;
|
||||
|
||||
require_once('mt/Item.php');
|
||||
require_once('mt/ChipQuality.php');
|
||||
require_once('mt/AttrHelper.php');
|
||||
|
||||
use mt;
|
||||
use phpcommon\SqlHelper;
|
||||
|
||||
class Goods extends BaseModel {
|
||||
|
||||
public static function getRemainBuyableNum($goodsMeta)
|
||||
{
|
||||
self::mustByBuyedNumHash();
|
||||
return max(0, $goodsMeta['number_of_props'] - getXVal(self::$buyedNumHash, $goodsMeta['id'], 0));
|
||||
}
|
||||
|
||||
private static function mustByBuyedNumHash()
|
||||
{
|
||||
if (!is_null(self::$buyedNumHash)) {
|
||||
return;
|
||||
}
|
||||
$rows = myself()->_getMarketMysql()->execQuery
|
||||
('SELECT goods_id, count(goods_idx) AS num FROM t_goods WHERE state=1 GROUP BY goods_id;',
|
||||
array(
|
||||
|
||||
));
|
||||
self::$buyedNumHash = array();
|
||||
foreach ($rows as $row) {
|
||||
self::$buyedNumHash[$row['goods_id']] = $row['num'];
|
||||
}
|
||||
}
|
||||
|
||||
private static $buyedNumHash;
|
||||
|
||||
}
|
@ -10,7 +10,6 @@ use phpcommon;
|
||||
class Market {
|
||||
|
||||
const SYS_TYPE = 0;
|
||||
const AUCTION_TYPE = 1;
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user