YouChuKoffee/app/services/ProductService.go

43 lines
1.1 KiB
Go

package services
import (
"qteam/app/constants/errorcode"
"qteam/app/http/entities/front"
"qteam/app/models/productsmodel"
"xorm.io/builder"
)
func MilkProductList() (code int, productList []productsmodel.MilkProductsList) {
err := productsmodel.GetInstance().GetDb().Alias("a").
Join("INNER", "brand b", "a.brand_id = b.id").
Where("a.status = ?", 1).Find(&productList)
return handErr(err), productList
}
func ProductDetail(request front.ProductDetailRequest) (code int, product productsmodel.Products) {
repo := productsmodel.GetInstance().GetDb()
conn := builder.NewCond()
if request.ProductId != 0 {
conn = conn.And(builder.Eq{"id": request.ProductId})
}
has, err := repo.Where(conn).Get(&product)
if !has {
return errorcode.NotFound, product
}
return handErr(err), product
}
func GetProductImage(ProductId int) (main_image string) {
repo := productsmodel.GetInstance().GetDb()
conn := builder.NewCond()
product := productsmodel.Products{}
if ProductId != 0 {
conn = conn.And(builder.Eq{"id": ProductId})
}
has, _ := repo.Where(conn).Get(&product)
if !has {
return main_image
}
return product.MainImage
}