feat: 베팅시 유산포인트 로그에 추가

This commit is contained in:
2022-02-05 07:43:28 +00:00
committed by Gitea
parent e9108ead86
commit e547971a6f
2 changed files with 32 additions and 27 deletions
+26 -25
View File
@@ -10,10 +10,9 @@ use sammo\DTO\BettingItem;
use sammo\Validator;
use sammo\GameConst;
use sammo\KVStorage;
use sammo\UserLogger;
use sammo\Util;
use function sammo\getAllNationStaticInfo;
class Bet extends \sammo\BaseAPI
{
public function validateArgs(): ?string
@@ -56,7 +55,7 @@ class Bet extends \sammo\BaseAPI
$bettingHelper = new Betting($bettingID);
$bettingInfo = $bettingHelper->getInfo();
if($bettingInfo->finished){
if ($bettingInfo->finished) {
return '이미 종료된 베팅입니다';
}
@@ -64,15 +63,15 @@ class Bet extends \sammo\BaseAPI
$yearMonth = Util::joinYearMonth($year, $month);
if($bettingInfo->closeYearMonth <= $yearMonth){
if ($bettingInfo->closeYearMonth <= $yearMonth) {
return '이미 마감된 베팅입니다';
}
if($bettingInfo->openYearMonth > $yearMonth){
if ($bettingInfo->openYearMonth > $yearMonth) {
return '아직 시작되지 않은 베팅입니다';
}
if(count($bettingType) != $bettingInfo->selectCnt){
if (count($bettingType) != $bettingInfo->selectCnt) {
return '필요한 선택 수를 채우지 못했습니다.';
}
@@ -82,19 +81,18 @@ class Bet extends \sammo\BaseAPI
$prevBetAmount = $db->queryFirstField('SELECT sum(amount) FROM ng_betting WHERE betting_id = %i AND user_id = %i', $bettingID, $session->userID) ?? 0;
if($prevBetAmount + $amount > 1000){
return (1000 - $prevBetAmount).' 포인트까지만 베팅 가능합니다.';
if ($prevBetAmount + $amount > 1000) {
return (1000 - $prevBetAmount) . ' 포인트까지만 베팅 가능합니다.';
}
if($bettingInfo->reqInheritancePoint){
$remainPoint = ($inheritStor->getValue('previous') ?? [0,0])[0];
if($remainPoint < $amount){
if ($bettingInfo->reqInheritancePoint) {
$remainPoint = ($inheritStor->getValue('previous') ?? [0, 0])[0];
if ($remainPoint < $amount) {
return '유산포인트가 충분하지 않습니다.';
}
}
else {
$remainPoint = $db->queryFirstField('SELECT gold FROM general WHERE no = %i', $session->generalID)??0;
if($remainPoint < GameConst::$generalMinimumGold + $amount){
} else {
$remainPoint = $db->queryFirstField('SELECT gold FROM general WHERE no = %i', $session->generalID) ?? 0;
if ($remainPoint < GameConst::$generalMinimumGold + $amount) {
return '금이 부족합니다.';
}
}
@@ -102,31 +100,34 @@ class Bet extends \sammo\BaseAPI
$userID = $session->userID;
$bettingItem = new BettingItem([
'betting_id'=>$bettingID,
'general_id'=>$session->generalID,
'user_id'=>$userID,
'betting_type'=>$bettingTypeKey,
'amount'=>$amount
'betting_id' => $bettingID,
'general_id' => $session->generalID,
'user_id' => $userID,
'betting_type' => $bettingTypeKey,
'amount' => $amount
]);
$db->insertUpdate(
'ng_betting',
$bettingItem->toArray(),
['amount' => $db->sqleval('amount + %i', $amount)]
); if($bettingInfo->reqInheritancePoint){
);
if ($bettingInfo->reqInheritancePoint) {
$inheritStor->setValue('previous', [$remainPoint - $amount, null]);
}
else{
$userLogger = new UserLogger($userID);
$userLogger->push("{$amount} 포인트를 베팅에 사용", "inheritPoint");
$userLogger->flush();
} else {
$db->update('general', [
'gold' => $db->sqleval('gold - %i', $amount)
], 'no = %i', $session->generalID);
}
if(!$db->affected_rows){
if (!$db->affected_rows) {
return '베팅을 실패했습니다.';
}
return [
'result'=>true
'result' => true
];
}
}
+6 -2
View File
@@ -78,8 +78,10 @@
<div class="col-2 text-end">{{ amount.toLocaleString() }}</div>
<div
class="col-3 text-center"
>{{ myBettings.has(betType) ? `(${myBettings.get(betType)?.toLocaleString()} -> ${((myBettings.get(betType)??0) * bettingAmount / amount).toLocaleString()})` : '' }}</div>
<div class="col-2 text-end">{{ (bettingAmount / amount).toFixed(1) }}</div>
>{{ myBettings.has(betType) ? `(${myBettings.get(betType)?.toLocaleString()} -> ${((myBettings.get(betType) ?? 0) * bettingAmount / amount / ((info.isExclusive && info.selectCnt > 1) ? 1 : 2)).toLocaleString()})` : '' }}</div>
<div
class="col-2 text-end"
>{{ (bettingAmount / amount / ((info.isExclusive && info.selectCnt > 1) ? 1 : 2)).toFixed(1) }}</div>
</div>
</div>
</template>
@@ -130,10 +132,12 @@ type BettingInfo = {
name: string;
finished: boolean;
selectCnt: number;
isExclusive?: boolean;
reqInheritancePoint: boolean;
openYearMonth: number;
closeYearMonth: number;
candidates: SelectItem[];
winner?: number[];
}
type BettingListResponse = ValidResponse & {