XinYeYouKu/app/services/ActivityService.go

39 lines
1.1 KiB
Go
Raw Normal View History

2024-06-12 19:11:00 +08:00
package services
import (
"github.com/ahmetb/go-linq/v3"
"qteam/app/constants/common"
"qteam/app/constants/errorcode"
"qteam/app/http/entities/front"
"qteam/app/models/activitymodel"
"qteam/app/models/productmodel"
"strings"
)
func ActivityDetailService(id int) (code int, data front.ActivityResponse) {
var err error
var activity activitymodel.Activity
code = errorcode.NotFound
2024-06-13 14:30:06 +08:00
has, err := activitymodel.GetInstance().GetDb().Where("id=?", id).Get(&activity)
2024-06-12 19:11:00 +08:00
if has {
2024-06-13 14:30:06 +08:00
data.ResponseFromDb(activity)
2024-06-12 19:11:00 +08:00
product := []productmodel.Product{}
productIds := strings.Split(activity.ProductIds, ",")
if count, err := productmodel.GetInstance().GetDb().Where("status = ?", common.STATUSABLED).In("id", productIds).FindAndCount(&product); err == nil {
code = handErr(err)
if count > 0 {
linq.From(product).SelectT(func(in productmodel.Product) (d front.ProductResponse) {
d.ResponseFromDb(in)
return
}).ToSlice(&data.Product)
}
} else {
data.Product = make([]front.ProductResponse, 0)
}
}
if err != nil {
code = handErr(err)
}
return errorcode.Success, data
}