feat: 签到,消耗,修复战报问题等等一系列东西。

main
NorthLan 3 years ago
parent 993eff94a9
commit aa1373fdfa

@ -31,3 +31,12 @@ message MqGift {
int64 totalCoin = 8;
int64 sendTime = 9;
}
// MqUserInfoUpdate
message MqUserInfoUpdate {
int64 userId = 1; // ID
}
// MqRankUpdate
message MqRankUpdate {
}

@ -1,9 +1,7 @@
@echo off
@echo ??????????????
::set tables=user,user_platform
::set tables=rank_pvp
set tables=gift
set tables=user_check_in
set targetDir=.\model
set templateDir=..\..\doc\template

@ -0,0 +1,76 @@
package model
import (
"context"
"git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc"
"github.com/jinzhu/now"
"gorm.io/gorm"
"time"
)
var _ UserCheckInModel = (*customUserCheckInModel)(nil)
type (
// UserCheckInModel is an interface to be customized, add more methods here,
// and implement the added methods in customUserCheckInModel.
UserCheckInModel interface {
userCheckInModel
InsertTx(ctx context.Context, tx *gorm.DB, data *UserCheckIn) error
// FindThisWeek 查询用户本周签到记录
FindThisWeek(ctx context.Context, tx *gorm.DB, userId int64) ([]UserCheckIn, error)
// CheckInToday 查询用户本日是否已签到
CheckInToday(ctx context.Context, tx *gorm.DB, userId int64) (bool, error)
}
customUserCheckInModel struct {
*defaultUserCheckInModel
}
)
// NewUserCheckInModel returns a model for the database table.
func NewUserCheckInModel(conn *gorm.DB) UserCheckInModel {
return &customUserCheckInModel{
defaultUserCheckInModel: newUserCheckInModel(conn),
}
}
func (m *customUserCheckInModel) InsertTx(ctx context.Context, tx *gorm.DB, data *UserCheckIn) error {
err := withTx(ctx, m.conn, tx).Create(&data).Error
return err
}
func (m *customUserCheckInModel) FindThisWeek(ctx context.Context, tx *gorm.DB, userId int64) ([]UserCheckIn, error) {
db := withTx(ctx, m.conn, tx)
// 取签到时间大于本周一的所有该用户签到记录,按签到时间升序排列
var resp []UserCheckIn
err := db.Model(&UserCheckIn{}).
Where("user_id = ? AND check_in_time >= ", userId, now.Monday()).
Order("check_in_time ASC").Find(resp).Error
switch err {
case nil:
return resp, nil
case gormc.ErrNotFound:
return []UserCheckIn{}, nil
default:
return nil, err
}
}
func (m *customUserCheckInModel) CheckInToday(ctx context.Context, tx *gorm.DB, userId int64) (bool, error) {
db := withTx(ctx, m.conn, tx)
n := time.Now()
var count int64
err := db.Table(m.table).
Where("user_id = ? AND check_in_time >= ? AND check_in_time <= ?", userId, now.With(n).BeginningOfDay(), now.With(n).EndOfDay()).
Count(&count).
Error
switch err {
case nil:
return count > 0, nil
case gormc.ErrNotFound:
return false, nil
default:
return false, err
}
}

