1
This commit is contained in:
parent
0d945f7a49
commit
13852c7719
@ -128,118 +128,30 @@ class ShopController extends BaseAuthedController {
|
||||
$nowTime = $this->_getNowTime();
|
||||
|
||||
if ($nowTime >= $discount_begin && $nowTime < $discount_end) {
|
||||
|
||||
$need_price = ceil($need_price * ($discount / 100.0));
|
||||
}
|
||||
|
||||
$costItemId = $this->getCostItemIdByTokenType($tokenType);
|
||||
|
||||
$costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price);
|
||||
switch ($tokenType) {
|
||||
case ShopController::TOKEN_TYPE_GOLD:
|
||||
$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']);
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
for ($i = 0; $i < $goodsNum; $i++) {
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0);
|
||||
}
|
||||
$awardService = new services\AwardService();
|
||||
$awardService->addItem($goodsMeta['goods_id'], $goodsNum);
|
||||
ShopBuyRecord::add($id, $goodsNum);
|
||||
$this->_decItems($costItems);
|
||||
$goodsDto = array(
|
||||
'goods_id' => $id,
|
||||
'item_id' => $goodsMeta['goods_id'],
|
||||
'price_info' => array(
|
||||
'item_id' => $goodsMeta['goods_id'],
|
||||
'cost_list' => array(),
|
||||
'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'],
|
||||
'bought_times' => $boughtTimes,
|
||||
'total_buy_times' => $goodsMeta['limit_num'],
|
||||
); {
|
||||
$priceInfo = mt\Item::getPriceInfo($itemMeta);
|
||||
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;
|
||||
{
|
||||
}
|
||||
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']);
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
for ($i = 0; $i < $goodsNum; $i++) {
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0);
|
||||
}
|
||||
$awardService = new services\AwardService();
|
||||
$awardService->addItem($goodsMeta['goods_id'], $goodsNum);
|
||||
ShopBuyRecord::add($id, $goodsNum);
|
||||
if ($isFreeBuy) {
|
||||
$this->addFreeBuyRecord($goodsMeta);
|
||||
}
|
||||
$this->_decItems($costItems);
|
||||
$event = [
|
||||
'name' => LogService::SHOP_BUY_ITEM,
|
||||
'val' => $costItems[0]['item_num']
|
||||
];
|
||||
LogService::consumeDiamond($event);
|
||||
|
||||
$goodsDto = array(
|
||||
'goods_id' => $id,
|
||||
'item_id' => $goodsMeta['goods_id'],
|
||||
'price_info' => array(
|
||||
'item_id' => $goodsMeta['goods_id'],
|
||||
'cost_list' => array(),
|
||||
'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'],
|
||||
'bought_times' => $boughtTimes,
|
||||
'total_buy_times' => $goodsMeta['limit_num'],
|
||||
); {
|
||||
$priceInfo = mt\Item::getPriceInfo($itemMeta);
|
||||
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;
|
||||
default: {
|
||||
{
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
$this->_rspErr(1, "token_type is unsupport, {$tokenType}");
|
||||
}
|
||||
break;
|
||||
}
|
||||
$lackItem = null;
|
||||
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ class ShopService {
|
||||
}
|
||||
}
|
||||
|
||||
private static function goodsMetaToInfo($goodsMeta)
|
||||
public static function goodsMetaToInfo($goodsMeta)
|
||||
{
|
||||
return array(
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user