1
This commit is contained in:
parent
12ea460246
commit
0d945f7a49
@ -135,163 +135,110 @@ class ShopController extends BaseAuthedController {
|
|||||||
$costItemId = $this->getCostItemIdByTokenType($tokenType);
|
$costItemId = $this->getCostItemIdByTokenType($tokenType);
|
||||||
|
|
||||||
switch ($tokenType) {
|
switch ($tokenType) {
|
||||||
case ShopController::TOKEN_TYPE_GOLD:
|
case ShopController::TOKEN_TYPE_GOLD:
|
||||||
$costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price);
|
$costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price);
|
||||||
$lackItem = null;
|
$lackItem = null;
|
||||||
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||||
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
|
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$itemMeta = mt\Item::get($goodsMeta['goods_id']);
|
$itemMeta = mt\Item::get($goodsMeta['goods_id']);
|
||||||
$propertyChgService = new services\PropertyChgService();
|
$propertyChgService = new services\PropertyChgService();
|
||||||
for ($i = 0; $i < $goodsNum; $i++) {
|
for ($i = 0; $i < $goodsNum; $i++) {
|
||||||
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0);
|
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0);
|
||||||
}
|
}
|
||||||
$awardService = new services\AwardService();
|
$awardService = new services\AwardService();
|
||||||
$awardService->addItem($goodsMeta['goods_id'], $goodsNum);
|
$awardService->addItem($goodsMeta['goods_id'], $goodsNum);
|
||||||
ShopBuyRecord::add($id, $goodsNum);
|
ShopBuyRecord::add($id, $goodsNum);
|
||||||
$this->_decItems($costItems);
|
$this->_decItems($costItems);
|
||||||
$goodsDto = array(
|
$goodsDto = array(
|
||||||
'goods_id' => $id,
|
'goods_id' => $id,
|
||||||
|
'item_id' => $goodsMeta['goods_id'],
|
||||||
|
'price_info' => array(
|
||||||
'item_id' => $goodsMeta['goods_id'],
|
'item_id' => $goodsMeta['goods_id'],
|
||||||
'price_info' => array(
|
'cost_list' => array(),
|
||||||
'item_id' => $goodsMeta['goods_id'],
|
'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']),
|
||||||
'cost_list' => array(),
|
'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end'])
|
||||||
'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']),
|
),
|
||||||
'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end'])
|
'flag_icon' => $goodsMeta['tag'],
|
||||||
),
|
'limit_type' => $goodsMeta['limit_type'],
|
||||||
'flag_icon' => $goodsMeta['tag'],
|
'bought_times' => $boughtTimes,
|
||||||
'limit_type' => $goodsMeta['limit_type'],
|
'total_buy_times' => $goodsMeta['limit_num'],
|
||||||
'bought_times' => $boughtTimes,
|
); {
|
||||||
'total_buy_times' => $goodsMeta['limit_num'],
|
$priceInfo = mt\Item::getPriceInfo($itemMeta);
|
||||||
); {
|
if (!empty($priceInfo)) {
|
||||||
$priceInfo = mt\Item::getPriceInfo($itemMeta);
|
$goodsDto['price_info'] = $priceInfo['price_info'];
|
||||||
if (!empty($priceInfo)) {
|
|
||||||
$goodsDto['price_info'] = $priceInfo['price_info'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$propertyChgService->addUserChg();
|
|
||||||
$this->_rspData(
|
|
||||||
array(
|
|
||||||
'award' => $awardService->toDto(),
|
|
||||||
'property_chg' => $propertyChgService->toDto(),
|
|
||||||
'goods_chg' => $goodsDto
|
|
||||||
)
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case ShopController::TOKEN_TYPE_DIAMOND:
|
|
||||||
if ($isFreeBuy) {
|
|
||||||
$need_price = 0;
|
|
||||||
}
|
|
||||||
$costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price);
|
|
||||||
$lackItem = null;
|
|
||||||
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
||||||
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
$propertyChgService->addUserChg();
|
||||||
|
$this->_rspData(
|
||||||
|
array(
|
||||||
|
'award' => $awardService->toDto(),
|
||||||
|
'property_chg' => $propertyChgService->toDto(),
|
||||||
|
'goods_chg' => $goodsDto
|
||||||
|
)
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case ShopController::TOKEN_TYPE_DIAMOND:
|
||||||
|
if ($isFreeBuy) {
|
||||||
|
$need_price = 0;
|
||||||
|
}
|
||||||
|
$costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price);
|
||||||
|
$lackItem = null;
|
||||||
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||||
|
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$itemMeta = mt\Item::get($goodsMeta['goods_id']);
|
$itemMeta = mt\Item::get($goodsMeta['goods_id']);
|
||||||
$propertyChgService = new services\PropertyChgService();
|
$propertyChgService = new services\PropertyChgService();
|
||||||
for ($i = 0; $i < $goodsNum; $i++) {
|
for ($i = 0; $i < $goodsNum; $i++) {
|
||||||
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0);
|
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0);
|
||||||
}
|
}
|
||||||
$awardService = new services\AwardService();
|
$awardService = new services\AwardService();
|
||||||
$awardService->addItem($goodsMeta['goods_id'], $goodsNum);
|
$awardService->addItem($goodsMeta['goods_id'], $goodsNum);
|
||||||
ShopBuyRecord::add($id, $goodsNum);
|
ShopBuyRecord::add($id, $goodsNum);
|
||||||
if ($isFreeBuy) {
|
if ($isFreeBuy) {
|
||||||
$this->addFreeBuyRecord($goodsMeta);
|
$this->addFreeBuyRecord($goodsMeta);
|
||||||
}
|
}
|
||||||
$this->_decItems($costItems);
|
$this->_decItems($costItems);
|
||||||
$event = [
|
$event = [
|
||||||
'name' => LogService::SHOP_BUY_ITEM,
|
'name' => LogService::SHOP_BUY_ITEM,
|
||||||
'val' => $costItems[0]['item_num']
|
'val' => $costItems[0]['item_num']
|
||||||
];
|
];
|
||||||
LogService::consumeDiamond($event);
|
LogService::consumeDiamond($event);
|
||||||
|
|
||||||
$goodsDto = array(
|
$goodsDto = array(
|
||||||
'goods_id' => $id,
|
'goods_id' => $id,
|
||||||
|
'item_id' => $goodsMeta['goods_id'],
|
||||||
|
'price_info' => array(
|
||||||
'item_id' => $goodsMeta['goods_id'],
|
'item_id' => $goodsMeta['goods_id'],
|
||||||
'price_info' => array(
|
'cost_list' => array(),
|
||||||
'item_id' => $goodsMeta['goods_id'],
|
'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']),
|
||||||
'cost_list' => array(),
|
'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end'])
|
||||||
'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']),
|
),
|
||||||
'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end'])
|
'flag_icon' => $goodsMeta['tag'],
|
||||||
),
|
'limit_type' => $goodsMeta['limit_type'],
|
||||||
'flag_icon' => $goodsMeta['tag'],
|
'bought_times' => $boughtTimes,
|
||||||
'limit_type' => $goodsMeta['limit_type'],
|
'total_buy_times' => $goodsMeta['limit_num'],
|
||||||
'bought_times' => $boughtTimes,
|
); {
|
||||||
'total_buy_times' => $goodsMeta['limit_num'],
|
$priceInfo = mt\Item::getPriceInfo($itemMeta);
|
||||||
); {
|
if (!empty($priceInfo)) {
|
||||||
$priceInfo = mt\Item::getPriceInfo($itemMeta);
|
$goodsDto['price_info'] = $priceInfo['price_info'];
|
||||||
if (!empty($priceInfo)) {
|
|
||||||
$goodsDto['price_info'] = $priceInfo['price_info'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$propertyChgService->addUserChg();
|
}
|
||||||
$this->_rspData(
|
$propertyChgService->addUserChg();
|
||||||
array(
|
$this->_rspData(
|
||||||
'award' => $awardService->toDto(),
|
array(
|
||||||
'property_chg' => $propertyChgService->toDto(),
|
'award' => $awardService->toDto(),
|
||||||
'goods_chg' => $goodsDto
|
'property_chg' => $propertyChgService->toDto(),
|
||||||
)
|
'goods_chg' => $goodsDto
|
||||||
);
|
)
|
||||||
break;
|
);
|
||||||
case ShopController::TOKEN_TYPE_CEG:
|
break;
|
||||||
case ShopController::TOKEN_TYPE_CEC:
|
|
||||||
if ($isFreeBuy) {
|
|
||||||
$propertyChgService = new services\PropertyChgService();
|
|
||||||
$this->addFreeBuyRecord($goodsMeta);
|
|
||||||
$itemMeta = mt\Item::get($goodsMeta['goods_id']);
|
|
||||||
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 1);
|
|
||||||
$this->_rspOk();
|
|
||||||
} else {
|
|
||||||
$price = $this->normalizeWeb3Price($goodsNum * $need_price);
|
|
||||||
$item_id = $goodsMeta['goods_id'];
|
|
||||||
$item_count = $goodsNum;
|
|
||||||
|
|
||||||
$response = services\BlockChainService::gameItemMallBuy(
|
|
||||||
Transaction::BUY_GOODS_ACTION_TYPE,
|
|
||||||
$price,
|
|
||||||
$item_id,
|
|
||||||
$item_count
|
|
||||||
);
|
|
||||||
|
|
||||||
BcOrder::upsert($response['trans_id'], array(
|
|
||||||
'item_id' => $item_id,
|
|
||||||
'item_num' => $item_count,
|
|
||||||
'order_type' => 1,
|
|
||||||
'price' => $goodsNum * $need_price,
|
|
||||||
'ext_data' => json_encode(array(
|
|
||||||
'mode' => SHOP_BUY_MODE_NORMAL,
|
|
||||||
'shop_id' => $goodsMeta['shop_id'],
|
|
||||||
'id' => $id,
|
|
||||||
)),
|
|
||||||
));
|
|
||||||
|
|
||||||
$response['item_id'] = $item_id;
|
|
||||||
$response['item_num'] = $item_count;
|
|
||||||
|
|
||||||
error_log("buy normal, item_id = " . $item_id . " item_count = " . $item_count . " need_price = " . $need_price . " price = " . $price . " response = " . json_encode($response));
|
|
||||||
|
|
||||||
$this->_rspData(
|
|
||||||
array(
|
|
||||||
"block_chain" => $response
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ShopController::TOKEN_TYPE_BCEG:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ShopController::TOKEN_TYPE_USDT:
|
|
||||||
case ShopController::TOKEN_TYPE_USDC:
|
|
||||||
case ShopController::TOKEN_TYPE_BUSD:
|
|
||||||
case ShopController::TOKEN_TYPE_MATIC:
|
|
||||||
case ShopController::TOKEN_TYPE_BNB:
|
|
||||||
default: {
|
default: {
|
||||||
$this->_rspErr(1, "token_type is unsupport, {$tokenType}");
|
$this->_rspErr(1, "token_type is unsupport, {$tokenType}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user