Ver código fonte

fix:add miniprogram left API

jimmyyem 4 meses atrás
pai
commit
82c45bfa12

+ 18 - 3
internal/logic/chatrecords/create_chat_records_logic.go

@@ -2,6 +2,8 @@ package chatrecords
 
 import (
 	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"wechat-api/internal/utils/dberrorhandler"
 
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
@@ -22,8 +24,21 @@ func NewCreateChatRecordsLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 		svcCtx: svcCtx}
 }
 
-func (l *CreateChatRecordsLogic) CreateChatRecords(req *types.ChatRecordsInfo) (resp *types.BaseMsgResp, err error) {
-	// todo: add your logic here and delete this line
+func (l *CreateChatRecordsLogic) CreateChatRecords(req *types.ChatRecordsInfo) (*types.BaseMsgResp, error) {
+	_, err := l.svcCtx.DB.ChatRecords.Create().
+		SetNotNilSessionID(req.SessionId).
+		SetNotNilUserID(req.UserId).
+		SetNotNilContent(req.Content).
+		SetNotNilContentType(req.ContentType).
+		SetNotNilBotID(req.BotId).
+		SetNotNilBotType(req.BotType).
+		Save(l.ctx)
+	if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	}
 
-	return
+	return &types.BaseMsgResp{
+		Code: 0,
+		Msg:  errormsg.Success,
+	}, nil
 }

+ 17 - 0
internal/logic/chatrecords/update_chat_records_logic.go

@@ -3,6 +3,8 @@ package chatrecords
 import (
 	"context"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/zeromicro/go-zero/core/errorx"
+	"wechat-api/internal/utils/dberrorhandler"
 
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
@@ -24,6 +26,21 @@ func NewUpdateChatRecordsLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 }
 
 func (l *UpdateChatRecordsLogic) UpdateChatRecords(req *types.ChatRecordsInfo) (*types.BaseMsgResp, error) {
+	if req.Id == nil || *req.Id <= 0 {
+		return nil, errorx.NewInvalidArgumentError("id cannot be null")
+	}
+
+	err := l.svcCtx.DB.ChatRecords.UpdateOneID(*req.Id).
+		SetNotNilSessionID(req.SessionId).
+		SetNotNilUserID(req.UserId).
+		SetNotNilContent(req.Content).
+		SetNotNilContentType(req.ContentType).
+		SetNotNilBotID(req.BotId).
+		SetNotNilBotType(req.BotType).
+		Exec(l.ctx)
+	if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	}
 	return &types.BaseMsgResp{
 		Code: 0,
 		Msg:  errormsg.Success,

+ 1 - 1
internal/logic/wxcard/get_wx_card_by_id_logic.go

@@ -28,7 +28,7 @@ func NewGetWxCardByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Get
 }
 
 func (l *GetWxCardByIdLogic) GetWxCardById(req *types.IDReq) (*types.WxCardInfoResp, error) {
-	if req.Id == 0 {
+	if req.Id <= 0 {
 		return nil, errorx.NewDefaultError("参数错误")
 	}
 

+ 18 - 1
internal/logic/wxcarduser/create_wx_card_user_logic.go

@@ -2,6 +2,8 @@ package wxcarduser
 
 import (
 	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"wechat-api/internal/utils/dberrorhandler"
 
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
@@ -23,6 +25,21 @@ func NewCreateWxCardUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
 }
 
 func (l *CreateWxCardUserLogic) CreateWxCardUser(req *types.WxCardUserInfo) (*types.BaseMsgResp, error) {
+	_, err := l.svcCtx.DB.WxCardUser.Create().
+		SetNotNilAccount(req.Account).
+		SetNotNilAvatar(req.Avatar).
+		SetNotNilNickname(req.Nickname).
+		SetNotNilRemark(req.Remark).
+		SetNotNilPhone(req.Phone).
+		SetNotNilOpenID(req.OpenId).
+		Save(l.ctx)
 
-	return &types.BaseMsgResp{}, nil
+	if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	}
+
+	return &types.BaseMsgResp{
+		Code: 0,
+		Msg:  errormsg.Success,
+	}, nil
 }

+ 11 - 1
internal/logic/wxcardvisit/create_wx_card_visit_logic.go

@@ -3,6 +3,7 @@ package wxcardvisit
 import (
 	"context"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"wechat-api/internal/utils/dberrorhandler"
 
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
@@ -23,6 +24,15 @@ func NewCreateWxCardVisitLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 		svcCtx: svcCtx}
 }
 
-func (l *CreateWxCardVisitLogic) CreateWxCardVisit(req *types.WxCardVisitInfo) (resp *types.BaseMsgResp, err error) {
+func (l *CreateWxCardVisitLogic) CreateWxCardVisit(req *types.WxCardVisitInfo) (*types.BaseMsgResp, error) {
+	err := l.svcCtx.DB.WxCardVisit.Create().
+		SetNotNilUserID(req.UserId).
+		SetNotNilBotID(req.BotId).
+		SetNotNilBotType(req.BotType).
+		Exec(l.ctx)
+	if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	}
+
 	return &types.BaseMsgResp{Msg: errormsg.Success}, nil
 }

+ 14 - 0
internal/logic/wxcardvisit/update_wx_card_visit_logic.go

@@ -3,6 +3,8 @@ package wxcardvisit
 import (
 	"context"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/zeromicro/go-zero/core/errorx"
+	"wechat-api/internal/utils/dberrorhandler"
 
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
@@ -24,6 +26,18 @@ func NewUpdateWxCardVisitLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 }
 
 func (l *UpdateWxCardVisitLogic) UpdateWxCardVisit(req *types.WxCardVisitInfo) (*types.BaseMsgResp, error) {
+	if req.Id == nil || *req.Id <= 0 {
+		return nil, errorx.NewInvalidArgumentError("id cannot be null")
+	}
+
+	err := l.svcCtx.DB.WxCardVisit.UpdateOneID(*req.Id).
+		SetNotNilUserID(req.UserId).
+		SetNotNilBotID(req.BotId).
+		SetNotNilBotType(req.BotType).
+		Exec(l.ctx)
+	if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	}
 
 	return &types.BaseMsgResp{Msg: errormsg.Success}, nil
 }