1
This commit is contained in:
parent
04c8272dce
commit
9838fb8d7b
34
doc/Shop.py
34
doc/Shop.py
@ -13,7 +13,7 @@ class Shop(object):
|
|||||||
'url': 'webapp/index.php?c=Shop&a=info',
|
'url': 'webapp/index.php?c=Shop&a=info',
|
||||||
'params': [
|
'params': [
|
||||||
_common.ReqHead(),
|
_common.ReqHead(),
|
||||||
['shop_id', '', '商店id'],
|
['shop_id', '', '商店id shop_id=100:商店外购买'],
|
||||||
],
|
],
|
||||||
'response': [
|
'response': [
|
||||||
_common.RspHead(),
|
_common.RspHead(),
|
||||||
@ -27,7 +27,7 @@ class Shop(object):
|
|||||||
'url': 'webapp/index.php?c=Shop&a=buyGoods',
|
'url': 'webapp/index.php?c=Shop&a=buyGoods',
|
||||||
'params': [
|
'params': [
|
||||||
_common.ReqHead(),
|
_common.ReqHead(),
|
||||||
['shop_id', 0, '商店id'],
|
['shop_id', 0, '商店id shop_id=100特殊商店id'],
|
||||||
['goods_id', 0, '商品id'],
|
['goods_id', 0, '商品id'],
|
||||||
['cost_item_id', 0, '支付方式'],
|
['cost_item_id', 0, '支付方式'],
|
||||||
],
|
],
|
||||||
@ -37,34 +37,4 @@ class Shop(object):
|
|||||||
['property_chg', _common.PropertyChg(), '属性变更'],
|
['property_chg', _common.PropertyChg(), '属性变更'],
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
'name': 'outsideBuy',
|
|
||||||
'desc': '购买道具(商店外购买)',
|
|
||||||
'group': 'Shop',
|
|
||||||
'url': 'webapp/index.php?c=Shop&a=outsideBuy',
|
|
||||||
'params': [
|
|
||||||
_common.ReqHead(),
|
|
||||||
['item_id', 0, '商品id'],
|
|
||||||
['item_num', 0, '购买数量'],
|
|
||||||
['cost_item_id', 0, '支付方式'],
|
|
||||||
],
|
|
||||||
'response': [
|
|
||||||
_common.RspHead(),
|
|
||||||
['award', _common.Award(), '奖励信息'],
|
|
||||||
['property_chg', _common.PropertyChg(), '属性变更'],
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'getOutsidePriceInfo',
|
|
||||||
'desc': '获取价格信息(商店外购买目前只有:英雄、英雄皮肤、枪支皮肤)',
|
|
||||||
'group': 'Shop',
|
|
||||||
'url': 'webapp/index.php?c=Shop&a=getOutsidePriceInfo',
|
|
||||||
'params': [
|
|
||||||
_common.ReqHead(),
|
|
||||||
],
|
|
||||||
'response': [
|
|
||||||
_common.RspHead(),
|
|
||||||
['!price_list', [_common.ItemPriceInfo()], '价格信息'],
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
|
@ -155,6 +155,7 @@ class Shop(object):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.fields = [
|
self.fields = [
|
||||||
|
['shop_id', 0, '商店id'],
|
||||||
['!goods_list1', [Goods()], '商品列表1'],
|
['!goods_list1', [Goods()], '商品列表1'],
|
||||||
['!goods_list2', [Goods()], '商品列表2'],
|
['!goods_list2', [Goods()], '商品列表2'],
|
||||||
]
|
]
|
||||||
|
@ -21,10 +21,15 @@ class ShopController extends BaseAuthedController {
|
|||||||
public function info()
|
public function info()
|
||||||
{
|
{
|
||||||
$shopId = getReqVal('shop_id', 0);
|
$shopId = getReqVal('shop_id', 0);
|
||||||
|
if ($shopId == mt\Shop::OUTSIDE_SHOP) {
|
||||||
|
$this->getOutsideShopInfo();
|
||||||
|
return;
|
||||||
|
}
|
||||||
$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,
|
||||||
'goods_list1' => array(),
|
'goods_list1' => array(),
|
||||||
'goods_list2' => array(),
|
'goods_list2' => array(),
|
||||||
)
|
)
|
||||||
@ -79,6 +84,7 @@ class ShopController extends BaseAuthedController {
|
|||||||
}
|
}
|
||||||
$this->_rspData(array(
|
$this->_rspData(array(
|
||||||
'info' => array(
|
'info' => array(
|
||||||
|
'shop_id' => $shopId,
|
||||||
'goods_list1' => $goodsDtoList1,
|
'goods_list1' => $goodsDtoList1,
|
||||||
'goods_list2' => $goodsDtoList2,
|
'goods_list2' => $goodsDtoList2,
|
||||||
)
|
)
|
||||||
@ -87,70 +93,74 @@ class ShopController extends BaseAuthedController {
|
|||||||
|
|
||||||
public function buyGoods()
|
public function buyGoods()
|
||||||
{
|
{
|
||||||
}
|
$shopId = getReqVal('shop_id', 0);
|
||||||
|
$goodsId = getReqVal('goods_id', 0);
|
||||||
public function outsideBuy()
|
$itemNum = getReqVal('goods_num', 0);
|
||||||
{
|
$costItemId = getReqVal('cost_item_id', 0);
|
||||||
$itemId = getReqVal('item_id', 0);
|
|
||||||
$itemNum = getReqVal('item_num', 0);
|
|
||||||
$costItemId = getReqVal('item_id', 0);
|
|
||||||
|
|
||||||
|
$itemId = $goodsId;
|
||||||
$itemMeta = mt\Item::get($itemId);
|
$itemMeta = mt\Item::get($itemId);
|
||||||
if (!$itemMeta) {
|
if (!$itemMeta) {
|
||||||
$this->_rspErr(1, 'item_id参数错误');
|
$this->_rspErr(1, 'goods_id参数错误');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($itemNum != 1) {
|
$goodsMeta = mt\ShopGoods::getGoodsInfo($shopId, $goodsId);
|
||||||
$this->_rspErr(1, 'item_num参数必须等于1');
|
if (!$goodsMeta) {
|
||||||
return;
|
$this->_rspErr(1, 'goods_id参数错误');
|
||||||
}
|
|
||||||
$costItemMeta = mt\Item::get($costItemId);
|
|
||||||
if (!$costItemMeta) {
|
|
||||||
$this->_rspErr(1, 'item_id参数错误');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$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参数错误');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$buyRecordHash = ShopBuyRecord::allToHash();
|
||||||
|
switch ($itemMeta['limit_type']) {
|
||||||
|
case mt\Item::DAILY_BUY_LIMIT:
|
||||||
{
|
{
|
||||||
switch ($itemMeta['type']) {
|
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
|
||||||
case mt\Item::HERO_TYPE:
|
if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $itemMeta['limit_num']) {
|
||||||
{
|
$this->_rspErr(2, '已达今日限购上限次数');
|
||||||
$heroDb = Hero::find($itemMeta['id']);
|
|
||||||
if (!$heroDb) {
|
|
||||||
$this->_rspErr(4, '你已经拥有该英雄');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case mt\Item::HERO_SKIN_TYPE:
|
|
||||||
{
|
|
||||||
$heroSkinDb = HeroSkin::find($itemMeta['id']);
|
|
||||||
if (!$heroSkinDb) {
|
|
||||||
$this->_rspErr(4, '你已经拥有该皮肤');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case mt\Item::GUN_SKIN_TYPE:
|
|
||||||
{
|
|
||||||
$gunSkinDb = GunSkin::find($itemMeta['id']);
|
|
||||||
if (!$gunSkinDb) {
|
|
||||||
$this->_rspErr(4, '你已经拥有该皮肤');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
$this->_rspErr(1, 'item_id参数错误');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
if ($itemMeta['limit_num'] <= 0) {
|
||||||
|
$this->_rspErr(2, '已达限购上限次数');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case mt\Item::WEEKLY_BUY_LIMIT:
|
||||||
|
{
|
||||||
|
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
|
||||||
|
if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $itemMeta['limit_num']) {
|
||||||
|
$this->_rspErr(2, '已达本周限购上限次数');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($itemMeta['limit_num'] <= 0) {
|
||||||
|
$this->_rspErr(2, '已达限购上限次数');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case mt\Item::TOTAL_BUY_LIMIT:
|
||||||
|
{
|
||||||
|
$buyRecord = getXVal($buyRecordHash, $itemMeta['id']);
|
||||||
|
if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $itemMeta['limit_num']) {
|
||||||
|
$this->_rspErr(2, '已达限购上限次数');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($itemMeta['limit_num'] <= 0) {
|
||||||
|
$this->_rspErr(2, '已达限购上限次数');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
$errCode = 0;
|
||||||
|
$errMsg = '';
|
||||||
|
if (!$this->canBuy($itemMeta, $errCode, $errMsg)) {
|
||||||
|
$this->_rspErr($errCode, $errMsg);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$priceInfo = mt\Item::getPriceInfo($itemMeta);
|
$priceInfo = mt\Item::getPriceInfo($itemMeta);
|
||||||
@ -181,7 +191,70 @@ class ShopController extends BaseAuthedController {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOutsidePriceInfo()
|
private function outsideBuy()
|
||||||
|
{
|
||||||
|
$itemId = getReqVal('item_id', 0);
|
||||||
|
$itemNum = getReqVal('item_num', 0);
|
||||||
|
$costItemId = getReqVal('cost_item_id', 0);
|
||||||
|
|
||||||
|
$itemMeta = mt\Item::get($itemId);
|
||||||
|
if (!$itemMeta) {
|
||||||
|
$this->_rspErr(1, 'item_id参数错误');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($itemNum != 1) {
|
||||||
|
$this->_rspErr(1, 'item_num参数必须等于1');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$costItemMeta = mt\Item::get($costItemId);
|
||||||
|
if (!$costItemMeta) {
|
||||||
|
$this->_rspErr(1, 'item_id参数错误');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$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参数错误');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
$errCode = 0;
|
||||||
|
$errMsg = '';
|
||||||
|
if (!$this->canBuy($itemMeta, $errCode, $errMsg)) {
|
||||||
|
$this->_rspErr($errCode, $errMsg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$priceInfo = mt\Item::getPriceInfo($itemMeta);
|
||||||
|
if (empty($priceInfo)) {
|
||||||
|
$this->_rspErr(2, '配置表错误');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$costItems = $this->getCostTimes($priceInfo, $costItemId);
|
||||||
|
if (empty($costItems)) {
|
||||||
|
$this->_rspErr(2, '配置表错误2');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$lackItem = null;
|
||||||
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||||
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->_decItems($costItems);
|
||||||
|
$this->internalAddItem($itemMeta);
|
||||||
|
$awardService = new services\AwardService();
|
||||||
|
$awardService->addItem($itemId, $itemNum);
|
||||||
|
ShopBuyRecord::add($itemId, $itemNum);
|
||||||
|
$this->rspData(array(
|
||||||
|
'award' => $awardService->toDto(),
|
||||||
|
'property_chg' => array(
|
||||||
|
'user_info' => User::info($this->_getOrmUserInfo())
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getOutsideShopInfo()
|
||||||
{
|
{
|
||||||
$items = array();
|
$items = array();
|
||||||
{
|
{
|
||||||
@ -195,12 +268,30 @@ class ShopController extends BaseAuthedController {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$priceList = array();
|
$goodsDtoList1 = array();
|
||||||
array_walk($items, function ($val) use(&$priceList) {
|
$goodsDtoList2 = array();
|
||||||
array_push($priceList, mt\Item::getPriceInfo($val));
|
array_walk($items, function ($val) use(&$priceList, &$goodsDtoList1, &$goodsDtoList2) {
|
||||||
|
$goodsDto = array(
|
||||||
|
'goods_id' => $val['id'],
|
||||||
|
'item_id' => $val['id'],
|
||||||
|
'price_info' => null,
|
||||||
|
'flag_icon' => '',
|
||||||
|
'limit_type' => $val['limit_type'],
|
||||||
|
'bought_times' => 0,
|
||||||
|
'total_buy_times' => $val['limit_num'],
|
||||||
|
);
|
||||||
|
$priceInfo = mt\Item::getPriceInfo($val);
|
||||||
|
if (!empty($priceInfo)) {
|
||||||
|
$goodsDto['price_info'] = $priceInfo;
|
||||||
|
array_push($goodsDtoList1, $goodsDto);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
$this->_rspData(array(
|
$this->_rspData(array(
|
||||||
'price_list' => $priceList
|
'info' => array(
|
||||||
|
'shop_id' => mt\Shop::OUTSIDE_SHOP,
|
||||||
|
'goods_list1' => $goodsDtoList1,
|
||||||
|
'goods_list2' => $goodsDtoList2,
|
||||||
|
)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,4 +356,47 @@ class ShopController extends BaseAuthedController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function canBuy($itemMeta, &$errCode, &$errMsg)
|
||||||
|
{
|
||||||
|
$errCode = 0;
|
||||||
|
$errMsg = '';
|
||||||
|
switch ($itemMeta['type']) {
|
||||||
|
case mt\Item::HERO_TYPE:
|
||||||
|
{
|
||||||
|
$heroDb = Hero::find($itemMeta['id']);
|
||||||
|
if (!$heroDb) {
|
||||||
|
$errCode = 10;
|
||||||
|
$errMsg = '你已经拥有该英雄';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case mt\Item::HERO_SKIN_TYPE:
|
||||||
|
{
|
||||||
|
$heroSkinDb = HeroSkin::find($itemMeta['id']);
|
||||||
|
if (!$heroSkinDb) {
|
||||||
|
$errCode = 10;
|
||||||
|
$errMsg = '你已经拥有该皮肤';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case mt\Item::GUN_SKIN_TYPE:
|
||||||
|
{
|
||||||
|
$gunSkinDb = GunSkin::find($itemMeta['id']);
|
||||||
|
if (!$gunSkinDb) {
|
||||||
|
$errCode = 10;
|
||||||
|
$errMsg = '你已经拥有该皮肤';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ use phpcommon;
|
|||||||
|
|
||||||
class Shop {
|
class Shop {
|
||||||
|
|
||||||
|
const OUTSIDE_SHOP = 100;
|
||||||
|
|
||||||
public static function get($id)
|
public static function get($id)
|
||||||
{
|
{
|
||||||
return getXVal(self::getMetaList(), $id);
|
return getXVal(self::getMetaList(), $id);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user