opt
This commit is contained in:
parent
9b70fb5ac8
commit
e3abdff08c
|
@ -38,3 +38,7 @@ type OpCoinOrderListData struct {
|
|||
//Offset int `json:"offset"`
|
||||
//More int `json:"more"`
|
||||
}
|
||||
|
||||
type DealOneCoinOrderReq struct {
|
||||
CoinOrderId string `json:"coin_order_id"`
|
||||
}
|
||||
|
|
|
@ -192,6 +192,7 @@ func Init(r *gin.Engine) {
|
|||
vasPayGroup.POST("withdraw_page", middleware.JSONParamValidator(vasproto.WithdrawPageReq{}), WithdrawPage)
|
||||
vasPayGroup.POST("withdraw_send_verifycode", middleware.JSONParamValidator(vasproto.WithdrawSendVerifycodeReq{}), WithdrawSendVerifycode)
|
||||
vasPayGroup.POST("withdraw_apply", middleware.JSONParamValidator(vasproto.WithdrawApplyReq{}), WithdrawApply)
|
||||
vasPayGroup.POST("deal_one_coin_order", middleware.JSONParamValidator(vasproto.DealOneCoinOrderReq{}), DealOneCoinOrder)
|
||||
|
||||
extVasPayGroup := r.Group("/ext/vas")
|
||||
extVasPayGroup.POST("alipay_callback", AlipayCallback)
|
||||
|
|
|
@ -257,3 +257,15 @@ func WithdrawApply(ctx *gin.Context) {
|
|||
}
|
||||
ReplyOk(ctx, nil)
|
||||
}
|
||||
|
||||
// 处理一个订单
|
||||
func DealOneCoinOrder(ctx *gin.Context) {
|
||||
req := ctx.MustGet("client_req").(*vasproto.DealOneCoinOrderReq)
|
||||
ec := service.DefaultService.DealOneCoinOrder(ctx, req)
|
||||
if ec != errcode.ErrCodeVasSrvOk {
|
||||
logger.Error("DealOneCoinOrder fail, req: %v, ec: %v", util.ToJson(req), ec)
|
||||
ReplyErrCodeMsg(ctx, ec)
|
||||
return
|
||||
}
|
||||
ReplyOk(ctx, nil)
|
||||
}
|
||||
|
|
|
@ -62,15 +62,16 @@ func (m *Mysql) DealTxCR(tx *sqlx.Tx, errIn error) (errOut error) {
|
|||
// mysql
|
||||
const (
|
||||
DatabaseVas = "vas"
|
||||
TableOrder = "vas_order" // 订单表
|
||||
TableWallet = "vas_wallet" // 钱包
|
||||
TableCoinOrder = "vas_coin_order" // 金币订单
|
||||
TableConsumeHistoryCost = "vas_ch_cost" // 消费明细
|
||||
TableConsumeHistoryCharge = "vas_ch_charge" // 充值明细
|
||||
TableConsumeHistoryIncome = "vas_ch_income" // 收入明细
|
||||
TableConsumeHistoryWithdraw = "vas_ch_withdraw" // 提现明细
|
||||
TableVasUserUnlock = "vas_user_unlock" // 用增解锁
|
||||
TableWithdrawOrder = "vas_withdraw_order" // 提现订单表
|
||||
TableOrder = "vas_order" // 订单表
|
||||
TableWallet = "vas_wallet" // 钱包
|
||||
TableCoinOrder = "vas_coin_order" // 金币订单
|
||||
TableConsumeHistoryCost = "vas_ch_cost" // 消费明细
|
||||
TableConsumeHistoryCharge = "vas_ch_charge" // 充值明细
|
||||
TableConsumeHistoryIncome = "vas_ch_income" // 收入明细
|
||||
TableConsumeHistoryWithdraw = "vas_ch_withdraw" // 提现明细
|
||||
TableVasUserUnlock = "vas_user_unlock" // 用增解锁
|
||||
TableWithdrawOrder = "vas_withdraw_order" // 提现订单表
|
||||
TableWithdrawDiamondsHis = "vas_withdraw_diamonds_his" // 提现金币历史
|
||||
)
|
||||
|
||||
func (m *Mysql) ChTableName(ch *dbstruct.ConsumeHistory) (string, error) {
|
||||
|
@ -343,6 +344,23 @@ func (m *Mysql) IncDiamonds(ctx *gin.Context, tx *sqlx.Tx, mid, dias int64) erro
|
|||
return err
|
||||
}
|
||||
|
||||
// 增加提现钻石
|
||||
func (m *Mysql) IncWithdrawDiamonds(ctx *gin.Context, tx *sqlx.Tx, mid, dias int64) error {
|
||||
var err error
|
||||
sqlStr := "update " + TableWallet + " set withdraw_diamonds=withdraw_diamonds+? where id=?"
|
||||
if tx != nil {
|
||||
_, err = tx.ExecContext(ctx, sqlStr, dias, mid)
|
||||
} else {
|
||||
db := m.getDBVas()
|
||||
_, err = db.ExecContext(ctx, sqlStr, dias, mid)
|
||||
}
|
||||
if err != nil {
|
||||
logger.Error("IncWithdrawDiamonds fail, mid: %v, dias: %v, err: %v", mid, dias, err)
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// 扣提现钻石
|
||||
func (m *Mysql) DecWithdrawDiamonds(ctx *gin.Context, tx *sqlx.Tx, mid, dias int64) error {
|
||||
var err error
|
||||
|
@ -427,6 +445,23 @@ func (m *Mysql) GetCoinOrders(ctx *gin.Context, tx *sqlx.Tx, mid, st, et int64)
|
|||
return
|
||||
}
|
||||
|
||||
// 更新订单状态
|
||||
func (m *Mysql) UpdateCoinOrderStatus(ctx *gin.Context, tx *sqlx.Tx, orderId string, status int32) error {
|
||||
var err error
|
||||
sqlStr := "update " + TableOrder + " set order_status=?,ut=? where id=?"
|
||||
if tx != nil {
|
||||
_, err = tx.ExecContext(ctx, sqlStr, status, time.Now().Unix(), orderId)
|
||||
} else {
|
||||
db := m.getDBVas()
|
||||
_, err = db.ExecContext(ctx, sqlStr, status, time.Now().Unix(), orderId)
|
||||
}
|
||||
if err != nil {
|
||||
logger.Error("UpdateCoinOrderStatus fail, orderId: %v, status: %v, err: %v", orderId, status, err)
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// 获取金币订单 for update
|
||||
func (m *Mysql) GetCoinOrderByIdForUpdate(ctx *gin.Context, tx *sqlx.Tx, id string) (order *dbstruct.CoinOrder, err error) {
|
||||
var tmpOrder dbstruct.CoinOrder
|
||||
|
@ -731,3 +766,26 @@ func (m *Mysql) GetWithdrawOrdersByMid(ctx *gin.Context, tx *sqlx.Tx, mid, st, e
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 创建提现订单
|
||||
func (m *Mysql) CreateWithdrawDiamondsHis(ctx *gin.Context, tx *sqlx.Tx, h *dbstruct.WithdrawDiamondsHis) error {
|
||||
var err error
|
||||
sqlStr := "insert into " + TableWithdrawDiamondsHis +
|
||||
" (mid, income_ch_id, order_id, ct, before_withdraw_diamonds, after_withdraw_diamonds, change) " +
|
||||
" values (?,?,?,?,?,?,?) "
|
||||
if tx != nil {
|
||||
_, err = tx.ExecContext(ctx, sqlStr,
|
||||
h.GetMid(), h.GetIncomeChId(), h.GetOrderId(), h.GetCt(), h.GetBeforeWithdrawDiamonds(), h.GetAfterWithdrawDiamonds(), h.GetChange(),
|
||||
)
|
||||
} else {
|
||||
db := m.getDBVas()
|
||||
_, err = db.ExecContext(ctx, sqlStr,
|
||||
h.GetMid(), h.GetIncomeChId(), h.GetOrderId(), h.GetCt(), h.GetBeforeWithdrawDiamonds(), h.GetAfterWithdrawDiamonds(), h.GetChange(),
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
logger.Error("CreateWithdrawDiamondsHis fail, h: %v, err: %v", util.ToJson(h), err)
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1929,7 +1929,18 @@ func (v *Vas) WithdrawApply(ctx *gin.Context, req *vasproto.WithdrawApplyReq) (t
|
|||
}
|
||||
|
||||
// 结算订单
|
||||
func (v *Vas) DealOneCoinOrder(ctx *gin.Context, coinOrder *dbstruct.CoinOrder) {
|
||||
func (v *Vas) DealOneCoinOrder(ctx *gin.Context, coinOrderId string) (err error) {
|
||||
coinOrder, err := v.store.GetCoinOrderById(ctx, nil, coinOrderId)
|
||||
if err != nil {
|
||||
logger.Error("GetCoinOrderById fail, id: %v, err: %v", coinOrderId, err)
|
||||
return
|
||||
}
|
||||
if coinOrder == nil {
|
||||
err = errs.ErrVasOrderNotExists
|
||||
logger.Error("GetCoinOrderById fail nil, id: %v, err: %v", coinOrderId, err)
|
||||
return
|
||||
}
|
||||
|
||||
// 判断时间,小于7天不处理
|
||||
if time.Now().Unix()-coinOrder.GetCt() < 7*86400 {
|
||||
logger.Info("DealOneCoinOrder ct fail, coinOrder: %v", coinOrder.ToString())
|
||||
|
@ -1958,13 +1969,56 @@ func (v *Vas) DealOneCoinOrder(ctx *gin.Context, coinOrder *dbstruct.CoinOrder)
|
|||
}()
|
||||
|
||||
// 把金币订单对应的收入记录拿出来
|
||||
//chList, err := v.store.GetIncomeCHList(ctx, tx, coinOrder.GetID())
|
||||
//if err != nil {
|
||||
// logger.Error("GetIncomeCHList fail, orderId: %v, err: %v", coinOrder.GetID(), err)
|
||||
// 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
|
||||
}
|
||||
|
||||
// 更新钱包
|
||||
// 处理
|
||||
for _, ch := range chList {
|
||||
if ch.GetMid() == common.OfficialMid {
|
||||
continue
|
||||
}
|
||||
|
||||
// 获取钱包
|
||||
wallet, errIn := v.store.GetWalletForUpdate(ctx, tx, ch.GetMid())
|
||||
if errIn != nil {
|
||||
logger.Error("GetWalletForUpdate fail, mid: %v, err: %v", ch.GetMid(), errIn)
|
||||
err = errIn
|
||||
return
|
||||
}
|
||||
|
||||
// 添加记录
|
||||
h := &dbstruct.WithdrawDiamondsHis{
|
||||
Mid: goproto.Int64(ch.GetMid()),
|
||||
IncomeChId: goproto.Int64(ch.GetId()),
|
||||
OrderId: goproto.String(ch.GetOrderId()),
|
||||
Ct: goproto.Int64(time.Now().Unix()),
|
||||
BeforeWithdrawDiamonds: goproto.Int64(wallet.GetWithdrawDiamonds()),
|
||||
AfterWithdrawDiamonds: goproto.Int64(wallet.GetWithdrawDiamonds() + ch.GetChange()),
|
||||
Change: goproto.Int64(ch.GetChange()),
|
||||
}
|
||||
errIn = v.store.CreateWithdrawDiamondsHis(ctx, tx, h)
|
||||
if errIn != nil {
|
||||
logger.Error("CreateWithdrawDiamondsHis fail, mid: %v, err: %v", ch.GetMid(), errIn)
|
||||
err = errIn
|
||||
return
|
||||
}
|
||||
|
||||
// 更新钱包
|
||||
errIn = v.store.IncWithdrawDiamonds(ctx, tx, ch.GetMid(), ch.GetChange())
|
||||
if errIn != nil {
|
||||
logger.Error("IncWithdrawDiamonds fail, mid: %v, change: %v, err: %v", ch.GetMid(), ch.GetChange(), errIn)
|
||||
err = errIn
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 更新订单状态
|
||||
err = v.store.UpdateCoinOrderStatus(ctx, tx, coinOrder.GetID(), dbstruct.VasCoinOrderStatusFinish)
|
||||
if err != nil {
|
||||
logger.Error("UpdateCoinOrderStatus fail, orderId: %v, err: %v", coinOrder.GetID(), err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -494,3 +494,13 @@ func (s *Service) OpCoinOrderList(ctx *gin.Context, req *vasproto.OpCoinOrderLis
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Service) DealOneCoinOrder(ctx *gin.Context, req *vasproto.DealOneCoinOrderReq) (ec errcode.ErrCode) {
|
||||
err := _DefaultVas.DealOneCoinOrder(ctx, req.CoinOrderId)
|
||||
ec, err = errs.DealVasErr(err)
|
||||
if err != nil {
|
||||
logger.Error("DealOneCoinOrder fail, req: %v, err: %v", util.ToJson(req), err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -136,3 +136,21 @@ CREATE TABLE `vas_withdraw_order`
|
|||
PRIMARY KEY (`id`)
|
||||
);
|
||||
CREATE INDEX ix_mid_applytime ON vas_withdraw_order (mid, apply_time);
|
||||
|
||||
|
||||
CREATE TABLE `vas_withdraw_diamonds_his`
|
||||
(
|
||||
`id` bigint AUTO_INCREMENT COMMENT 'id',
|
||||
`mid` bigint NOT NULL COMMENT '用户id',
|
||||
`income_ch_id` bigint NOT NULL COMMENT '收入明细中的id',
|
||||
`order_id` varchar(128) NOT NULL COMMENT '金币订单id',
|
||||
`ct` bigint DEFAULT NULL COMMENT '时间',
|
||||
`before_withdraw_diamonds` bigint DEFAULT NULL COMMENT 'before',
|
||||
`after_withdraw_diamonds` bigint DEFAULT NULL COMMENT 'after',
|
||||
`change` bigint DEFAULT NULL COMMENT '增加的可提现钻石数',
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
CREATE INDEX ix_mid ON vas_withdraw_diamonds_his (mid);
|
||||
CREATE INDEX ix_ct ON vas_withdraw_diamonds_his (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);
|
|
@ -519,6 +519,13 @@ type ConsumeHistory struct {
|
|||
Ct *int64 `json:"ct" db:"ct"`
|
||||
}
|
||||
|
||||
func (p *ConsumeHistory) GetId() int64 {
|
||||
if p != nil && p.Id != nil {
|
||||
return *p.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (p *ConsumeHistory) GetMid() int64 {
|
||||
if p != nil && p.Mid != nil {
|
||||
return *p.Mid
|
||||
|
@ -781,3 +788,63 @@ func (p *WithdrawOrder) GetOpTime() int64 {
|
|||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// 处理记录
|
||||
type WithdrawDiamondsHis struct {
|
||||
Mid *int64 `json:"mid" bson:"mid"`
|
||||
IncomeChId *int64 `json:"income_ch_id" db:"income_ch_id"`
|
||||
OrderId *string `json:"order_id" db:"order_id"`
|
||||
Ct *int64 `json:"ct" db:"ct"`
|
||||
BeforeWithdrawDiamonds *int64 `json:"before_withdraw_diamonds" db:"before_withdraw_diamonds"`
|
||||
AfterWithdrawDiamonds *int64 `json:"after_withdraw_diamonds" db:"after_withdraw_diamonds"`
|
||||
Change *int64 `json:"change" db:"change"`
|
||||
}
|
||||
|
||||
func (p *WithdrawDiamondsHis) GetMid() int64 {
|
||||
if p != nil && p.Mid != nil {
|
||||
return *p.Mid
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (p *WithdrawDiamondsHis) GetIncomeChId() int64 {
|
||||
if p != nil && p.IncomeChId != nil {
|
||||
return *p.IncomeChId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (p *WithdrawDiamondsHis) GetOrderId() string {
|
||||
if p != nil && p.OrderId != nil {
|
||||
return *p.OrderId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (p *WithdrawDiamondsHis) GetCt() int64 {
|
||||
if p != nil && p.Ct != nil {
|
||||
return *p.Ct
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (p *WithdrawDiamondsHis) GetBeforeWithdrawDiamonds() int64 {
|
||||
if p != nil && p.BeforeWithdrawDiamonds != nil {
|
||||
return *p.BeforeWithdrawDiamonds
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (p *WithdrawDiamondsHis) GetAfterWithdrawDiamonds() int64 {
|
||||
if p != nil && p.AfterWithdrawDiamonds != nil {
|
||||
return *p.AfterWithdrawDiamonds
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (p *WithdrawDiamondsHis) GetChange() int64 {
|
||||
if p != nil && p.Change != nil {
|
||||
return *p.Change
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue