package chatrecords import ( "context" "github.com/suyuan32/simple-admin-common/msg/errormsg" "github.com/zeromicro/go-zero/core/errorx" "wechat-api/internal/svc" "wechat-api/internal/types" "github.com/zeromicro/go-zero/core/logx" ) type SaveApiChatLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewSaveApiChatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveApiChatLogic { return &SaveApiChatLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx} } func (l *SaveApiChatLogic) SaveApiChat(req *types.ChatRecordsInfo) (*types.BaseMsgResp, error) { userId := uint64(1) //l.ctx.Value("userId").(uint64) sessionId := *req.SessionId // 记录下问题 _, err := l.svcCtx.DB.ChatRecords.Create(). SetUserID(userId). SetSessionID(sessionId). SetBotType(*req.BotType). SetBotID(*req.BotId). SetContentType(2). SetContent(*req.Content). Save(l.ctx) if err != nil { return nil, errorx.NewInternalError(err.Error()) } return &types.BaseMsgResp{Msg: errormsg.Success}, nil }