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.
 
 
 
 
 
 

48 lines
1.1 KiB

package logic
import (
"context"
"time"
"healthapi/internal/model"
"healthapi/internal/svc"
"healthapi/internal/types"
"healthapi/pkg/errorx"
"github.com/zeromicro/go-zero/core/logx"
)
type SyncPurchaseLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSyncPurchaseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SyncPurchaseLogic {
return &SyncPurchaseLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SyncPurchaseLogic) SyncPurchase(req *types.SyncPurchaseReq) (resp *types.CommonResp, err error) {
// TODO: 验证 API Key(从 Header 获取)
purchasedAt, _ := time.Parse("2006-01-02 15:04:05", req.PurchasedAt)
history := model.PurchaseHistory{
UserID: req.UserID,
OrderNo: req.OrderNo,
ProductID: req.ProductID,
ProductName: req.ProductName,
PurchasedAt: purchasedAt,
Source: req.Source,
}
if err := l.svcCtx.DB.Create(&history).Error; err != nil {
return nil, errorx.ErrServerError
}
return &types.CommonResp{Code: 0, Message: "同步成功"}, nil
}