...
This commit is contained in:
parent
2c7a64bfea
commit
c28cb72a82
@ -27,7 +27,8 @@ use models\Gun;
|
||||
use models\GunSkin;
|
||||
use models\ShopBuyRecord;
|
||||
|
||||
class ShopController extends BaseAuthedController {
|
||||
class ShopController extends BaseAuthedController
|
||||
{
|
||||
|
||||
const TOKEN_TYPE_CEG = '1';
|
||||
const TOKEN_TYPE_CEC = '2';
|
||||
@ -48,27 +49,57 @@ class ShopController extends BaseAuthedController {
|
||||
public function getGoodsList()
|
||||
{
|
||||
$goodsList = mt\ShopGoods::all();
|
||||
|
||||
$this->_rspData(array(
|
||||
'goods_list' => $goodsList ? $goodsList : array(),
|
||||
));
|
||||
$goodsList = $goodsList ? $goodsList : array();
|
||||
$buyRecordHash = ShopBuyRecord::allToHash();
|
||||
|
||||
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()
|
||||
{
|
||||
$shopList = mt\Shop::all();
|
||||
|
||||
$this->_rspData(array(
|
||||
'shop_name_list' => $shopList ? $shopList : array(),
|
||||
));
|
||||
$this->_rspData(
|
||||
array(
|
||||
'shop_name_list' => $shopList ? $shopList : array(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function buyGoodsNew()
|
||||
{
|
||||
$id = getReqVal('id', 0);
|
||||
$token_type = getReqVal('token_type', '');
|
||||
$goods_num = getReqVal('goods_num', 0);
|
||||
|
||||
|
||||
$row = mt\ShopGoods::get($id);
|
||||
|
||||
$desired_token_type = $row['token_type'];
|
||||
@ -79,7 +110,7 @@ class ShopController extends BaseAuthedController {
|
||||
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']}");
|
||||
return;
|
||||
}
|
||||
@ -87,84 +118,80 @@ class ShopController extends BaseAuthedController {
|
||||
$buyRecordHash = ShopBuyRecord::allToHash();
|
||||
$boughtTimes = 1;
|
||||
switch ($row['limit_type']) {
|
||||
case ShopController::DAILY_BUY_LIMIT:
|
||||
{
|
||||
$buyRecord = getXVal($buyRecordHash, $id);
|
||||
$boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1: 1;
|
||||
if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $row['limit_num']) {
|
||||
$this->_rspErr(2, 'Has reached the maximum number of purchase restrictions today');
|
||||
return;
|
||||
}
|
||||
if ($row['limit_num'] <= 0) {
|
||||
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ShopController::WEEKLY_BUY_LIMIT:
|
||||
{
|
||||
$buyRecord = getXVal($buyRecordHash, $id);
|
||||
$boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1: 1;
|
||||
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');
|
||||
return;
|
||||
}
|
||||
if ($row['limit_num'] <= 0) {
|
||||
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ShopController::TOTAL_BUY_LIMIT:
|
||||
{
|
||||
$buyRecord = getXVal($buyRecordHash, $id);
|
||||
$boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1: 1;
|
||||
if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $row['limit_num']) {
|
||||
$this->_rspErr(2, 'The 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;
|
||||
case ShopController::DAILY_BUY_LIMIT: {
|
||||
$buyRecord = getXVal($buyRecordHash, $id);
|
||||
$boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1 : 1;
|
||||
if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $row['limit_num']) {
|
||||
$this->_rspErr(2, 'Has reached the maximum number of purchase restrictions today');
|
||||
return;
|
||||
}
|
||||
if ($row['limit_num'] <= 0) {
|
||||
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ShopController::WEEKLY_BUY_LIMIT: {
|
||||
$buyRecord = getXVal($buyRecordHash, $id);
|
||||
$boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1;
|
||||
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');
|
||||
return;
|
||||
}
|
||||
if ($row['limit_num'] <= 0) {
|
||||
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ShopController::TOTAL_BUY_LIMIT: {
|
||||
$buyRecord = getXVal($buyRecordHash, $id);
|
||||
$boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1;
|
||||
if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $row['limit_num']) {
|
||||
$this->_rspErr(2, 'The 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;
|
||||
}
|
||||
|
||||
$price_array = splitStr1($row['price']);
|
||||
$discount_array = splitStr1($row['discount']);
|
||||
|
||||
|
||||
$need_price = $price_array[$token_pos];
|
||||
$discount = $discount_array[$token_pos];
|
||||
|
||||
$discount_begin = strtotime($row['discount_begin'].' UTC');
|
||||
$discount_end = strtotime($row['discount_end'].' UTC');
|
||||
$discount_begin = strtotime($row['discount_begin'] . ' UTC');
|
||||
$discount_end = strtotime($row['discount_end'] . ' UTC');
|
||||
$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));
|
||||
}
|
||||
|
||||
$costItemId = $this->getCostItemIdByTokenType($token_type);
|
||||
|
||||
switch($token_type) {
|
||||
|
||||
switch ($token_type) {
|
||||
case ShopController::TOKEN_TYPE_CEG:
|
||||
case ShopController::TOKEN_TYPE_CEC:
|
||||
$costItems = $this->makeCostItems($costItemId, $goods_num*$need_price);
|
||||
$costItems = $this->makeCostItems($costItemId, $goods_num * $need_price);
|
||||
$lackItem = null;
|
||||
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$itemMeta = mt\Item::get($row['goods_id']);
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
for ($i = 0; $i<$goods_num; $i++) {
|
||||
for ($i = 0; $i < $goods_num; $i++) {
|
||||
$this->internalAddItem($propertyChgService, $itemMeta);
|
||||
}
|
||||
$awardService = new services\AwardService();
|
||||
@ -184,19 +211,20 @@ class ShopController extends BaseAuthedController {
|
||||
'limit_type' => $row['limit_type'],
|
||||
'bought_times' => $boughtTimes,
|
||||
'total_buy_times' => $row['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
|
||||
));
|
||||
$this->_rspData(
|
||||
array(
|
||||
'award' => $awardService->toDto(),
|
||||
'property_chg' => $propertyChgService->toDto(),
|
||||
'goods_chg' => $goodsDto
|
||||
)
|
||||
);
|
||||
break;
|
||||
|
||||
case ShopController::TOKEN_TYPE_BCEG:
|
||||
@ -208,13 +236,13 @@ class ShopController extends BaseAuthedController {
|
||||
case ShopController::TOKEN_TYPE_MATIC:
|
||||
case ShopController::TOKEN_TYPE_BNB:
|
||||
default:
|
||||
$this->_rspErr(1, "token_type is unsupport, {$token_type}");
|
||||
$this->_rspErr(1, "token_type is unsupport, {$token_type}");
|
||||
}
|
||||
}
|
||||
|
||||
private function getCostItemIdByTokenType($token_type)
|
||||
{
|
||||
switch($token_type) {
|
||||
switch ($token_type) {
|
||||
case ShopController::TOKEN_TYPE_CEG:
|
||||
return V_ITEM_GOLD;
|
||||
break;
|
||||
@ -254,13 +282,15 @@ class ShopController extends BaseAuthedController {
|
||||
}
|
||||
$goodsList = mt\ShopGoods::getGoodsList($shopId);
|
||||
if (!$goodsList) {
|
||||
$this->_rspData(array(
|
||||
'info' => array(
|
||||
'shop_id' => $shopId,
|
||||
'goods_list1' => array(),
|
||||
'goods_list2' => array(),
|
||||
$this->_rspData(
|
||||
array(
|
||||
'info' => array(
|
||||
'shop_id' => $shopId,
|
||||
'goods_list1' => array(),
|
||||
'goods_list2' => array(),
|
||||
)
|
||||
)
|
||||
));
|
||||
);
|
||||
return;
|
||||
}
|
||||
$buyRecordHash = ShopBuyRecord::allToHash();
|
||||
@ -279,28 +309,24 @@ class ShopController extends BaseAuthedController {
|
||||
'total_buy_times' => $itemMeta['limit_num'],
|
||||
);
|
||||
switch ($itemMeta['limit_type']) {
|
||||
case mt\Item::DAILY_BUY_LIMIT:
|
||||
{
|
||||
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
|
||||
$goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_day_buy_times'] : 0;
|
||||
}
|
||||
break;
|
||||
case mt\Item::WEEKLY_BUY_LIMIT:
|
||||
{
|
||||
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
|
||||
$goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0;
|
||||
}
|
||||
break;
|
||||
case mt\Item::TOTAL_BUY_LIMIT:
|
||||
{
|
||||
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
|
||||
$goodsDto['bought_times'] = $buyRecord ? $buyRecord['total_buy_times'] : 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
break;
|
||||
case mt\Item::DAILY_BUY_LIMIT: {
|
||||
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
|
||||
$goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_day_buy_times'] : 0;
|
||||
}
|
||||
break;
|
||||
case mt\Item::WEEKLY_BUY_LIMIT: {
|
||||
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
|
||||
$goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0;
|
||||
}
|
||||
break;
|
||||
case mt\Item::TOTAL_BUY_LIMIT: {
|
||||
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
|
||||
$goodsDto['bought_times'] = $buyRecord ? $buyRecord['total_buy_times'] : 0;
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
}
|
||||
break;
|
||||
}
|
||||
$priceInfo = mt\Item::getPriceInfo($itemMeta);
|
||||
if (!empty($priceInfo)) {
|
||||
@ -309,13 +335,15 @@ class ShopController extends BaseAuthedController {
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->_rspData(array(
|
||||
'info' => array(
|
||||
'shop_id' => $shopId,
|
||||
'goods_list1' => $goodsDtoList1,
|
||||
'goods_list2' => $goodsDtoList2,
|
||||
$this->_rspData(
|
||||
array(
|
||||
'info' => array(
|
||||
'shop_id' => $shopId,
|
||||
'goods_list1' => $goodsDtoList1,
|
||||
'goods_list2' => $goodsDtoList2,
|
||||
)
|
||||
)
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
public function buyGoods()
|
||||
@ -345,54 +373,49 @@ class ShopController extends BaseAuthedController {
|
||||
$buyRecordHash = ShopBuyRecord::allToHash();
|
||||
$boughtTimes = 1;
|
||||
switch ($itemMeta['limit_type']) {
|
||||
case mt\Item::DAILY_BUY_LIMIT:
|
||||
{
|
||||
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
|
||||
$boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1: 1;
|
||||
if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $itemMeta['limit_num']) {
|
||||
$this->_rspErr(2, 'Has reached the maximum number of purchase restrictions today');
|
||||
return;
|
||||
}
|
||||
if ($itemMeta['limit_num'] <= 0) {
|
||||
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case mt\Item::WEEKLY_BUY_LIMIT:
|
||||
{
|
||||
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
|
||||
$boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1: 1;
|
||||
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');
|
||||
return;
|
||||
}
|
||||
if ($itemMeta['limit_num'] <= 0) {
|
||||
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case mt\Item::TOTAL_BUY_LIMIT:
|
||||
{
|
||||
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
|
||||
$boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1: 1;
|
||||
if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $itemMeta['limit_num']) {
|
||||
$this->_rspErr(2, 'The 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;
|
||||
}
|
||||
{
|
||||
case mt\Item::DAILY_BUY_LIMIT: {
|
||||
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
|
||||
$boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1 : 1;
|
||||
if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $itemMeta['limit_num']) {
|
||||
$this->_rspErr(2, 'Has reached the maximum number of purchase restrictions today');
|
||||
return;
|
||||
}
|
||||
if ($itemMeta['limit_num'] <= 0) {
|
||||
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case mt\Item::WEEKLY_BUY_LIMIT: {
|
||||
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
|
||||
$boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1;
|
||||
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');
|
||||
return;
|
||||
}
|
||||
if ($itemMeta['limit_num'] <= 0) {
|
||||
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case mt\Item::TOTAL_BUY_LIMIT: {
|
||||
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
|
||||
$boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1;
|
||||
if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $itemMeta['limit_num']) {
|
||||
$this->_rspErr(2, 'The 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;
|
||||
} {
|
||||
$errCode = 0;
|
||||
$errMsg = '';
|
||||
if (!$this->canBuy($itemMeta, $errCode, $errMsg)) {
|
||||
@ -433,29 +456,31 @@ class ShopController extends BaseAuthedController {
|
||||
'limit_type' => $itemMeta['limit_type'],
|
||||
'bought_times' => $boughtTimes,
|
||||
'total_buy_times' => $itemMeta['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
|
||||
));
|
||||
$this->_rspData(
|
||||
array(
|
||||
'award' => $awardService->toDto(),
|
||||
'property_chg' => $propertyChgService->toDto(),
|
||||
'goods_chg' => $goodsDto
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getDiscountList()
|
||||
{
|
||||
$items = array();
|
||||
{
|
||||
$types = array(mt\Item::HERO_TYPE,
|
||||
mt\Item::HERO_SKIN_TYPE,
|
||||
mt\Item::GUN_SKIN_TYPE);
|
||||
mt\Item::filter(function ($meta) use(&$items, &$types) {
|
||||
$items = array(); {
|
||||
$types = array(
|
||||
mt\Item::HERO_TYPE,
|
||||
mt\Item::HERO_SKIN_TYPE,
|
||||
mt\Item::GUN_SKIN_TYPE
|
||||
);
|
||||
mt\Item::filter(function ($meta) use (&$items, &$types) {
|
||||
if (mt\Item::inTypes($meta, $types)) {
|
||||
array_push($items, $meta);
|
||||
}
|
||||
@ -463,7 +488,7 @@ class ShopController extends BaseAuthedController {
|
||||
});
|
||||
}
|
||||
$goodsDtoList = array();
|
||||
array_walk($items, function ($val) use(&$priceList, &$goodsDtoList) {
|
||||
array_walk($items, function ($val) use (&$priceList, &$goodsDtoList) {
|
||||
$goodsDto = array(
|
||||
'item_id' => $val['id'],
|
||||
'gold_discount' => 0,
|
||||
@ -475,16 +500,14 @@ class ShopController extends BaseAuthedController {
|
||||
foreach ($costGroup as $cost) {
|
||||
if ($cost['discount'] > 0) {
|
||||
switch ($cost['item_id']) {
|
||||
case V_ITEM_GOLD:
|
||||
{
|
||||
$goodsDto['gold_discount'] = $cost['discount'];
|
||||
}
|
||||
break;
|
||||
case V_ITEM_DIAMOND:
|
||||
{
|
||||
$goodsDto['diamond_discount'] = $cost['discount'];
|
||||
}
|
||||
break;
|
||||
case V_ITEM_GOLD: {
|
||||
$goodsDto['gold_discount'] = $cost['discount'];
|
||||
}
|
||||
break;
|
||||
case V_ITEM_DIAMOND: {
|
||||
$goodsDto['diamond_discount'] = $cost['discount'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -492,11 +515,13 @@ class ShopController extends BaseAuthedController {
|
||||
if ($goodsDto['gold_discount'] > 0 || $goodsDto['diamond_discount'] > 0) {
|
||||
array_push($goodsDtoList, $goodsDto);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
$this->_rspData(array(
|
||||
'goods_list' => $goodsDtoList,
|
||||
));
|
||||
$this->_rspData(
|
||||
array(
|
||||
'goods_list' => $goodsDtoList,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function outsideBuy($shopId, $itemId, $itemNum, $costItemId)
|
||||
@ -516,14 +541,15 @@ class ShopController extends BaseAuthedController {
|
||||
$this->_rspErr(1, 'cost_item_id parameter error');
|
||||
return;
|
||||
}
|
||||
$types = array(mt\Item::HERO_TYPE,
|
||||
mt\Item::HERO_SKIN_TYPE,
|
||||
mt\Item::GUN_SKIN_TYPE);
|
||||
$types = array(
|
||||
mt\Item::HERO_TYPE,
|
||||
mt\Item::HERO_SKIN_TYPE,
|
||||
mt\Item::GUN_SKIN_TYPE
|
||||
);
|
||||
if (!mt\Item::inTypes($itemMeta, $types)) {
|
||||
$this->_rspErr(1, 'item_id parameter error');
|
||||
return;
|
||||
}
|
||||
{
|
||||
} {
|
||||
$errCode = 0;
|
||||
$errMsg = '';
|
||||
if (!$this->canBuy($itemMeta, $errCode, $errMsg)) {
|
||||
@ -564,29 +590,31 @@ class ShopController extends BaseAuthedController {
|
||||
'limit_type' => $itemMeta['limit_type'],
|
||||
'bought_times' => 0,
|
||||
'total_buy_times' => $itemMeta['limit_num'],
|
||||
);
|
||||
{
|
||||
); {
|
||||
$priceInfo = mt\Item::getPriceInfo($itemMeta);
|
||||
if (!empty($priceInfo)) {
|
||||
$goodsDto['price_info'] = $priceInfo;
|
||||
}
|
||||
}
|
||||
$propertyChgService->addUserChg();
|
||||
$this->_rspData(array(
|
||||
'award' => $awardService->toDto(),
|
||||
'property_chg' => $propertyChgService->toDto(),
|
||||
'goods_chg' => $goodsDto
|
||||
));
|
||||
$this->_rspData(
|
||||
array(
|
||||
'award' => $awardService->toDto(),
|
||||
'property_chg' => $propertyChgService->toDto(),
|
||||
'goods_chg' => $goodsDto
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function getOutsideShopInfo()
|
||||
{
|
||||
$items = array();
|
||||
{
|
||||
$types = array(mt\Item::HERO_TYPE,
|
||||
mt\Item::HERO_SKIN_TYPE,
|
||||
mt\Item::GUN_SKIN_TYPE);
|
||||
mt\Item::filter(function ($meta) use(&$items, &$types) {
|
||||
$items = array(); {
|
||||
$types = array(
|
||||
mt\Item::HERO_TYPE,
|
||||
mt\Item::HERO_SKIN_TYPE,
|
||||
mt\Item::GUN_SKIN_TYPE
|
||||
);
|
||||
mt\Item::filter(function ($meta) use (&$items, &$types) {
|
||||
if (mt\Item::inTypes($meta, $types)) {
|
||||
array_push($items, $meta);
|
||||
}
|
||||
@ -595,7 +623,7 @@ class ShopController extends BaseAuthedController {
|
||||
}
|
||||
$goodsDtoList1 = array();
|
||||
$goodsDtoList2 = array();
|
||||
array_walk($items, function ($val) use(&$priceList, &$goodsDtoList1, &$goodsDtoList2) {
|
||||
array_walk($items, function ($val) use (&$priceList, &$goodsDtoList1, &$goodsDtoList2) {
|
||||
$goodsDto = array(
|
||||
'goods_id' => $val['id'],
|
||||
'item_id' => $val['id'],
|
||||
@ -611,19 +639,21 @@ class ShopController extends BaseAuthedController {
|
||||
array_push($goodsDtoList1, $goodsDto);
|
||||
}
|
||||
});
|
||||
$this->_rspData(array(
|
||||
'info' => array(
|
||||
'shop_id' => mt\Shop::OUTSIDE_SHOP,
|
||||
'goods_list1' => $goodsDtoList1,
|
||||
'goods_list2' => $goodsDtoList2,
|
||||
$this->_rspData(
|
||||
array(
|
||||
'info' => array(
|
||||
'shop_id' => mt\Shop::OUTSIDE_SHOP,
|
||||
'goods_list1' => $goodsDtoList1,
|
||||
'goods_list2' => $goodsDtoList2,
|
||||
)
|
||||
)
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
private function getCostItems($priceInfo, $costItemId)
|
||||
{
|
||||
$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) {
|
||||
return;
|
||||
}
|
||||
@ -637,19 +667,22 @@ class ShopController extends BaseAuthedController {
|
||||
}
|
||||
$costItems = array();
|
||||
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_end_time']
|
||||
) {
|
||||
array_push($costItems, array(
|
||||
'item_id' => $val['item_id'],
|
||||
'item_num' => (int)($val['item_num'] * ($priceInfo['discount'] / 100)),
|
||||
));
|
||||
'item_num' => (int) ($val['item_num'] * ($priceInfo['discount'] / 100)),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
array_push($costItems, array(
|
||||
'item_id' => $val['item_id'],
|
||||
'item_num' => $val['item_num'],
|
||||
));
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
return $costItems;
|
||||
@ -658,37 +691,32 @@ class ShopController extends BaseAuthedController {
|
||||
private function internalAddItem($propertyChgService, $itemMeta)
|
||||
{
|
||||
switch ($itemMeta['type']) {
|
||||
case mt\Item::HERO_TYPE:
|
||||
{
|
||||
Hero::addHero($itemMeta);
|
||||
$propertyChgService->addHeroChg();
|
||||
$propertyChgService->addUserChg();
|
||||
}
|
||||
break;
|
||||
case mt\Item::HERO_SKIN_TYPE:
|
||||
{
|
||||
HeroSkin::addSkin($itemMeta);
|
||||
$propertyChgService->addHeroSkinChg();
|
||||
}
|
||||
break;
|
||||
case mt\Item::GUN_TYPE:
|
||||
{
|
||||
Gun::addGun($itemMeta);
|
||||
$propertyChgService->addGunChg();
|
||||
}
|
||||
break;
|
||||
case mt\Item::GUN_SKIN_TYPE:
|
||||
{
|
||||
GunSkin::addSkin($itemMeta);
|
||||
$propertyChgService->addGunSkinChg();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
Bag::addItem($itemMeta['id'], 1);
|
||||
$propertyChgService->addBagChg();
|
||||
}
|
||||
break;
|
||||
case mt\Item::HERO_TYPE: {
|
||||
Hero::addHero($itemMeta);
|
||||
$propertyChgService->addHeroChg();
|
||||
$propertyChgService->addUserChg();
|
||||
}
|
||||
break;
|
||||
case mt\Item::HERO_SKIN_TYPE: {
|
||||
HeroSkin::addSkin($itemMeta);
|
||||
$propertyChgService->addHeroSkinChg();
|
||||
}
|
||||
break;
|
||||
case mt\Item::GUN_TYPE: {
|
||||
Gun::addGun($itemMeta);
|
||||
$propertyChgService->addGunChg();
|
||||
}
|
||||
break;
|
||||
case mt\Item::GUN_SKIN_TYPE: {
|
||||
GunSkin::addSkin($itemMeta);
|
||||
$propertyChgService->addGunSkinChg();
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
Bag::addItem($itemMeta['id'], 1);
|
||||
$propertyChgService->addBagChg();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -697,43 +725,39 @@ class ShopController extends BaseAuthedController {
|
||||
$errCode = 0;
|
||||
$errMsg = '';
|
||||
switch ($itemMeta['type']) {
|
||||
case mt\Item::HERO_TYPE:
|
||||
{
|
||||
$heroDb = Hero::find($itemMeta['id']);
|
||||
if ($heroDb) {
|
||||
$errCode = 10;
|
||||
$errMsg = 'You already have the hero';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case mt\Item::HERO_SKIN_TYPE:
|
||||
{
|
||||
$heroSkinDb = HeroSkin::find($itemMeta['id']);
|
||||
if ($heroSkinDb) {
|
||||
$errCode = 10;
|
||||
$errMsg = 'You already have the skin';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case mt\Item::GUN_SKIN_TYPE:
|
||||
{
|
||||
$gunSkinDb = GunSkin::find($itemMeta['id']);
|
||||
if ($gunSkinDb) {
|
||||
$errCode = 10;
|
||||
$errMsg = 'You already have the skin';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case mt\Item::HERO_TYPE: {
|
||||
$heroDb = Hero::find($itemMeta['id']);
|
||||
if ($heroDb) {
|
||||
$errCode = 10;
|
||||
$errMsg = 'You already have the hero';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case mt\Item::HERO_SKIN_TYPE: {
|
||||
$heroSkinDb = HeroSkin::find($itemMeta['id']);
|
||||
if ($heroSkinDb) {
|
||||
$errCode = 10;
|
||||
$errMsg = 'You already have the skin';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case mt\Item::GUN_SKIN_TYPE: {
|
||||
$gunSkinDb = GunSkin::find($itemMeta['id']);
|
||||
if ($gunSkinDb) {
|
||||
$errCode = 10;
|
||||
$errMsg = 'You already have the skin';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user