Merge pull request 'by Robin at 20240123; add consume his' (#77) from feat-20240121-001-Robin into main
Reviewed-on: #77
This commit is contained in:
commit
5761f02b8b
|
@ -1685,7 +1685,7 @@ func (v *Vas) AlipayCallback(ctx *gin.Context, p *vasproto.AlipayCallbackParamIn
|
|||
}
|
||||
case product.Id == dbstruct.ProductIdMembership:
|
||||
// 解锁会员资格
|
||||
_, err = v.UnlockMembership(ctx, util.DerefInt64(order.Mid), product, order)
|
||||
_, err = v.UnlockMembership(ctx, util.DerefInt64(order.Mid), product, order, wallet)
|
||||
if err != nil {
|
||||
logger.Error("UnlockMembership fail, order: %v", util.ToJson(order))
|
||||
return
|
||||
|
@ -2037,12 +2037,13 @@ func (v *Vas) DealOneCoinOrder(ctx *gin.Context, coinOrderId string) (err error)
|
|||
}
|
||||
|
||||
// 解锁会员资格
|
||||
func (v *Vas) UnlockMembership(ctx *gin.Context, mid int64, product *dbstruct.Product, order *dbstruct.Order) (orderId string, err error) {
|
||||
func (v *Vas) UnlockMembership(ctx *gin.Context, mid int64, product *dbstruct.Product, order *dbstruct.Order, wallet *dbstruct.Wallet) (orderId string, err error) {
|
||||
|
||||
var (
|
||||
did = util.DerefString(order.Did)
|
||||
productId = product.Id
|
||||
timeNow = time.Now().Unix()
|
||||
coinPrice = order.GetCoins()
|
||||
)
|
||||
orderId = util.DerefString(order.ID)
|
||||
|
||||
|
@ -2078,6 +2079,26 @@ func (v *Vas) UnlockMembership(ctx *gin.Context, mid int64, product *dbstruct.Pr
|
|||
inviterWallet, _ = v.CheckWalletExist(ctx, inviterMid)
|
||||
}
|
||||
|
||||
// 增加金币消费历史(伪记录,仅为对账平插入一条消费流水)
|
||||
ch := &dbstruct.ConsumeHistory{
|
||||
Mid: goproto.Int64(mid),
|
||||
Uid: goproto.Int64(mid),
|
||||
Did: goproto.String(did),
|
||||
Type: goproto.Int32(dbstruct.CHTypeCost),
|
||||
SType: goproto.Int32(dbstruct.CHSTypeCostMembership),
|
||||
TypeId: goproto.String(productId),
|
||||
OrderId: goproto.String(orderId),
|
||||
Change: goproto.Int64(-coinPrice),
|
||||
Before: goproto.Int64(util.DerefInt64(wallet.Coins)),
|
||||
After: goproto.Int64(util.DerefInt64(wallet.Coins) - coinPrice),
|
||||
Ct: goproto.Int64(timeNow),
|
||||
}
|
||||
err = v.store.CreateConsumeHistory(ctx, tx, ch)
|
||||
if err != nil {
|
||||
logger.Error("CreateConsumeHistory fail, ch: %v, err: %v", util.ToJson(ch), err)
|
||||
return
|
||||
}
|
||||
|
||||
// 解锁记录
|
||||
userVasMembershipUnlock := &dbstruct.UserVasMembershipUnlock{
|
||||
Mid: goproto.Int64(mid),
|
||||
|
|
|
@ -3,7 +3,6 @@ package service
|
|||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"service/api/errcode"
|
||||
"service/api/errs"
|
||||
vasproto "service/api/proto/vas/proto"
|
||||
|
@ -12,6 +11,8 @@ import (
|
|||
"service/dbstruct"
|
||||
"service/library/logger"
|
||||
"service/library/mycrypto"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 一键解锁
|
||||
|
@ -248,6 +249,12 @@ func (s *Service) chListCost(ctx *gin.Context, chList []*dbstruct.ConsumeHistory
|
|||
case dbstruct.CHSTypeCostRefund:
|
||||
item.Desc = fmt.Sprintf("购买\"%s\"微信退款", util.DerefString(acnt.Name))
|
||||
item.Change = changeMark + fmt.Sprintf("%d金币", chDB.GetChange())
|
||||
case dbstruct.CHSTypeCostMembership:
|
||||
item.Desc = "购买会员"
|
||||
item.Change = changeMark + fmt.Sprintf("%d金币", chDB.GetChange())
|
||||
if chDB.GetChange() < 0 {
|
||||
item.Change = fmt.Sprintf("%d金币", chDB.GetChange())
|
||||
}
|
||||
}
|
||||
list = append(list, item)
|
||||
}
|
||||
|
|
|
@ -492,6 +492,7 @@ const (
|
|||
|
||||
CHSTypeCostContact = 10001 // 消费明细,联系方式
|
||||
CHSTypeCostRefund = 10002 // 消费明细,金币退款
|
||||
CHSTypeCostMembership = 10003 // 消费明细,会员资格解锁(伪金币记录,会员资格解锁中间无转金币过程)
|
||||
|
||||
CHSTypeChargeUser = 20001 // 充值明细,用户自己冲
|
||||
CHSTypeChargeOp = 20002 // 充值明细,OP充值
|
||||
|
|
Loading…
Reference in New Issue