...
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,19 +49,49 @@ class ShopController extends BaseAuthedController {
|
||||
public function getGoodsList()
|
||||
{
|
||||
$goodsList = mt\ShopGoods::all();
|
||||
$goodsList = $goodsList ? $goodsList : array();
|
||||
$buyRecordHash = ShopBuyRecord::allToHash();
|
||||
|
||||
$this->_rspData(array(
|
||||
'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()
|
||||
{
|
||||
$shopList = mt\Shop::all();
|
||||
|
||||
$this->_rspData(array(
|
||||
$this->_rspData(
|
||||
array(
|
||||
'shop_name_list' => $shopList ? $shopList : array(),
|
||||
));
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function buyGoodsNew()
|
||||
@ -87,8 +118,7 @@ class ShopController extends BaseAuthedController {
|
||||
$buyRecordHash = ShopBuyRecord::allToHash();
|
||||
$boughtTimes = 1;
|
||||
switch ($row['limit_type']) {
|
||||
case ShopController::DAILY_BUY_LIMIT:
|
||||
{
|
||||
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']) {
|
||||
@ -101,8 +131,7 @@ class ShopController extends BaseAuthedController {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ShopController::WEEKLY_BUY_LIMIT:
|
||||
{
|
||||
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']) {
|
||||
@ -115,8 +144,7 @@ class ShopController extends BaseAuthedController {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ShopController::TOTAL_BUY_LIMIT:
|
||||
{
|
||||
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']) {
|
||||
@ -129,8 +157,7 @@ class ShopController extends BaseAuthedController {
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
default: {
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -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(
|
||||
$this->_rspData(
|
||||
array(
|
||||
'award' => $awardService->toDto(),
|
||||
'property_chg' => $propertyChgService->toDto(),
|
||||
'goods_chg' => $goodsDto
|
||||
));
|
||||
)
|
||||
);
|
||||
break;
|
||||
|
||||
case ShopController::TOKEN_TYPE_BCEG:
|
||||
@ -254,13 +282,15 @@ class ShopController extends BaseAuthedController {
|
||||
}
|
||||
$goodsList = mt\ShopGoods::getGoodsList($shopId);
|
||||
if (!$goodsList) {
|
||||
$this->_rspData(array(
|
||||
$this->_rspData(
|
||||
array(
|
||||
'info' => array(
|
||||
'shop_id' => $shopId,
|
||||
'goods_list1' => array(),
|
||||
'goods_list2' => array(),
|
||||
)
|
||||
));
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
$buyRecordHash = ShopBuyRecord::allToHash();
|
||||
@ -279,26 +309,22 @@ class ShopController extends BaseAuthedController {
|
||||
'total_buy_times' => $itemMeta['limit_num'],
|
||||
);
|
||||
switch ($itemMeta['limit_type']) {
|
||||
case mt\Item::DAILY_BUY_LIMIT:
|
||||
{
|
||||
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:
|
||||
{
|
||||
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:
|
||||
{
|
||||
case mt\Item::TOTAL_BUY_LIMIT: {
|
||||
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
|
||||
$goodsDto['bought_times'] = $buyRecord ? $buyRecord['total_buy_times'] : 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
default: {
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -309,13 +335,15 @@ class ShopController extends BaseAuthedController {
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->_rspData(array(
|
||||
$this->_rspData(
|
||||
array(
|
||||
'info' => array(
|
||||
'shop_id' => $shopId,
|
||||
'goods_list1' => $goodsDtoList1,
|
||||
'goods_list2' => $goodsDtoList2,
|
||||
)
|
||||
));
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function buyGoods()
|
||||
@ -345,8 +373,7 @@ class ShopController extends BaseAuthedController {
|
||||
$buyRecordHash = ShopBuyRecord::allToHash();
|
||||
$boughtTimes = 1;
|
||||
switch ($itemMeta['limit_type']) {
|
||||
case mt\Item::DAILY_BUY_LIMIT:
|
||||
{
|
||||
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']) {
|
||||
@ -359,8 +386,7 @@ class ShopController extends BaseAuthedController {
|
||||
}
|
||||
}
|
||||
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;
|
||||
if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $itemMeta['limit_num']) {
|
||||
@ -373,8 +399,7 @@ class ShopController extends BaseAuthedController {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case mt\Item::TOTAL_BUY_LIMIT:
|
||||
{
|
||||
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']) {
|
||||
@ -387,12 +412,10 @@ class ShopController extends BaseAuthedController {
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
default: {
|
||||
}
|
||||
break;
|
||||
}
|
||||
{
|
||||
} {
|
||||
$errCode = 0;
|
||||
$errMsg = '';
|
||||
if (!$this->canBuy($itemMeta, $errCode, $errMsg)) {
|
||||
@ -433,28 +456,30 @@ 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(
|
||||
$this->_rspData(
|
||||
array(
|
||||
'award' => $awardService->toDto(),
|
||||
'property_chg' => $propertyChgService->toDto(),
|
||||
'goods_chg' => $goodsDto
|
||||
));
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getDiscountList()
|
||||
{
|
||||
$items = array();
|
||||
{
|
||||
$types = array(mt\Item::HERO_TYPE,
|
||||
$items = array(); {
|
||||
$types = array(
|
||||
mt\Item::HERO_TYPE,
|
||||
mt\Item::HERO_SKIN_TYPE,
|
||||
mt\Item::GUN_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);
|
||||
@ -475,13 +500,11 @@ class ShopController extends BaseAuthedController {
|
||||
foreach ($costGroup as $cost) {
|
||||
if ($cost['discount'] > 0) {
|
||||
switch ($cost['item_id']) {
|
||||
case V_ITEM_GOLD:
|
||||
{
|
||||
case V_ITEM_GOLD: {
|
||||
$goodsDto['gold_discount'] = $cost['discount'];
|
||||
}
|
||||
break;
|
||||
case V_ITEM_DIAMOND:
|
||||
{
|
||||
case V_ITEM_DIAMOND: {
|
||||
$goodsDto['diamond_discount'] = $cost['discount'];
|
||||
}
|
||||
break;
|
||||
@ -494,9 +517,11 @@ class ShopController extends BaseAuthedController {
|
||||
}
|
||||
}
|
||||
});
|
||||
$this->_rspData(array(
|
||||
$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,
|
||||
$types = array(
|
||||
mt\Item::HERO_TYPE,
|
||||
mt\Item::HERO_SKIN_TYPE,
|
||||
mt\Item::GUN_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,28 +590,30 @@ 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(
|
||||
$this->_rspData(
|
||||
array(
|
||||
'award' => $awardService->toDto(),
|
||||
'property_chg' => $propertyChgService->toDto(),
|
||||
'goods_chg' => $goodsDto
|
||||
));
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function getOutsideShopInfo()
|
||||
{
|
||||
$items = array();
|
||||
{
|
||||
$types = array(mt\Item::HERO_TYPE,
|
||||
$items = array(); {
|
||||
$types = array(
|
||||
mt\Item::HERO_TYPE,
|
||||
mt\Item::HERO_SKIN_TYPE,
|
||||
mt\Item::GUN_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);
|
||||
@ -611,13 +639,15 @@ class ShopController extends BaseAuthedController {
|
||||
array_push($goodsDtoList1, $goodsDto);
|
||||
}
|
||||
});
|
||||
$this->_rspData(array(
|
||||
$this->_rspData(
|
||||
array(
|
||||
'info' => array(
|
||||
'shop_id' => mt\Shop::OUTSIDE_SHOP,
|
||||
'goods_list1' => $goodsDtoList1,
|
||||
'goods_list2' => $goodsDtoList2,
|
||||
)
|
||||
));
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function getCostItems($priceInfo, $costItemId)
|
||||
@ -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)),
|
||||
));
|
||||
)
|
||||
);
|
||||
} else {
|
||||
array_push($costItems, array(
|
||||
'item_id' => $val['item_id'],
|
||||
'item_num' => $val['item_num'],
|
||||
));
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
return $costItems;
|
||||
@ -658,33 +691,28 @@ class ShopController extends BaseAuthedController {
|
||||
private function internalAddItem($propertyChgService, $itemMeta)
|
||||
{
|
||||
switch ($itemMeta['type']) {
|
||||
case mt\Item::HERO_TYPE:
|
||||
{
|
||||
case mt\Item::HERO_TYPE: {
|
||||
Hero::addHero($itemMeta);
|
||||
$propertyChgService->addHeroChg();
|
||||
$propertyChgService->addUserChg();
|
||||
}
|
||||
break;
|
||||
case mt\Item::HERO_SKIN_TYPE:
|
||||
{
|
||||
case mt\Item::HERO_SKIN_TYPE: {
|
||||
HeroSkin::addSkin($itemMeta);
|
||||
$propertyChgService->addHeroSkinChg();
|
||||
}
|
||||
break;
|
||||
case mt\Item::GUN_TYPE:
|
||||
{
|
||||
case mt\Item::GUN_TYPE: {
|
||||
Gun::addGun($itemMeta);
|
||||
$propertyChgService->addGunChg();
|
||||
}
|
||||
break;
|
||||
case mt\Item::GUN_SKIN_TYPE:
|
||||
{
|
||||
case mt\Item::GUN_SKIN_TYPE: {
|
||||
GunSkin::addSkin($itemMeta);
|
||||
$propertyChgService->addGunSkinChg();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
default: {
|
||||
Bag::addItem($itemMeta['id'], 1);
|
||||
$propertyChgService->addBagChg();
|
||||
}
|
||||
@ -697,8 +725,7 @@ class ShopController extends BaseAuthedController {
|
||||
$errCode = 0;
|
||||
$errMsg = '';
|
||||
switch ($itemMeta['type']) {
|
||||
case mt\Item::HERO_TYPE:
|
||||
{
|
||||
case mt\Item::HERO_TYPE: {
|
||||
$heroDb = Hero::find($itemMeta['id']);
|
||||
if ($heroDb) {
|
||||
$errCode = 10;
|
||||
@ -707,8 +734,7 @@ class ShopController extends BaseAuthedController {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case mt\Item::HERO_SKIN_TYPE:
|
||||
{
|
||||
case mt\Item::HERO_SKIN_TYPE: {
|
||||
$heroSkinDb = HeroSkin::find($itemMeta['id']);
|
||||
if ($heroSkinDb) {
|
||||
$errCode = 10;
|
||||
@ -717,8 +743,7 @@ class ShopController extends BaseAuthedController {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case mt\Item::GUN_SKIN_TYPE:
|
||||
{
|
||||
case mt\Item::GUN_SKIN_TYPE: {
|
||||
$gunSkinDb = GunSkin::find($itemMeta['id']);
|
||||
if ($gunSkinDb) {
|
||||
$errCode = 10;
|
||||
@ -727,8 +752,7 @@ class ShopController extends BaseAuthedController {
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
default: {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user