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,27 +49,57 @@ class ShopController extends BaseAuthedController {
public function getGoodsList() public function getGoodsList()
{ {
$goodsList = mt\ShopGoods::all(); $goodsList = mt\ShopGoods::all();
$goodsList = $goodsList ? $goodsList : array();
$this->_rspData(array( $buyRecordHash = ShopBuyRecord::allToHash();
'goods_list' => $goodsList ? $goodsList : array(),
)); foreach ($goodsList as $goods) {
$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(
'shop_name_list' => $shopList ? $shopList : array(), array(
)); 'shop_name_list' => $shopList ? $shopList : array(),
)
);
} }
public function buyGoodsNew() public function buyGoodsNew()
{ {
$id = getReqVal('id', 0); $id = getReqVal('id', 0);
$token_type = getReqVal('token_type', ''); $token_type = getReqVal('token_type', '');
$goods_num = getReqVal('goods_num', 0); $goods_num = getReqVal('goods_num', 0);
$row = mt\ShopGoods::get($id); $row = mt\ShopGoods::get($id);
$desired_token_type = $row['token_type']; $desired_token_type = $row['token_type'];
@ -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,84 +118,80 @@ 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; }
} if ($row['limit_num'] <= 0) {
if ($row['limit_num'] <= 0) { $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; }
} }
} break;
break; case ShopController::WEEKLY_BUY_LIMIT: {
case ShopController::WEEKLY_BUY_LIMIT: $buyRecord = getXVal($buyRecordHash, $id);
{ $boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1;
$buyRecord = getXVal($buyRecordHash, $id); if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $row['limit_num']) {
$boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1: 1; $this->_rspErr(2, 'The maximum number of purchase restrictions this week has been reached');
if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $row['limit_num']) { return;
$this->_rspErr(2, 'The maximum number of purchase restrictions this week has been reached'); }
return; if ($row['limit_num'] <= 0) {
} $this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
if ($row['limit_num'] <= 0) { return;
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached'); }
return; }
} break;
} case ShopController::TOTAL_BUY_LIMIT: {
break; $buyRecord = getXVal($buyRecordHash, $id);
case ShopController::TOTAL_BUY_LIMIT: $boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1;
{ if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $row['limit_num']) {
$buyRecord = getXVal($buyRecordHash, $id); $this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
$boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1: 1; return;
if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $row['limit_num']) { }
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached'); if ($row['limit_num'] <= 0) {
return; $this->_rspErr(2, 'he maximum number of purchase restrictions has been reached');
} return;
if ($row['limit_num'] <= 0) { }
$this->_rspErr(2, 'he maximum number of purchase restrictions has been reached'); }
return; break;
} default: {
} }
break; break;
default:
{
}
break;
} }
$price_array = splitStr1($row['price']); $price_array = splitStr1($row['price']);
$discount_array = splitStr1($row['discount']); $discount_array = splitStr1($row['discount']);
$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));
return; return;
} }
$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(
'award' => $awardService->toDto(), array(
'property_chg' => $propertyChgService->toDto(), 'award' => $awardService->toDto(),
'goods_chg' => $goodsDto 'property_chg' => $propertyChgService->toDto(),
)); 'goods_chg' => $goodsDto
)
);
break; break;
case ShopController::TOKEN_TYPE_BCEG: case ShopController::TOKEN_TYPE_BCEG:
@ -208,13 +236,13 @@ class ShopController extends BaseAuthedController {
case ShopController::TOKEN_TYPE_MATIC: case ShopController::TOKEN_TYPE_MATIC:
case ShopController::TOKEN_TYPE_BNB: case ShopController::TOKEN_TYPE_BNB:
default: default:
$this->_rspErr(1, "token_type is unsupport, {$token_type}"); $this->_rspErr(1, "token_type is unsupport, {$token_type}");
} }
} }
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(
'info' => array( array(
'shop_id' => $shopId, 'info' => array(
'goods_list1' => array(), 'shop_id' => $shopId,
'goods_list2' => array(), 'goods_list1' => array(),
'goods_list2' => array(),
)
) )
)); );
return; return;
} }
$buyRecordHash = ShopBuyRecord::allToHash(); $buyRecordHash = ShopBuyRecord::allToHash();
@ -279,28 +309,24 @@ 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']);
{ $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0;
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']); }
$goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0; break;
} case mt\Item::TOTAL_BUY_LIMIT: {
break; $buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
case mt\Item::TOTAL_BUY_LIMIT: $goodsDto['bought_times'] = $buyRecord ? $buyRecord['total_buy_times'] : 0;
{ }
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']); break;
$goodsDto['bought_times'] = $buyRecord ? $buyRecord['total_buy_times'] : 0; default: {
} }
break; break;
default:
{
}
break;
} }
$priceInfo = mt\Item::getPriceInfo($itemMeta); $priceInfo = mt\Item::getPriceInfo($itemMeta);
if (!empty($priceInfo)) { if (!empty($priceInfo)) {
@ -309,13 +335,15 @@ class ShopController extends BaseAuthedController {
} }
} }
} }
$this->_rspData(array( $this->_rspData(
'info' => array( array(
'shop_id' => $shopId, 'info' => array(
'goods_list1' => $goodsDtoList1, 'shop_id' => $shopId,
'goods_list2' => $goodsDtoList2, 'goods_list1' => $goodsDtoList1,
'goods_list2' => $goodsDtoList2,
)
) )
)); );
} }
public function buyGoods() public function buyGoods()
@ -345,54 +373,49 @@ 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; }
} if ($itemMeta['limit_num'] <= 0) {
if ($itemMeta['limit_num'] <= 0) { $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; }
} }
} break;
break; case mt\Item::WEEKLY_BUY_LIMIT: {
case mt\Item::WEEKLY_BUY_LIMIT: $buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
{ $boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1;
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']); if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $itemMeta['limit_num']) {
$boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1: 1; $this->_rspErr(2, 'The maximum number of purchase restrictions this week has been reached');
if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $itemMeta['limit_num']) { return;
$this->_rspErr(2, 'The maximum number of purchase restrictions this week has been reached'); }
return; if ($itemMeta['limit_num'] <= 0) {
} $this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
if ($itemMeta['limit_num'] <= 0) { return;
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached'); }
return; }
} break;
} case mt\Item::TOTAL_BUY_LIMIT: {
break; $buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
case mt\Item::TOTAL_BUY_LIMIT: $boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1;
{ if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $itemMeta['limit_num']) {
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']); $this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
$boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1: 1; return;
if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $itemMeta['limit_num']) { }
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached'); if ($itemMeta['limit_num'] <= 0) {
return; $this->_rspErr(2, 'he maximum number of purchase restrictions has been reached');
} return;
if ($itemMeta['limit_num'] <= 0) { }
$this->_rspErr(2, 'he maximum number of purchase restrictions has been reached'); }
return; break;
} default: {
} }
break; break;
default: } {
{
}
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(
'award' => $awardService->toDto(), array(
'property_chg' => $propertyChgService->toDto(), 'award' => $awardService->toDto(),
'goods_chg' => $goodsDto 'property_chg' => $propertyChgService->toDto(),
)); '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,16 +500,14 @@ 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;
} }
} }
} }
@ -492,11 +515,13 @@ class ShopController extends BaseAuthedController {
if ($goodsDto['gold_discount'] > 0 || $goodsDto['diamond_discount'] > 0) { if ($goodsDto['gold_discount'] > 0 || $goodsDto['diamond_discount'] > 0) {
array_push($goodsDtoList, $goodsDto); array_push($goodsDtoList, $goodsDto);
} }
} }
}); });
$this->_rspData(array( $this->_rspData(
'goods_list' => $goodsDtoList, array(
)); '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_SKIN_TYPE, mt\Item::HERO_TYPE,
mt\Item::GUN_SKIN_TYPE); mt\Item::HERO_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(
'award' => $awardService->toDto(), array(
'property_chg' => $propertyChgService->toDto(), 'award' => $awardService->toDto(),
'goods_chg' => $goodsDto 'property_chg' => $propertyChgService->toDto(),
)); '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(
'info' => array( array(
'shop_id' => mt\Shop::OUTSIDE_SHOP, 'info' => array(
'goods_list1' => $goodsDtoList1, 'shop_id' => mt\Shop::OUTSIDE_SHOP,
'goods_list2' => $goodsDtoList2, 'goods_list1' => $goodsDtoList1,
'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,37 +691,32 @@ 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);
{ $propertyChgService->addHeroSkinChg();
HeroSkin::addSkin($itemMeta); }
$propertyChgService->addHeroSkinChg(); break;
} case mt\Item::GUN_TYPE: {
break; Gun::addGun($itemMeta);
case mt\Item::GUN_TYPE: $propertyChgService->addGunChg();
{ }
Gun::addGun($itemMeta); break;
$propertyChgService->addGunChg(); case mt\Item::GUN_SKIN_TYPE: {
} GunSkin::addSkin($itemMeta);
break; $propertyChgService->addGunSkinChg();
case mt\Item::GUN_SKIN_TYPE: }
{ break;
GunSkin::addSkin($itemMeta); default: {
$propertyChgService->addGunSkinChg(); Bag::addItem($itemMeta['id'], 1);
} $propertyChgService->addBagChg();
break; }
default: break;
{
Bag::addItem($itemMeta['id'], 1);
$propertyChgService->addBagChg();
}
break;
} }
} }
@ -697,43 +725,39 @@ 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; $errMsg = 'You already have the hero';
$errMsg = 'You already have the hero'; return false;
return false; }
} }
} break;
break; case mt\Item::HERO_SKIN_TYPE: {
case mt\Item::HERO_SKIN_TYPE: $heroSkinDb = HeroSkin::find($itemMeta['id']);
{ if ($heroSkinDb) {
$heroSkinDb = HeroSkin::find($itemMeta['id']); $errCode = 10;
if ($heroSkinDb) { $errMsg = 'You already have the skin';
$errCode = 10; return false;
$errMsg = 'You already have the skin'; }
return false; }
} break;
} case mt\Item::GUN_SKIN_TYPE: {
break; $gunSkinDb = GunSkin::find($itemMeta['id']);
case mt\Item::GUN_SKIN_TYPE: if ($gunSkinDb) {
{ $errCode = 10;
$gunSkinDb = GunSkin::find($itemMeta['id']); $errMsg = 'You already have the skin';
if ($gunSkinDb) { return false;
$errCode = 10; }
$errMsg = 'You already have the skin'; }
return false; break;
} default: {
} return true;
break; }
default: break;
{
return true;
}
break;
} }
return true; return true;
} }
} }