fix: 暂时忽略更新积分影响行数为0的问题。

main
NorthLan 3 years ago
parent aa1373fdfa
commit f5194c7ef8

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc" "git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm" "gorm.io/gorm"
"live-service/common/nerr" "live-service/common/nerr"
) )
@ -45,20 +46,22 @@ func (m *customUserIntegralModel) InsertTx(ctx context.Context, tx *gorm.DB, dat
return err return err
} }
func (m *customUserIntegralModel) UpdateIntegralTx(ctx context.Context, tx *gorm.DB, userId, change int64) error { func (m *customUserIntegralModel) UpdateIntegralTx(ctx context.Context, tx *gorm.DB, userId, integral int64) error {
if change < 0 { if integral < 0 {
return errors.New("无法将积分更新至负数") return errors.New("无法将积分更新至负数")
} }
db := withTx(ctx, m.conn, tx) db := withTx(ctx, m.conn, tx)
result := db.Table(m.table). result := db.Table(m.table).
Where("user_id = ?", userId). Where("`user_id` = ?", userId).
Update("integral", change) Update("`integral`", integral)
if result.Error != nil { if result.Error != nil {
return result.Error return result.Error
} }
// TODO 这里得处理一下
if result.RowsAffected == 0 { if result.RowsAffected == 0 {
return ErrRowsAffectedZero logx.Statf("更新积分影响行数为0, user_id: %d, integral: %d", userId, integral)
return nil
} }
return nil return nil
} }
@ -67,7 +70,7 @@ func (m *customUserIntegralModel) FindIntegral(ctx context.Context, tx *gorm.DB,
var resp int64 var resp int64
err := withTx(ctx, m.conn, tx).Table(m.table). err := withTx(ctx, m.conn, tx).Table(m.table).
Select(fmt.Sprintf("%s.integral", m.table)). Select(fmt.Sprintf("%s.integral", m.table)).
Where("user_id = ?", userId).Take(&resp).Error Where("`user_id` = ?", userId).Take(&resp).Error
switch err { switch err {
case nil: case nil:
return resp, nil return resp, nil

@ -5,7 +5,6 @@ import (
"git.noahlan.cn/northlan/ntools-go/uuid" "git.noahlan.cn/northlan/ntools-go/uuid"
"live-service/app/user_center/model" "live-service/app/user_center/model"
"live-service/app/user_center/rpc/internal/logic/gift_collect" "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/svc" "live-service/app/user_center/rpc/internal/svc"
"live-service/app/user_center/rpc/pb" "live-service/app/user_center/rpc/pb"
"strconv" "strconv"
@ -62,14 +61,18 @@ func (l *UserSendGiftLogic) UserSendGift(in *pb.UserSendGiftReq) (*pb.UserSendGi
addonIntegral = calcIntegral(l.svcCtx.Config, in.Platform, tmpData.IsPaid, tmpData.Price, in.Num) addonIntegral = calcIntegral(l.svcCtx.Config, in.Platform, tmpData.IsPaid, tmpData.Price, in.Num)
} }
} }
newIntegral, err := integral.NewChangeIntegralLogic(l.ctx, l.svcCtx).ChangeIntegral(&pb.ChangeIntegralReq{ newIntegral, err := l.svcCtx.UserIntegralModel.ChangeIntegral(l.ctx, nil, in.UserId, addonIntegral)
UserId: in.UserId, if err != nil {
Change: addonIntegral, return nil, err
}) }
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp.Integral = newIntegral resp.Integral = &pb.ChangeIntegralResp{
UserId: in.UserId,
Change: addonIntegral,
Integral: newIntegral,
}
} }
return resp, nil return resp, nil
} }

Loading…
Cancel
Save