fusenapi/server/home-user-auth/internal/logic/usercontactservicelogic.go

69 lines
1.8 KiB
Go
Raw Normal View History

2023-06-28 11:32:41 +00:00
package logic
import (
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/collect"
"context"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
type UserContactServiceLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUserContactServiceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserContactServiceLogic {
return &UserContactServiceLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UserContactServiceLogic) UserContactService(req *types.RequestContactService, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
if !userinfo.IsUser() {
return resp.SetStatus(basic.CodeUnAuth)
}
2023-06-29 10:04:59 +00:00
cs := gmodel.FsContactService{
UserId: &userinfo.UserId,
}
collect.LoadJsonTag(&cs, &req)
2023-06-28 11:32:41 +00:00
switch req.Type {
case "order":
2023-06-29 10:04:59 +00:00
_, err := l.svcCtx.AllModels.FsOrder.FindOneAndCreateServiceContact(l.ctx, userinfo.UserId, req.RelationID, &cs)
2023-06-28 11:32:41 +00:00
if err != nil {
if err == gorm.ErrRecordNotFound {
return resp.SetStatus(basic.CodeOrderNotFoundErr)
}
return resp.SetStatus(basic.CodeDbSqlErr)
}
case "cloud":
2023-06-29 10:04:59 +00:00
_, err := l.svcCtx.AllModels.FsCloudPickUp.GetCloudPickUpByIDAndUserID(l.ctx, userinfo.UserId, req.RelationID, &cs)
2023-06-28 11:32:41 +00:00
if err != nil {
if err == gorm.ErrRecordNotFound {
return resp.SetStatus(basic.CodeCloudOrderNotFoundErr)
}
return resp.SetStatus(basic.CodeDbSqlErr)
}
2023-06-29 10:04:59 +00:00
return
2023-06-28 11:32:41 +00:00
default:
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "type is unknown")
}
2023-06-29 10:04:59 +00:00
return resp.SetStatus(basic.CodeOK, cs)
2023-06-28 11:32:41 +00:00
}