flag multiple bets with same bet outcomes
This commit is contained in:
parent
e3545f3f8c
commit
f63e35fb4e
|
|
@ -106,6 +106,10 @@ SELECT COUNT(*)
|
||||||
FROM bets
|
FROM bets
|
||||||
WHERE user_id = $1
|
WHERE user_id = $1
|
||||||
AND outcomes_hash = $2;
|
AND outcomes_hash = $2;
|
||||||
|
-- name: GetBetCountByOutcomesHash :one
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM bets
|
||||||
|
WHERE outcomes_hash = $1;
|
||||||
-- name: UpdateCashOut :exec
|
-- name: UpdateCashOut :exec
|
||||||
UPDATE bets
|
UPDATE bets
|
||||||
SET cashed_out = $2,
|
SET cashed_out = $2,
|
||||||
|
|
|
||||||
|
|
@ -282,6 +282,19 @@ func (q *Queries) GetBetByUserID(ctx context.Context, userID int64) ([]BetWithOu
|
||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const GetBetCountByOutcomesHash = `-- name: GetBetCountByOutcomesHash :one
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM bets
|
||||||
|
WHERE outcomes_hash = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetBetCountByOutcomesHash(ctx context.Context, outcomesHash string) (int64, error) {
|
||||||
|
row := q.db.QueryRow(ctx, GetBetCountByOutcomesHash, outcomesHash)
|
||||||
|
var count int64
|
||||||
|
err := row.Scan(&count)
|
||||||
|
return count, err
|
||||||
|
}
|
||||||
|
|
||||||
const GetBetCountByUserID = `-- name: GetBetCountByUserID :one
|
const GetBetCountByUserID = `-- name: GetBetCountByUserID :one
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM bets
|
FROM bets
|
||||||
|
|
|
||||||
|
|
@ -290,6 +290,15 @@ func (s *Store) GetBetCountByUserID(ctx context.Context, UserID int64, outcomesH
|
||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Store) GetBetCountByOutcomesHash(ctx context.Context, outcomesHash string) (int64, error) {
|
||||||
|
count, err := s.queries.GetBetCountByOutcomesHash(ctx, outcomesHash)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return count, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Store) UpdateCashOut(ctx context.Context, id int64, cashedOut bool) error {
|
func (s *Store) UpdateCashOut(ctx context.Context, id int64, cashedOut bool) error {
|
||||||
err := s.queries.UpdateCashOut(ctx, dbgen.UpdateCashOutParams{
|
err := s.queries.UpdateCashOut(ctx, dbgen.UpdateCashOutParams{
|
||||||
ID: id,
|
ID: id,
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ type BetStore interface {
|
||||||
GetBetOutcomeByEventID(ctx context.Context, eventID int64, is_filtered bool) ([]domain.BetOutcome, error)
|
GetBetOutcomeByEventID(ctx context.Context, eventID int64, is_filtered bool) ([]domain.BetOutcome, error)
|
||||||
GetBetOutcomeByBetID(ctx context.Context, betID int64) ([]domain.BetOutcome, error)
|
GetBetOutcomeByBetID(ctx context.Context, betID int64) ([]domain.BetOutcome, error)
|
||||||
GetBetCountByUserID(ctx context.Context, userID int64, outcomesHash string) (int64, error)
|
GetBetCountByUserID(ctx context.Context, userID int64, outcomesHash string) (int64, error)
|
||||||
|
GetBetCountByOutcomesHash(ctx context.Context, outcomesHash string) (int64, error)
|
||||||
UpdateCashOut(ctx context.Context, id int64, cashedOut bool) error
|
UpdateCashOut(ctx context.Context, id int64, cashedOut bool) error
|
||||||
UpdateStatus(ctx context.Context, id int64, status domain.OutcomeStatus) error
|
UpdateStatus(ctx context.Context, id int64, status domain.OutcomeStatus) error
|
||||||
UpdateBetOutcomeStatus(ctx context.Context, id int64, status domain.OutcomeStatus) (domain.BetOutcome, error)
|
UpdateBetOutcomeStatus(ctx context.Context, id int64, status domain.OutcomeStatus) (domain.BetOutcome, error)
|
||||||
|
|
|
||||||
|
|
@ -360,15 +360,15 @@ func (s *Service) PlaceBet(ctx context.Context, req domain.CreateBetReq, userID
|
||||||
case domain.RoleCustomer:
|
case domain.RoleCustomer:
|
||||||
// Only the customer is able to create a online bet
|
// Only the customer is able to create a online bet
|
||||||
newBet.IsShopBet = false
|
newBet.IsShopBet = false
|
||||||
// err = s.DeductBetFromCustomerWallet(ctx, req.Amount, userID)
|
err = s.DeductBetFromCustomerWallet(ctx, req.Amount, userID)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// s.mongoLogger.Error("customer wallet deduction failed",
|
s.mongoLogger.Error("customer wallet deduction failed",
|
||||||
// zap.Float32("amount", req.Amount),
|
zap.Float32("amount", req.Amount),
|
||||||
// zap.Int64("user_id", userID),
|
zap.Int64("user_id", userID),
|
||||||
// zap.Error(err),
|
zap.Error(err),
|
||||||
// )
|
)
|
||||||
// return domain.CreateBetRes{}, err
|
return domain.CreateBetRes{}, err
|
||||||
// }
|
}
|
||||||
default:
|
default:
|
||||||
s.mongoLogger.Error("unknown role type",
|
s.mongoLogger.Error("unknown role type",
|
||||||
zap.String("role", string(role)),
|
zap.String("role", string(role)),
|
||||||
|
|
@ -415,6 +415,34 @@ func (s *Service) PlaceBet(ctx context.Context, req domain.CreateBetReq, userID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// large amount of users betting on the same bet_outcomes
|
||||||
|
total_bet_count, err := s.betStore.GetBetCountByOutcomesHash(ctx, outcomesHash)
|
||||||
|
if err != nil {
|
||||||
|
s.mongoLogger.Error("failed to get bet outcomes count",
|
||||||
|
zap.String("outcomes_hash", outcomesHash),
|
||||||
|
zap.Error(err),
|
||||||
|
)
|
||||||
|
return domain.CreateBetRes{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("total bet count: ", total_bet_count)
|
||||||
|
|
||||||
|
if total_bet_count > 3 {
|
||||||
|
flag := domain.CreateFlagReq{
|
||||||
|
BetID: bet.ID,
|
||||||
|
OddID: 0,
|
||||||
|
Reason: fmt.Sprintf("too many users bet on same outcomes - (%s)", outcomesHash),
|
||||||
|
}
|
||||||
|
_, err := s.betStore.CreateFlag(ctx, flag)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
s.mongoLogger.Error("failed to get bet outcomes count",
|
||||||
|
zap.String("outcomes_hash", outcomesHash),
|
||||||
|
zap.Error(err),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
res := domain.ConvertCreateBet(bet, rows)
|
res := domain.ConvertCreateBet(bet, rows)
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
|
|
@ -820,6 +848,10 @@ func (s *Service) GetBetCountByUserID(ctx context.Context, UserID int64, outcome
|
||||||
return s.betStore.GetBetCountByUserID(ctx, UserID, outcomesHash)
|
return s.betStore.GetBetCountByUserID(ctx, UserID, outcomesHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Service) GetBetCountByOutcomesHash(ctx context.Context, outcomesHash string) (int64, error) {
|
||||||
|
return s.betStore.GetBetCountByOutcomesHash(ctx, outcomesHash)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Service) UpdateCashOut(ctx context.Context, id int64, cashedOut bool) error {
|
func (s *Service) UpdateCashOut(ctx context.Context, id int64, cashedOut bool) error {
|
||||||
return s.betStore.UpdateCashOut(ctx, id, cashedOut)
|
return s.betStore.UpdateCashOut(ctx, id, cashedOut)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
Sports Betting Reports (Periodic)
|
|
||||||
Period,Total Bets,Total Cash Made,Total Cash Out,Total Cash Backs,Total Deposits,Total Withdrawals,Total Tickets
|
|
||||||
5min,0,0.00,0.00,0.00,0.00,0.00,0
|
|
||||||
|
|
||||||
Virtual Game Reports (Periodic)
|
|
||||||
Game Name,Number of Bets,Total Transaction Sum
|
|
||||||
|
|
||||||
Company Reports (Periodic)
|
|
||||||
Company ID,Company Name,Total Bets,Total Cash In,Total Cash Out,Total Cash Backs
|
|
||||||
|
|
||||||
Branch Reports (Periodic)
|
|
||||||
Branch ID,Branch Name,Company ID,Total Bets,Total Cash In,Total Cash Out,Total Cash Backs
|
|
||||||
|
|
||||||
Total Summary
|
|
||||||
Total Bets,Total Cash In,Total Cash Out,Total Cash Backs
|
|
||||||
0,0.00,0.00,0.00
|
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
Sports Betting Reports (Periodic)
|
|
||||||
Period,Total Bets,Total Cash Made,Total Cash Out,Total Cash Backs,Total Deposits,Total Withdrawals,Total Tickets
|
|
||||||
5min,0,0.00,0.00,0.00,0.00,0.00,0
|
|
||||||
|
|
||||||
Virtual Game Reports (Periodic)
|
|
||||||
Game Name,Number of Bets,Total Transaction Sum
|
|
||||||
|
|
||||||
Company Reports (Periodic)
|
|
||||||
Company ID,Company Name,Total Bets,Total Cash In,Total Cash Out,Total Cash Backs
|
|
||||||
|
|
||||||
Branch Reports (Periodic)
|
|
||||||
Branch ID,Branch Name,Company ID,Total Bets,Total Cash In,Total Cash Out,Total Cash Backs
|
|
||||||
|
|
||||||
Total Summary
|
|
||||||
Total Bets,Total Cash In,Total Cash Out,Total Cash Backs
|
|
||||||
0,0.00,0.00,0.00
|
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
Sports Betting Reports (Periodic)
|
|
||||||
Period,Total Bets,Total Cash Made,Total Cash Out,Total Cash Backs,Total Deposits,Total Withdrawals,Total Tickets
|
|
||||||
5min,0,0.00,0.00,0.00,0.00,0.00,0
|
|
||||||
|
|
||||||
Virtual Game Reports (Periodic)
|
|
||||||
Game Name,Number of Bets,Total Transaction Sum
|
|
||||||
|
|
||||||
Company Reports (Periodic)
|
|
||||||
Company ID,Company Name,Total Bets,Total Cash In,Total Cash Out,Total Cash Backs
|
|
||||||
|
|
||||||
Branch Reports (Periodic)
|
|
||||||
Branch ID,Branch Name,Company ID,Total Bets,Total Cash In,Total Cash Out,Total Cash Backs
|
|
||||||
|
|
||||||
Total Summary
|
|
||||||
Total Bets,Total Cash In,Total Cash Out,Total Cash Backs
|
|
||||||
0,0.00,0.00,0.00
|
|
||||||
|
Loading…
Reference in New Issue
Block a user