1
This commit is contained in:
parent
0985ce84db
commit
ca45a487c0
@ -65,7 +65,150 @@ class BcShopController extends BaseController {
|
|||||||
|
|
||||||
public function buy()
|
public function buy()
|
||||||
{
|
{
|
||||||
|
$token = getReqVal('token', '');
|
||||||
|
$type = getReqVal('type', '');
|
||||||
|
$rawBuyerAddress = getReqVal('buyer_address', '');
|
||||||
|
$buyerAddress = strtolower($rawBuyerAddress);
|
||||||
|
$price = getReqVal('price', '');
|
||||||
|
$paymentTokenAddress = getReqVal('payment_token_address', '');
|
||||||
|
$nonce = getReqVal('nonce', '');
|
||||||
|
$signature = getReqVal('signature', '');
|
||||||
|
$netId = getReqVal('net_id', '');
|
||||||
|
$gameId = 2006;
|
||||||
|
$funcId = MarketService::FUNCID_SHOP;
|
||||||
|
if (!MarketService::isValidToken($buyerAddress, $token)) {
|
||||||
|
myself()->_rspErr(100, 'invalid token');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MarketService::buyBoxVerifySignature(
|
||||||
|
$buyerAddress,
|
||||||
|
$type,
|
||||||
|
$paymentTokenAddress,
|
||||||
|
$price,
|
||||||
|
$nonce,
|
||||||
|
$signature);
|
||||||
|
|
||||||
|
$batchIdx = 0;
|
||||||
|
$idx = 0;
|
||||||
|
$itemId = 0;
|
||||||
|
if (!phpcommon\extractBoxId($type, $batchIdx, $idx, $itemId)) {
|
||||||
|
myself()->_rspErr(2, 'type parameter error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($type) ||
|
||||||
|
empty($buyerAddress) ||
|
||||||
|
empty($price) ||
|
||||||
|
empty($paymentTokenAddress) ||
|
||||||
|
empty($signature) ||
|
||||||
|
empty($nonce)) {
|
||||||
|
myself()->_rspErr(2, 'parameter error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$currBatchMeta = mt\MarketBatch::getCurrentBatch();
|
||||||
|
if (!$currBatchMeta) {
|
||||||
|
myself()->_rspErr(500, 'server internal error1');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($batchIdx != $currBatchMeta['id']) {
|
||||||
|
myself()->_rspErr(500, 'server internal error2');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$goodsMeta = mt\MarketGoods::getOnSaleGoods($currBatchMeta['batch_id'], $idx, $itemId);
|
||||||
|
if (!$goodsMeta) {
|
||||||
|
myself()->_rspErr(500, 'server internal error3');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($currBatchMeta['white_list'] && !mt\WhiteList::inWhiteList($buyerAddress)) {
|
||||||
|
myself()->_rspErr(500, 'not white list user');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$originalPrice = $goodsMeta['price'] * pow(10, MarketService::CURRENCY_DECIMALS);
|
||||||
|
$discountPrice = $goodsMeta['discount'] * 100 > 0 ?
|
||||||
|
$originalPrice * $goodsMeta['discount'] : $originalPrice;
|
||||||
|
|
||||||
|
$discountPrice .= MarketService::PRICE_PAD;
|
||||||
|
error_log('price:' . $price . ' discountPrice:' . $discountPrice);
|
||||||
|
if (!$discountPrice || strcmp($price, $discountPrice) != 0) {
|
||||||
|
myself()->_rspErr(500, 'price error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$itemMeta = mt\Item::get($itemId);
|
||||||
|
if (!$itemMeta) {
|
||||||
|
myself()->_rspErr(500, 'server internal error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$currencyMeta = mt\Currency::get($goodsMeta['currency_id']);
|
||||||
|
if (!$currencyMeta || $currencyMeta['address'] != $paymentTokenAddress) {
|
||||||
|
myself()->_rspErr(500, 'currency error');
|
||||||
|
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\isValidBcFuncId($funcId)) {
|
||||||
|
myself()->_rspErr(500, 'server internal error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!MarketService::isTestMode() &&
|
||||||
|
BoxOrder::isBuyed($buyerAddress, $currBatchMeta['id'])) {
|
||||||
|
myself()->_rspErr(1, 'account can only choose 1 hero to purchase');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$fieldsKv = array(
|
||||||
|
'game_id' => $gameId,
|
||||||
|
'func_id' => $funcId,
|
||||||
|
'batch_idx' => $currBatchMeta['id'],
|
||||||
|
'type' => $type,
|
||||||
|
'raw_buyer_address' => $rawBuyerAddress,
|
||||||
|
'buyer_address' => $buyerAddress,
|
||||||
|
'price' => $price,
|
||||||
|
'payment_token_address' => $paymentTokenAddress,
|
||||||
|
'nonce' => $nonce,
|
||||||
|
'signature' => $signature,
|
||||||
|
'net_id' => $netId,
|
||||||
|
'done' => 0,
|
||||||
|
'createtime' => myself()->_getNowTime(),
|
||||||
|
'modifytime' => myself()->_getNowTime()
|
||||||
|
);
|
||||||
|
$items = array();
|
||||||
|
MarketService::openBox($itemMeta, $items);
|
||||||
|
for ($i = 1; $i <= BoxOrder::MAX_NFT_NUM; ++$i) {
|
||||||
|
if ($i <= count($items)) {
|
||||||
|
$tokenId = phpcommon\setOrderIdSubIdx($orderId, $i);
|
||||||
|
$fieldsKv['bc_mint_tokenid' . $i] = $tokenId;
|
||||||
|
$fieldsKv['bc_mint_need' . $i] = $items[$i]['need'];
|
||||||
|
$fieldsKv['bc_mint_itemid' . $i] = $items[$i]['item_id'];
|
||||||
|
$fieldsKv['bc_mint_token_type' . $i] = $items[$i]['token_type'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (MarketService::isTestMode()) {
|
||||||
|
$fieldsKv['bc_paid'] = 1;
|
||||||
|
}
|
||||||
|
$orderId = BuyRecord::genOrderId($gameId,
|
||||||
|
$funcId,
|
||||||
|
myself()->_getNowTime(),
|
||||||
|
$buyerAddress);
|
||||||
|
$fieldsKv['order_id'] = $orderId;
|
||||||
|
SqlHelper::insert(
|
||||||
|
myself()->_getMarketMysql(),
|
||||||
|
't_box_order',
|
||||||
|
$fieldsKv
|
||||||
|
);
|
||||||
|
myself()->_rspData(array(
|
||||||
|
'order_id' => $orderId
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function queryOrder()
|
public function queryOrder()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user