You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.4 KiB
52 lines
1.4 KiB
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"healthapi/internal/model"
|
|
"healthapi/internal/svc"
|
|
"healthapi/internal/types"
|
|
"healthapi/pkg/errorx"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type CompleteSurveyLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewCompleteSurveyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CompleteSurveyLogic {
|
|
return &CompleteSurveyLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *CompleteSurveyLogic) CompleteSurvey() (resp *types.CommonResp, err error) {
|
|
userID, err := GetUserIDFromCtx(l.ctx)
|
|
if err != nil {
|
|
return nil, errorx.ErrUnauthorized
|
|
}
|
|
|
|
// 检查基础信息
|
|
var profile model.HealthProfile
|
|
if err := l.svcCtx.DB.Where("user_id = ?", userID).First(&profile).Error; err != nil {
|
|
return nil, errorx.NewCodeError(errorx.CodeBadRequest, "请先完成基础信息填写")
|
|
}
|
|
|
|
// 检查生活习惯
|
|
var lifestyle model.LifestyleInfo
|
|
if err := l.svcCtx.DB.Where("user_id = ?", userID).First(&lifestyle).Error; err != nil {
|
|
return nil, errorx.NewCodeError(errorx.CodeBadRequest, "请先完成生活习惯填写")
|
|
}
|
|
|
|
// 标记调查完成
|
|
if err := l.svcCtx.DB.Model(&model.User{}).Where("id = ?", userID).Update("survey_completed", true).Error; err != nil {
|
|
return nil, errorx.ErrServerError
|
|
}
|
|
|
|
return &types.CommonResp{Code: 0, Message: "调查完成"}, nil
|
|
}
|
|
|