Merge branch 'james' of git.kingsome.cn:server/game2006api into james
This commit is contained in:
commit
bee6e6cdf5
@ -86,7 +86,7 @@ class Shop(object):
|
||||
'params': [
|
||||
_common.ReqHead(),
|
||||
['id', 0, '商品唯一id,参见shopGoods表'],
|
||||
['token_type', '', "选用币种"]
|
||||
['token_type', '', "选用币种"],
|
||||
['goods_num', 0, '商品数量'],
|
||||
],
|
||||
'response': [
|
||||
|
@ -383,6 +383,7 @@ class NewGoods(object):
|
||||
self.fields = [
|
||||
['id', 0, '商品唯一id'],
|
||||
['goods_id', 0, '商品id'],
|
||||
['max_amount', 0, '最高购买数量,单次购买'],
|
||||
['shop_id', 0, '所属商店id'],
|
||||
['shopstage', 0, '商店层级'],
|
||||
['tag', 0, '标签'],
|
||||
|
@ -817,14 +817,19 @@ CREATE TABLE `t_shop_names` (
|
||||
-- Table structure for table `t_shop_goods`
|
||||
--
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for t_shop_goods
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `t_shop_goods`;
|
||||
CREATE TABLE `t_shop_goods` (
|
||||
`id` int(11) NOT NULL,
|
||||
`shop_id` int(11) DEFAULT NULL,
|
||||
`shopstage` int(11) DEFAULT NULL,
|
||||
`goods_id` int(11) DEFAULT NULL,
|
||||
`tag` varchar(32) DEFAULT NULL,
|
||||
`recommend` int(11) DEFAULT NULL,
|
||||
`token_type` varchar(32) DEFAULT NULL,
|
||||
`max_amount` int(11) NOT NULL DEFAULT '1',
|
||||
`price` varchar(32) DEFAULT NULL,
|
||||
`discount` varchar(32) DEFAULT NULL,
|
||||
`discount_begin` varchar(32) DEFAULT NULL,
|
||||
|
@ -27,12 +27,23 @@ use models\ShopBuyRecord;
|
||||
|
||||
class ShopController extends BaseAuthedController {
|
||||
|
||||
const TOKEN_TYPE_CEG = '1';
|
||||
const TOKEN_TYPE_CEC = '2';
|
||||
const TOKEN_TYPE_BCEG = '3';
|
||||
|
||||
const TOKEN_TYPE_USDT = '11';
|
||||
const TOKEN_TYPE_USDC = '12';
|
||||
const TOKEN_TYPE_BUSD = '13';
|
||||
|
||||
const TOKEN_TYPE_MATIC = '101';
|
||||
const TOKEN_TYPE_BNB = '102';
|
||||
|
||||
public function getGoodsList()
|
||||
{
|
||||
$row = SqlHelper::ormSelect(
|
||||
$this->_getSelfMysql(),
|
||||
't_shop_goods',
|
||||
array(),
|
||||
array()
|
||||
);
|
||||
$this->_rspData(array(
|
||||
'goods_list' => $row ? $row : array(),
|
||||
@ -44,7 +55,7 @@ class ShopController extends BaseAuthedController {
|
||||
$row = SqlHelper::ormSelect(
|
||||
$this->_getSelfMysql(),
|
||||
't_shop_names',
|
||||
array(),
|
||||
array()
|
||||
);
|
||||
$this->_rspData(array(
|
||||
'shop_name_list' => $row ? $row : array(),
|
||||
@ -55,7 +66,7 @@ class ShopController extends BaseAuthedController {
|
||||
{
|
||||
$id = getReqVal('id', 0);
|
||||
$token_type = getReqVal('token_type', '');
|
||||
$num = getReqVal('goods_num', 0);
|
||||
$goods_num = getReqVal('goods_num', 0);
|
||||
|
||||
$row = SqlHelper::ormSelectOne(
|
||||
$this->_getSelfMysql(),
|
||||
@ -64,12 +75,121 @@ class ShopController extends BaseAuthedController {
|
||||
'id' => $id,
|
||||
)
|
||||
);
|
||||
|
||||
$desired_token_type = $row['token_type'];
|
||||
$check_token_type = splitStr1($desired_token_type);
|
||||
$token_pos = array_search($token_type, $check_token_type, true);
|
||||
if (!in_array($token_type, $check_token_type)) {
|
||||
$this->_rspErr(1, "token_type parameter error, desired_token_type: {$desired_token_type}");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($goods_num>$row['max_amount']) {
|
||||
$this->_rspErr(1, "goods_num parameter error, max_amount: {$row['max_amount']}");
|
||||
return;
|
||||
}
|
||||
|
||||
$price_array = splitStr1($row['price']);
|
||||
$discount_array = splitStr1($row['discount']);
|
||||
|
||||
$need_price = $price_array[$token_pos];
|
||||
$discount = $discount_array[$token_pos];
|
||||
|
||||
$costItemId = $this->getCostItemIdByTokenType($token_type);
|
||||
|
||||
switch($token_type) {
|
||||
case ShopController::TOKEN_TYPE_CEG:
|
||||
$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();
|
||||
$this->internalAddItem($propertyChgService, $itemMeta);
|
||||
$awardService = new services\AwardService();
|
||||
$awardService->addItem($row['goods_id'], $goods_num);
|
||||
ShopBuyRecord::add($row['goods_id'], $itemNum);
|
||||
$this->_decItems($costItems);
|
||||
$goodsDto = array(
|
||||
'goods_id' => $itemMeta['id'],
|
||||
'item_id' => $itemMeta['id'],
|
||||
'price_info' => array(
|
||||
'item_id' => $itemMeta['id'],
|
||||
'cost_list' => array(),
|
||||
'discount_begin_time' => phpcommon\datetimeToTimestamp($itemMeta['discount_begin']),
|
||||
'discount_end_time' => phpcommon\datetimeToTimestamp($itemMeta['discount_end'])
|
||||
),
|
||||
'flag_icon' => $goodsMeta['tag'],
|
||||
'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(
|
||||
'id' => $id,
|
||||
'token_type' => $token_type,
|
||||
'num' => $num,
|
||||
'row' => $row ? $row : array(),
|
||||
'award' => $awardService->toDto(),
|
||||
'property_chg' => $propertyChgService->toDto(),
|
||||
'goods_chg' => $goodsDto
|
||||
));
|
||||
break;
|
||||
|
||||
case ShopController::TOKEN_TYPE_CEC:
|
||||
echo "token type: {$token_type} {$need_price} {$discount}";
|
||||
|
||||
break;
|
||||
|
||||
case ShopController::TOKEN_TYPE_BCEG:
|
||||
break;
|
||||
|
||||
case ShopController::TOKEN_TYPE_USDT:
|
||||
case ShopController::TOKEN_TYPE_USDC:
|
||||
case ShopController::TOKEN_TYPE_BUSD:
|
||||
case ShopController::TOKEN_TYPE_MATIC:
|
||||
case ShopController::TOKEN_TYPE_BNB:
|
||||
default:
|
||||
$this->_rspErr(1, "token_type is unsupport, {$token_type}");
|
||||
}
|
||||
}
|
||||
|
||||
private function getCostItemIdByTokenType($token_type)
|
||||
{
|
||||
switch($token_type) {
|
||||
case ShopController::TOKEN_TYPE_CEG:
|
||||
return V_ITEM_GOLD;
|
||||
break;
|
||||
|
||||
case ShopController::TOKEN_TYPE_CEC:
|
||||
return V_ITEM_DIAMOND;
|
||||
break;
|
||||
|
||||
case ShopController::TOKEN_TYPE_BCEG:
|
||||
case ShopController::TOKEN_TYPE_USDT:
|
||||
case ShopController::TOKEN_TYPE_USDC:
|
||||
case ShopController::TOKEN_TYPE_BUSD:
|
||||
case ShopController::TOKEN_TYPE_MATIC:
|
||||
case ShopController::TOKEN_TYPE_BNB:
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private function makeCostItems($item_id, $num)
|
||||
{
|
||||
$costItems = array(
|
||||
array(
|
||||
'item_id' => $item_id,
|
||||
'item_num' => $num
|
||||
)
|
||||
);
|
||||
return $costItems;
|
||||
}
|
||||
|
||||
public function info()
|
||||
|
Loading…
x
Reference in New Issue
Block a user