Merge branch 'star' of git.kingsome.cn:server/game2006api into star
This commit is contained in:
commit
e88026c9d5
@ -1135,8 +1135,8 @@ CREATE TABLE `t_first_topup` (
|
||||
`status1` int(11) NOT NULL DEFAULT '0' COMMENT '领取状态1 0 不能领取 1 可领取状态 2 已领取',
|
||||
`status2` int(11) NOT NULL DEFAULT '0' COMMENT '领取状态2',
|
||||
`status3` int(11) NOT NULL DEFAULT '0' COMMENT '领取状态3',
|
||||
PRIMARY KEY (`idx`,`account_id`),
|
||||
UNIQUE KEY `account` (`account_id`)
|
||||
PRIMARY KEY (`idx`,`address`),
|
||||
UNIQUE KEY `address` (`address`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
|
@ -157,6 +157,25 @@ class ShopController extends BaseAuthedController
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$goods_id = $goods['goods_id'];
|
||||
$itemMeta = mt\Item::get($goods_id);
|
||||
if ($itemMeta) {
|
||||
// 如果是皮肤,判断是否已经拥有,如果已经拥有,不能购买
|
||||
if ($itemMeta['type'] == mt\Item::HERO_SKIN_TYPE) {
|
||||
$errCode = 0;
|
||||
$errMsg = '';
|
||||
if (!$this->canBuy($itemMeta, $errCode, $errMsg)) {
|
||||
$goods['bought_times'] = 1;
|
||||
} else {
|
||||
$goods['bought_times'] = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// error !!!!!!
|
||||
error_log('item not found:' . $goods_id);
|
||||
}
|
||||
|
||||
if (empty($goods['goods_num'])) {
|
||||
$goods['goods_num'] = 1;
|
||||
}
|
||||
@ -168,7 +187,8 @@ class ShopController extends BaseAuthedController
|
||||
|
||||
$address = $this->_getAddress();
|
||||
if ($address) {
|
||||
$goods['pending'] = $this->checkPendingBuyGoodsNormal($address, $goods['goods_id'], $goods['shop_id'], $goods['id']);
|
||||
// $goods['pending'] = $this->checkPendingBuyGoodsNormal($address, $goods['goods_id'], $goods['shop_id'], $goods['id']);
|
||||
$goods['pending'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -797,7 +817,8 @@ class ShopController extends BaseAuthedController
|
||||
$goodsList[$i] = mt\Dailyselection::get($selection['grid_' . $i]);
|
||||
if ($goodsList[$i]) {
|
||||
$goodsList[$i]['count'] = $selection['count_' . $i];
|
||||
$goodsList[$i]['pending'] = $this->checkPendingBuyGoodsDS($address, $goodsList[$i]['goods_id'], $selection['idx'], $i);
|
||||
// $goodsList[$i]['pending'] = $this->checkPendingBuyGoodsDS($address, $goodsList[$i]['goods_id'], $selection['idx'], $i);
|
||||
$goodsList[$i]['pending'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -845,11 +866,11 @@ class ShopController extends BaseAuthedController
|
||||
|
||||
$goods_id = $row['goods_id'];
|
||||
if (!empty($address)) {
|
||||
$pending = $this->checkPendingBuyGoodsNormal($address, $goods_id, $row['shop_id'], $id);
|
||||
if ($pending) {
|
||||
$this->_rspErr(1, 'pending');
|
||||
return;
|
||||
}
|
||||
// $pending = $this->checkPendingBuyGoodsNormal($address, $goods_id, $row['shop_id'], $id);
|
||||
// if ($pending) {
|
||||
// $this->_rspErr(1, 'pending');
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
|
||||
$desired_token_type = $row['token_type'];
|
||||
@ -879,38 +900,55 @@ 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, 'Daily purchase limit');
|
||||
return;
|
||||
|
||||
$itemMeta = mt\Item::get($row['goods_id']);
|
||||
if (!$itemMeta) {
|
||||
$this->_rspErr(1, 'goods not found, goods_id: ' . $row['goods_id']);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($itemMeta['type'] == mt\Item::HERO_SKIN_TYPE) {
|
||||
$errCode = 0;
|
||||
$errMsg = '';
|
||||
if (!$this->canBuy($itemMeta, $errCode, $errMsg)) {
|
||||
$this->_rspErr($errCode, $errMsg);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
||||
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, 'Daily purchase limit');
|
||||
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, 'Weekly purchase limit 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, 'Weekly purchase limit reached');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ShopController::TOTAL_BUY_LIMIT: {
|
||||
// error_log("total buy limit " . $address . " " . $id . " " . $row['limit_num']);
|
||||
$buyRecord = getXVal($buyRecordHash, $goods_id);
|
||||
$boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1;
|
||||
if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $row['limit_num']) {
|
||||
$this->_rspErr(2, 'Purchase limit reached');
|
||||
return;
|
||||
break;
|
||||
case ShopController::TOTAL_BUY_LIMIT: {
|
||||
// error_log("total buy limit " . $address . " " . $id . " " . $row['limit_num']);
|
||||
$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, 'Purchase limit reached');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
}
|
||||
break;
|
||||
break;
|
||||
default: {
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$price_array = splitStr1($row['price']);
|
||||
@ -1233,167 +1271,6 @@ class ShopController extends BaseAuthedController
|
||||
);
|
||||
}
|
||||
|
||||
private function buyGoodsDSOld()
|
||||
{
|
||||
$account = $this->_getAccountId();
|
||||
$address = $this->_getAddress();
|
||||
if (empty($address)) {
|
||||
$this->_rspErr(5, 'address is empty');
|
||||
return;
|
||||
}
|
||||
|
||||
$idx = getReqVal('idx', 0);
|
||||
$grid = getReqVal('grid', 0);
|
||||
$count = getReqVal('count', 0);
|
||||
|
||||
$conn = $this->_getMysql('');
|
||||
|
||||
$row = SqlHelper::selectOne(
|
||||
$conn,
|
||||
't_shop_dailyselection',
|
||||
array(
|
||||
'idx',
|
||||
'address',
|
||||
'grid_' . $grid,
|
||||
'count_' . $grid,
|
||||
),
|
||||
array('idx' => $idx)
|
||||
);
|
||||
|
||||
if (!$row) {
|
||||
$this->_rspErr(2, 'idx is invalid');
|
||||
return;
|
||||
}
|
||||
|
||||
if ($row['grid_' . $grid] == 0) {
|
||||
$this->_rspErr(2, 'grid is invalid');
|
||||
return;
|
||||
}
|
||||
|
||||
if ($row['count_' . $grid] < $count) {
|
||||
$this->_rspErr(2, 'count is invalid');
|
||||
return;
|
||||
}
|
||||
|
||||
$sel_id = $row['grid_' . $grid];
|
||||
|
||||
$goods = mt\Dailyselection::get($sel_id);
|
||||
|
||||
$pending = $this->checkPendingBuyGoodsDS($address, $goods['goods_id'], $idx, $grid);
|
||||
if ($pending) {
|
||||
$this->_rspErr(2, 'pending');
|
||||
return;
|
||||
}
|
||||
|
||||
$price = $this->normalizeWeb3Price($goods['price'] * $count);
|
||||
$item_id = $goods['goods_id'];
|
||||
$item_count = $goods['goods_num'] * $count;
|
||||
error_log("buyGoodsDS start " . json_encode(
|
||||
array(
|
||||
'idx' => $idx,
|
||||
'grid' => $grid,
|
||||
'count' => $count,
|
||||
'goodPrice' => $goods['price'],
|
||||
'price' => $price,
|
||||
'item_id' => $item_id,
|
||||
'item_count' => $item_count,
|
||||
)
|
||||
));
|
||||
$response = services\BlockChainService::gameItemMallBuy(
|
||||
Transaction::BUY_GOODS_ACTION_TYPE,
|
||||
$price,
|
||||
$item_id,
|
||||
$item_count
|
||||
);
|
||||
|
||||
BcOrder::upsert($response['trans_id'], array(
|
||||
'item_id' => $item_id,
|
||||
'item_num' => $item_count,
|
||||
'order_type' => 1,
|
||||
'price' => $goods['price'] * $count,
|
||||
'ext_data' => json_encode(array(
|
||||
'mode' => SHOP_BUY_MODE_DAILY_SELECTION,
|
||||
'idx' => $idx,
|
||||
'grid' => $grid,
|
||||
'count' => $count,
|
||||
)),
|
||||
));
|
||||
|
||||
error_log("buyGoodsDS start " . json_encode(
|
||||
array(
|
||||
'idx' => $idx,
|
||||
'grid' => $grid,
|
||||
'count' => $count,
|
||||
'block_chain' => $response,
|
||||
)
|
||||
));
|
||||
|
||||
$this->_rspData(
|
||||
array(
|
||||
'idx' => $idx,
|
||||
'grid' => $grid,
|
||||
'count' => $count,
|
||||
'block_chain' => $response,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function openBlindBox()
|
||||
{
|
||||
$account = $this->_getAccountId();
|
||||
|
||||
$item_id = getReqVal('item_id', 0);
|
||||
$meta = mt\Item::get($item_id);
|
||||
$box = Bag::find($item_id);
|
||||
error_log('openBlindBox ' . json_encode($box) . ' ' . $item_id . ' ' . $meta['sub_type']);
|
||||
if (!$box) {
|
||||
$this->_rspErr(2, 'item_id is invalid');
|
||||
return;
|
||||
}
|
||||
|
||||
$num = $box['item_num'];
|
||||
if ($num < 1) {
|
||||
$this->_rspErr(2, 'num is invalid');
|
||||
return;
|
||||
}
|
||||
|
||||
$itemStore = mt\ShopChest::getRandomItemListByChestType($meta['sub_type']);
|
||||
$result = array();
|
||||
Bag::decItem($item_id, $num);
|
||||
for ($i = 0; $i < $num; $i++) {
|
||||
$record = array();
|
||||
foreach ($itemStore as $key => $value) {
|
||||
$item = $this->weighted_random($value);
|
||||
$itemMeta = mt\Item::get($item['item_id']);
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
if ($item['item_type'] == 2) {
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, $item['num'], 1);
|
||||
} else {
|
||||
for ($j = 0; $j < $item['num']; $j++) {
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, 1, 1);
|
||||
}
|
||||
}
|
||||
$record[$key] = array("item_id" => $item['item_id'], "item_num" => $item['num']);
|
||||
array_push($result, $record[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
error_log("openBlindBox start " . json_encode(
|
||||
array(
|
||||
'account' => $account,
|
||||
'item_id' => $item_id,
|
||||
'num' => $num,
|
||||
'items' => $result,
|
||||
)
|
||||
));
|
||||
|
||||
$this->_rspData(
|
||||
array(
|
||||
'items' => $result,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getChestItems()
|
||||
{
|
||||
// $address = $this->_getAddress();
|
||||
@ -1717,174 +1594,6 @@ class ShopController extends BaseAuthedController
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function outsideBuy($shopId, $itemId, $itemNum, $costItemId)
|
||||
{
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
$itemMeta = mt\Item::get($itemId);
|
||||
if (!$itemMeta) {
|
||||
$this->_rspErr(1, 'item_id parameter error');
|
||||
return;
|
||||
}
|
||||
if ($itemNum != 1) {
|
||||
$this->_rspErr(1, 'the item_num parameter must be equal to 1');
|
||||
return;
|
||||
}
|
||||
$costItemMeta = mt\Item::get($costItemId);
|
||||
if (!$costItemMeta) {
|
||||
$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
|
||||
);
|
||||
if (!mt\Item::inTypes($itemMeta, $types)) {
|
||||
$this->_rspErr(1, 'item_id parameter error');
|
||||
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, 'config error');
|
||||
return;
|
||||
}
|
||||
$costItems = $this->getCostItems($priceInfo, $costItemId);
|
||||
if (empty($costItems)) {
|
||||
$this->_rspErr(2, 'config error2');
|
||||
return;
|
||||
}
|
||||
$lackItem = null;
|
||||
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
||||
return;
|
||||
}
|
||||
$this->_decItems($costItems);
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, 1, 0);
|
||||
$awardService = new services\AwardService();
|
||||
$awardService->addItem($itemId, $itemNum);
|
||||
ShopBuyRecord::add($itemId, $itemNum);
|
||||
$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' => '',
|
||||
'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
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
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) {
|
||||
if (mt\Item::inTypes($meta, $types)) {
|
||||
array_push($items, $meta);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
$goodsDtoList1 = array();
|
||||
$goodsDtoList2 = array();
|
||||
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['price_info'];
|
||||
array_push($goodsDtoList1, $goodsDto);
|
||||
}
|
||||
});
|
||||
$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) {
|
||||
if ($costGroup) {
|
||||
return;
|
||||
}
|
||||
if (count($val) > 0 && $val[0]['item_id'] == $costItemId) {
|
||||
$costGroup = $val;
|
||||
return;
|
||||
}
|
||||
});
|
||||
if (!$costGroup) {
|
||||
return null;
|
||||
}
|
||||
$costItems = array();
|
||||
array_walk($costGroup, function ($val) use (&$costItems, $priceInfo) {
|
||||
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;
|
||||
}
|
||||
|
||||
private function internalAddItem($propertyChgService, $itemMeta, $count, $sysAdd, $grade = null)
|
||||
{
|
||||
switch ($itemMeta['type']) {
|
||||
@ -2085,155 +1794,6 @@ class ShopController extends BaseAuthedController
|
||||
}
|
||||
}
|
||||
|
||||
private 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'];
|
||||
$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;
|
||||
}
|
||||
|
||||
// 这里命名混乱了, 购买个数,一捆个数命名冲突
|
||||
$goods_count = $row['goods_num'];
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
$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');
|
||||
$nowTime = $this->_getNowTime();
|
||||
|
||||
if ($nowTime >= $discount_begin && $nowTime < $discount_end) {
|
||||
|
||||
$need_price = ceil($need_price * ($discount / 100.0));
|
||||
}
|
||||
|
||||
$costItemId = $this->getCostItemIdByTokenType($token_type);
|
||||
|
||||
switch ($token_type) {
|
||||
case ShopController::TOKEN_TYPE_CEG:
|
||||
case ShopController::TOKEN_TYPE_CEC:
|
||||
$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++) {
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0);
|
||||
}
|
||||
$awardService = new services\AwardService();
|
||||
$awardService->addItem($row['goods_id'], $goods_num);
|
||||
ShopBuyRecord::add($id, $goods_num);
|
||||
$this->_decItems($costItems);
|
||||
$goodsDto = array(
|
||||
'goods_id' => $id,
|
||||
'item_id' => $row['goods_id'],
|
||||
'price_info' => array(
|
||||
'item_id' => $row['goods_id'],
|
||||
'cost_list' => array(),
|
||||
'discount_begin_time' => phpcommon\datetimeToTimestamp($row['discount_begin']),
|
||||
'discount_end_time' => phpcommon\datetimeToTimestamp($row['discount_end'])
|
||||
),
|
||||
'flag_icon' => $row['tag'],
|
||||
'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
|
||||
)
|
||||
);
|
||||
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}");
|
||||
}
|
||||
}
|
||||
|
||||
public function buyBlindBox()
|
||||
{
|
||||
$account = $this->_getAccountId();
|
||||
@ -2329,255 +1889,4 @@ class ShopController extends BaseAuthedController
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function buyGoods()
|
||||
{
|
||||
$shopId = getReqVal('shop_id', 0);
|
||||
$goodsId = getReqVal('goods_id', 0);
|
||||
$itemNum = getReqVal('goods_num', 0);
|
||||
$costItemId = getReqVal('cost_item_id', 0);
|
||||
$itemId = $goodsId;
|
||||
|
||||
if ($shopId == mt\Shop::OUTSIDE_SHOP) {
|
||||
$this->outsideBuy($shopId, $itemId, $itemNum, $costItemId);
|
||||
return;
|
||||
}
|
||||
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
$itemMeta = mt\Item::get($itemId);
|
||||
if (!$itemMeta) {
|
||||
$this->_rspErr(1, 'goods_id parameter error');
|
||||
return;
|
||||
}
|
||||
$goodsMeta = mt\ShopGoods::getGoodsInfo($shopId, $goodsId);
|
||||
if (!$goodsMeta) {
|
||||
$this->_rspErr(1, 'goods_id parameter error');
|
||||
return;
|
||||
}
|
||||
$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;
|
||||
} {
|
||||
$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, 'config error');
|
||||
return;
|
||||
}
|
||||
$costItems = $this->getCostItems($priceInfo, $costItemId);
|
||||
if (empty($costItems)) {
|
||||
$this->_rspErr(2, 'config error2');
|
||||
return;
|
||||
}
|
||||
$lackItem = null;
|
||||
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
||||
return;
|
||||
}
|
||||
$this->_decItems($costItems);
|
||||
$this->internalAddItem($propertyChgService, $itemMeta, 1, 0);
|
||||
$awardService = new services\AwardService();
|
||||
$awardService->addItem($itemId, $itemNum);
|
||||
ShopBuyRecord::add($itemId, $itemNum);
|
||||
$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(
|
||||
'award' => $awardService->toDto(),
|
||||
'property_chg' => $propertyChgService->toDto(),
|
||||
'goods_chg' => $goodsDto
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private 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) {
|
||||
if (mt\Item::inTypes($meta, $types)) {
|
||||
array_push($items, $meta);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
$goodsDtoList = array();
|
||||
array_walk($items, function ($val) use (&$priceList, &$goodsDtoList) {
|
||||
$goodsDto = array(
|
||||
'item_id' => $val['id'],
|
||||
'gold_discount' => 0,
|
||||
'diamond_discount' => 0,
|
||||
);
|
||||
$priceInfo = mt\Item::getPriceInfo($val);
|
||||
if (!empty($priceInfo)) {
|
||||
foreach ($priceInfo['price_info']['cost_list'] as $costGroup) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($goodsDto['gold_discount'] > 0 || $goodsDto['diamond_discount'] > 0) {
|
||||
array_push($goodsDtoList, $goodsDto);
|
||||
}
|
||||
}
|
||||
});
|
||||
$this->_rspData(
|
||||
array(
|
||||
'goods_list' => $goodsDtoList,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function info()
|
||||
{
|
||||
$shopId = getReqVal('shop_id', 0);
|
||||
if ($shopId == mt\Shop::OUTSIDE_SHOP) {
|
||||
$this->getOutsideShopInfo();
|
||||
return;
|
||||
}
|
||||
$goodsList = mt\ShopGoods::getGoodsList($shopId);
|
||||
if (!$goodsList) {
|
||||
$this->_rspData(
|
||||
array(
|
||||
'info' => array(
|
||||
'shop_id' => $shopId,
|
||||
'goods_list1' => array(),
|
||||
'goods_list2' => array(),
|
||||
)
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
$buyRecordHash = ShopBuyRecord::allToHash();
|
||||
$goodsDtoList1 = array();
|
||||
$goodsDtoList2 = array();
|
||||
foreach ($goodsList as $goods) {
|
||||
$itemMeta = mt\Item::get($goods['goods_id']);
|
||||
if ($itemMeta) {
|
||||
$goodsDto = array(
|
||||
'goods_id' => $goods['goods_id'],
|
||||
'item_id' => $itemMeta['id'],
|
||||
'price_info' => null,
|
||||
'flag_icon' => $goods['tag'],
|
||||
'limit_type' => $itemMeta['limit_type'],
|
||||
'bought_times' => 0,
|
||||
'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;
|
||||
}
|
||||
$priceInfo = mt\Item::getPriceInfo($itemMeta);
|
||||
if (!empty($priceInfo)) {
|
||||
$goodsDto['price_info'] = $priceInfo['price_info'];
|
||||
array_push($goodsDtoList1, $goodsDto);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->_rspData(
|
||||
array(
|
||||
'info' => array(
|
||||
'shop_id' => $shopId,
|
||||
'goods_list1' => $goodsDtoList1,
|
||||
'goods_list2' => $goodsDtoList2,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user