1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package merchant
- import (
- "errors"
- logger "eta/eta_mini_ht_api/common/component/log"
- merchantDao "eta/eta_mini_ht_api/models/merchant"
- "github.com/shopspring/decimal"
- "gorm.io/gorm"
- )
- var (
- typeTransfer = map[merchantDao.MerchantProductType]string{
- merchantDao.Report: "单篇报告",
- merchantDao.Video: "单个视频",
- merchantDao.Audio: "单个音频",
- merchantDao.Package: "套餐",
- }
- )
- type MerchantProductDTO struct {
- Id int
- Title string
- CoverSrc string
- Description string
- Price decimal.Decimal
- ProductTile string
- RiskLevel string
- Type string
- TypeCN string
- IsPermanent bool
- ValidDays int
- SaleStatus string
- SourceId int
- }
- func GetMerchantProductById(id int) (productDTO MerchantProductDTO, err error) {
- product, err := merchantDao.GetMerchantProductById(id)
- if err != nil {
- if errors.Is(err, gorm.ErrRecordNotFound) {
- logger.Error("商品信息不存在[productId:%d]", id)
- } else {
- logger.Error("获取商品信息失败[productId:%d],err:", id, err)
- }
- }
- productDTO = convertToDTO(product)
- return
- }
- func convertToDTO(product merchantDao.MerchantProduct) MerchantProductDTO {
- return MerchantProductDTO{
- Id: product.ID,
- Title: product.Title,
- CoverSrc: product.CoverSrc,
- Description: product.Description,
- ProductTile: product.Title,
- Price: product.Price,
- RiskLevel: "",
- Type: string(product.Type),
- TypeCN: typeTransfer[product.Type],
- IsPermanent: product.IsPermanent,
- ValidDays: product.ValidDays,
- SourceId: product.SourceID,
- }
- }
- func GetProductBySourceId(id int, productType merchantDao.MerchantProductType) (product MerchantProductDTO, err error) {
- productDao, err := merchantDao.GetMerchantProductBySourceId(id, productType)
- if err != nil {
- if errors.Is(err, gorm.ErrRecordNotFound) {
- logger.Error("商品信息不存在[sourceId:%d,type:%v]", id, productType)
- } else {
- logger.Error("获取商品信息失败[sourceId:%d,type:%v],err:%v", id, productType, err)
- }
- return
- }
- product = convertToDTO(productDao)
- return
- }
|