You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"git.noahlan.cn/northlan/ntools-go/uuid"
|
|
"github.com/pkg/errors"
|
|
"live-service/app/gift/model"
|
|
"strconv"
|
|
|
|
"live-service/app/gift/rpc/internal/svc"
|
|
"live-service/app/gift/rpc/pb"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type CollectGiftLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewCollectGiftLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectGiftLogic {
|
|
return &CollectGiftLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
// CollectGift 收集礼物,仅作为收集使用
|
|
func (l *CollectGiftLogic) CollectGift(in *pb.CollectGift) (*pb.Empty, error) {
|
|
giftIdStr := strconv.FormatInt(in.GiftId, 10)
|
|
dbGift, err := l.svcCtx.GiftModel.FindOneByGiftId(l.ctx, giftIdStr)
|
|
if err == nil {
|
|
return &pb.Empty{}, nil
|
|
}
|
|
if err != nil {
|
|
if !errors.Is(err, model.ErrNotFound) {
|
|
return nil, errors.Wrap(err, "数据库错误")
|
|
}
|
|
}
|
|
dbGift = &model.Gift{
|
|
Id: uuid.NextId(),
|
|
GiftId: giftIdStr,
|
|
GiftName: in.GiftName,
|
|
Platform: in.Platform,
|
|
PPrice: in.TotalCoin,
|
|
}
|
|
if _, err := l.svcCtx.GiftModel.Insert(l.ctx, dbGift); err != nil {
|
|
return nil, errors.Wrap(err, "数据库插入错误")
|
|
}
|
|
return &pb.Empty{}, nil
|
|
}
|