-
Notifications
You must be signed in to change notification settings - Fork 1
/
updateworkcntlogic.go
40 lines (33 loc) · 1013 Bytes
/
updateworkcntlogic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package logic
import (
"context"
"douyin-tiktok/service/user/cmd/rpc/internal/svc"
"douyin-tiktok/service/user/cmd/rpc/types"
"douyin-tiktok/service/user/model"
"github.com/zeromicro/go-zero/core/logx"
)
type UpdateWorkCntLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdateWorkCntLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateWorkCntLogic {
return &UpdateWorkCntLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *UpdateWorkCntLogic) UpdateWorkCnt(in *__.UpdateWorkCntReq) (*__.CodeResp, error) {
session := l.svcCtx.UserInfo
if in.IsAdd == 1 {
session.SetExpr("work_count", "work_count + 1")
} else {
session.SetExpr("work_count", "work_count - 1").Where("work_count > 0")
}
if _, err := session.ID(in.UserId).Update(&model.UserInfo{}); err != nil {
logx.Errorf("[DB ERROR] UpdateWorkCnt 更新作品输失败 %v\n", err)
return &__.CodeResp{Code: -1}, err
}
return &__.CodeResp{}, nil
}