service userdata stats added
This commit is contained in:
parent
b1b3c7ed79
commit
f5b6329e99
15
model/userdata/bonus_stats.go
Normal file
15
model/userdata/bonus_stats.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package userdata
|
||||||
|
|
||||||
|
type BonusStats struct {
|
||||||
|
Xid string `json:"xid" form:"xid" gorm:"column:xid;size:100;" binding:"required"`
|
||||||
|
UserNo string `json:"userNo" form:"userNo" gorm:"column:user_no;size:50;" binding:"required"`
|
||||||
|
BonusId string `json:"bonusId" form:"bonusId" gorm:"column:bonus_id;size:50;" binding:"required"`
|
||||||
|
Ymd string `json:"ymd" form:"ymd" gorm:"column:ymd;size:10;"`
|
||||||
|
Coin int `json:"coin" form:"coin" gorm:"column:coin;type:int;"`
|
||||||
|
Count int `json:"count" form:"count" gorm:"column:count;type:int;"`
|
||||||
|
Ut int64 `json:"ut" form:"ut" gorm:"column:ut;type:bigint;"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (BonusStats) TableName() string {
|
||||||
|
return "bonus_stats"
|
||||||
|
}
|
||||||
16
model/userdata/game_stats.go
Normal file
16
model/userdata/game_stats.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package userdata
|
||||||
|
|
||||||
|
type GameStats struct {
|
||||||
|
Xid string `json:"xid" form:"xid" gorm:"column:xid;size:100;" binding:"required"`
|
||||||
|
UserNo string `json:"userNo" form:"userNo" gorm:"column:user_no;size:50;" binding:"required"`
|
||||||
|
Ymd string `json:"ymd" form:"ymd" gorm:"column:ymd;size:10;"`
|
||||||
|
GameType int `json:"gameType" form:"gameType" gorm:"column:game_type;type:int;"`
|
||||||
|
GameId string `json:"gameId" form:"gameId" gorm:"column:game_id;size:20;"`
|
||||||
|
BetCoin int `json:"betCoin" form:"betCoin" gorm:"column:bet_coin;type:int;"`
|
||||||
|
BetCount int `json:"betCount" form:"betCount" gorm:"column:bet_count;type:int;"`
|
||||||
|
Ut int64 `json:"ut" form:"ut" gorm:"column:ut;type:bigint;"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (GameStats) TableName() string {
|
||||||
|
return "game_stats"
|
||||||
|
}
|
||||||
15
model/userdata/payment_stats.go
Normal file
15
model/userdata/payment_stats.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package userdata
|
||||||
|
|
||||||
|
type PaymentStats struct {
|
||||||
|
Xid string `json:"xid" form:"xid" gorm:"column:xid;size:100;" binding:"required"`
|
||||||
|
UserNo string `json:"userNo" form:"userNo" gorm:"column:user_no;size:50;" binding:"required"`
|
||||||
|
Ymd string `json:"ymd" form:"ymd" gorm:"column:ymd;size:10;"`
|
||||||
|
Money int `json:"money" form:"money" gorm:"column:money;type:int;"`
|
||||||
|
Coin int `json:"coin" form:"coin" gorm:"column:coin;type:int;"`
|
||||||
|
Count int `json:"count" form:"count" gorm:"column:count;type:int;"`
|
||||||
|
Ut int64 `json:"ut" form:"ut" gorm:"column:ut;type:bigint;"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (PaymentStats) TableName() string {
|
||||||
|
return "payment_stats"
|
||||||
|
}
|
||||||
@ -1,17 +0,0 @@
|
|||||||
package userdata
|
|
||||||
|
|
||||||
import "bygdata/global"
|
|
||||||
|
|
||||||
type UserBonusStats struct {
|
|
||||||
global.GVA_MODEL
|
|
||||||
Xid *string `json:"xid" form:"xid" gorm:"column:xid;size:100;" binding:"required"`
|
|
||||||
UserNo *string `json:"userNo" form:"userNo" gorm:"column:user_no;size:50;" binding:"required"`
|
|
||||||
Ymd *string `json:"ymd" form:"ymd" gorm:"column:ymd;size:10;"`
|
|
||||||
Coin *int `json:"coin" form:"coin" gorm:"column:coin;type:int;"`
|
|
||||||
Count *int `json:"count" form:"count" gorm:"column:count;type:int;"`
|
|
||||||
Ut *int64 `json:"ut" form:"ut" gorm:"column:ut;type:bigint;"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (UserBonusStats) TableName() string {
|
|
||||||
return "user_bonus_stats"
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
package userdata
|
|
||||||
|
|
||||||
import "bygdata/global"
|
|
||||||
|
|
||||||
type UserGameStats struct {
|
|
||||||
global.GVA_MODEL
|
|
||||||
Xid *string `json:"xid" form:"xid" gorm:"column:xid;size:100;" binding:"required"`
|
|
||||||
UserNo *string `json:"userNo" form:"userNo" gorm:"column:user_no;size:50;" binding:"required"`
|
|
||||||
Ymd *string `json:"ymd" form:"ymd" gorm:"column:ymd;size:10;"`
|
|
||||||
GameType *int `json:"gameType" form:"gameType" gorm:"column:game_type;type:int;"`
|
|
||||||
GameId *string `json:"gameId" form:"gameId" gorm:"column:game_id;size:20;"`
|
|
||||||
BetCoin *int `json:"betCoin" form:"betCoin" gorm:"column:bet_coin;type:int;"`
|
|
||||||
BetCount *int `json:"betCount" form:"betCount" gorm:"column:bet_count;type:int;"`
|
|
||||||
Ut *int64 `json:"ut" form:"ut" gorm:"column:ut;type:bigint;"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (UserGameStats) TableName() string {
|
|
||||||
return "user_game_stats"
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
package userdata
|
|
||||||
|
|
||||||
import "bygdata/global"
|
|
||||||
|
|
||||||
type UserPaymentStats struct {
|
|
||||||
global.GVA_MODEL
|
|
||||||
Xid *string `json:"xid" form:"xid" gorm:"column:xid;size:100;" binding:"required"`
|
|
||||||
UserNo *string `json:"userNo" form:"userNo" gorm:"column:user_no;size:50;" binding:"required"`
|
|
||||||
Ymd *string `json:"ymd" form:"ymd" gorm:"column:ymd;size:10;"`
|
|
||||||
Money *int `json:"money" form:"money" gorm:"column:money;type:int;"`
|
|
||||||
Coin *int `json:"coin" form:"coin" gorm:"column:coin;type:int;"`
|
|
||||||
Count *int `json:"count" form:"count" gorm:"column:count;type:int;"`
|
|
||||||
Ut *int64 `json:"ut" form:"ut" gorm:"column:ut;type:bigint;"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (UserPaymentStats) TableName() string {
|
|
||||||
return "user_payment_stats"
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
package userdata
|
|
||||||
|
|
||||||
import "bygdata/global"
|
|
||||||
|
|
||||||
type UserWithdrawalStats struct {
|
|
||||||
global.GVA_MODEL
|
|
||||||
Xid *string `json:"xid" form:"xid" gorm:"column:xid;size:100;" binding:"required"`
|
|
||||||
UserNo *string `json:"userNo" form:"userNo" gorm:"column:user_no;size:50;" binding:"required"`
|
|
||||||
Ymd *string `json:"ymd" form:"ymd" gorm:"column:ymd;size:10;"`
|
|
||||||
Money *int `json:"money" form:"money" gorm:"column:money;type:int;"`
|
|
||||||
Coin *int `json:"coin" form:"coin" gorm:"column:coin;type:int;"`
|
|
||||||
Count *int `json:"count" form:"count" gorm:"column:count;type:int;"`
|
|
||||||
Ut *int64 `json:"ut" form:"ut" gorm:"column:ut;type:bigint;"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (UserWithdrawalStats) TableName() string {
|
|
||||||
return "user_withdrawal_stats"
|
|
||||||
}
|
|
||||||
18
model/userdata/withdrawal_stats.go
Normal file
18
model/userdata/withdrawal_stats.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package userdata
|
||||||
|
|
||||||
|
import "bygdata/global"
|
||||||
|
|
||||||
|
type WithdrawalStats struct {
|
||||||
|
global.GVA_MODEL
|
||||||
|
Xid string `json:"xid" form:"xid" gorm:"column:xid;size:100;" binding:"required"`
|
||||||
|
UserNo string `json:"userNo" form:"userNo" gorm:"column:user_no;size:50;" binding:"required"`
|
||||||
|
Ymd string `json:"ymd" form:"ymd" gorm:"column:ymd;size:10;"`
|
||||||
|
Money int `json:"money" form:"money" gorm:"column:money;type:int;"`
|
||||||
|
Coin int `json:"coin" form:"coin" gorm:"column:coin;type:int;"`
|
||||||
|
Count int `json:"count" form:"count" gorm:"column:count;type:int;"`
|
||||||
|
Ut int64 `json:"ut" form:"ut" gorm:"column:ut;type:bigint;"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (WithdrawalStats) TableName() string {
|
||||||
|
return "withdrawal_stats"
|
||||||
|
}
|
||||||
167
service/userdata/stats.go
Normal file
167
service/userdata/stats.go
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
package userdata
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bygdata/global"
|
||||||
|
"bygdata/model/userdata"
|
||||||
|
"fmt"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"gorm.io/gorm/clause"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type StatsService struct{}
|
||||||
|
|
||||||
|
var StatsServiceApp = new(StatsService)
|
||||||
|
|
||||||
|
func (statsService *StatsService) AddGameData(data userdata.GameStats) (err error) {
|
||||||
|
history, year, month, week, day := statsService.formatTimestamp2Dates(data.Ut)
|
||||||
|
|
||||||
|
data.Ymd = history
|
||||||
|
err = statsService.addGameItem(data)
|
||||||
|
|
||||||
|
data.Ymd = year
|
||||||
|
err = statsService.addGameItem(data)
|
||||||
|
|
||||||
|
data.Ymd = month
|
||||||
|
err = statsService.addGameItem(data)
|
||||||
|
|
||||||
|
data.Ymd = week
|
||||||
|
err = statsService.addGameItem(data)
|
||||||
|
|
||||||
|
data.Ymd = day
|
||||||
|
err = statsService.addGameItem(data)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (statsService *StatsService) addGameItem(data userdata.GameStats) (err error) {
|
||||||
|
|
||||||
|
data.Xid = fmt.Sprintf("%s-%d-%d-%s", data.UserNo, data.GameType, data.GameId, data.Ymd)
|
||||||
|
err = global.GVA_DB.Clauses(clause.OnConflict{
|
||||||
|
Columns: []clause.Column{{Name: "xid"}},
|
||||||
|
DoUpdates: clause.Assignments(map[string]interface{}{
|
||||||
|
"bet_coin": gorm.Expr("bet_coin+?", data.BetCoin),
|
||||||
|
"bet_count": gorm.Expr("bet_count+?", data.BetCount),
|
||||||
|
"ut": data.Ut,
|
||||||
|
}),
|
||||||
|
}).Create(&data).Error
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (statsService *StatsService) AddPaymentData(data userdata.PaymentStats) (err error) {
|
||||||
|
history, year, month, week, day := statsService.formatTimestamp2Dates(data.Ut)
|
||||||
|
|
||||||
|
data.Ymd = history
|
||||||
|
err = statsService.addPaymentItem(data)
|
||||||
|
|
||||||
|
data.Ymd = year
|
||||||
|
err = statsService.addPaymentItem(data)
|
||||||
|
|
||||||
|
data.Ymd = month
|
||||||
|
err = statsService.addPaymentItem(data)
|
||||||
|
|
||||||
|
data.Ymd = week
|
||||||
|
err = statsService.addPaymentItem(data)
|
||||||
|
|
||||||
|
data.Ymd = day
|
||||||
|
err = statsService.addPaymentItem(data)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (statsService *StatsService) addPaymentItem(data userdata.PaymentStats) (err error) {
|
||||||
|
|
||||||
|
data.Xid = fmt.Sprintf("%s-%s", data.UserNo, data.Ymd)
|
||||||
|
err = global.GVA_DB.Clauses(clause.OnConflict{
|
||||||
|
Columns: []clause.Column{{Name: "xid"}},
|
||||||
|
DoUpdates: clause.Assignments(map[string]interface{}{
|
||||||
|
"money": gorm.Expr("money+?", data.Money),
|
||||||
|
"coin": gorm.Expr("coin+?", data.Coin),
|
||||||
|
"count": gorm.Expr("count+?", data.Count),
|
||||||
|
"ut": data.Ut,
|
||||||
|
}),
|
||||||
|
}).Create(&data).Error
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (statsService *StatsService) AddWithdrawalData(data userdata.WithdrawalStats) (err error) {
|
||||||
|
history, year, month, week, day := statsService.formatTimestamp2Dates(data.Ut)
|
||||||
|
|
||||||
|
data.Ymd = history
|
||||||
|
err = statsService.addWithdrawalItem(data)
|
||||||
|
|
||||||
|
data.Ymd = year
|
||||||
|
err = statsService.addWithdrawalItem(data)
|
||||||
|
|
||||||
|
data.Ymd = month
|
||||||
|
err = statsService.addWithdrawalItem(data)
|
||||||
|
|
||||||
|
data.Ymd = week
|
||||||
|
err = statsService.addWithdrawalItem(data)
|
||||||
|
|
||||||
|
data.Ymd = day
|
||||||
|
err = statsService.addWithdrawalItem(data)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (statsService *StatsService) addWithdrawalItem(data userdata.WithdrawalStats) (err error) {
|
||||||
|
|
||||||
|
data.Xid = fmt.Sprintf("%s-%s", data.UserNo, data.Ymd)
|
||||||
|
err = global.GVA_DB.Clauses(clause.OnConflict{
|
||||||
|
Columns: []clause.Column{{Name: "xid"}},
|
||||||
|
DoUpdates: clause.Assignments(map[string]interface{}{
|
||||||
|
"money": gorm.Expr("money+?", data.Money),
|
||||||
|
"coin": gorm.Expr("coin+?", data.Coin),
|
||||||
|
"count": gorm.Expr("count+?", data.Count),
|
||||||
|
"ut": data.Ut,
|
||||||
|
}),
|
||||||
|
}).Create(&data).Error
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (statsService *StatsService) AddBonusData(data userdata.BonusStats) (err error) {
|
||||||
|
history, year, month, week, day := statsService.formatTimestamp2Dates(data.Ut)
|
||||||
|
|
||||||
|
data.Ymd = history
|
||||||
|
err = statsService.addBonusItem(data)
|
||||||
|
|
||||||
|
data.Ymd = year
|
||||||
|
err = statsService.addBonusItem(data)
|
||||||
|
|
||||||
|
data.Ymd = month
|
||||||
|
err = statsService.addBonusItem(data)
|
||||||
|
|
||||||
|
data.Ymd = week
|
||||||
|
err = statsService.addBonusItem(data)
|
||||||
|
|
||||||
|
data.Ymd = day
|
||||||
|
err = statsService.addBonusItem(data)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (statsService *StatsService) addBonusItem(data userdata.BonusStats) (err error) {
|
||||||
|
|
||||||
|
data.Xid = fmt.Sprintf("%s-%s-%s", data.UserNo, data.BonusId, data.Ymd)
|
||||||
|
err = global.GVA_DB.Clauses(clause.OnConflict{
|
||||||
|
Columns: []clause.Column{{Name: "xid"}},
|
||||||
|
DoUpdates: clause.Assignments(map[string]interface{}{
|
||||||
|
"coin": gorm.Expr("coin+?", data.Coin),
|
||||||
|
"count": gorm.Expr("count+?", data.Count),
|
||||||
|
"ut": data.Ut,
|
||||||
|
}),
|
||||||
|
}).Create(&data).Error
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (statsService *StatsService) formatTimestamp2Dates(ts int64) (history, year, month, week, day string) {
|
||||||
|
tt := time.Unix(ts, 0)
|
||||||
|
y, w := tt.ISOWeek()
|
||||||
|
history = "0000-00-00"
|
||||||
|
year = fmt.Sprintf("%d-00-00", y)
|
||||||
|
month = tt.Format("2006-01") + "-00"
|
||||||
|
week = fmt.Sprintf("%d-00-%2d", y, w)
|
||||||
|
day = tt.Format("2006-01-02")
|
||||||
|
return
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user