healthapp
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.
 
 
 
 
 
 

931 lines
29 KiB

syntax = "v1"
info (
title: "健康AI助手API"
desc: "健康AI问询助手后端服务"
author: "healthApps"
version: "v1"
)
// ==================== 公共类型 ====================
type (
// 通用响应
CommonResp {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
// 分页请求
PageReq {
Page int `form:"page,default=1"`
PageSize int `form:"page_size,default=10"`
}
// 分页响应
PageInfo {
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"page_size"`
}
)
// ==================== 认证模块 ====================
type (
// 注册请求
RegisterReq {
Phone string `json:"phone,optional"`
Email string `json:"email,optional"`
Password string `json:"password"`
Code string `json:"code,optional"`
}
// 登录请求
LoginReq {
Phone string `json:"phone,optional"`
Email string `json:"email,optional"`
Password string `json:"password"`
}
// 登录响应
LoginResp {
Token string `json:"token"`
ExpiresAt int64 `json:"expires_at"`
User UserInfo `json:"user"`
}
// 用户信息
UserInfo {
ID uint `json:"id"`
Phone string `json:"phone,omitempty"`
Email string `json:"email,omitempty"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar"`
SurveyCompleted bool `json:"survey_completed"`
}
// 刷新Token请求
RefreshTokenReq {
Token string `json:"token"`
}
// 发送验证码请求
SendCodeReq {
Phone string `json:"phone,optional"`
Email string `json:"email,optional"`
Type string `json:"type"` // register/login/reset
}
// 更新用户资料请求
UpdateProfileReq {
Nickname string `json:"nickname,optional"`
Avatar string `json:"avatar,optional"`
}
)
// ==================== 健康档案模块 ====================
type (
// 健康档案
HealthProfile {
ID uint `json:"id"`
UserID uint `json:"user_id"`
Name string `json:"name"`
BirthDate string `json:"birth_date"`
Gender string `json:"gender"`
Height float64 `json:"height"`
Weight float64 `json:"weight"`
BMI float64 `json:"bmi"`
BloodType string `json:"blood_type"`
Occupation string `json:"occupation"`
MaritalStatus string `json:"marital_status"`
Region string `json:"region"`
}
// 生活习惯
LifestyleInfo {
ID uint `json:"id"`
UserID uint `json:"user_id"`
SleepTime string `json:"sleep_time"`
WakeTime string `json:"wake_time"`
SleepQuality string `json:"sleep_quality"`
MealRegularity string `json:"meal_regularity"`
DietPreference string `json:"diet_preference"`
DailyWaterML int `json:"daily_water_ml"`
ExerciseFrequency string `json:"exercise_frequency"`
ExerciseType string `json:"exercise_type"`
ExerciseDurationMin int `json:"exercise_duration_min"`
IsSmoker bool `json:"is_smoker"`
AlcoholFrequency string `json:"alcohol_frequency"`
}
// 病史
MedicalHistory {
ID uint `json:"id"`
HealthProfileID uint `json:"health_profile_id"`
DiseaseName string `json:"disease_name"`
DiseaseType string `json:"disease_type"`
DiagnosedDate string `json:"diagnosed_date"`
Status string `json:"status"`
Notes string `json:"notes"`
}
// 家族病史
FamilyHistory {
ID uint `json:"id"`
HealthProfileID uint `json:"health_profile_id"`
Relation string `json:"relation"`
DiseaseName string `json:"disease_name"`
Notes string `json:"notes"`
}
// 过敏记录
AllergyRecord {
ID uint `json:"id"`
HealthProfileID uint `json:"health_profile_id"`
AllergyType string `json:"allergy_type"`
Allergen string `json:"allergen"`
Severity string `json:"severity"`
ReactionDesc string `json:"reaction_desc"`
}
// 完整健康档案响应
FullHealthProfileResp {
Profile HealthProfile `json:"profile"`
Lifestyle LifestyleInfo `json:"lifestyle"`
MedicalHistory []MedicalHistory `json:"medical_history"`
FamilyHistory []FamilyHistory `json:"family_history"`
AllergyRecords []AllergyRecord `json:"allergy_records"`
}
// 更新健康档案请求
UpdateHealthProfileReq {
Name string `json:"name,optional"`
BirthDate string `json:"birth_date,optional"`
Gender string `json:"gender,optional"`
Height float64 `json:"height,optional"`
Weight float64 `json:"weight,optional"`
BloodType string `json:"blood_type,optional"`
Occupation string `json:"occupation,optional"`
MaritalStatus string `json:"marital_status,optional"`
Region string `json:"region,optional"`
}
// 更新生活习惯请求
UpdateLifestyleReq {
SleepTime string `json:"sleep_time,optional"`
WakeTime string `json:"wake_time,optional"`
SleepQuality string `json:"sleep_quality,optional"`
MealRegularity string `json:"meal_regularity,optional"`
DietPreference string `json:"diet_preference,optional"`
DailyWaterML int `json:"daily_water_ml,optional"`
ExerciseFrequency string `json:"exercise_frequency,optional"`
ExerciseType string `json:"exercise_type,optional"`
ExerciseDurationMin int `json:"exercise_duration_min,optional"`
IsSmoker bool `json:"is_smoker,optional"`
AlcoholFrequency string `json:"alcohol_frequency,optional"`
}
// ID路径参数
IdPathReq {
Id uint `path:"id"`
}
)
// ==================== 健康调查模块 ====================
type (
// 调查状态响应
SurveyStatusResp {
Completed bool `json:"completed"`
BasicInfo bool `json:"basic_info"`
Lifestyle bool `json:"lifestyle"`
MedicalHistory bool `json:"medical_history"`
FamilyHistory bool `json:"family_history"`
Allergy bool `json:"allergy"`
}
// 提交基础信息请求
SubmitBasicInfoReq {
Name string `json:"name"`
BirthDate string `json:"birth_date"`
Gender string `json:"gender"`
Height float64 `json:"height"`
Weight float64 `json:"weight"`
BloodType string `json:"blood_type,optional"`
Occupation string `json:"occupation,optional"`
MaritalStatus string `json:"marital_status,optional"`
Region string `json:"region,optional"`
}
// 提交生活习惯请求
SubmitLifestyleReq {
SleepTime string `json:"sleep_time"`
WakeTime string `json:"wake_time"`
SleepQuality string `json:"sleep_quality"`
MealRegularity string `json:"meal_regularity"`
DietPreference string `json:"diet_preference,optional"`
DailyWaterML int `json:"daily_water_ml,optional"`
ExerciseFrequency string `json:"exercise_frequency"`
ExerciseType string `json:"exercise_type,optional"`
ExerciseDurationMin int `json:"exercise_duration_min,optional"`
IsSmoker bool `json:"is_smoker"`
AlcoholFrequency string `json:"alcohol_frequency"`
}
// 提交病史请求
SubmitMedicalHistoryReq {
DiseaseName string `json:"disease_name"`
DiseaseType string `json:"disease_type,optional"`
DiagnosedDate string `json:"diagnosed_date,optional"`
Status string `json:"status,optional"`
Notes string `json:"notes,optional"`
}
// 批量提交病史请求
BatchMedicalHistoryReq {
Items []SubmitMedicalHistoryReq `json:"items"`
}
// 提交家族史请求
SubmitFamilyHistoryReq {
Relation string `json:"relation"`
DiseaseName string `json:"disease_name"`
Notes string `json:"notes,optional"`
}
// 批量提交家族史请求
BatchFamilyHistoryReq {
Items []SubmitFamilyHistoryReq `json:"items"`
}
// 提交过敏信息请求
SubmitAllergyReq {
AllergyType string `json:"allergy_type"`
Allergen string `json:"allergen"`
Severity string `json:"severity,optional"`
ReactionDesc string `json:"reaction_desc,optional"`
}
// 批量提交过敏信息请求
BatchAllergyReq {
Items []SubmitAllergyReq `json:"items"`
}
)
// ==================== 体质辨识模块 ====================
type (
// 问卷题目
Question {
ID int `json:"id"`
ConstitutionType string `json:"constitution_type"`
QuestionText string `json:"question_text"`
Options []string `json:"options"`
OrderNum int `json:"order_num"`
}
// 问卷题目列表响应
QuestionsResp {
Questions []Question `json:"questions"`
}
// 分组问卷响应
GroupedQuestionsResp {
Groups map[string][]Question `json:"groups"`
}
// 提交测评请求
SubmitAssessmentReq {
Answers []AnswerItem `json:"answers"`
}
// 答题项
AnswerItem {
QuestionID int `json:"question_id"`
Score int `json:"score"` // 1-5
}
// 测评结果
AssessmentResult {
ID uint `json:"id"`
UserID uint `json:"user_id"`
AssessedAt string `json:"assessed_at"`
Scores map[string]float64 `json:"scores"`
PrimaryConstitution string `json:"primary_constitution"`
SecondaryConstitutions []string `json:"secondary_constitutions"`
Recommendations map[string]string `json:"recommendations"`
}
// 测评历史响应
AssessmentHistoryResp {
History []AssessmentResult `json:"history"`
}
// 调养建议响应
RecommendationsResp {
Constitution string `json:"constitution"`
Recommendations map[string]string `json:"recommendations"`
}
)
// ==================== AI对话模块 ====================
type (
// 对话列表项
ConversationItem {
ID uint `json:"id"`
Title string `json:"title"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
// 对话列表响应
ConversationListResp {
Conversations []ConversationItem `json:"conversations"`
}
// 创建对话请求
CreateConversationReq {
Title string `json:"title,optional"`
}
// 消息
Message {
ID uint `json:"id"`
ConversationID uint `json:"conversation_id"`
Role string `json:"role"` // user/assistant/system
Content string `json:"content"`
CreatedAt string `json:"created_at"`
}
// 对话详情响应
ConversationDetailResp {
ID uint `json:"id"`
Title string `json:"title"`
Messages []Message `json:"messages"`
CreatedAt string `json:"created_at"`
}
// 对话ID路径参数
ConversationIdReq {
Id uint `path:"id"`
}
// 发送消息请求
SendMessageReq {
Id uint `path:"id"`
Content string `json:"content"`
}
// 消息响应
MessageResp {
UserMessage Message `json:"user_message"`
AssistantMessage Message `json:"assistant_message"`
}
)
// ==================== 产品模块 ====================
type (
// 产品
Product {
ID uint `json:"id"`
Name string `json:"name"`
Category string `json:"category"`
Description string `json:"description"`
Efficacy string `json:"efficacy"`
Suitable string `json:"suitable"`
Price float64 `json:"price"`
ImageURL string `json:"image_url"`
MallURL string `json:"mall_url"`
IsActive bool `json:"is_active"`
}
// 产品列表请求
ProductListReq {
Page int `form:"page,default=1"`
PageSize int `form:"page_size,default=10"`
Category string `form:"category,optional"`
}
// 产品列表响应
ProductListResp {
Products []Product `json:"products"`
PageInfo PageInfo `json:"page_info"`
}
// 产品搜索请求
ProductSearchReq {
Keyword string `form:"keyword"`
Page int `form:"page,default=1"`
PageSize int `form:"page_size,default=10"`
}
// 推荐产品响应
RecommendProductsResp {
Products []Product `json:"products"`
Constitution string `json:"constitution"`
Reason string `json:"reason"`
}
// 购买历史
PurchaseHistory {
ID uint `json:"id"`
UserID uint `json:"user_id"`
OrderNo string `json:"order_no"`
ProductID uint `json:"product_id"`
ProductName string `json:"product_name"`
PurchasedAt string `json:"purchased_at"`
Source string `json:"source"`
}
// 购买历史响应
PurchaseHistoryResp {
History []PurchaseHistory `json:"history"`
PageInfo PageInfo `json:"page_info"`
}
// 同步购买请求
SyncPurchaseReq {
OrderNo string `json:"order_no"`
ProductID uint `json:"product_id"`
ProductName string `json:"product_name"`
UserID uint `json:"user_id"`
PurchasedAt string `json:"purchased_at"`
Source string `json:"source"`
}
)
// ==================== 路由定义 ====================
// 无需认证的路由
@server (
prefix: /api
)
service healthapi-api {
// 健康检查
@handler HealthCheckHandler
get /health returns (CommonResp)
// 认证模块
@handler RegisterHandler
post /auth/register (RegisterReq) returns (LoginResp)
@handler LoginHandler
post /auth/login (LoginReq) returns (LoginResp)
@handler RefreshTokenHandler
post /auth/refresh (RefreshTokenReq) returns (LoginResp)
@handler SendCodeHandler
post /auth/send-code (SendCodeReq) returns (CommonResp)
// 产品模块(公开)
@handler GetProductListHandler
get /products (ProductListReq) returns (ProductListResp)
@handler GetProductHandler
get /products/:id (IdPathReq) returns (Product)
@handler GetProductsByCategoryHandler
get /products/category (ProductListReq) returns (ProductListResp)
@handler SearchProductsHandler
get /products/search (ProductSearchReq) returns (ProductListResp)
// 商城同步(需要API Key,在handler中验证)
@handler SyncPurchaseHandler
post /sync/purchase (SyncPurchaseReq) returns (CommonResp)
}
// 需要认证的路由
@server (
prefix: /api
jwt: Auth
)
service healthapi-api {
// 用户模块
@handler GetUserProfileHandler
get /user/profile returns (UserInfo)
@handler UpdateUserProfileHandler
put /user/profile (UpdateProfileReq) returns (UserInfo)
// 健康档案模块
@handler GetHealthProfileHandler
get /user/health-profile returns (FullHealthProfileResp)
@handler UpdateHealthProfileHandler
put /user/health-profile (UpdateHealthProfileReq) returns (HealthProfile)
@handler GetBasicProfileHandler
get /user/basic-profile returns (HealthProfile)
@handler GetLifestyleHandler
get /user/lifestyle returns (LifestyleInfo)
@handler UpdateLifestyleHandler
put /user/lifestyle (UpdateLifestyleReq) returns (LifestyleInfo)
@handler GetMedicalHistoryHandler
get /user/medical-history returns ([]MedicalHistory)
@handler DeleteMedicalHistoryHandler
delete /user/medical-history/:id (IdPathReq) returns (CommonResp)
@handler GetFamilyHistoryHandler
get /user/family-history returns ([]FamilyHistory)
@handler DeleteFamilyHistoryHandler
delete /user/family-history/:id (IdPathReq) returns (CommonResp)
@handler GetAllergyRecordsHandler
get /user/allergy-records returns ([]AllergyRecord)
@handler DeleteAllergyRecordHandler
delete /user/allergy-records/:id (IdPathReq) returns (CommonResp)
@handler GetPurchaseHistoryHandler
get /user/purchase-history (PageReq) returns (PurchaseHistoryResp)
// 健康调查模块
@handler GetSurveyStatusHandler
get /survey/status returns (SurveyStatusResp)
@handler SubmitBasicInfoHandler
post /survey/basic-info (SubmitBasicInfoReq) returns (CommonResp)
@handler SubmitLifestyleHandler
post /survey/lifestyle (SubmitLifestyleReq) returns (CommonResp)
@handler SubmitMedicalHistoryHandler
post /survey/medical-history (SubmitMedicalHistoryReq) returns (CommonResp)
@handler BatchSubmitMedicalHistoryHandler
post /survey/medical-history/batch (BatchMedicalHistoryReq) returns (CommonResp)
@handler SubmitFamilyHistoryHandler
post /survey/family-history (SubmitFamilyHistoryReq) returns (CommonResp)
@handler BatchSubmitFamilyHistoryHandler
post /survey/family-history/batch (BatchFamilyHistoryReq) returns (CommonResp)
@handler SubmitAllergyHandler
post /survey/allergy (SubmitAllergyReq) returns (CommonResp)
@handler BatchSubmitAllergyHandler
post /survey/allergy/batch (BatchAllergyReq) returns (CommonResp)
@handler CompleteSurveyHandler
post /survey/complete returns (CommonResp)
// 体质辨识模块
@handler GetQuestionsHandler
get /constitution/questions returns (QuestionsResp)
@handler GetGroupedQuestionsHandler
get /constitution/questions/grouped returns (GroupedQuestionsResp)
@handler SubmitAssessmentHandler
post /constitution/submit (SubmitAssessmentReq) returns (AssessmentResult)
@handler GetAssessmentResultHandler
get /constitution/result returns (AssessmentResult)
@handler GetAssessmentHistoryHandler
get /constitution/history returns (AssessmentHistoryResp)
@handler GetRecommendationsHandler
get /constitution/recommendations returns (RecommendationsResp)
// AI对话模块
@handler GetConversationsHandler
get /conversations returns (ConversationListResp)
@handler CreateConversationHandler
post /conversations (CreateConversationReq) returns (ConversationItem)
@handler GetConversationHandler
get /conversations/:id (ConversationIdReq) returns (ConversationDetailResp)
@handler DeleteConversationHandler
delete /conversations/:id (ConversationIdReq) returns (CommonResp)
@handler SendMessageHandler
post /conversations/:id/messages (SendMessageReq) returns (MessageResp)
// 流式消息需要特殊处理,在handler中实现SSE
@handler SendMessageStreamHandler
post /conversations/:id/messages/stream (SendMessageReq)
// 产品推荐(需要认证,基于用户体质)
@handler GetRecommendProductsHandler
get /products/recommend returns (RecommendProductsResp)
}
// ==================== 会员系统模块 ====================
type (
// 会员信息
MemberInfo {
Level string `json:"level"` // normal/silver/gold/diamond
LevelName string `json:"level_name"` // 等级名称
TotalSpent float64 `json:"total_spent"` // 累计消费
Points int `json:"points"` // 当前积分
MemberSince string `json:"member_since"` // 首次消费时间
NextLevel string `json:"next_level"` // 下一等级
NextLevelSpent float64 `json:"next_level_spent"` // 升级还需消费
Discount float64 `json:"discount"` // 当前折扣
PointsMultiplier float64 `json:"points_multiplier"` // 积分倍率
FreeShippingMin float64 `json:"free_shipping_min"` // 包邮门槛
}
// 积分记录
PointsRecord {
ID uint `json:"id"`
Type string `json:"type"` // earn/spend/expire/adjust
Points int `json:"points"` // 变动积分
Balance int `json:"balance"` // 变动后余额
Source string `json:"source"` // order/activity/system
Remark string `json:"remark"`
CreatedAt string `json:"created_at"`
}
// 积分记录列表响应
PointsRecordsResp {
Records []PointsRecord `json:"records"`
PageInfo PageInfo `json:"page_info"`
}
// 积分兑换请求(积分抵扣现金)
UsePointsReq {
Points int `json:"points"` // 使用积分数
OrderNo string `json:"order_no,optional"` // 关联订单
}
)
// ==================== 商城商品模块 ====================
type (
// 商品分类
ProductCategory {
ID uint `json:"id"`
Name string `json:"name"`
ParentID uint `json:"parent_id"`
Icon string `json:"icon"`
Description string `json:"description"`
Sort int `json:"sort"`
}
// 分类列表响应
CategoryListResp {
Categories []ProductCategory `json:"categories"`
}
// 商品SKU
ProductSku {
ID uint `json:"id"`
ProductID uint `json:"product_id"`
SkuCode string `json:"sku_code"`
Name string `json:"name"`
Attributes string `json:"attributes"`
Price float64 `json:"price"`
Stock int `json:"stock"`
Image string `json:"image"`
}
// 商品详情(包含SKU)
ProductDetail {
ID uint `json:"id"`
CategoryID uint `json:"category_id"`
Name string `json:"name"`
Description string `json:"description"`
MainImage string `json:"main_image"`
Images []string `json:"images"`
Price float64 `json:"price"`
OriginalPrice float64 `json:"original_price"`
Stock int `json:"stock"`
SalesCount int `json:"sales_count"`
IsFeatured bool `json:"is_featured"`
ConstitutionTypes []string `json:"constitution_types"`
HealthTags []string `json:"health_tags"`
Efficacy string `json:"efficacy"`
Ingredients string `json:"ingredients"`
Usage string `json:"usage"`
Contraindications string `json:"contraindications"`
Skus []ProductSku `json:"skus"`
}
)
// ==================== 购物车模块 ====================
type (
// 购物车项
CartItem {
ID uint `json:"id"`
ProductID uint `json:"product_id"`
SkuID uint `json:"sku_id"`
ProductName string `json:"product_name"`
SkuName string `json:"sku_name"`
Image string `json:"image"`
Price float64 `json:"price"`
Quantity int `json:"quantity"`
Selected bool `json:"selected"`
Stock int `json:"stock"` // 当前库存
}
// 购物车响应
CartResp {
Items []CartItem `json:"items"`
TotalCount int `json:"total_count"`
SelectedCount int `json:"selected_count"`
TotalAmount float64 `json:"total_amount"`
}
// 添加购物车请求
AddCartReq {
ProductID uint `json:"product_id"`
SkuID uint `json:"sku_id,optional"`
Quantity int `json:"quantity,default=1"`
}
// 更新购物车请求
UpdateCartReq {
Id uint `path:"id"`
Quantity int `json:"quantity,optional"`
Selected bool `json:"selected,optional"`
}
// 批量选择请求
BatchSelectCartReq {
Ids []uint `json:"ids"`
Selected bool `json:"selected"`
}
)
// ==================== 收货地址模块 ====================
type (
// 收货地址
Address {
ID uint `json:"id"`
ReceiverName string `json:"receiver_name"`
Phone string `json:"phone"`
Province string `json:"province"`
City string `json:"city"`
District string `json:"district"`
DetailAddr string `json:"detail_addr"`
PostalCode string `json:"postal_code"`
IsDefault bool `json:"is_default"`
Tag string `json:"tag"` // home/company/other
}
// 地址列表响应
AddressListResp {
Addresses []Address `json:"addresses"`
}
// 创建/更新地址请求
SaveAddressReq {
ReceiverName string `json:"receiver_name"`
Phone string `json:"phone"`
Province string `json:"province"`
City string `json:"city"`
District string `json:"district"`
DetailAddr string `json:"detail_addr"`
PostalCode string `json:"postal_code,optional"`
IsDefault bool `json:"is_default,optional"`
Tag string `json:"tag,optional"`
}
// 地址ID请求
AddressIdReq {
Id uint `path:"id"`
}
)
// ==================== 订单模块 ====================
type (
// 订单商品项
OrderItem {
ID uint `json:"id"`
ProductID uint `json:"product_id"`
SkuID uint `json:"sku_id"`
ProductName string `json:"product_name"`
SkuName string `json:"sku_name"`
Image string `json:"image"`
Price float64 `json:"price"`
Quantity int `json:"quantity"`
TotalAmount float64 `json:"total_amount"`
}
// 订单
Order {
ID uint `json:"id"`
OrderNo string `json:"order_no"`
Status string `json:"status"`
TotalAmount float64 `json:"total_amount"`
DiscountAmount float64 `json:"discount_amount"`
ShippingFee float64 `json:"shipping_fee"`
PayAmount float64 `json:"pay_amount"`
PointsUsed int `json:"points_used"`
PointsEarned int `json:"points_earned"`
PayMethod string `json:"pay_method"`
PayTime string `json:"pay_time"`
ShipTime string `json:"ship_time"`
ReceiveTime string `json:"receive_time"`
ReceiverName string `json:"receiver_name"`
ReceiverPhone string `json:"receiver_phone"`
ReceiverAddr string `json:"receiver_addr"`
ShippingCompany string `json:"shipping_company"`
TrackingNo string `json:"tracking_no"`
Remark string `json:"remark"`
CancelReason string `json:"cancel_reason"`
Items []OrderItem `json:"items"`
CreatedAt string `json:"created_at"`
}
// 订单列表响应
OrderListResp {
Orders []Order `json:"orders"`
PageInfo PageInfo `json:"page_info"`
}
// 订单列表请求
OrderListReq {
Page int `form:"page,default=1"`
PageSize int `form:"page_size,default=10"`
Status string `form:"status,optional"` // 筛选状态
}
// 创建订单请求
CreateOrderReq {
AddressID uint `json:"address_id"`
CartItemIDs []uint `json:"cart_item_ids"` // 购物车项ID
PointsUsed int `json:"points_used,optional"` // 使用积分
Remark string `json:"remark,optional"`
}
// 订单预览(结算页)
OrderPreview {
Items []CartItem `json:"items"`
TotalAmount float64 `json:"total_amount"`
DiscountAmount float64 `json:"discount_amount"`
ShippingFee float64 `json:"shipping_fee"`
PayAmount float64 `json:"pay_amount"`
MaxPointsUse int `json:"max_points_use"` // 最多可用积分
PointsDiscount float64 `json:"points_discount"` // 积分可抵扣金额
}
// 订单预览请求
OrderPreviewReq {
CartItemIDs []uint `json:"cart_item_ids"`
AddressID uint `json:"address_id,optional"`
}
// 订单ID请求
OrderIdReq {
Id uint `path:"id"`
}
// 支付订单请求
PayOrderReq {
Id uint `path:"id"`
PayMethod string `json:"pay_method"` // wechat/alipay
}
// 取消订单请求
CancelOrderReq {
Id uint `path:"id"`
Reason string `json:"reason,optional"`
}
)
// ==================== 商城公开路由 ====================
@server (
prefix: /api/mall
)
service healthapi-api {
// 商品分类
@handler GetCategoriesHandler
get /categories returns (CategoryListResp)
// 商品列表(支持分类筛选)
@handler GetMallProductsHandler
get /products (ProductListReq) returns (ProductListResp)
// 商品详情
@handler GetMallProductDetailHandler
get /products/:id (IdPathReq) returns (ProductDetail)
// 搜索商品
@handler SearchMallProductsHandler
get /products/search (ProductSearchReq) returns (ProductListResp)
// 推荐/热门商品
@handler GetFeaturedProductsHandler
get /products/featured (PageReq) returns (ProductListResp)
}
// ==================== 商城认证路由 ====================
@server (
prefix: /api/mall
jwt: Auth
)
service healthapi-api {
// ===== 会员 =====
@handler GetMemberInfoHandler
get /member/info returns (MemberInfo)
@handler GetPointsRecordsHandler
get /member/points/records (PageReq) returns (PointsRecordsResp)
// ===== 购物车 =====
@handler GetCartHandler
get /cart returns (CartResp)
@handler AddCartHandler
post /cart (AddCartReq) returns (CartItem)
@handler UpdateCartHandler
put /cart/:id (UpdateCartReq) returns (CartItem)
@handler DeleteCartHandler
delete /cart/:id (IdPathReq) returns (CommonResp)
@handler BatchSelectCartHandler
post /cart/batch-select (BatchSelectCartReq) returns (CommonResp)
@handler ClearCartHandler
delete /cart/clear returns (CommonResp)
// ===== 收货地址 =====
@handler GetAddressesHandler
get /addresses returns (AddressListResp)
@handler GetAddressHandler
get /addresses/:id (AddressIdReq) returns (Address)
@handler CreateAddressHandler
post /addresses (SaveAddressReq) returns (Address)
@handler UpdateAddressHandler
put /addresses/:id (AddressIdReq)
@handler DeleteAddressHandler
delete /addresses/:id (AddressIdReq) returns (CommonResp)
@handler SetDefaultAddressHandler
put /addresses/:id/default (AddressIdReq) returns (CommonResp)
// ===== 订单 =====
@handler GetOrdersHandler
get /orders (OrderListReq) returns (OrderListResp)
@handler GetOrderHandler
get /orders/:id (OrderIdReq) returns (Order)
@handler PreviewOrderHandler
post /orders/preview (OrderPreviewReq) returns (OrderPreview)
@handler CreateOrderHandler
post /orders (CreateOrderReq) returns (Order)
@handler PayOrderHandler
post /orders/:id/pay (PayOrderReq) returns (CommonResp)
@handler CancelOrderHandler
post /orders/:id/cancel (CancelOrderReq) returns (CommonResp)
@handler ConfirmReceiveHandler
post /orders/:id/receive (OrderIdReq) returns (CommonResp)
// ===== 基于体质的商品推荐 =====
@handler GetConstitutionProductsHandler
get /products/constitution-recommend returns (RecommendProductsResp)
}