@ -66,8 +66,22 @@ type allPrice struct {
DiscountPrice decimal . Decimal ` gorm:"column:discount_price" json:"discountPrice" `
Commission decimal . Decimal ` gorm:"column:commission" json:"commission" `
PurchasePrice decimal . Decimal ` gorm:"column:purchase_price" json:"purchasePrice" `
Min uint ` gorm:"column:min_num" json:"min" `
Limit uint ` gorm:"column:limit_num" json:"limit" `
Min uint ` gorm:"column:min" json:"min" `
Limit uint ` gorm:"column:limit" json:"limit" `
SalePrice decimal . Decimal ` gorm:"column:sale_price" json:"sale_price" `
}
func ( o allPrice ) GetSalePrice ( level int ) decimal . Decimal {
switch level {
case 2 :
s1 := o . PurchasePrice . Mul ( decimal . NewFromFloat ( 1.03 ) ) . Round ( 2 )
s1 = s1 . Add ( o . DiscountPrice . Sub ( o . PurchasePrice ) . Mul ( decimal . NewFromFloat ( 0.2 ) ) . Round ( 2 ) )
return s1 . Round ( 2 )
case 10 :
return o . PurchasePrice . Mul ( decimal . NewFromFloat ( 1.03 ) ) . Round ( 2 )
default :
return decimal . Zero
}
}
type recommend struct {
@ -313,31 +327,33 @@ func QueryGoodsDetailNew(c *gin.Context) {
selectMinPriceStr := "MIN(original_price) AS original_price, " +
"MIN(discount_price) AS discount_price, " +
"MIN(commission) AS commission, " +
"MIN(purchase_price) AS purchase_price " +
"MIN(min_num) AS min " +
"MIN(purchase_price) AS purchase_price , " +
"MIN(min_num) AS min , " +
"MIN(limit_num) AS limit "
dbc . DB . Table ( ( & goods . Sku { } ) . TableName ( ) ) . Select ( selectMinPriceStr ) . First ( & minAllPrice , "goods_id = ?" , p . GoodsID )
minAllPrice . SalePrice = minAllPrice . GetSalePrice ( u1 . Level )
var maxAllPrice allPrice
selectMaxPriceStr := "MAX(original_price) AS original_price, " +
"MAX(discount_price) AS discount_price, " +
"MAX(commission) AS commission, " +
"MAX(purchase_price) AS purchase_price " +
"MAX(min_num) AS min " +
"MAX(purchase_price) AS purchase_price , " +
"MAX(min_num) AS min , " +
"MAX(limit_num) AS limit "
dbc . DB . Table ( ( & goods . Sku { } ) . TableName ( ) ) . Select ( selectMaxPriceStr ) . First ( & maxAllPrice , "goods_id = ?" , p . GoodsID )
maxAllPrice . SalePrice = maxAllPrice . GetSalePrice ( u1 . Level )
minCost := minAllPrice . PurchasePrice . Mul ( decimal . NewFromFloat ( 1.03 ) )
min b ase := minAllPrice . DiscountPrice . Sub ( minCost ) . Mul ( decimal . NewFromFloat ( define . Coefficient ) ) . Round ( 2 )
minCommission1 := min b ase. Mul ( rate1 ) . Round ( 2 )
minCommission2 := min b ase. Mul ( rate2 ) . Round ( 2 )
minCommission3 := min b ase. Mul ( rate3 ) . Round ( 2 )
min B ase := minAllPrice . DiscountPrice . Sub ( minCost ) . Mul ( decimal . NewFromFloat ( define . Coefficient ) ) . Round ( 2 )
minCommission1 := min B ase. Mul ( rate1 ) . Round ( 2 )
minCommission2 := min B ase. Mul ( rate2 ) . Round ( 2 )
minCommission3 := min B ase. Mul ( rate3 ) . Round ( 2 )
max b ase := maxAllPrice . DiscountPrice . Sub ( minCost ) . Mul ( decimal . NewFromFloat ( define . Coefficient ) ) . Round ( 2 )
maxCommission1 := max b ase. Mul ( rate1 ) . Round ( 2 )
maxCommission2 := max b ase. Mul ( rate2 ) . Round ( 2 )
maxCommission3 := max b ase. Mul ( rate3 ) . Round ( 2 )
max B ase := maxAllPrice . DiscountPrice . Sub ( minCost ) . Mul ( decimal . NewFromFloat ( define . Coefficient ) ) . Round ( 2 )
maxCommission1 := max B ase. Mul ( rate1 ) . Round ( 2 )
maxCommission2 := max B ase. Mul ( rate2 ) . Round ( 2 )
maxCommission3 := max B ase. Mul ( rate3 ) . Round ( 2 )
summary . Price = priceBorderSub {
priceSub {
@ -374,6 +390,7 @@ func QueryGoodsDetailNew(c *gin.Context) {
sc2 := skb . Mul ( rate2 ) . Round ( 2 )
sc3 := skb . Mul ( rate3 ) . Round ( 2 )
summary . Sku [ index ] . Commission = sc1 . Add ( sc2 ) . Add ( sc3 )
summary . Sku [ index ] . SalePrice = v . GetSalePrice ( u1 . Level )
}
now := time . Now ( )
var promotionGoods promotion . Goods
@ -392,27 +409,13 @@ func QueryGoodsDetailNew(c *gin.Context) {
dbc . DB . Model ( & goods . Information { } ) . Where ( "brand_id = ?" , summary . BrandID ) . Where ( "publish_status = ?" , 1 ) . Count ( & brandGoodsCount )
summary . Brand . GoodsCount = brandGoodsCount
//var country goods2.RecookAbroadCountryModel
//dbc.DB.Table(country.TableName()).First(&country, "id = ?", summary.Country)
//summary.CountryIcon = country.Icon
//var vo live
//dbc.DB.Table("recook_live_live_item").Where("main_goods_id=?", summary.ID).Select("status,id as item_id").Order("id desc").First(&vo)
//summary.Live = live{
// Status: vo.Status,
// RoomId: vo.RoomId,
//}
//dbc.DB.Table((&goods.Evaluation{}).TableName()).Where("goods_id = ? and pass=?", p.GoodsID, 1).Count(&(summary.Evaluations.Total))
//dbc.DB.Table((&goods.Evaluation{}).TableName()).Limit(5).Find(&(summary.Evaluations.Children), "goods_id = ? and pass=?", p.GoodsID, 1)
dbc . DB . Table ( ( & goods . Evaluation { } ) . TableName ( ) ) . Where ( "goods_id = ? and pass=?" , p . GoodsID , 1 ) . Count ( & ( summary . Evaluations . Total ) )
dbc . DB . Table ( ( & goods . Evaluation { } ) . TableName ( ) ) . Limit ( 5 ) . Find ( & ( summary . Evaluations . Children ) , "goods_id = ? and pass=?" , p . GoodsID , 1 )
dbc . DB . Table ( ( & goods . Attribute { } ) . TableName ( ) ) . Select ( "name" ) . Group ( "name" ) . Find ( & ( summary . Attributes ) , "goods_id = ?" , p . GoodsID )
for i , v := range summary . Attributes {
dbc . DB . Table ( ( & goods . Attribute { } ) . TableName ( ) ) . Select ( "id, value" ) . Find ( & ( summary . Attributes [ i ] . Children ) , "goods_id = ? AND name = ?" , p . GoodsID , v . Name )
}
// 找优惠券
//dbc.DB.Table((&coupon.Information{}).TableName()).Limit(2).Order("id desc").Find(&(summary.Coupons), "((scope = ?) OR (scope = ? AND brand_id = ?)) AND end_time > ?", define.CouponScopeUniversal, define.CouponScopeBrand, summary.BrandID, now)
if p . UserID > 0 {
var f goods . Favorites
dbc . DB . First ( & f , "user_id = ? AND goods_id = ?" , p . UserID , p . GoodsID )
@ -432,11 +435,11 @@ func QueryGoodsDetailNew(c *gin.Context) {
recookGoodsNoticeModel := & goods2 . RecookGoodsNoticeModel { }
noticeInfo := recookGoodsNoticeModel . FindById ( noticeGoods . NoticeId )
now := time . Now ( ) . Unix ( )
var img s [ ] string
dbc . DB . Table ( ( & goods2 . RecookGoodsNoticeImageModel { } ) . TableName ( ) ) . Where ( "noticeId=?" , noticeInfo . Id ) . Pluck ( "image" , & img s)
var img Li st [ ] string
dbc . DB . Table ( ( & goods2 . RecookGoodsNoticeImageModel { } ) . TableName ( ) ) . Where ( "noticeId=?" , noticeInfo . Id ) . Pluck ( "image" , & img Li st )
if noticeInfo . Id > 0 && now > noticeInfo . StartTime . Time . Unix ( ) && now < noticeInfo . EndTime . Time . Unix ( ) {
summary . Notice . Title = noticeInfo . Title
summary . Notice . Img = img s
summary . Notice . Img = img Li st
summary . Notice . Type = noticeInfo . Type
}
}