1
This commit is contained in:
parent
647e861417
commit
cc117b6450
@ -27,45 +27,7 @@ class MarketController extends BaseController {
|
|||||||
public function getPreSaleInfo()
|
public function getPreSaleInfo()
|
||||||
{
|
{
|
||||||
$account = getReqVal('account', '');
|
$account = getReqVal('account', '');
|
||||||
$currBatchMeta = mt\MarketBatch::getCurrentBatch();
|
$presaleInfo = MarketService::getPreSaleInfo($account);
|
||||||
if (!$currBatchMeta) {
|
|
||||||
myself()->_rspData(array(
|
|
||||||
'presale_info' => $this->getDefaultPresaleInfo()
|
|
||||||
));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$countdown = mt\MarketBatch::getCountdown($currBatchMeta);
|
|
||||||
$soldNum = min(BoxOrder::getSoldNum($currBatchMeta['id']),
|
|
||||||
$currBatchMeta['number_of_props']);
|
|
||||||
$totalNum = $currBatchMeta['number_of_props'];
|
|
||||||
$buyed = MarketService::isTestMode() ?
|
|
||||||
0 : BoxOrder::isBuyed($account, $currBatchMeta['id']);
|
|
||||||
$title = '';
|
|
||||||
$state = MarketService::PRESALE_PREPARE;
|
|
||||||
if ($countdown > 0) {
|
|
||||||
$state = MarketService::PRESALE_PREPARE;
|
|
||||||
} else {
|
|
||||||
if ($soldNum >= $totalNum) {
|
|
||||||
$title = $this->escapeString($currBatchMeta['end_title']);
|
|
||||||
$state = MarketService::PRESALE_SOLD_OUT;
|
|
||||||
} else {
|
|
||||||
$title = $this->escapeString($currBatchMeta['begin_title']);
|
|
||||||
$state = MarketService::PRESALE_STARTED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$presaleInfo = array(
|
|
||||||
'batch_id' => $currBatchMeta['batch_id'],
|
|
||||||
'countdown' => $countdown,
|
|
||||||
'sold_num' => $soldNum,
|
|
||||||
'total_num' => $totalNum,
|
|
||||||
'state' => $state,
|
|
||||||
'title' => $title,
|
|
||||||
'hint' => $this->escapeString($currBatchMeta['hint']),
|
|
||||||
'buyable_list' => array(),
|
|
||||||
//'buyed' => $buyed
|
|
||||||
);
|
|
||||||
|
|
||||||
if (MarketService::isTestMode()) {
|
if (MarketService::isTestMode()) {
|
||||||
foreach(array_keys($presaleInfo) as $key) {
|
foreach(array_keys($presaleInfo) as $key) {
|
||||||
if (!is_null(getReqVal($key, null))) {
|
if (!is_null(getReqVal($key, null))) {
|
||||||
@ -73,25 +35,6 @@ class MarketController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
$batchMetas = mt\MarketGoods::getBatchMetas($currBatchMeta['batch_id']);
|
|
||||||
if ($batchMetas) {
|
|
||||||
foreach ($batchMetas as $meta) {
|
|
||||||
$boxId = phpcommon\genBoxId($currBatchMeta['id'], $meta['id'], $meta['item_id']);
|
|
||||||
if (!$buyed) {
|
|
||||||
if ($currBatchMeta['white_list'] && !mt\WhiteList::inWhiteList($account)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
array_push($presaleInfo['buyable_list'],
|
|
||||||
array(
|
|
||||||
'box_id' => $boxId
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
myself()->_rspData(array(
|
myself()->_rspData(array(
|
||||||
'presale_info' => $presaleInfo
|
'presale_info' => $presaleInfo
|
||||||
));
|
));
|
||||||
@ -406,11 +349,6 @@ class MarketController extends BaseController {
|
|||||||
return $nft;
|
return $nft;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function escapeString($str)
|
|
||||||
{
|
|
||||||
return str_replace("\n", '\n', $str);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNonce()
|
public function getNonce()
|
||||||
{
|
{
|
||||||
$account = getReqVal('account', '');
|
$account = getReqVal('account', '');
|
||||||
@ -444,24 +382,4 @@ class MarketController extends BaseController {
|
|||||||
MarketService::auth($account, $tips, $nonce, $signature);
|
MarketService::auth($account, $tips, $nonce, $signature);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDefaultPresaleInfo()
|
|
||||||
{
|
|
||||||
$title = $this->escapeString(
|
|
||||||
mt\Parameter::getVal('pre_sale_not_started_title', ''));
|
|
||||||
$hint = $this->escapeString(
|
|
||||||
mt\Parameter::getVal('pre_sale_not_started_hint', ''));
|
|
||||||
$presaleInfo = array(
|
|
||||||
'batch_id' => 0,
|
|
||||||
'countdown' => 0,
|
|
||||||
'sold_num' => 0,
|
|
||||||
'total_num' => 0,
|
|
||||||
'state' => MarketService::PRESALE_NOT_STARTED,
|
|
||||||
'title' => $title,
|
|
||||||
'hint' => $hint,
|
|
||||||
'buyable_list' => array(),
|
|
||||||
//'buyed' => 0
|
|
||||||
);
|
|
||||||
return $presaleInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,25 @@
|
|||||||
|
|
||||||
namespace services;
|
namespace services;
|
||||||
|
|
||||||
|
require_once('mt/MarketGoods.php');
|
||||||
|
require_once('mt/MarketBatch.php');
|
||||||
|
require_once('mt/Item.php');
|
||||||
|
require_once('mt/WhiteList.php');
|
||||||
|
require_once('mt/Currency.php');
|
||||||
|
require_once('mt/Hero.php');
|
||||||
require_once('mt/Parameter.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 MarketService extends BaseService {
|
class MarketService extends BaseService {
|
||||||
|
|
||||||
const CURRENCY_DECIMALS = 8;
|
const CURRENCY_DECIMALS = 8;
|
||||||
@ -154,4 +171,90 @@ class MarketService extends BaseService {
|
|||||||
return base64_encode(json_encode($data));
|
return base64_encode(json_encode($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function getPreSaleInfo($account)
|
||||||
|
{
|
||||||
|
$currBatchMeta = mt\MarketBatch::getCurrentBatch();
|
||||||
|
if (!$currBatchMeta) {
|
||||||
|
return self::getDefaultPresaleInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
$countdown = mt\MarketBatch::getCountdown($currBatchMeta);
|
||||||
|
$soldNum = min(BoxOrder::getSoldNum($currBatchMeta['id']),
|
||||||
|
$currBatchMeta['number_of_props']);
|
||||||
|
$totalNum = $currBatchMeta['number_of_props'];
|
||||||
|
$buyed = self::isTestMode() ?
|
||||||
|
0 : BoxOrder::isBuyed($account, $currBatchMeta['id']);
|
||||||
|
$title = '';
|
||||||
|
$state = self::PRESALE_PREPARE;
|
||||||
|
if ($countdown > 0) {
|
||||||
|
$state = self::PRESALE_PREPARE;
|
||||||
|
} else {
|
||||||
|
if ($soldNum >= $totalNum) {
|
||||||
|
$title = self::escapeString($currBatchMeta['end_title']);
|
||||||
|
$state = self::PRESALE_SOLD_OUT;
|
||||||
|
} else {
|
||||||
|
$title = self::escapeString($currBatchMeta['begin_title']);
|
||||||
|
$state = self::PRESALE_STARTED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$presaleInfo = array(
|
||||||
|
'batch_id' => $currBatchMeta['batch_id'],
|
||||||
|
'countdown' => $countdown,
|
||||||
|
'sold_num' => $soldNum,
|
||||||
|
'total_num' => $totalNum,
|
||||||
|
'state' => $state,
|
||||||
|
'title' => $title,
|
||||||
|
'hint' => self::escapeString($currBatchMeta['hint']),
|
||||||
|
'buyable_list' => array(),
|
||||||
|
//'buyed' => $buyed
|
||||||
|
);
|
||||||
|
|
||||||
|
$batchMetas = mt\MarketGoods::getBatchMetas($currBatchMeta['batch_id']);
|
||||||
|
if ($batchMetas) {
|
||||||
|
foreach ($batchMetas as $meta) {
|
||||||
|
$boxId = phpcommon\genBoxId($currBatchMeta['id'],
|
||||||
|
$meta['id'],
|
||||||
|
$meta['item_id']);
|
||||||
|
if (!$buyed) {
|
||||||
|
if ($currBatchMeta['white_list'] &&
|
||||||
|
!mt\WhiteList::inWhiteList($account)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
array_push($presaleInfo['buyable_list'],
|
||||||
|
array(
|
||||||
|
'box_id' => $boxId
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $presaleInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function getDefaultPresaleInfo()
|
||||||
|
{
|
||||||
|
$title = self::escapeString(
|
||||||
|
mt\Parameter::getVal('pre_sale_not_started_title', ''));
|
||||||
|
$hint = self::escapeString(
|
||||||
|
mt\Parameter::getVal('pre_sale_not_started_hint', ''));
|
||||||
|
$presaleInfo = array(
|
||||||
|
'batch_id' => 0,
|
||||||
|
'countdown' => 0,
|
||||||
|
'sold_num' => 0,
|
||||||
|
'total_num' => 0,
|
||||||
|
'state' => self::PRESALE_NOT_STARTED,
|
||||||
|
'title' => $title,
|
||||||
|
'hint' => $hint,
|
||||||
|
'buyable_list' => array(),
|
||||||
|
//'buyed' => 0
|
||||||
|
);
|
||||||
|
return $presaleInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function escapeString($str)
|
||||||
|
{
|
||||||
|
return str_replace("\n", '\n', $str);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user