This commit is contained in:
aozhiwei 2023-08-03 17:25:43 +08:00
parent 69366ec028
commit e85b514195

View File

@ -193,6 +193,29 @@ class DailySelectionController extends BaseAuthedController {
$propertyChgService $propertyChgService
); );
{
$event = [
'name' => LogService::SHOP_BUY_ITEM_DAILY,
'val' => $costItems[0]['item_num']
];
switch ($tokenType) {
case mt\Shop::TOKEN_TYPE_GOLD:
{
LogService::consumeGold($event);
}
break;
case mt\Shop::TOKEN_TYPE_DIAMOND:
{
LogService::consumeDiamond($event);
}
break;
default:
{
break;
}
}
}
myself()->_rspData(array( myself()->_rspData(array(
'award' => $awardService->toDto(), 'award' => $awardService->toDto(),
'property_chg' => $propertyChgService->toDto() 'property_chg' => $propertyChgService->toDto()
@ -251,155 +274,4 @@ class DailySelectionController extends BaseAuthedController {
$remainSec * 1000); $remainSec * 1000);
} }
public function buyGoodsDSOld()
{
$idx = getReqVal('idx', 0);
if ($idx <= 0) {
$this->_rspErr(2, 'idx is invalid');
return;
}
$grid = getReqVal('grid', 0);
if ($grid < 1 || $grid > 6) {
$this->_rspErr(2, 'grid is invalid');
return;
}
$count = getReqVal('count', 0);
if ($count<=0) {
$this->_rspErr(2, 'count is invalid');
return;
}
$token_type = getReqVal('token_type', '4');
switch ($token_type) {
case ShopController::TOKEN_TYPE_GOLD:
case ShopController::TOKEN_TYPE_DIAMOND:
break;
default:
$this->_rspErr(1, "token_type is unsupport, {$token_type}");
return;
}
$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);
$desired_token_type = $goods['token_type'];
$check_token_type = splitStr1($desired_token_type);
if (!in_array($token_type, $check_token_type)) {
$this->_rspErr(1, "token_type parameter error, desired_token_type: {$desired_token_type}");
return;
}
$token_pos = array_search($token_type, $check_token_type, true);
$price_array = splitStr1($goods['price']);
$discount_array = splitStr1($goods['discount']);
$need_price = $price_array[$token_pos];
$discount = $discount_array[$token_pos];
$costItemId = $this->getCostItemIdByTokenType($token_type);
$costItems = $this->makeCostItems($costItemId, $count * $need_price);
error_log("buyGoodsDS costItems " . json_encode($costItems));
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
return;
}
$item_id = $goods['goods_id'];
$item_num = $goods['goods_num'];
$sql = "UPDATE t_shop_dailyselection SET count_$grid = count_$grid - $count WHERE idx = $idx";
$chk = $conn->execScript($sql);
$itemMeta = mt\Item::get($item_id);
$propertyChgService = new services\PropertyChgService();
for ($i = 0; $i < $count; $i++) {
$this->internalAddItem($propertyChgService, $itemMeta, $item_num, 0);
}
$awardService = new services\AwardService();
$awardService->addItem($goods['goods_id'], $count * $item_num);
$this->_decItems($costItems);
$event = [
'name' => LogService::SHOP_BUY_ITEM_DAILY,
'val' => $costItems[0]['item_num']
];
switch ($token_type) {
case ShopController::TOKEN_TYPE_GOLD:
LogService::consumeGold($event);
break;
case ShopController::TOKEN_TYPE_DIAMOND:
LogService::consumeDiamond($event);
break;
default:
// 这里不应该出现,出现了说明配置表新增了一种货币,但是这里没有处理
error_log("buyGoodsDS token_type is invalid, token_type: {$token_type}");
return;
}
$goodsDto = array(
'goods_id' => $sel_id,
'item_id' => $goods['goods_id'],
'price_info' => array(
'item_id' => $goods['goods_id'],
'cost_list' => array(),
),
'bought_times' => 0,
'total_buy_times' => 0,
);
{
$priceInfo = mt\Item::getPriceInfo($itemMeta);
if (!empty($priceInfo)) {
$goodsDto['price_info'] = $priceInfo['price_info'];
}
}
$propertyChgService->addUserChg();
$this->_rspData(
array(
'idx' => $idx,
'grid' => $grid,
'count' => $count,
'award' => $awardService->toDto(),
'property_chg' => $propertyChgService->toDto(),
)
);
}
} }