add withdraw

This commit is contained in:
lwl0608 2024-05-10 10:17:07 +08:00
parent f11e7e15ae
commit 6a7ff7a8ff
5 changed files with 76 additions and 1 deletions

View File

@ -96,7 +96,9 @@ type WithdrawPageReq struct {
}
type WithdrawPageData struct {
WithdrawDiamonds int64 `json:"withdraw_diamonds"` // 可提现的钻石
WithdrawDiamonds int64 `json:"withdraw_diamonds"` // 可提现的钻石
Day7TotalDiamonds int64 `json:"day7_total_diamonds"` // 7天前024点总收益
Day7TotalWithdrawDiamonds int64 `json:"day7_total_withdraw_diamonds"` // 7天前024点已结算总收益
}
// 提现发送验证码

View File

@ -1158,3 +1158,44 @@ func (m *Mysql) CreateWithdrawDiamondsHis(ctx *gin.Context, tx *sqlx.Tx, h *dbst
}
return err
}
// 根据时间段获取收益钻石
func (m *Mysql) GetIncomeList(ctx *gin.Context, tx *sqlx.Tx, mid, st, et int64) (list []*dbstruct.ConsumeHistory, err error) {
list = make([]*dbstruct.ConsumeHistory, 0)
tableName, err := m.ChTableName(&dbstruct.ConsumeHistory{Type: goproto.Int32(dbstruct.CHTypeIncome)})
sqlStr := fmt.Sprintf("select order_id,`change` from %s where mid=? and ct>=? and ct<?", tableName)
args := []any{mid, st, et}
if tx != nil {
err = tx.SelectContext(ctx, &list, sqlStr, args...)
} else {
db := m.getDBVas()
err = db.SelectContext(ctx, &list, sqlStr, args...)
}
if err != nil {
return
}
return
}
// 根据时间段获取结算收益
func (m *Mysql) GetTotalFinishIncome(ctx *gin.Context, tx *sqlx.Tx, mid int64, orderIds []string) (int64, error) {
type S struct {
Dias int64 `json:"dias"`
}
var (
tmp = S{}
err error
)
sqlStr := fmt.Sprintf("select sum(`change`) as dias from %s where mid=? and order_id in (%s)", TableWithdrawDiamondsHis, util.Convert2SqlArr(orderIds))
args := []any{mid}
if tx != nil {
err = tx.GetContext(ctx, &tmp, sqlStr, args...)
} else {
db := m.getDBVas()
err = db.GetContext(ctx, &tmp, sqlStr, args...)
}
if err != nil {
return 0, err
}
return tmp.Dias, nil
}

View File

@ -3451,3 +3451,11 @@ func (v *Vas) payRefund(ctx *gin.Context, order *dbstruct.Order) error {
}
return nil
}
func (v *Vas) GetIncomeList(ctx *gin.Context, tx *sqlx.Tx, mid, st, et int64) (list []*dbstruct.ConsumeHistory, err error) {
return v.store.GetIncomeList(ctx, tx, mid, st, et)
}
func (v *Vas) GetTotalFinishIncome(ctx *gin.Context, tx *sqlx.Tx, mid int64, orderIds []string) (int64, error) {
return v.store.GetTotalFinishIncome(ctx, tx, mid, orderIds)
}

View File

@ -510,6 +510,29 @@ func (s *Service) WithdrawPage(ctx *gin.Context, req *vasproto.WithdrawPageReq)
if wallet != nil {
data.WithdrawDiamonds = wallet.GetWithdrawDiamonds()
}
st := util.GetTodayZeroTime().Unix() - 86400*7
et := st + 86400
// 获取 7天前024点总收益
day7TotalDiamonds := int64(0)
incomeList, err := _DefaultVas.GetIncomeList(ctx, nil, req.Mid, st, et)
if err != nil {
logger.Error("GetIncomeList fail, mid: %v, st: %v, et: %v, err: %v", req.Mid, st, et)
}
orderIds := make([]string, 0)
for _, c := range incomeList {
day7TotalDiamonds += c.GetChange()
orderIds = append(orderIds, c.GetOrderId())
}
data.Day7TotalDiamonds = day7TotalDiamonds
// 获取 7天前024点已结算总收益
day7TotalWithdrawDiamonds, err := _DefaultVas.GetTotalFinishIncome(ctx, nil, req.Mid, orderIds)
if err != nil {
logger.Error("GetTotalFinishIncome fail, mid: %v, st: %v, et: %v, err: %v", req.Mid, st, et)
}
data.Day7TotalWithdrawDiamonds = day7TotalWithdrawDiamonds
ec = errcode.ErrCodeOk
return
}

View File

@ -158,6 +158,7 @@ CREATE TABLE `vas_withdraw_diamonds_his`
);
CREATE INDEX ix_mid ON vas_withdraw_diamonds_his (mid);
CREATE INDEX ix_ct ON vas_withdraw_diamonds_his (ct);
CREATE INDEX ix_mid_ct ON vas_withdraw_diamonds_his (mid,ct);
CREATE INDEX ix_order_id ON vas_withdraw_diamonds_his (order_id);
CREATE INDEX ix_chid ON vas_withdraw_diamonds_his (income_ch_id);