game2006api/webapp/controller/BcShopController.class.php
aozhiwei e262c8ce1e 1
2022-04-04 13:20:48 +08:00

148 lines
4.6 KiB
PHP

<?php
require_once('mt/MarketGoods.php');
require_once('mt/MarketBatch.php');
require_once('mt/Item.php');
require_once('mt/Currency.php');
require_once('mt/Hero.php');
require_once('mt/Parameter.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 BcShopController extends BaseController {
public function search()
{
$account = getReqVal('account', '');
$page = getReqVal('page', 1);
$type = getReqVal('type', 0);
$sort = getReqVal('sort', '');
$perPage = 10000;
$rows = array();
$pageInfo = array(
'total' => 0,
'count' => 0,
'per_page' => $perPage,
'current_page' => $page,
'total_pages' => 0
);
$startPos= $pageInfo['per_page'] * ($pageInfo['current_page'] - 1);
$currBatchMeta = mt\MarketBatch::getCurrentBatch();
if ($currBatchMeta) {
$batchMetas = mt\MarketGoods::getBatchMetas($currBatchMeta['batch_id']);
if ($batchMetas) {
foreach ($batchMetas as $meta) {
$saleBox = $this->fillPresaleBox($currBatchMeta, $meta);
if ($saleBox) {
++$pageInfo['total'];
if ($pageInfo['total'] > $startPos &&
count($rows) < $pageInfo['per_page']) {
array_push($rows, $saleBox);
}
}
}
}
}
$pageInfo['count'] = count($rows);
$pageInfo['total_pages'] = ceil($pageInfo['total'] / $pageInfo['per_page']);
myself()->_rspData(array(
'rows' => $rows,
'page' => $pageInfo,
));
}
public function buy()
{
}
public function queryOrder()
{
$token = getReqVal('token', '');
$account = getReqVal('account', '');
$orderId = getReqVal('order_id', '');
if (!MarketService::isValidToken($account, $token)) {
myself()->_rspErr(100, 'invalid token');
return;
}
$orderDb = BoxOrder::findByOrderId($orderId);
if ($orderDb) {
if (!$orderDb['done']) {
myself()->_rspData(array(
'state' => 2
));
} else {
if ($orderDb['bc_paid'] == 1) {
myself()->_rspData(array(
'state' => 1
));
} else {
myself()->_rspData(array(
'state' => 3
));
}
}
} else {
myself()->_rspData(array(
'state' => 0
));
}
}
private function fillPresaleBox($batchMeta, $goodsMeta)
{
$currencyMeta = mt\Currency::get($goodsMeta['currency_id']);
if (!$currencyMeta) {
return null;
}
$boxId = phpcommon\genBoxId($batchMeta['id'],
$goodsMeta['id'],
$goodsMeta['item_id']);
$itemMeta = mt\Item::get($goodsMeta['item_id']);
$originalPrice = $goodsMeta['price'] * pow(10, MarketService::CURRENCY_DECIMALS);
$discountPrice = $goodsMeta['discount'] * 100 > 0 ?
$originalPrice * $goodsMeta['discount'] : $originalPrice;
$name = '';
$job = 0;
{
$heroMeta = mt\Hero::get($goodsMeta['item_id']);
if ($heroMeta) {
$name = emptyReplace($heroMeta['name'], 'Hill');
$job = emptyReplace($heroMeta['herotype'], '1');
}
}
$saleBox = array(
'box_id' => $boxId,
'item_id' => $goodsMeta['item_id'],
'name' => $name,
'job' => $job,
//'avatar_url' => 'https://www.cebg.games/res/avatars/' . $itemMeta['nft_image_id'] . '.png',
'currency_list' => array(
array(
'name' => $currencyMeta['name'],
'original_price' => $originalPrice,
'discount_price' => $discountPrice,
'discount_rate' => $goodsMeta['discount'],
'decimals' => MarketService::CURRENCY_DECIMALS,
'contract_address' => $currencyMeta['address'],
)
));
return $saleBox;
}
}