92 lines
2.4 KiB
PHP
92 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace services;
|
|
|
|
require_once('phpcommon/bchelper.php');
|
|
|
|
require_once('models/Nft.php');
|
|
require_once('models/ActivateNft.php');
|
|
require_once('models/BuyRecord.php');
|
|
require_once('models/ActivateNftEvent.php');
|
|
require_once('models/Phase3Box.php');
|
|
|
|
use phpcommon;
|
|
use models\Nft;
|
|
use models\ActivateNft;
|
|
use models\BuyRecord;
|
|
use models\ActivateNftEvent;
|
|
use models\Phase3Box;
|
|
|
|
class Phase3BoxService {
|
|
|
|
public static function getPhase3Box($account)
|
|
{
|
|
$rows = array();
|
|
$boxDb = Phase3Box::find($account);
|
|
if ($boxDb && $boxDb['state'] == Phase3Box::INIT_STATE) {
|
|
array_push($rows, array(
|
|
'box_id' => $boxDb['token_id'],
|
|
'image_box_1' => 'https://www.cebg.games/res/nfts/box_1.png',
|
|
'image_box_2' => 'https://www.cebg.games/res/nfts/box_2.png',
|
|
'image_box_3' => 'https://www.cebg.games/res/nfts/box_3.png',
|
|
));
|
|
}
|
|
myself()->_rspData(array(
|
|
'rows' => $rows
|
|
));
|
|
}
|
|
|
|
public static function openPhase3Box($account, $boxId)
|
|
{
|
|
$boxDb = Phase3Box::find($account);
|
|
if (!$boxDb) {
|
|
myself()->_rspErr(100, 'box not exists');
|
|
return;
|
|
}
|
|
if ($boxDb['state'] == Phase3Box::INIT_STATE) {
|
|
Phase3Box::give($account);
|
|
}
|
|
myself()->_rspOk();
|
|
}
|
|
|
|
public static function queryPhase3Box($account, $boxId)
|
|
{
|
|
$boxDb = Phase3Box::find($account);
|
|
if (!$boxDb) {
|
|
myself()->_rspErr(100, 'box not exists');
|
|
return;
|
|
}
|
|
if ($boxDb['state'] == Phase3Box::INIT_STATE) {
|
|
myself()->_rspData(array(
|
|
'state' => 0
|
|
));
|
|
return;
|
|
}
|
|
if ($boxDb['cec'] > 0) {
|
|
myself()->_rspData(array(
|
|
'state' => 1,
|
|
'cec' => $boxDb['cec']
|
|
));
|
|
return;
|
|
} else {
|
|
$nftDb = Nft::getNft($boxDb['token_id']);
|
|
if ($nftDb) {
|
|
myself()->_rspData(array(
|
|
'state' => 1,
|
|
'cec' => 0,
|
|
'nfts' => array(
|
|
Nft::toDto($nftDb)
|
|
)
|
|
));
|
|
return;
|
|
} else {
|
|
myself()->_rspData(array(
|
|
'state' => 0
|
|
));
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|