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.
72 lines
1.8 KiB
72 lines
1.8 KiB
package order
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/jinzhu/gorm"
|
|
"github.com/shopspring/decimal"
|
|
"recook/internal/dbc"
|
|
"recook/internal/v2/model/recook/goods"
|
|
)
|
|
|
|
var SLogic = &scanner{}
|
|
|
|
type scanner struct {
|
|
}
|
|
|
|
type UploadReq struct {
|
|
SkuCode string `json:"skuCode"`
|
|
}
|
|
|
|
type ScanResp struct {
|
|
GoodsID uint `json:"goodsID"`
|
|
SkuID uint `json:"skuID"`
|
|
SkuCode string `json:"skuCode"`
|
|
SkuName string `json:"skuName"`
|
|
BrandName string `json:"brandName"`
|
|
BrandImg string `json:"brandImg"`
|
|
GoodsName string `json:"goodsName"`
|
|
GoodsImg string `json:"goodsImg"`
|
|
Discount decimal.Decimal `json:"discount"`
|
|
Commission decimal.Decimal `json:"commission"`
|
|
Inventory uint `json:"inventory"`
|
|
}
|
|
|
|
func (s *scanner) Scan(req *UploadReq) (*ScanResp, error) {
|
|
var m goods.RecookGoodsSkuModel
|
|
if err := dbc.DB.Table(m.TableName()).First(&m, "code = ?", req.SkuCode).Error; err != nil {
|
|
if err == gorm.ErrRecordNotFound {
|
|
return nil, errors.New("商品编码未找到商品")
|
|
}
|
|
return nil, err
|
|
}
|
|
|
|
var g goods.RecookGoodsInfoModel
|
|
if err := dbc.DB.Table(g.TableName()).First(&g, "id = ?", m.GoodsId).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var photo goods.RecookGoodsMainPhotoModel
|
|
if err := dbc.DB.Table(photo.TableName()).First(&photo, "goods_id = ?", g.Id).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var b goods.RecookGoodsBrandModel
|
|
if err := dbc.DB.Table(b.TableName()).First(&b, "id = ?", g.BrandID).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
result := &ScanResp{
|
|
GoodsID: m.GoodsId,
|
|
SkuID: m.Id,
|
|
SkuCode: m.Code,
|
|
SkuName: m.Name,
|
|
BrandName: b.Name,
|
|
BrandImg: b.LogoUrl,
|
|
GoodsName: g.GoodsName,
|
|
GoodsImg: photo.Url,
|
|
Discount: m.DiscountPrice,
|
|
Commission: m.Commission,
|
|
Inventory: m.Inventory,
|
|
}
|
|
return result, nil
|
|
}
|