YouChuKoffee/app/services/ProductService.go

43 lines
1.1 KiB
Go
Raw Normal View History

2024-06-17 16:29:39 +08:00
package services
2024-06-24 11:44:38 +08:00
import (
"qteam/app/constants/errorcode"
"qteam/app/http/entities/front"
"qteam/app/models/productsmodel"
"xorm.io/builder"
)
2024-06-17 16:29:39 +08:00
func MilkProductList() (code int, productList []productsmodel.MilkProductsList) {
err := productsmodel.GetInstance().GetDb().Alias("a").
Join("INNER", "brand b", "a.brand_id = b.id").
2024-07-10 17:13:36 +08:00
Where("a.status = ?", 1).OrderBy("brand_id asc").Find(&productList)
2024-06-17 16:29:39 +08:00
return handErr(err), productList
}
2024-06-24 11:44:38 +08:00
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
}
2024-06-27 18:36:01 +08:00
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
}