This commit is contained in:
songliang 2023-04-04 21:02:28 +08:00
parent 2c7a64bfea
commit c28cb72a82

View File

@ -27,7 +27,8 @@ use models\Gun;
use models\GunSkin; use models\GunSkin;
use models\ShopBuyRecord; use models\ShopBuyRecord;
class ShopController extends BaseAuthedController { class ShopController extends BaseAuthedController
{
const TOKEN_TYPE_CEG = '1'; const TOKEN_TYPE_CEG = '1';
const TOKEN_TYPE_CEC = '2'; const TOKEN_TYPE_CEC = '2';
@ -48,19 +49,49 @@ class ShopController extends BaseAuthedController {
public function getGoodsList() public function getGoodsList()
{ {
$goodsList = mt\ShopGoods::all(); $goodsList = mt\ShopGoods::all();
$goodsList = $goodsList ? $goodsList : array();
$buyRecordHash = ShopBuyRecord::allToHash();
$this->_rspData(array( foreach ($goodsList as $goods) {
'goods_list' => $goodsList ? $goodsList : array(), $goods['bought_times'] = 0;
)); switch ($goods['limit_type']) {
case mt\Item::DAILY_BUY_LIMIT: {
$buyRecord = getXVal($buyRecordHash, $goods['id']);
$goods['bought_times'] = $buyRecord ? $buyRecord['this_day_buy_times'] : 0;
}
break;
case mt\Item::WEEKLY_BUY_LIMIT: {
$buyRecord = getXVal($buyRecordHash, $goods['id']);
$goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0;
}
break;
case mt\Item::TOTAL_BUY_LIMIT: {
$buyRecord = getXVal($buyRecordHash, $goods['id']);
$goodsDto['bought_times'] = $buyRecord ? $buyRecord['total_buy_times'] : 0;
}
break;
default: {
}
break;
}
}
$this->_rspData(
array(
'goods_list' => $goodsList,
)
);
} }
public function getShopNames() public function getShopNames()
{ {
$shopList = mt\Shop::all(); $shopList = mt\Shop::all();
$this->_rspData(array( $this->_rspData(
array(
'shop_name_list' => $shopList ? $shopList : array(), 'shop_name_list' => $shopList ? $shopList : array(),
)); )
);
} }
public function buyGoodsNew() public function buyGoodsNew()
@ -79,7 +110,7 @@ class ShopController extends BaseAuthedController {
return; return;
} }
if ($goods_num>$row['max_amount']) { if ($goods_num > $row['max_amount']) {
$this->_rspErr(1, "goods_num parameter error, max_amount: {$row['max_amount']}"); $this->_rspErr(1, "goods_num parameter error, max_amount: {$row['max_amount']}");
return; return;
} }
@ -87,10 +118,9 @@ class ShopController extends BaseAuthedController {
$buyRecordHash = ShopBuyRecord::allToHash(); $buyRecordHash = ShopBuyRecord::allToHash();
$boughtTimes = 1; $boughtTimes = 1;
switch ($row['limit_type']) { switch ($row['limit_type']) {
case ShopController::DAILY_BUY_LIMIT: case ShopController::DAILY_BUY_LIMIT: {
{
$buyRecord = getXVal($buyRecordHash, $id); $buyRecord = getXVal($buyRecordHash, $id);
$boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1: 1; $boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1 : 1;
if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $row['limit_num']) { if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $row['limit_num']) {
$this->_rspErr(2, 'Has reached the maximum number of purchase restrictions today'); $this->_rspErr(2, 'Has reached the maximum number of purchase restrictions today');
return; return;
@ -101,10 +131,9 @@ class ShopController extends BaseAuthedController {
} }
} }
break; break;
case ShopController::WEEKLY_BUY_LIMIT: case ShopController::WEEKLY_BUY_LIMIT: {
{
$buyRecord = getXVal($buyRecordHash, $id); $buyRecord = getXVal($buyRecordHash, $id);
$boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1: 1; $boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1;
if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $row['limit_num']) { if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $row['limit_num']) {
$this->_rspErr(2, 'The maximum number of purchase restrictions this week has been reached'); $this->_rspErr(2, 'The maximum number of purchase restrictions this week has been reached');
return; return;
@ -115,10 +144,9 @@ class ShopController extends BaseAuthedController {
} }
} }
break; break;
case ShopController::TOTAL_BUY_LIMIT: case ShopController::TOTAL_BUY_LIMIT: {
{
$buyRecord = getXVal($buyRecordHash, $id); $buyRecord = getXVal($buyRecordHash, $id);
$boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1: 1; $boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1;
if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $row['limit_num']) { if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $row['limit_num']) {
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached'); $this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
return; return;
@ -129,8 +157,7 @@ class ShopController extends BaseAuthedController {
} }
} }
break; break;
default: default: {
{
} }
break; break;
} }
@ -141,21 +168,21 @@ class ShopController extends BaseAuthedController {
$need_price = $price_array[$token_pos]; $need_price = $price_array[$token_pos];
$discount = $discount_array[$token_pos]; $discount = $discount_array[$token_pos];
$discount_begin = strtotime($row['discount_begin'].' UTC'); $discount_begin = strtotime($row['discount_begin'] . ' UTC');
$discount_end = strtotime($row['discount_end'].' UTC'); $discount_end = strtotime($row['discount_end'] . ' UTC');
$nowTime = $this->_getNowTime(); $nowTime = $this->_getNowTime();
if ($nowTime>=$discount_begin && $nowTime<$discount_end) { if ($nowTime >= $discount_begin && $nowTime < $discount_end) {
$need_price = ceil($need_price * ($discount / 100.0)); $need_price = ceil($need_price * ($discount / 100.0));
} }
$costItemId = $this->getCostItemIdByTokenType($token_type); $costItemId = $this->getCostItemIdByTokenType($token_type);
switch($token_type) { switch ($token_type) {
case ShopController::TOKEN_TYPE_CEG: case ShopController::TOKEN_TYPE_CEG:
case ShopController::TOKEN_TYPE_CEC: case ShopController::TOKEN_TYPE_CEC:
$costItems = $this->makeCostItems($costItemId, $goods_num*$need_price); $costItems = $this->makeCostItems($costItemId, $goods_num * $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));
@ -164,7 +191,7 @@ class ShopController extends BaseAuthedController {
$itemMeta = mt\Item::get($row['goods_id']); $itemMeta = mt\Item::get($row['goods_id']);
$propertyChgService = new services\PropertyChgService(); $propertyChgService = new services\PropertyChgService();
for ($i = 0; $i<$goods_num; $i++) { for ($i = 0; $i < $goods_num; $i++) {
$this->internalAddItem($propertyChgService, $itemMeta); $this->internalAddItem($propertyChgService, $itemMeta);
} }
$awardService = new services\AwardService(); $awardService = new services\AwardService();
@ -184,19 +211,20 @@ class ShopController extends BaseAuthedController {
'limit_type' => $row['limit_type'], 'limit_type' => $row['limit_type'],
'bought_times' => $boughtTimes, 'bought_times' => $boughtTimes,
'total_buy_times' => $row['limit_num'], 'total_buy_times' => $row['limit_num'],
); ); {
{
$priceInfo = mt\Item::getPriceInfo($itemMeta); $priceInfo = mt\Item::getPriceInfo($itemMeta);
if (!empty($priceInfo)) { if (!empty($priceInfo)) {
$goodsDto['price_info'] = $priceInfo['price_info']; $goodsDto['price_info'] = $priceInfo['price_info'];
} }
} }
$propertyChgService->addUserChg(); $propertyChgService->addUserChg();
$this->_rspData(array( $this->_rspData(
array(
'award' => $awardService->toDto(), 'award' => $awardService->toDto(),
'property_chg' => $propertyChgService->toDto(), 'property_chg' => $propertyChgService->toDto(),
'goods_chg' => $goodsDto 'goods_chg' => $goodsDto
)); )
);
break; break;
case ShopController::TOKEN_TYPE_BCEG: case ShopController::TOKEN_TYPE_BCEG:
@ -214,7 +242,7 @@ class ShopController extends BaseAuthedController {
private function getCostItemIdByTokenType($token_type) private function getCostItemIdByTokenType($token_type)
{ {
switch($token_type) { switch ($token_type) {
case ShopController::TOKEN_TYPE_CEG: case ShopController::TOKEN_TYPE_CEG:
return V_ITEM_GOLD; return V_ITEM_GOLD;
break; break;
@ -254,13 +282,15 @@ class ShopController extends BaseAuthedController {
} }
$goodsList = mt\ShopGoods::getGoodsList($shopId); $goodsList = mt\ShopGoods::getGoodsList($shopId);
if (!$goodsList) { if (!$goodsList) {
$this->_rspData(array( $this->_rspData(
array(
'info' => array( 'info' => array(
'shop_id' => $shopId, 'shop_id' => $shopId,
'goods_list1' => array(), 'goods_list1' => array(),
'goods_list2' => array(), 'goods_list2' => array(),
) )
)); )
);
return; return;
} }
$buyRecordHash = ShopBuyRecord::allToHash(); $buyRecordHash = ShopBuyRecord::allToHash();
@ -279,26 +309,22 @@ class ShopController extends BaseAuthedController {
'total_buy_times' => $itemMeta['limit_num'], 'total_buy_times' => $itemMeta['limit_num'],
); );
switch ($itemMeta['limit_type']) { switch ($itemMeta['limit_type']) {
case mt\Item::DAILY_BUY_LIMIT: case mt\Item::DAILY_BUY_LIMIT: {
{
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']); $buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
$goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_day_buy_times'] : 0; $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_day_buy_times'] : 0;
} }
break; break;
case mt\Item::WEEKLY_BUY_LIMIT: case mt\Item::WEEKLY_BUY_LIMIT: {
{
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']); $buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
$goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0; $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0;
} }
break; break;
case mt\Item::TOTAL_BUY_LIMIT: case mt\Item::TOTAL_BUY_LIMIT: {
{
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']); $buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
$goodsDto['bought_times'] = $buyRecord ? $buyRecord['total_buy_times'] : 0; $goodsDto['bought_times'] = $buyRecord ? $buyRecord['total_buy_times'] : 0;
} }
break; break;
default: default: {
{
} }
break; break;
} }
@ -309,13 +335,15 @@ class ShopController extends BaseAuthedController {
} }
} }
} }
$this->_rspData(array( $this->_rspData(
array(
'info' => array( 'info' => array(
'shop_id' => $shopId, 'shop_id' => $shopId,
'goods_list1' => $goodsDtoList1, 'goods_list1' => $goodsDtoList1,
'goods_list2' => $goodsDtoList2, 'goods_list2' => $goodsDtoList2,
) )
)); )
);
} }
public function buyGoods() public function buyGoods()
@ -345,10 +373,9 @@ class ShopController extends BaseAuthedController {
$buyRecordHash = ShopBuyRecord::allToHash(); $buyRecordHash = ShopBuyRecord::allToHash();
$boughtTimes = 1; $boughtTimes = 1;
switch ($itemMeta['limit_type']) { switch ($itemMeta['limit_type']) {
case mt\Item::DAILY_BUY_LIMIT: case mt\Item::DAILY_BUY_LIMIT: {
{
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']); $buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
$boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1: 1; $boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1 : 1;
if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $itemMeta['limit_num']) { if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $itemMeta['limit_num']) {
$this->_rspErr(2, 'Has reached the maximum number of purchase restrictions today'); $this->_rspErr(2, 'Has reached the maximum number of purchase restrictions today');
return; return;
@ -359,10 +386,9 @@ class ShopController extends BaseAuthedController {
} }
} }
break; break;
case mt\Item::WEEKLY_BUY_LIMIT: case mt\Item::WEEKLY_BUY_LIMIT: {
{
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']); $buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
$boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1: 1; $boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1;
if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $itemMeta['limit_num']) { if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $itemMeta['limit_num']) {
$this->_rspErr(2, 'The maximum number of purchase restrictions this week has been reached'); $this->_rspErr(2, 'The maximum number of purchase restrictions this week has been reached');
return; return;
@ -373,10 +399,9 @@ class ShopController extends BaseAuthedController {
} }
} }
break; break;
case mt\Item::TOTAL_BUY_LIMIT: case mt\Item::TOTAL_BUY_LIMIT: {
{
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']); $buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
$boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1: 1; $boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1;
if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $itemMeta['limit_num']) { if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $itemMeta['limit_num']) {
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached'); $this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
return; return;
@ -387,12 +412,10 @@ class ShopController extends BaseAuthedController {
} }
} }
break; break;
default: default: {
{
} }
break; break;
} } {
{
$errCode = 0; $errCode = 0;
$errMsg = ''; $errMsg = '';
if (!$this->canBuy($itemMeta, $errCode, $errMsg)) { if (!$this->canBuy($itemMeta, $errCode, $errMsg)) {
@ -433,29 +456,31 @@ class ShopController extends BaseAuthedController {
'limit_type' => $itemMeta['limit_type'], 'limit_type' => $itemMeta['limit_type'],
'bought_times' => $boughtTimes, 'bought_times' => $boughtTimes,
'total_buy_times' => $itemMeta['limit_num'], 'total_buy_times' => $itemMeta['limit_num'],
); ); {
{
$priceInfo = mt\Item::getPriceInfo($itemMeta); $priceInfo = mt\Item::getPriceInfo($itemMeta);
if (!empty($priceInfo)) { if (!empty($priceInfo)) {
$goodsDto['price_info'] = $priceInfo['price_info']; $goodsDto['price_info'] = $priceInfo['price_info'];
} }
} }
$propertyChgService->addUserChg(); $propertyChgService->addUserChg();
$this->_rspData(array( $this->_rspData(
array(
'award' => $awardService->toDto(), 'award' => $awardService->toDto(),
'property_chg' => $propertyChgService->toDto(), 'property_chg' => $propertyChgService->toDto(),
'goods_chg' => $goodsDto 'goods_chg' => $goodsDto
)); )
);
} }
public function getDiscountList() public function getDiscountList()
{ {
$items = array(); $items = array(); {
{ $types = array(
$types = array(mt\Item::HERO_TYPE, mt\Item::HERO_TYPE,
mt\Item::HERO_SKIN_TYPE, mt\Item::HERO_SKIN_TYPE,
mt\Item::GUN_SKIN_TYPE); mt\Item::GUN_SKIN_TYPE
mt\Item::filter(function ($meta) use(&$items, &$types) { );
mt\Item::filter(function ($meta) use (&$items, &$types) {
if (mt\Item::inTypes($meta, $types)) { if (mt\Item::inTypes($meta, $types)) {
array_push($items, $meta); array_push($items, $meta);
} }
@ -463,7 +488,7 @@ class ShopController extends BaseAuthedController {
}); });
} }
$goodsDtoList = array(); $goodsDtoList = array();
array_walk($items, function ($val) use(&$priceList, &$goodsDtoList) { array_walk($items, function ($val) use (&$priceList, &$goodsDtoList) {
$goodsDto = array( $goodsDto = array(
'item_id' => $val['id'], 'item_id' => $val['id'],
'gold_discount' => 0, 'gold_discount' => 0,
@ -475,13 +500,11 @@ class ShopController extends BaseAuthedController {
foreach ($costGroup as $cost) { foreach ($costGroup as $cost) {
if ($cost['discount'] > 0) { if ($cost['discount'] > 0) {
switch ($cost['item_id']) { switch ($cost['item_id']) {
case V_ITEM_GOLD: case V_ITEM_GOLD: {
{
$goodsDto['gold_discount'] = $cost['discount']; $goodsDto['gold_discount'] = $cost['discount'];
} }
break; break;
case V_ITEM_DIAMOND: case V_ITEM_DIAMOND: {
{
$goodsDto['diamond_discount'] = $cost['discount']; $goodsDto['diamond_discount'] = $cost['discount'];
} }
break; break;
@ -494,9 +517,11 @@ class ShopController extends BaseAuthedController {
} }
} }
}); });
$this->_rspData(array( $this->_rspData(
array(
'goods_list' => $goodsDtoList, 'goods_list' => $goodsDtoList,
)); )
);
} }
private function outsideBuy($shopId, $itemId, $itemNum, $costItemId) private function outsideBuy($shopId, $itemId, $itemNum, $costItemId)
@ -516,14 +541,15 @@ class ShopController extends BaseAuthedController {
$this->_rspErr(1, 'cost_item_id parameter error'); $this->_rspErr(1, 'cost_item_id parameter error');
return; return;
} }
$types = array(mt\Item::HERO_TYPE, $types = array(
mt\Item::HERO_TYPE,
mt\Item::HERO_SKIN_TYPE, mt\Item::HERO_SKIN_TYPE,
mt\Item::GUN_SKIN_TYPE); mt\Item::GUN_SKIN_TYPE
);
if (!mt\Item::inTypes($itemMeta, $types)) { if (!mt\Item::inTypes($itemMeta, $types)) {
$this->_rspErr(1, 'item_id parameter error'); $this->_rspErr(1, 'item_id parameter error');
return; return;
} } {
{
$errCode = 0; $errCode = 0;
$errMsg = ''; $errMsg = '';
if (!$this->canBuy($itemMeta, $errCode, $errMsg)) { if (!$this->canBuy($itemMeta, $errCode, $errMsg)) {
@ -564,29 +590,31 @@ class ShopController extends BaseAuthedController {
'limit_type' => $itemMeta['limit_type'], 'limit_type' => $itemMeta['limit_type'],
'bought_times' => 0, 'bought_times' => 0,
'total_buy_times' => $itemMeta['limit_num'], 'total_buy_times' => $itemMeta['limit_num'],
); ); {
{
$priceInfo = mt\Item::getPriceInfo($itemMeta); $priceInfo = mt\Item::getPriceInfo($itemMeta);
if (!empty($priceInfo)) { if (!empty($priceInfo)) {
$goodsDto['price_info'] = $priceInfo; $goodsDto['price_info'] = $priceInfo;
} }
} }
$propertyChgService->addUserChg(); $propertyChgService->addUserChg();
$this->_rspData(array( $this->_rspData(
array(
'award' => $awardService->toDto(), 'award' => $awardService->toDto(),
'property_chg' => $propertyChgService->toDto(), 'property_chg' => $propertyChgService->toDto(),
'goods_chg' => $goodsDto 'goods_chg' => $goodsDto
)); )
);
} }
private function getOutsideShopInfo() private function getOutsideShopInfo()
{ {
$items = array(); $items = array(); {
{ $types = array(
$types = array(mt\Item::HERO_TYPE, mt\Item::HERO_TYPE,
mt\Item::HERO_SKIN_TYPE, mt\Item::HERO_SKIN_TYPE,
mt\Item::GUN_SKIN_TYPE); mt\Item::GUN_SKIN_TYPE
mt\Item::filter(function ($meta) use(&$items, &$types) { );
mt\Item::filter(function ($meta) use (&$items, &$types) {
if (mt\Item::inTypes($meta, $types)) { if (mt\Item::inTypes($meta, $types)) {
array_push($items, $meta); array_push($items, $meta);
} }
@ -595,7 +623,7 @@ class ShopController extends BaseAuthedController {
} }
$goodsDtoList1 = array(); $goodsDtoList1 = array();
$goodsDtoList2 = array(); $goodsDtoList2 = array();
array_walk($items, function ($val) use(&$priceList, &$goodsDtoList1, &$goodsDtoList2) { array_walk($items, function ($val) use (&$priceList, &$goodsDtoList1, &$goodsDtoList2) {
$goodsDto = array( $goodsDto = array(
'goods_id' => $val['id'], 'goods_id' => $val['id'],
'item_id' => $val['id'], 'item_id' => $val['id'],
@ -611,19 +639,21 @@ class ShopController extends BaseAuthedController {
array_push($goodsDtoList1, $goodsDto); array_push($goodsDtoList1, $goodsDto);
} }
}); });
$this->_rspData(array( $this->_rspData(
array(
'info' => array( 'info' => array(
'shop_id' => mt\Shop::OUTSIDE_SHOP, 'shop_id' => mt\Shop::OUTSIDE_SHOP,
'goods_list1' => $goodsDtoList1, 'goods_list1' => $goodsDtoList1,
'goods_list2' => $goodsDtoList2, 'goods_list2' => $goodsDtoList2,
) )
)); )
);
} }
private function getCostItems($priceInfo, $costItemId) private function getCostItems($priceInfo, $costItemId)
{ {
$costGroup = null; $costGroup = null;
array_walk($priceInfo['price_info']['cost_list'], function ($val) use(&$costGroup, $costItemId) { array_walk($priceInfo['price_info']['cost_list'], function ($val) use (&$costGroup, $costItemId) {
if ($costGroup) { if ($costGroup) {
return; return;
} }
@ -637,19 +667,22 @@ class ShopController extends BaseAuthedController {
} }
$costItems = array(); $costItems = array();
array_walk($costGroup, function ($val) use (&$costItems, $priceInfo) { array_walk($costGroup, function ($val) use (&$costItems, $priceInfo) {
if ($val['discount'] > 0 && if (
$val['discount'] > 0 &&
$this->_getNowTime() >= $priceInfo['discount_begin_time'] && $this->_getNowTime() >= $priceInfo['discount_begin_time'] &&
$this->_getNowTime() <= $priceInfo['discount_end_time'] $this->_getNowTime() <= $priceInfo['discount_end_time']
) { ) {
array_push($costItems, array( array_push($costItems, array(
'item_id' => $val['item_id'], 'item_id' => $val['item_id'],
'item_num' => (int)($val['item_num'] * ($priceInfo['discount'] / 100)), 'item_num' => (int) ($val['item_num'] * ($priceInfo['discount'] / 100)),
)); )
);
} else { } else {
array_push($costItems, array( array_push($costItems, array(
'item_id' => $val['item_id'], 'item_id' => $val['item_id'],
'item_num' => $val['item_num'], 'item_num' => $val['item_num'],
)); )
);
} }
}); });
return $costItems; return $costItems;
@ -658,33 +691,28 @@ class ShopController extends BaseAuthedController {
private function internalAddItem($propertyChgService, $itemMeta) private function internalAddItem($propertyChgService, $itemMeta)
{ {
switch ($itemMeta['type']) { switch ($itemMeta['type']) {
case mt\Item::HERO_TYPE: case mt\Item::HERO_TYPE: {
{
Hero::addHero($itemMeta); Hero::addHero($itemMeta);
$propertyChgService->addHeroChg(); $propertyChgService->addHeroChg();
$propertyChgService->addUserChg(); $propertyChgService->addUserChg();
} }
break; break;
case mt\Item::HERO_SKIN_TYPE: case mt\Item::HERO_SKIN_TYPE: {
{
HeroSkin::addSkin($itemMeta); HeroSkin::addSkin($itemMeta);
$propertyChgService->addHeroSkinChg(); $propertyChgService->addHeroSkinChg();
} }
break; break;
case mt\Item::GUN_TYPE: case mt\Item::GUN_TYPE: {
{
Gun::addGun($itemMeta); Gun::addGun($itemMeta);
$propertyChgService->addGunChg(); $propertyChgService->addGunChg();
} }
break; break;
case mt\Item::GUN_SKIN_TYPE: case mt\Item::GUN_SKIN_TYPE: {
{
GunSkin::addSkin($itemMeta); GunSkin::addSkin($itemMeta);
$propertyChgService->addGunSkinChg(); $propertyChgService->addGunSkinChg();
} }
break; break;
default: default: {
{
Bag::addItem($itemMeta['id'], 1); Bag::addItem($itemMeta['id'], 1);
$propertyChgService->addBagChg(); $propertyChgService->addBagChg();
} }
@ -697,8 +725,7 @@ class ShopController extends BaseAuthedController {
$errCode = 0; $errCode = 0;
$errMsg = ''; $errMsg = '';
switch ($itemMeta['type']) { switch ($itemMeta['type']) {
case mt\Item::HERO_TYPE: case mt\Item::HERO_TYPE: {
{
$heroDb = Hero::find($itemMeta['id']); $heroDb = Hero::find($itemMeta['id']);
if ($heroDb) { if ($heroDb) {
$errCode = 10; $errCode = 10;
@ -707,8 +734,7 @@ class ShopController extends BaseAuthedController {
} }
} }
break; break;
case mt\Item::HERO_SKIN_TYPE: case mt\Item::HERO_SKIN_TYPE: {
{
$heroSkinDb = HeroSkin::find($itemMeta['id']); $heroSkinDb = HeroSkin::find($itemMeta['id']);
if ($heroSkinDb) { if ($heroSkinDb) {
$errCode = 10; $errCode = 10;
@ -717,8 +743,7 @@ class ShopController extends BaseAuthedController {
} }
} }
break; break;
case mt\Item::GUN_SKIN_TYPE: case mt\Item::GUN_SKIN_TYPE: {
{
$gunSkinDb = GunSkin::find($itemMeta['id']); $gunSkinDb = GunSkin::find($itemMeta['id']);
if ($gunSkinDb) { if ($gunSkinDb) {
$errCode = 10; $errCode = 10;
@ -727,8 +752,7 @@ class ShopController extends BaseAuthedController {
} }
} }
break; break;
default: default: {
{
return true; return true;
} }
break; break;