|
@@ -2,17 +2,24 @@ package product
|
|
|
|
|
|
import (
|
|
|
"eta/eta_mini_ht_api/common/exception"
|
|
|
+ "eta/eta_mini_ht_api/common/utils/page"
|
|
|
"eta/eta_mini_ht_api/controllers"
|
|
|
productService "eta/eta_mini_ht_api/service/product"
|
|
|
"fmt"
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
- productMap = map[string]int{}
|
|
|
+ productMap = map[string]bool{
|
|
|
+ "audio": true,
|
|
|
+ "video": true,
|
|
|
+ "media": true,
|
|
|
+ "report": true,
|
|
|
+ "package": true,
|
|
|
+ }
|
|
|
)
|
|
|
|
|
|
type ProductController struct {
|
|
|
- controllers.BaseController
|
|
|
+ controllers.ListController
|
|
|
}
|
|
|
|
|
|
// GetProductInfo 获取商品信息
|
|
@@ -38,9 +45,9 @@ func (p *ProductController) GetProductInfo(productId int) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-// RelatePackage 获取商品信息
|
|
|
-// @Summary 获取商品信息
|
|
|
-// @Description 获取商品信息
|
|
|
+// RelatePackage 关联套餐搜索
|
|
|
+// @Summary 关联套餐搜索
|
|
|
+// @Description 关联套餐搜索
|
|
|
// @Success 200 {object} controllers.BaseResponse
|
|
|
// @router /relatePackage [get]
|
|
|
func (p *ProductController) RelatePackage(productId int) {
|
|
@@ -86,6 +93,11 @@ func (p *ProductController) RelatePackage(productId int) {
|
|
|
func (p *ProductController) ProductSearch(productType, key string) {
|
|
|
controllers.Wrap(&p.BaseController, func() (result *controllers.WrapData, err error) {
|
|
|
result = p.InitWrapData("搜索产品信息失败")
|
|
|
+ if !productMap[productType] {
|
|
|
+ p.FailedResult("搜索产品信息失败", result)
|
|
|
+ err = exception.New(exception.ProductTypeError)
|
|
|
+ return
|
|
|
+ }
|
|
|
//for i := 0; i < len(productMap); i++ {
|
|
|
// //if productType == productMap[i] {
|
|
|
// // productList, err := productService.ProductSearch(productType, key)
|
|
@@ -109,3 +121,43 @@ func (p *ProductController) ProductSearch(productType, key string) {
|
|
|
return
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+// ProductList 产品列表
|
|
|
+// @Summary 产品列表
|
|
|
+// @Description 产品列表
|
|
|
+// @Success 200 {object} controllers.BaseResponse
|
|
|
+// @router /ProductList [get]
|
|
|
+func (p *ProductController) ProductList(productType string) {
|
|
|
+ controllers.Wrap(&p.BaseController, func() (result *controllers.WrapData, err error) {
|
|
|
+ result = p.InitWrapData("分页查询产品列表失败")
|
|
|
+ if !productMap[productType] {
|
|
|
+ err = exception.New(exception.ProductTypeError)
|
|
|
+ p.FailedResult("分页查询产品列表失败", result)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ pageRes := page.Page{
|
|
|
+ Current: p.PageInfo.Current,
|
|
|
+ PageSize: p.PageInfo.PageSize,
|
|
|
+ }
|
|
|
+ pageRes.Total, pageRes.LatestId = productService.GetTotalPageCountByProductType(productType)
|
|
|
+ if p.PageInfo.LatestId == 0 {
|
|
|
+ p.PageInfo.LatestId = pageRes.LatestId
|
|
|
+ p.PageInfo.Total = pageRes.Total
|
|
|
+ } else {
|
|
|
+ pageRes.LatestId = p.PageInfo.LatestId
|
|
|
+ pageRes.Total = p.PageInfo.Total
|
|
|
+ }
|
|
|
+ pageRes.TotalPage = page.TotalPages(pageRes.Total, pageRes.PageSize)
|
|
|
+ list, err := productService.ProductList(productType, p.PageInfo)
|
|
|
+ if err != nil {
|
|
|
+ p.FailedResult("分页查询产品列表失败", result)
|
|
|
+ err = exception.NewWithException(exception.GetProductListInfoFailed, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ productList := new(page.PageResult)
|
|
|
+ productList.Data = list
|
|
|
+ productList.Page = pageRes
|
|
|
+ p.SuccessResult("分页查询产品列表成功", productList, result)
|
|
|
+ return
|
|
|
+ })
|
|
|
+}
|