apply time

This commit is contained in:
lwl0608 2024-01-08 22:38:18 +08:00
parent 447ba67460
commit ca0ed7bec9
7 changed files with 112 additions and 0 deletions

View File

@ -214,6 +214,7 @@ const (
ErrCodeVasNoEnoughWithdrawDias ErrCode = -7019 // 参数错误
ErrCodeVasInvalidVerifycode ErrCode = -7020 // 提现验证码错误
ErrCodeVasAlipayUniTransferFail ErrCode = -7021 // 支付宝提现失败
ErrCodeVasOverTodayWithdrawCnt ErrCode = -7022 // 今天提现次数到达上限
// Moment: 8xxx
ErrCodeMomentSrvOk ErrCode = ErrCodeOk

View File

@ -40,6 +40,7 @@ var ErrEcMap = map[error]errcode.ErrCode{
ErrVasInvalidParam: errcode.ErrCodeVasInvalidParam,
ErrVasNoEnoughWithdrawDias: errcode.ErrCodeVasNoEnoughWithdrawDias,
ErrVasAlipayUniTransferFail: errcode.ErrCodeVasAlipayUniTransferFail,
ErrVasOverTodayWithdrawCnt: errcode.ErrCodeVasOverTodayWithdrawCnt,
}
var (
@ -60,4 +61,5 @@ var (
ErrVasInvalidParam = errors.New("invalid param")
ErrVasNoEnoughWithdrawDias = errors.New("no enough withdraw dias")
ErrVasAlipayUniTransferFail = errors.New("alipay uni transfer fail")
ErrVasOverTodayWithdrawCnt = errors.New("over today withdraw cnt")
)

View File

@ -8,6 +8,7 @@ import (
"service/bizcommon/common"
"service/bizcommon/util"
"service/library/logger"
"time"
)
// 获取充值商品
@ -237,6 +238,17 @@ func WithdrawSendVerifycode(ctx *gin.Context) {
// 提现申请
func WithdrawApply(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*vasproto.WithdrawApplyReq)
if req.Diamonds < 2000 {
ReplyErrorMsg(ctx, "最低提现金额不能小于200元")
return
}
if req.Diamonds > 20000 {
ReplyErrorMsg(ctx, "最大提现金额不能大于2000元")
return
}
time.Sleep(time.Second * 1)
data, ec := service.DefaultService.WithdrawApply(ctx, req)
if ec != errcode.ErrCodeVasSrvOk {
logger.Error("WithdrawApply fail, req: %v, data: %v, ec: %v", util.ToJson(req), data, ec)

View File

@ -594,6 +594,23 @@ func (m *Mysql) GetUCHList(ctx *gin.Context, tx *sqlx.Tx, mid int64, typ int32,
return
}
// 获取收入历史
func (m *Mysql) GetIncomeCHList(ctx *gin.Context, tx *sqlx.Tx, orderId string) (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 * from %s where order_id=?", tableName)
if tx != nil {
err = tx.SelectContext(ctx, &list, sqlStr, orderId)
} else {
db := m.getDBVas()
err = db.SelectContext(ctx, &list, sqlStr, orderId)
}
if err != nil {
return
}
return
}
// 获取订单
func (m *Mysql) GetOrderCountGroupByStatus(ctx *gin.Context, tx *sqlx.Tx, orderStatuses []int32, ctStart *int64, ctEnd *int64) (list []*dbstruct.VasOrderStatusCount, err error) {
var sql strings.Builder
@ -675,3 +692,23 @@ func (m *Mysql) UpdateWithdrawOrderStatus(ctx *gin.Context, tx *sqlx.Tx, orderId
}
return err
}
// 获取提现订单
func (m *Mysql) GetWithdrawOrdersByMid(ctx *gin.Context, tx *sqlx.Tx, mid, st, et int64) (list []*dbstruct.WithdrawOrder, err error) {
list = make([]*dbstruct.WithdrawOrder, 0)
sqlStr := fmt.Sprintf("select * from %s where mid=? and apply_time>=? and apply_time<?", TableWithdrawOrder)
if tx != nil {
err = tx.SelectContext(ctx, &list, sqlStr, mid, st, et)
} else {
db := m.getDBVas()
err = db.SelectContext(ctx, &list, sqlStr, mid, st, et)
}
if err == sql.ErrNoRows {
err = nil
return
}
if err != nil {
return
}
return
}

View File

@ -1763,6 +1763,15 @@ func (v *Vas) WithdrawApply(ctx *gin.Context, req *vasproto.WithdrawApplyReq) (t
authAlipayName = req.AuthAlipayName
)
// 今日提现次数
st := util.GetTodayZeroTime().Unix()
et := st + 86400
list, _ := v.store.GetWithdrawOrdersByMid(ctx, nil, mid, st, et)
if len(list) > 0 {
err = errs.ErrVasOverTodayWithdrawCnt
return
}
// todo 分布式锁
// 检查余额
@ -1918,3 +1927,44 @@ func (v *Vas) WithdrawApply(ctx *gin.Context, req *vasproto.WithdrawApplyReq) (t
}
return
}
// 结算订单
func (v *Vas) DealOneCoinOrder(ctx *gin.Context, coinOrder *dbstruct.CoinOrder) {
// 判断时间小于7天不处理
if time.Now().Unix()-coinOrder.GetCt() < 7*86400 {
logger.Info("DealOneCoinOrder ct fail, coinOrder: %v", coinOrder.ToString())
return
}
if coinOrder.GetOrderStatus() >= dbstruct.VasCoinOrderStatusFinish {
logger.Info("DealOneCoinOrder status fail, coinOrder: %v", coinOrder.ToString())
return
}
// 开启事务
tx, err := v.store.VasBegin(ctx)
if err != nil {
logger.Error("vas begin fail, err: %v", err)
return
}
defer func() {
if err != nil {
logger.Error("global err, coinOrder: %v, err: %v", util.ToJson(coinOrder), err)
}
errTx := v.store.DealTxCR(tx, err)
if errTx != nil {
logger.Error("DealTxCR fail, err: %v", errTx)
return
}
}()
// 把金币订单对应的收入记录拿出来
//chList, err := v.store.GetIncomeCHList(ctx, tx, coinOrder.GetID())
//if err != nil {
// logger.Error("GetIncomeCHList fail, orderId: %v, err: %v", coinOrder.GetID(), err)
// return
//}
// 更新钱包
// 更新订单状态
}

View File

@ -74,3 +74,10 @@ func GetHourStartTimeStamp(t time.Time) int64 {
}
return duetimecst.Unix()
}
// 获取今天0点
func GetTodayZeroTime() time.Time {
currentTime := time.Now()
zeroTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 0, 0, 0, 0, currentTime.Location())
return zeroTime
}

View File

@ -64,6 +64,7 @@ CREATE INDEX mid_ct ON vas_ch_charge (mid, ct);
CREATE INDEX uid_ct ON vas_ch_charge (uid, ct);
CREATE INDEX mid_ct ON vas_ch_income (mid, ct);
CREATE INDEX uid_ct ON vas_ch_income (uid, ct);
CREATE INDEX ix_orderid ON vas_ch_income (order_id);
CREATE INDEX mid_ct ON vas_ch_withdraw (mid, ct);
CREATE INDEX uid_ct ON vas_ch_withdraw (uid, ct);
@ -99,6 +100,7 @@ CREATE TABLE `vas_coin_order`
PRIMARY KEY (`id`)
);
CREATE INDEX uid_product_id_status ON vas_coin_order (uid, product_id, order_status);
CREATE INDEX ix_ct ON vas_coin_order (ct);
CREATE TABLE `vas_user_unlock`
@ -133,3 +135,4 @@ CREATE TABLE `vas_withdraw_order`
`op_time` int DEFAULT NULL COMMENT 'op操作时间',
PRIMARY KEY (`id`)
);
CREATE INDEX ix_mid_applytime ON vas_withdraw_order (mid, apply_time);