@ -0,0 +1,86 @@
// Code generated by goctl. DO NOT EDIT!
package model
import (
"context"
"git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stringx"
"gorm.io/gorm"
)
var (
userCheckInFieldNames = builder.RawFieldNames(&UserCheckIn{})
userCheckInRows = strings.Join(userCheckInFieldNames, ",")
userCheckInRowsExpectAutoSet = strings.Join(stringx.Remove(userCheckInFieldNames, "`create_time`", "`update_time`"), ",")
userCheckInRowsWithPlaceHolder = strings.Join(stringx.Remove(userCheckInFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
)
type (
userCheckInModel interface {
Insert(ctx context.Context, data *UserCheckIn) error
FindOne(ctx context.Context, id int64) (*UserCheckIn, error)
Update(ctx context.Context, data *UserCheckIn) error
Delete(ctx context.Context, id int64) error
}
defaultUserCheckInModel struct {
conn *gorm.DB
table string
}
UserCheckIn struct {
Id int64 `gorm:"column:id;primaryKey"` // ID
UserId int64 `gorm:"column:user_id"` // 用户ID
CheckInTime time.Time `gorm:"column:check_in_time;default:null"` // 签到时间
}
)
func newUserCheckInModel(conn *gorm.DB) *defaultUserCheckInModel {
return &defaultUserCheckInModel{
conn: conn,
table: "`user_check_in`",
}
}
func (m *defaultUserCheckInModel) Insert(ctx context.Context, data *UserCheckIn) error {
err := m.conn.WithContext(ctx).Create(&data).Error
return err
}
func (m *defaultUserCheckInModel) FindOne(ctx context.Context, id int64) (*UserCheckIn, error) {
var resp UserCheckIn
err := m.conn.WithContext(ctx).Model(&UserCheckIn{}).Where("`id` = ?", id).Take(&resp).Error
switch err {
case nil:
return &resp, nil
case gormc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultUserCheckInModel) Update(ctx context.Context, data *UserCheckIn) error {
err := m.conn.WithContext(ctx).Save(data).Error
return err
}
func (m *defaultUserCheckInModel) Delete(ctx context.Context, id int64) error {
err := m.conn.WithContext(ctx).Delete(&UserCheckIn{}, id).Error
return err
}
func (m *defaultUserCheckInModel) tableName() string {
return m.table
}
func (UserCheckIn) TableName() string {
model := newUserCheckInModel(nil)
return model.tableName()
}

@ -6,6 +6,7 @@ import (
"git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc"
"github.com/pkg/errors"
"gorm.io/gorm"
"live-service/common/nerr"
)
var _ UserIntegralModel = (*customUserIntegralModel)(nil)
@ -19,6 +20,8 @@ type (
InsertTx(ctx context.Context, tx *gorm.DB, data *UserIntegral) error
UpdateIntegralTx(ctx context.Context, tx *gorm.DB, userId, addon int64) error
FindIntegral(ctx context.Context, tx *gorm.DB, userId int64) (int64, error)
// ChangeIntegral 用户积分变动
ChangeIntegral(ctx context.Context, tx *gorm.DB, userId int64, change int64) (int64, error)
}
customUserIntegralModel struct {
@ -74,3 +77,36 @@ func (m *customUserIntegralModel) FindIntegral(ctx context.Context, tx *gorm.DB,
return 0, err
}
}
func (m *customUserIntegralModel) ChangeIntegral(ctx context.Context, tx *gorm.DB, userId int64, change int64) (int64, error) {
resp := change
err := withTx(ctx, m.conn, tx).Transaction(func(tx *gorm.DB) error {
integral, err := m.FindIntegral(ctx, tx, userId)
if err != nil {
if errors.Is(err, ErrNotFound) {
if change < 0 {
return nerr.NewWithCode(nerr.UserIntegralNotEnoughError)
}
// 用户积分记录不存在,进行插入
if err = m.InsertTx(ctx, tx, &UserIntegral{
UserId: userId,
Integral: change,
}); err != nil {
return errors.Wrap(err, "插入用户积分失败")
}
return nil
} else {
return errors.Wrap(err, "获取当前用户积分失败")
}
}
if integral+change < 0 {
return errors.New("用户积分不足")
}
if err = m.UpdateIntegralTx(ctx, tx, userId, integral+change); err != nil {
return errors.Wrap(err, "更新用户积分失败")
}
resp = integral + change
return nil
})
return resp, err
}

@ -13,6 +13,7 @@ type (
// and implement the added methods in customUserModel.
UserModel interface {
userModel
Transact(ctx context.Context, tx *gorm.DB, fn func(tx *gorm.DB) error) error
// InsertTx 插入事务
InsertTx(ctx context.Context, tx *gorm.DB, data *User) error
FindOneTx(ctx context.Context, tx *gorm.DB, id int64) (*User, error)
@ -30,6 +31,10 @@ func NewUserModel(conn *gorm.DB) UserModel {
}
}
func (m *customUserModel) Transact(ctx context.Context, tx *gorm.DB, fn func(tx *gorm.DB) error) error {
return withTx(ctx, m.conn, tx).Transaction(fn)
}
func (m *customUserModel) InsertTx(ctx context.Context, tx *gorm.DB, data *User) error {
return withTx(ctx, m.conn, tx).Create(data).Error
}

@ -4,7 +4,7 @@ Timeout: 5000
Etcd:
Hosts:
- 127.0.0.1:2379
Key: usercenter.rpc.v2.dev
Key: usercenter.rpc.dev
Timeout: 5000 # default is 2000
NonBlock: true
Log:
@ -14,6 +14,13 @@ Log:
DB:
#DataSource: root:root@tcp(192.168.1.100:3306)/dmgame?charset=utf8mb4&loc=Asia%2FShanghai&parseTime=true
DataSource: root:root@tcp(127.0.0.1:3306)/dmgame?charset=utf8mb4&loc=Asia%2FShanghai&parseTime=true
Kafka:
UserNotify:
Addr: [ "127.0.0.1:9093" ]
Topic: "notify-user"
RankUpdate:
Addr: [ "127.0.0.1:9093" ]
Topic: "rank-update"
UserRetriever:
Enabled: false
UpdateDuration: 720 # 720 hours = 30 Day = 1 Month
@ -37,6 +44,15 @@ GiftCollector:
Cron:
CollectGift: "0 0 0/6 * * ?" # 每隔6小时执行一次
Integral:
# 签到积分配置
CheckIn:
# 签到积分 一周 0(周日) 1 2 3 4 5 6
Points: [ 10000,2500,2500,3500,5000,6500,8000 ]
Critical: 0.15 # 签到积分暴击率
CriticalRadio: [ 1.0, 1.0, 1.2, 1.5, 1.8 ] # 暴击倍率
BattleReport:
WinRadio: 0.02 # 伤害量 1/50
LostRadio: 0.008 # 伤害量 1/120
# RMB到积分的转换
RMBToIntegral: 1000
# 平台礼物到RMB的转换
@ -44,4 +60,4 @@ Integral:
bilibili: 0.001
# 平台免费礼物到积分的转换
FreeToIntegral:
bilibili: 0.0001
bilibili: 0.00025

@ -4,7 +4,7 @@ Timeout: 5000
Etcd:
Hosts:
- 127.0.0.1:2379
Key: usercenter.rpc.v2
Key: usercenter.rpc
Timeout: 5000 # default is 2000
NonBlock: true
Log:
@ -14,6 +14,13 @@ Log:
DB:
#DataSource: root:root@tcp(192.168.1.100:3306)/dmgame?charset=utf8mb4&loc=Asia%2FShanghai&parseTime=true
DataSource: root:root@tcp(127.0.0.1:3306)/dmgame?charset=utf8mb4&loc=Asia%2FShanghai&parseTime=true
Kafka:
UserNotify:
Addr: [ "127.0.0.1:9093" ]
Topic: "notify-user"
RankUpdate:
Addr: [ "127.0.0.1:9093" ]
Topic: "rank-update"
UserRetriever:
Enabled: true
UpdateDuration: 720 # 720 hours = 30 Day = 1 Month
@ -37,6 +44,15 @@ GiftCollector:
Cron:
CollectGift: "0 0 0/6 * * ?" # 每隔6小时执行一次
Integral:
# 签到积分配置
CheckIn:
# 签到积分 一周 0(周日) 1 2 3 4 5 6
Points: [ 10000,2500,2500,3500,5000,6500,8000 ]
Critical: 0.15 # 签到积分暴击率
CriticalRadio: [ 1.0, 1.0, 1.2, 1.5, 1.8 ] # 暴击倍率
BattleReport:
WinRadio: 0.02 # 伤害量 1/50
LostRadio: 0.008 # 伤害量 1/120
# RMB到积分的转换
RMBToIntegral: 1000
# 平台礼物到RMB的转换
@ -44,4 +60,4 @@ Integral:
bilibili: 0.001
# 平台免费礼物到积分的转换
FreeToIntegral:
bilibili: 0.0001
bilibili: 0.00025

@ -6,13 +6,10 @@ import (
)
type (
/*
Kafka struct {
Addr []string
Addr []string // 连接地址
Topic string
ConsumerGroupId string
}
*/
// Config 配置
Config struct {
@ -21,7 +18,11 @@ type (
DB struct {
DataSource string
}
// Kafka 消息队列配置
Kafka struct {
UserNotify Kafka // 用户信息通知队列
RankUpdate Kafka // 排行榜更新通知队列
}
UserRetriever struct {
Enabled bool // 是否开启
UpdateDuration int64 // 用户信息更新最短间隔 单位 h
@ -37,7 +38,6 @@ type (
TopListApi string
}
}
Rank struct {
Enabled bool // 是否开启
Cron struct {
@ -45,7 +45,6 @@ type (
Persistence string // 持久化
}
}
GiftCollector struct {
Enabled bool // 是否开启
Platforms []string // 需搜集的平台
@ -54,6 +53,17 @@ type (
}
}
Integral struct {
// CheckIn 签到
CheckIn struct {
Points []int64 // 签到积分 次数分数
Critical float32 // 暴击率(百分比)
CriticalRadio []float32 // 暴击倍数
}
// 战局积分
BattleReport struct {
WinRadio float64 // 获胜方积分因子 乘法
LostRadio float64 // 失败方积分因子 乘法
}
RMBToIntegral float64 // RMB到积分的转换
GiftToRMB map[string]float64 // 平台礼物到RMB的转换
FreeToIntegral map[string]float64 // 平台免费礼物到积分的转换

@ -6,7 +6,6 @@ import (
"live-service/app/user_center/model"
"live-service/app/user_center/rpc/internal/logic/gift_collect"
"live-service/app/user_center/rpc/internal/logic/integral"
"live-service/app/user_center/rpc/internal/logic/platform_user"
"live-service/app/user_center/rpc/internal/svc"
"live-service/app/user_center/rpc/pb"
"strconv"
@ -32,25 +31,12 @@ func NewUserSendGiftLogic(ctx context.Context, svcCtx *svc.ServiceContext) *User
// 1. 记录用户赠送信息
// 2. 新增用户积分
func (l *UserSendGiftLogic) UserSendGift(in *pb.UserSendGiftReq) (*pb.UserSendGiftResp, error) {
// 首先获取用户id
var err error
sysUser, err := platform_user.NewRetrievePlatformUserLogic(l.ctx, l.svcCtx).RetrievePlatformUser(&pb.PlatformUserReq{
Platform: in.Platform,
PUid: in.PUid,
})
if err != nil {
return nil, err
}
resp := &pb.UserSendGiftResp{
User: sysUser.User,
}
resp := &pb.UserSendGiftResp{}
// 记录送礼信息
{
dbUserGift := &model.UserGift{
Id: uuid.NextId(),
UserId: sysUser.User.Id,
UserId: in.UserId,
Platform: in.Platform,
RoomId: in.RoomId,
GiftId: strconv.FormatInt(in.GiftId, 10),
@ -62,23 +48,22 @@ func (l *UserSendGiftLogic) UserSendGift(in *pb.UserSendGiftReq) (*pb.UserSendGi
} else {
dbUserGift.FreePrice = in.Price
}
if err = l.svcCtx.UserGiftModel.Insert(l.ctx, dbUserGift); err != nil {
l.Logger.Errorf("记录用户[%d]送礼信息 [%d:%s:%d] 失败,操作继续...", sysUser.User.Id, in.GiftId, in.GiftName, in.Num)
if err := l.svcCtx.UserGiftModel.Insert(l.ctx, dbUserGift); err != nil {
l.Logger.Errorf("记录用户[%d]送礼信息 [%d:%s:%d] 失败,操作继续...", in.UserId, in.GiftId, in.GiftName, in.Num)
}
}
// 积分
{
// 待增加的积分
// 计算积分
addonIntegral := calcIntegral(l.svcCtx.Config, in.Platform, in.IsPaid, float64(in.Price), in.Num)
if tmpMap, ok := gift_collect.Service.GetCacheByPlatform(in.Platform); ok {
if tmpData, ok := tmpMap[in.GiftId]; ok {
addonIntegral = calcIntegral(l.svcCtx.Config, in.Platform, tmpData.IsPaid, tmpData.Price, in.Num)
}
}
newIntegral, err := integral.NewChangeIntegralLogic(l.ctx, l.svcCtx).ChangeIntegral(&pb.ChangeIntegralReq{
UserId: sysUser.User.Id,
UserId: in.UserId,
Change: addonIntegral,
})
if err != nil {
@ -86,6 +71,5 @@ func (l *UserSendGiftLogic) UserSendGift(in *pb.UserSendGiftReq) (*pb.UserSendGi
}
resp.Integral = newIntegral
}
return resp, nil
}

@ -3,8 +3,6 @@ package integral
import (
"context"
"github.com/pkg/errors"
"gorm.io/gorm"
"live-service/app/user_center/model"
"live-service/common/nerr"
"live-service/app/user_center/rpc/internal/svc"
@ -29,43 +27,11 @@ func NewChangeIntegralLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ch
// ChangeIntegral 新增用户积分
func (l *ChangeIntegralLogic) ChangeIntegral(in *pb.ChangeIntegralReq) (*pb.ChangeIntegralResp, error) {
if err := l.svcCtx.UserIntegralModel.Transact(l.ctx, nil, func(tx *gorm.DB) error {
integral, err := l.svcCtx.UserIntegralModel.FindIntegral(l.ctx, tx, in.UserId)
integral, err := l.svcCtx.UserIntegralModel.ChangeIntegral(l.ctx, nil, in.UserId, in.Change)
if err != nil {
if errors.Is(err, model.ErrNotFound) {
if in.Change < 0 {
return errors.New("用户积分不足")
}
// 用户积分记录不存在,进行插入
if err = l.svcCtx.UserIntegralModel.InsertTx(l.ctx, tx, &model.UserIntegral{
UserId: in.UserId,
Integral: in.Change,
}); err != nil {
return errors.Wrap(err, "插入用户积分失败")
}
return nil
} else {
return errors.Wrap(err, "获取当前用户积分失败")
}
}
if integral+in.Change < 0 {
return errors.New("用户积分不足")
}
if err = l.svcCtx.UserIntegralModel.UpdateIntegralTx(l.ctx, tx, in.UserId, integral+in.Change); err != nil {
return errors.Wrap(err, "更新用户积分失败")
}
return nil
}); err != nil {
return nil, errors.Wrapf(nerr.NewWithErr(err), "记录积分-事务执行失败, err:%+v", err)
}
// 查询当前用户积分
integral, err := l.svcCtx.UserIntegralModel.FindIntegral(l.ctx, nil, in.UserId)
if err != nil {
return nil, errors.Wrapf(nerr.NewWithMsg("查询用户积分失败"), "查询用户积分失败, err:%+v", err)
}
return &pb.ChangeIntegralResp{
UserId: in.UserId,
Change: in.Change,

@ -26,7 +26,7 @@ func NewGetUserIntegralLogic(ctx context.Context, svcCtx *svc.ServiceContext) *G
}
// GetUserIntegral 获取用户积分
func (l *GetUserIntegralLogic) GetUserIntegral(in *pb.UserIdResp) (*pb.UserIntegralResp, error) {
func (l *GetUserIntegralLogic) GetUserIntegral(in *pb.UserIdReq) (*pb.UserIntegralResp, error) {
// 查询当前用户积分
integral, err := l.svcCtx.UserIntegralModel.FindIntegral(l.ctx, nil, in.UserId)
if err != nil {

@ -83,7 +83,7 @@ func (r *UserRetriever) retrieveNobility(platform ...string) {
if handle, ok := r.nobilityMapper[plat]; ok {
list, err := handle(r.svcCtx)
if err != nil {
r.Logger.Errorf("获取贵族列表失败, err: %+v\n", err)
r.Logger.Errorf("获取贵族列表失败, err: %v\n", err)
return
}
for _, data := range list {
@ -128,7 +128,7 @@ func (r *UserRetriever) retrieveList(list []model.UserPlatform) {
func (r *UserRetriever) retrieveUser(platform, pUid string) *PlatformUser {
if handle, ok := r.platformRetrieverMapper[platform]; ok {
if p, err := handle(pUid); err != nil {
r.Logger.Errorf("获取平台用户信息错误: err: %s\n", err.Error())
//r.Logger.Errorf("获取平台用户信息错误: err: %s\n", err.Error())
} else {
return p
}

@ -8,7 +8,6 @@ import (
"live-service/app/user_center/model"
"live-service/app/user_center/rpc/internal/svc"
"live-service/app/user_center/rpc/pb"
"live-service/common/nerr"
)
type StatPvpReportLogic struct {
@ -25,14 +24,12 @@ func NewStatPvpReportLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Sta
}
}
func (l *StatPvpReportLogic) StatPvpReport(in *pb.StatPvPReportReq) (*pb.Empty, error) {
// 虚拟UID
if in.GeneralUid <= 0 {
return &pb.Empty{}, nil
}
err := l.svcCtx.StatisticsPvpModel.Transaction(l.ctx, nil, func(tx *gorm.DB) error {
// 名将
func (l *StatPvpReportLogic) StatPvpReport(in *pb.StatPvPReportReq) (*pb.StatPvPReportResp, error) {
resp := &pb.StatPvPReportResp{}
// 名将记录
{
if in.GeneralUid > 0 {
if err := l.svcCtx.Db.Transaction(func(tx *gorm.DB) error {
if err := l.svcCtx.StatisticsPvpModel.UpdateRecord(l.ctx, tx, in.GeneralUid,
&model.UpdateRecordProps{General: true}); err != nil {
if errors.Is(err, model.ErrRowsAffectedZero) {
@ -47,25 +44,67 @@ func (l *StatPvpReportLogic) StatPvpReport(in *pb.StatPvPReportReq) (*pb.Empty,
return errors.Wrapf(err, ErrUpdateErr, err)
}
}
return nil
}); err != nil {
l.Logger.Errorf("PvP名将记录事务执行失败, err:%v", err)
}
}
}
// 玩家记录
{
// 获胜记录
if err := l.reports(tx, true, in.WinItems); err != nil {
return errors.Wrapf(err, "获胜PvP记录失败: %+v", err)
if err := l.reports(true, in.WinItems); err != nil {
l.Logger.Errorf("获胜PvP记录失败, err:%v", err)
}
// 战败记录
if err := l.reports(tx, false, in.LostItems); err != nil {
return errors.Wrapf(err, "获胜PvP记录失败: %+v", err)
if err := l.reports(false, in.LostItems); err != nil {
l.Logger.Errorf("战败PvP记录失败, err:%v", err)
}
return nil
})
}
// 积分记录
{
winItemResp := make([]*pb.StatPvPReportResp_Item, 0, len(in.WinItems))
lostItemResp := make([]*pb.StatPvPReportResp_Item, 0, len(in.LostItems))
battleReportCfg := l.svcCtx.Config.Integral.BattleReport
if err := l.svcCtx.Db.Transaction(func(tx *gorm.DB) error {
for _, item := range in.WinItems {
uid, damage := item.Uid, item.Damage
addIntegral := int64(float64(damage) * battleReportCfg.WinRadio)
_, err := l.svcCtx.UserIntegralModel.ChangeIntegral(l.ctx, tx, uid, addIntegral)
if err != nil {
return nil, errors.Wrapf(nerr.NewWithCode(nerr.DBError), "PvP战报-事务执行失败 err: %+v", err)
return err
}
winItemResp = append(winItemResp, &pb.StatPvPReportResp_Item{
Uid: uid,
AddonIntegral: addIntegral,
})
}
for _, item := range in.LostItems {
uid, damage := item.Uid, item.Damage
addIntegral := int64(float64(damage) * battleReportCfg.LostRadio)
_, err := l.svcCtx.UserIntegralModel.ChangeIntegral(l.ctx, tx, uid, addIntegral)
if err != nil {
return err
}
lostItemResp = append(winItemResp, &pb.StatPvPReportResp_Item{
Uid: uid,
AddonIntegral: addIntegral,
})
}
return nil
}); err != nil {
l.Logger.Errorf("战局积分计算失败, err:%v", err)
}
resp.WinItems = winItemResp
resp.LostItems = lostItemResp
}
return &pb.Empty{}, nil
l.Logger.Info("PvP战报记录成功...")
return resp, nil
}
func (l *StatPvpReportLogic) reports(tx *gorm.DB, win bool, items []*pb.StatPvPReportReq_Item) error {
return l.svcCtx.StatisticsPvpModel.Transaction(l.ctx, tx, func(tx *gorm.DB) error {
func (l *StatPvpReportLogic) reports(win bool, items []*pb.StatPvPReportReq_Item) error {
return l.svcCtx.Db.Transaction(func(tx *gorm.DB) error {
for _, item := range items {
if err := l.svcCtx.StatisticsPvpModel.UpdateRecord(l.ctx, tx, item.Uid,
&model.UpdateRecordProps{

@ -0,0 +1,106 @@
package user
import (
"context"
"git.noahlan.cn/northlan/ntools-go/uuid"
"github.com/pkg/errors"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
"live-service/app/user_center/model"
"live-service/app/user_center/rpc/internal/svc"
"live-service/app/user_center/rpc/pb"
"math/rand"
"time"
)
type UserCheckInLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUserCheckInLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserCheckInLogic {
return &UserCheckInLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
const (
MsgAlreadyCheckIn = "今天已打过卡了!"
MsgCheckInSuccess = "打卡成功,哔哩哔哩 (゜-゜)つロ 干杯"
)
var (
ErrAlreadyCheckIn = errors.New(MsgAlreadyCheckIn)
)
// UserCheckIn 用户签到|打卡
func (l *UserCheckInLogic) UserCheckIn(in *pb.UserIdReq) (*pb.UserCheckInResp, error) {
resp := &pb.UserCheckInResp{
Success: false,
Msg: "",
IntegralChange: 0,
Integral: 0,
IsCritical: false,
}
if err := l.svcCtx.Db.Transaction(func(tx *gorm.DB) error {
isCheckInToday, err := l.svcCtx.UserCheckInModel.CheckInToday(l.ctx, tx, in.UserId)
if err != nil {
return err
}
if isCheckInToday {
return ErrAlreadyCheckIn
}
// 打卡记录
if err = l.svcCtx.UserCheckInModel.InsertTx(l.ctx, tx, &model.UserCheckIn{
Id: uuid.NextId(),
UserId: in.UserId,
CheckInTime: time.Now(),
}); err != nil {
return err
}
// 积分记录,计算当日可得积分
change, critical := l.getCriticalPoint()
if resp.Integral, err = l.svcCtx.UserIntegralModel.ChangeIntegral(l.ctx, tx, in.UserId, change); err != nil {
return err
}
resp.IsCritical = critical
resp.IntegralChange = change
resp.Msg = MsgCheckInSuccess
resp.Success = true
return nil
}); err != nil {
if errors.Is(err, ErrAlreadyCheckIn) {
resp.Msg = MsgAlreadyCheckIn
return resp, nil
}
return nil, err
}
return resp, nil
}
func (l *UserCheckInLogic) getCriticalPoint() (int64, bool) {
checkInCfg := l.svcCtx.Config.Integral.CheckIn
nt := time.Now()
weekDay := int(nt.Weekday())
point := checkInCfg.Points[weekDay]
rand.Seed(nt.UnixNano())
isCritical := rand.Float32() <= checkInCfg.Critical
var radio float32
if len(checkInCfg.CriticalRadio) == 0 {
radio = 1
} else {
radio = checkInCfg.CriticalRadio[rand.Intn(len(checkInCfg.CriticalRadio))]
}
if isCritical {
return int64(float32(point) * radio), isCritical
} else {
return point, isCritical
}
}

@ -7,9 +7,9 @@ import (
"context"
"live-service/app/user_center/rpc/internal/logic/gift"
"live-service/app/user_center/rpc/internal/logic/integral"
"live-service/app/user_center/rpc/internal/logic/platform_user"
"live-service/app/user_center/rpc/internal/logic/rank"
"live-service/app/user_center/rpc/internal/logic/statistics"
"live-service/app/user_center/rpc/internal/logic/user"
"live-service/app/user_center/rpc/internal/svc"
"live-service/app/user_center/rpc/pb"
@ -28,13 +28,13 @@ func NewUserCenterServer(svcCtx *svc.ServiceContext) *UserCenterServer {
// retrievePlatformUser 新增或获取用户
func (s *UserCenterServer) RetrievePlatformUser(ctx context.Context, in *pb.PlatformUserReq) (*pb.PlatformUserResp, error) {
l := platform_user.NewRetrievePlatformUserLogic(ctx, s.svcCtx)
l := user.NewRetrievePlatformUserLogic(ctx, s.svcCtx)
return l.RetrievePlatformUser(in)
}
// getUserIdByPUid 通过平台用户id获取系统用户ID
func (s *UserCenterServer) GetUserIdByPUid(ctx context.Context, in *pb.PlatformUserReq) (*pb.UserIdResp, error) {
l := platform_user.NewGetUserIdByPUidLogic(ctx, s.svcCtx)
l := user.NewGetUserIdByPUidLogic(ctx, s.svcCtx)
return l.GetUserIdByPUid(in)
}
@ -45,11 +45,17 @@ func (s *UserCenterServer) ChangeIntegral(ctx context.Context, in *pb.ChangeInte
}
// GetUserIntegral 获取用户积分
func (s *UserCenterServer) GetUserIntegral(ctx context.Context, in *pb.UserIdResp) (*pb.UserIntegralResp, error) {
func (s *UserCenterServer) GetUserIntegral(ctx context.Context, in *pb.UserIdReq) (*pb.UserIntegralResp, error) {
l := integral.NewGetUserIntegralLogic(ctx, s.svcCtx)
return l.GetUserIntegral(in)
}
// UserCheckIn 用户签到|打卡
func (s *UserCenterServer) UserCheckIn(ctx context.Context, in *pb.UserIdReq) (*pb.UserCheckInResp, error) {
l := user.NewUserCheckInLogic(ctx, s.svcCtx)
return l.UserCheckIn(in)
}
// UserSendGift 用户赠送礼物
func (s *UserCenterServer) UserSendGift(ctx context.Context, in *pb.UserSendGiftReq) (*pb.UserSendGiftResp, error) {
l := gift.NewUserSendGiftLogic(ctx, s.svcCtx)
@ -71,7 +77,7 @@ func (s *UserCenterServer) StatPvpFirstBlood(ctx context.Context, in *pb.StatPvP
return l.StatPvpFirstBlood(in)
}
func (s *UserCenterServer) StatPvpReport(ctx context.Context, in *pb.StatPvPReportReq) (*pb.Empty, error) {
func (s *UserCenterServer) StatPvpReport(ctx context.Context, in *pb.StatPvPReportReq) (*pb.StatPvPReportResp, error) {
l := statistics.NewStatPvpReportLogic(ctx, s.svcCtx)
return l.StatPvpReport(in)
}

@ -13,12 +13,14 @@ import (
type ServiceContext struct {
Config config.Config
Db *gorm.DB
UserModel model.UserModel
UserPlatformModel model.UserPlatformModel
UserGiftModel model.UserGiftModel
UserIntegralModel model.UserIntegralModel
UserNobilityModel model.UserNobilityModel
UserCheckInModel model.UserCheckInModel
StatisticsPvpModel model.StatisticsPvpModel
RankPvpModel model.RankPvpModel
@ -43,11 +45,13 @@ func NewServiceContext(c config.Config) *ServiceContext {
}
return &ServiceContext{
Config: c,
Db: gormDb,
UserModel: model.NewUserModel(gormDb),
UserPlatformModel: model.NewUserPlatformModel(gormDb),
UserGiftModel: model.NewUserGiftModel(gormDb),
UserIntegralModel: model.NewUserIntegralModel(gormDb),
UserNobilityModel: model.NewUserNobilityModel(gormDb),
UserCheckInModel: model.NewUserCheckInModel(gormDb),
StatisticsPvpModel: model.NewStatisticsPvpModel(gormDb),
RankPvpModel: model.NewRankPvpModel(gormDb),
GiftModel: model.NewGiftModel(gormDb),

File diff suppressed because it is too large Load Diff

@ -29,42 +29,63 @@ message PlatformUserResp {
User user = 1;
}
// ID
message UserIdReq {
int64 userId = 1;
}
// ID
message UserIdResp {
int64 userId = 1;
}
//
message ChangeIntegralReq {
int64 userId = 1; // ID
int64 change = 2; //
}
//
message ChangeIntegralResp {
int64 userId = 1; // ID
int64 change = 2; //
int64 integral = 3; //
}
//
message UserIntegralResp {
int64 userId = 1; // ID
int64 integral = 2; //
}
//
message UserCheckInResp {
bool success = 1; //
string msg = 2; //
int64 integralChange = 3; //
int64 integral = 4; //
bool isCritical = 5; //
}
//
message UserSendGiftReq {
string platform = 1; //
string pUid = 2; // ID
string roomId = 3; // ID
int64 giftId = 4; // ID
string giftName = 5; //
int64 num = 6; //
int64 price = 7; // (使)
bool isPaid = 8; //
int64 userId = 2; // ID
string pUid = 3; // ID
string roomId = 4; // ID
int64 giftId = 5; // ID
string giftName = 6; //
int64 num = 7; //
int64 price = 8; // (使)
bool isPaid = 9; //
}
//
message UserSendGiftResp {
User user = 1; //
ChangeIntegralResp integral = 10; //
}
//
message UserBuyNobilityReq {
string platform = 1; //
string pUid = 2; // ID
@ -78,6 +99,7 @@ message UserBuyNobilityReq {
int64 endTime = 10; //
}
//
message UserBuyNobilityResp {
User user = 1; //
ChangeIntegralResp integral = 10; //
@ -111,6 +133,16 @@ message StatPvPReportReq {
repeated Item lostItems = 4; //
}
// -PvP
message StatPvPReportResp {
message Item {
int64 uid = 1; // ID
int64 addonIntegral = 2; //
}
repeated Item winItems = 3; //
repeated Item lostItems = 4; //
}
// rank
message RankPvpReq {
int32 type = 1; // rank
@ -141,7 +173,9 @@ service userCenter {
//ChangeIntegral
rpc ChangeIntegral(ChangeIntegralReq) returns (ChangeIntegralResp);
//GetUserIntegral
rpc GetUserIntegral(UserIdResp) returns (UserIntegralResp);
rpc GetUserIntegral(UserIdReq) returns (UserIntegralResp);
//UserCheckIn |
rpc UserCheckIn(UserIdReq) returns (UserCheckInResp);
/// @ZeroGroup: gift
@ -153,7 +187,7 @@ service userCenter {
rpc statPvpKill(StatPvPKillReq) returns (Empty);
rpc statPvpFirstBlood(StatPvPFirstBloodReq) returns (Empty);
rpc statPvpReport(StatPvPReportReq) returns (Empty);
rpc statPvpReport(StatPvPReportReq) returns (StatPvPReportResp);
/// @ZeroGroup: rank

@ -29,13 +29,15 @@ type UserCenterClient interface {
//ChangeIntegral 新增用户积分
ChangeIntegral(ctx context.Context, in *ChangeIntegralReq, opts ...grpc.CallOption) (*ChangeIntegralResp, error)
//GetUserIntegral 获取用户积分
GetUserIntegral(ctx context.Context, in *UserIdResp, opts ...grpc.CallOption) (*UserIntegralResp, error)
GetUserIntegral(ctx context.Context, in *UserIdReq, opts ...grpc.CallOption) (*UserIntegralResp, error)
//UserCheckIn 用户签到|打卡
UserCheckIn(ctx context.Context, in *UserIdReq, opts ...grpc.CallOption) (*UserCheckInResp, error)
// UserSendGift 用户赠送礼物
UserSendGift(ctx context.Context, in *UserSendGiftReq, opts ...grpc.CallOption) (*UserSendGiftResp, error)
UserBuyNobility(ctx context.Context, in *UserBuyNobilityReq, opts ...grpc.CallOption) (*UserBuyNobilityResp, error)
StatPvpKill(ctx context.Context, in *StatPvPKillReq, opts ...grpc.CallOption) (*Empty, error)
StatPvpFirstBlood(ctx context.Context, in *StatPvPFirstBloodReq, opts ...grpc.CallOption) (*Empty, error)
StatPvpReport(ctx context.Context, in *StatPvPReportReq, opts ...grpc.CallOption) (*Empty, error)
StatPvpReport(ctx context.Context, in *StatPvPReportReq, opts ...grpc.CallOption) (*StatPvPReportResp, error)
// rankPvp pvp排行
RankPvp(ctx context.Context, in *RankPvpReq, opts ...grpc.CallOption) (*RankPvpResp, error)
}
@ -75,7 +77,7 @@ func (c *userCenterClient) ChangeIntegral(ctx context.Context, in *ChangeIntegra
return out, nil
}
func (c *userCenterClient) GetUserIntegral(ctx context.Context, in *UserIdResp, opts ...grpc.CallOption) (*UserIntegralResp, error) {
func (c *userCenterClient) GetUserIntegral(ctx context.Context, in *UserIdReq, opts ...grpc.CallOption) (*UserIntegralResp, error) {
out := new(UserIntegralResp)
err := c.cc.Invoke(ctx, "/pb.userCenter/GetUserIntegral", in, out, opts...)
if err != nil {
@ -84,6 +86,15 @@ func (c *userCenterClient) GetUserIntegral(ctx context.Context, in *UserIdResp,
return out, nil
}
func (c *userCenterClient) UserCheckIn(ctx context.Context, in *UserIdReq, opts ...grpc.CallOption) (*UserCheckInResp, error) {
out := new(UserCheckInResp)
err := c.cc.Invoke(ctx, "/pb.userCenter/UserCheckIn", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *userCenterClient) UserSendGift(ctx context.Context, in *UserSendGiftReq, opts ...grpc.CallOption) (*UserSendGiftResp, error) {
out := new(UserSendGiftResp)
err := c.cc.Invoke(ctx, "/pb.userCenter/userSendGift", in, out, opts...)
@ -120,8 +131,8 @@ func (c *userCenterClient) StatPvpFirstBlood(ctx context.Context, in *StatPvPFir
return out, nil
}
func (c *userCenterClient) StatPvpReport(ctx context.Context, in *StatPvPReportReq, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
func (c *userCenterClient) StatPvpReport(ctx context.Context, in *StatPvPReportReq, opts ...grpc.CallOption) (*StatPvPReportResp, error) {
out := new(StatPvPReportResp)
err := c.cc.Invoke(ctx, "/pb.userCenter/statPvpReport", in, out, opts...)
if err != nil {
return nil, err
@ -149,13 +160,15 @@ type UserCenterServer interface {
//ChangeIntegral 新增用户积分
ChangeIntegral(context.Context, *ChangeIntegralReq) (*ChangeIntegralResp, error)
//GetUserIntegral 获取用户积分
GetUserIntegral(context.Context, *UserIdResp) (*UserIntegralResp, error)
GetUserIntegral(context.Context, *UserIdReq) (*UserIntegralResp, error)
//UserCheckIn 用户签到|打卡
UserCheckIn(context.Context, *UserIdReq) (*UserCheckInResp, error)
// UserSendGift 用户赠送礼物
UserSendGift(context.Context, *UserSendGiftReq) (*UserSendGiftResp, error)
UserBuyNobility(context.Context, *UserBuyNobilityReq) (*UserBuyNobilityResp, error)
StatPvpKill(context.Context, *StatPvPKillReq) (*Empty, error)
StatPvpFirstBlood(context.Context, *StatPvPFirstBloodReq) (*Empty, error)
StatPvpReport(context.Context, *StatPvPReportReq) (*Empty, error)
StatPvpReport(context.Context, *StatPvPReportReq) (*StatPvPReportResp, error)
// rankPvp pvp排行
RankPvp(context.Context, *RankPvpReq) (*RankPvpResp, error)
mustEmbedUnimplementedUserCenterServer()
@ -174,9 +187,12 @@ func (UnimplementedUserCenterServer) GetUserIdByPUid(context.Context, *PlatformU
func (UnimplementedUserCenterServer) ChangeIntegral(context.Context, *ChangeIntegralReq) (*ChangeIntegralResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method ChangeIntegral not implemented")
}
func (UnimplementedUserCenterServer) GetUserIntegral(context.Context, *UserIdResp) (*UserIntegralResp, error) {
func (UnimplementedUserCenterServer) GetUserIntegral(context.Context, *UserIdReq) (*UserIntegralResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetUserIntegral not implemented")
}
func (UnimplementedUserCenterServer) UserCheckIn(context.Context, *UserIdReq) (*UserCheckInResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method UserCheckIn not implemented")
}
func (UnimplementedUserCenterServer) UserSendGift(context.Context, *UserSendGiftReq) (*UserSendGiftResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method UserSendGift not implemented")
}
@ -189,7 +205,7 @@ func (UnimplementedUserCenterServer) StatPvpKill(context.Context, *StatPvPKillRe
func (UnimplementedUserCenterServer) StatPvpFirstBlood(context.Context, *StatPvPFirstBloodReq) (*Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method StatPvpFirstBlood not implemented")
}
func (UnimplementedUserCenterServer) StatPvpReport(context.Context, *StatPvPReportReq) (*Empty, error) {
func (UnimplementedUserCenterServer) StatPvpReport(context.Context, *StatPvPReportReq) (*StatPvPReportResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method StatPvpReport not implemented")
}
func (UnimplementedUserCenterServer) RankPvp(context.Context, *RankPvpReq) (*RankPvpResp, error) {
@ -263,7 +279,7 @@ func _UserCenter_ChangeIntegral_Handler(srv interface{}, ctx context.Context, de
}
func _UserCenter_GetUserIntegral_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UserIdResp)
in := new(UserIdReq)
if err := dec(in); err != nil {
return nil, err
}
@ -275,7 +291,25 @@ func _UserCenter_GetUserIntegral_Handler(srv interface{}, ctx context.Context, d
FullMethod: "/pb.userCenter/GetUserIntegral",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UserCenterServer).GetUserIntegral(ctx, req.(*UserIdResp))
return srv.(UserCenterServer).GetUserIntegral(ctx, req.(*UserIdReq))
}
return interceptor(ctx, in, info, handler)
}
func _UserCenter_UserCheckIn_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UserIdReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UserCenterServer).UserCheckIn(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/pb.userCenter/UserCheckIn",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UserCenterServer).UserCheckIn(ctx, req.(*UserIdReq))
}
return interceptor(ctx, in, info, handler)
}
@ -411,6 +445,10 @@ var UserCenter_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetUserIntegral",
Handler: _UserCenter_GetUserIntegral_Handler,
},
{
MethodName: "UserCheckIn",
Handler: _UserCenter_UserCheckIn_Handler,
},
{
MethodName: "userSendGift",
Handler: _UserCenter_UserSendGift_Handler,

@ -25,9 +25,13 @@ type (
StatPvPKillReq = pb.StatPvPKillReq
StatPvPReportReq = pb.StatPvPReportReq
StatPvPReportReq_Item = pb.StatPvPReportReq_Item
StatPvPReportResp = pb.StatPvPReportResp
StatPvPReportResp_Item = pb.StatPvPReportResp_Item
User = pb.User
UserBuyNobilityReq = pb.UserBuyNobilityReq
UserBuyNobilityResp = pb.UserBuyNobilityResp
UserCheckInResp = pb.UserCheckInResp
UserIdReq = pb.UserIdReq
UserIdResp = pb.UserIdResp
UserIntegralResp = pb.UserIntegralResp
UserSendGiftReq = pb.UserSendGiftReq
@ -41,13 +45,15 @@ type (
// ChangeIntegral 新增用户积分
ChangeIntegral(ctx context.Context, in *ChangeIntegralReq, opts ...grpc.CallOption) (*ChangeIntegralResp, error)
// GetUserIntegral 获取用户积分
GetUserIntegral(ctx context.Context, in *UserIdResp, opts ...grpc.CallOption) (*UserIntegralResp, error)
GetUserIntegral(ctx context.Context, in *UserIdReq, opts ...grpc.CallOption) (*UserIntegralResp, error)
// UserCheckIn 用户签到|打卡
UserCheckIn(ctx context.Context, in *UserIdReq, opts ...grpc.CallOption) (*UserCheckInResp, error)
// UserSendGift 用户赠送礼物
UserSendGift(ctx context.Context, in *UserSendGiftReq, opts ...grpc.CallOption) (*UserSendGiftResp, error)
UserBuyNobility(ctx context.Context, in *UserBuyNobilityReq, opts ...grpc.CallOption) (*UserBuyNobilityResp, error)
StatPvpKill(ctx context.Context, in *StatPvPKillReq, opts ...grpc.CallOption) (*Empty, error)
StatPvpFirstBlood(ctx context.Context, in *StatPvPFirstBloodReq, opts ...grpc.CallOption) (*Empty, error)
StatPvpReport(ctx context.Context, in *StatPvPReportReq, opts ...grpc.CallOption) (*Empty, error)
StatPvpReport(ctx context.Context, in *StatPvPReportReq, opts ...grpc.CallOption) (*StatPvPReportResp, error)
// rankPvp pvp排行
RankPvp(ctx context.Context, in *RankPvpReq, opts ...grpc.CallOption) (*RankPvpResp, error)
}
@ -82,11 +88,17 @@ func (m *defaultUserCenter) ChangeIntegral(ctx context.Context, in *ChangeIntegr
}
// GetUserIntegral 获取用户积分
func (m *defaultUserCenter) GetUserIntegral(ctx context.Context, in *UserIdResp, opts ...grpc.CallOption) (*UserIntegralResp, error) {
func (m *defaultUserCenter) GetUserIntegral(ctx context.Context, in *UserIdReq, opts ...grpc.CallOption) (*UserIntegralResp, error) {
client := pb.NewUserCenterClient(m.cli.Conn())
return client.GetUserIntegral(ctx, in, opts...)
}
// UserCheckIn 用户签到|打卡
func (m *defaultUserCenter) UserCheckIn(ctx context.Context, in *UserIdReq, opts ...grpc.CallOption) (*UserCheckInResp, error) {
client := pb.NewUserCenterClient(m.cli.Conn())
return client.UserCheckIn(ctx, in, opts...)
}
// UserSendGift 用户赠送礼物
func (m *defaultUserCenter) UserSendGift(ctx context.Context, in *UserSendGiftReq, opts ...grpc.CallOption) (*UserSendGiftResp, error) {
client := pb.NewUserCenterClient(m.cli.Conn())
@ -108,7 +120,7 @@ func (m *defaultUserCenter) StatPvpFirstBlood(ctx context.Context, in *StatPvPFi
return client.StatPvpFirstBlood(ctx, in, opts...)
}
func (m *defaultUserCenter) StatPvpReport(ctx context.Context, in *StatPvPReportReq, opts ...grpc.CallOption) (*Empty, error) {
func (m *defaultUserCenter) StatPvpReport(ctx context.Context, in *StatPvPReportReq, opts ...grpc.CallOption) (*StatPvPReportResp, error) {
client := pb.NewUserCenterClient(m.cli.Conn())
return client.StatPvpReport(ctx, in, opts...)
}

@ -0,0 +1,13 @@
package kafka
import (
nkfk "git.noahlan.cn/northlan/ntools-go/kafka"
"github.com/Shopify/sarama"
)
var DefaultProducerConfig = &nkfk.ProducerConfig{
RequiredAcks: sarama.WaitForAll,
Partitioner: sarama.NewHashPartitioner,
IsReturnSuccess: true,
Marshaler: ProtobufMarshaler,
}

@ -16,3 +16,9 @@ const (
DBUpdateAffectedZeroError uint32 = 100006
CopyError uint32 = 100007
)
// 用户积分相关 UserIntegral
const (
UserIntegralNotEnoughError uint32 = 200100 // 用户积分不足
)

@ -14,6 +14,8 @@ func init() {
message[DBError] = "数据库繁忙,请稍后再试。"
message[DBUpdateAffectedZeroError] = "更新数据影响行数为0" // 不一定是错误
message[CopyError] = "数据转换失败,请稍后再试。"
// 业务
message[UserIntegralNotEnoughError] = "用户积分不足"
}
func MapErrMsg(code uint32) string {

@ -16,7 +16,7 @@ require (
)
require (
github.com/Shopify/sarama v1.32.0 // indirect
github.com/Shopify/sarama v1.33.0 // indirect
github.com/VividCortex/mysqlerr v1.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
@ -38,6 +38,8 @@ require (
github.com/google/go-cmp v0.5.7 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/googleapis/gnostic v0.4.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
@ -48,7 +50,7 @@ require (
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.15.1 // indirect
github.com/klauspost/compress v1.15.4 // indirect
github.com/longzhiri/gozset v0.0.0-20210113140059-91f2d281daf1 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
@ -74,8 +76,8 @@ require (
go.uber.org/automaxprocs v1.5.1 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/net v0.0.0-20220421235706-1d1ef9303861 // indirect
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167 // indirect
golang.org/x/net v0.0.0-20220516155154-20f960328961 // indirect
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect

@ -56,6 +56,8 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdko
github.com/Shopify/sarama v1.30.0/go.mod h1:zujlQQx1kzHsh4jfV1USnptCQrHAEZ2Hk8fTKCulPVs=
github.com/Shopify/sarama v1.32.0 h1:P+RUjEaRU0GMMbYexGMDyrMkLhbbBVUVISDywi+IlFU=
github.com/Shopify/sarama v1.32.0/go.mod h1:+EmJJKZWVT/faR9RcOxJerP+LId4iWdQPBGLy1Y1Njs=
github.com/Shopify/sarama v1.33.0 h1:2K4mB9M4fo46sAM7t6QTsmSO8dLX1OqznLM7vn3OjZ8=
github.com/Shopify/sarama v1.33.0/go.mod h1:lYO7LwEBkE0iAeTl94UfPSrDaavFzSFlmn+5isARATQ=
github.com/Shopify/toxiproxy/v2 v2.1.6-0.20210914104332-15ea381dcdae/go.mod h1:/cvHQkZ1fst0EmZnA5dFtiQdWCNCFYzb+uE2vqVgvx0=
github.com/Shopify/toxiproxy/v2 v2.3.0 h1:62YkpiP4bzdhKMH+6uC5E95y608k3zDwdzuBMsnn3uQ=
github.com/Shopify/toxiproxy/v2 v2.3.0/go.mod h1:KvQTtB6RjCJY4zqNJn7C7JDFgsG5uoHYDirfUfpIm0c=
@ -255,6 +257,11 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
@ -297,8 +304,11 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.14.4/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.15.1 h1:y9FcTHGyrebwfP0ZZqFiaxTaiDnUrGkJkI+f583BL1A=
github.com/klauspost/compress v1.15.1/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.15.4 h1:1kn4/7MepF/CHmYub99/nNX8az0IJjfSOU/jbnTVfqQ=
github.com/klauspost/compress v1.15.4/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
@ -433,7 +443,9 @@ github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/X
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs=
github.com/xdg-go/scram v1.1.0/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs=
github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM=
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
@ -495,6 +507,8 @@ golang.org/x/crypto v0.0.0-20210920023735-84f357641f63/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA=
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167 h1:O8uGbHCqlTp2P6QJSLmCojM4mN6UemYv8K+dCnmHmu0=
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@ -570,6 +584,8 @@ golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220421235706-1d1ef9303861 h1:yssD99+7tqHWO5Gwh81phT+67hg+KttniBr6UnEXOY8=
golang.org/x/net v0.0.0-20220421235706-1d1ef9303861/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220516155154-20f960328961 h1:+W/iTMPG0EL7aW+/atntZwZrvSRIj3m3yX414dSULUU=
golang.org/x/net v0.0.0-20220516155154-20f960328961/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=

Loading…
Cancel
Save