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").
|
|
|
|
Where("a.status = ?", 1).Find(&productList)
|
|
|
|
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
|
|
|
|
}
|