Browse Source

产品列表

kobe6258 4 tháng trước cách đây
mục cha
commit
a708ed0a9c

+ 3 - 6
controllers/product/product_controller.go

@@ -153,12 +153,8 @@ func (p *ProductController) ProductList(productType string, permissionIds string
 			Current:  p.PageInfo.Current,
 			PageSize: p.PageInfo.PageSize,
 		}
-		list, err := productService.GetProductListByProductType(productType, permissionIdList, userInfo.Id)
-		if err != nil {
-			p.FailedResult("分页查询产品列表失败", result)
-			err = exception.NewWithException(exception.GetProductListFailed, err.Error())
-			return
-		}
+		var productIds []int
+		pageRes.Total, pageRes.LatestId, productIds = productService.GetProductListByProductType(productType, permissionIdList, userInfo.Id)
 		if p.PageInfo.LatestId == 0 {
 			p.PageInfo.LatestId = pageRes.LatestId
 			p.PageInfo.Total = pageRes.Total
@@ -167,6 +163,7 @@ func (p *ProductController) ProductList(productType string, permissionIds string
 			pageRes.Total = p.PageInfo.Total
 		}
 		pageRes.TotalPage = page.TotalPages(pageRes.Total, pageRes.PageSize)
+		list, err := productService.ProductList(productIds, userInfo.Id, p.PageInfo)
 		productList := new(page.PageResult)
 		productList.Data = list
 		productList.Page = pageRes

+ 3 - 3
domian/merchant/merchant_product.go

@@ -110,11 +110,11 @@ func GetProductListByProductType(productType string) (list []MerchantProductDTO,
 	return
 }
 
-func GetProductPageByProductType(productType string, info page.PageInfo) (dtoList []MerchantProductDTO, err error) {
+func GetProductPageByProductType(productIds []int, info page.PageInfo) (dtoList []MerchantProductDTO, err error) {
 	offset := page.StartIndex(info.Current, info.PageSize)
-	productList, err := merchantDao.GetProductPageByProductType(typeKindTransfer[productType], info.LatestId, offset, info.PageSize)
+	productList, err := merchantDao.GetProductPageByProductType(productIds, info.LatestId, offset, info.PageSize)
 	if err != nil {
-		logger.Error("获取商品列表失败[productType:%v,pageInfo:%v],err:%v", productType, info, err)
+		logger.Error("获取商品列表失败[productIds:%v,pageInfo:%v],err:%v", productIds, info, err)
 		return
 	}
 	for _, product := range productList {

+ 3 - 7
models/merchant/merchant_product.go

@@ -110,13 +110,9 @@ func GetTotalPageCountByProductType(productType MerchantProductType) (total int6
 	return
 }
 
-func GetProductPageByProductType(productType MerchantProductType, id int64, offset int, limit int) (list []MerchantProduct, err error) {
+func GetProductPageByProductType(productIds []int, id int64, offset int, limit int) (list []MerchantProduct, err error) {
 	db := models.Main()
-	if productType == "" {
-		err = errors.New("productType参数不能为空")
-		return
-	}
-	err = db.Select(detailColumns).Where("id <= ? and type = ? and deleted =? order by created_time desc limit ?,? ", id, productType, false, offset, limit).Find(&list).Error
+	err = db.Select(detailColumns).Where("id <= ?  and deleted =?  and id in ? order by created_time desc limit ?,? ", id, false, productIds, offset, limit).Find(&list).Error
 	return
 }
 
@@ -132,7 +128,7 @@ func GetProductListByProductType(productType MerchantProductType, detail bool) (
 		err = errors.New("productType参数不能为空")
 		return
 	}
-	err = db.Select(columns).Where("id <= ? and type = ? and deleted =? order by created_time desc", productType, false).Find(&list).Error
+	err = db.Select(columns).Where(" type = ? and deleted =? order by created_time desc", productType, false).Find(&list).Error
 	return
 }
 func CountProductList(isSignal bool) (total, latestId int64, ids []int) {

+ 1 - 0
routers/commentsRouter.go

@@ -139,6 +139,7 @@ func init() {
             AllowHTTPMethods: []string{"get"},
             MethodParams: param.Make(
 				param.New("productType"),
+				param.New("permissionIds"),
 			),
             Filters: nil,
             Params: nil})

+ 27 - 5
service/product/product_service.go

@@ -20,6 +20,7 @@ import (
 )
 
 type ProductDTO struct {
+	Id              int      `json:"-"`
 	Title           string   `json:"title"`
 	SourceTile      string   `json:"sourceTile"`
 	Abstract        string   `json:"abstract"`
@@ -35,6 +36,7 @@ type ProductDTO struct {
 	BeginDate       string   `json:"beginDate"`
 	EndDate         string   `json:"endDate"`
 	SourceId        int      `json:"sourceId"`
+	IsSubscribe     bool     `json:"isSubscribe"`
 	ReportId        int      `json:"reportId"`
 	MediaId         int      `json:"mediaId"`
 }
@@ -131,6 +133,7 @@ func convertToProductDTO(product merchantService.MerchantProductDTO) (productDTO
 	beginDate := time.Now()
 	endDate := beginDate.Add(time.Duration(product.ValidDays) * 24 * time.Hour)
 	productDTO = ProductDTO{
+		Id:          product.Id,
 		Title:       product.Title,
 		Description: product.Description,
 		Price:       product.Price.String(),
@@ -230,11 +233,12 @@ func GetRelatePackage(info ProductDTO) (prodList []ProductDTO, err error) {
 	}
 }
 
-func GetProductListByProductType(productType string, permissionIds []int, templateUserId int) (dtoList []ProductDTO, err error) {
+func GetProductListByProductType(productType string, permissionIds []int, templateUserId int) (total, latestId int64, productIds []int) {
 	filterPermissionIds, riskLevel, err := reportService.CheckUserRisk(permissionIds, true, templateUserId)
 	if err != nil {
 		return
 	}
+	var dtoList []*ProductDTO
 	productList, err := merchantService.GetProductListByProductType(productType)
 	var wg sync.WaitGroup
 	wg.Add(len(productList))
@@ -258,10 +262,19 @@ func GetProductListByProductType(productType string, permissionIds []int, templa
 			if !match {
 				return
 			}
-			dtoList = append(dtoList, product)
+			dtoList = append(dtoList, &product)
 		}(productList[i])
 	}
 	wg.Wait()
+	total = int64(len(dtoList))
+	var maxId int
+	for i := 0; i < len(dtoList); i++ {
+		productIds = append(productIds, dtoList[i].Id)
+		if dtoList[i].Id > maxId {
+			maxId = dtoList[i].Id
+		}
+	}
+	latestId = int64(maxId)
 	return
 }
 
@@ -274,19 +287,28 @@ func compare(riskLevel, MatchRiskLevel string) bool {
 	if riskErr != nil {
 		return false
 	}
-	if pRiskNum > riskLevelNum {
+	if pRiskNum <= riskLevelNum {
 		return true
 	}
 	return false
 }
-func ProductList(productType string, info page.PageInfo) (dtoList []ProductDTO, err error) {
+func ProductList(productIds []int, templateUserId int, info page.PageInfo) (dtoList []ProductDTO, err error) {
 	var merchantProductList []merchantService.MerchantProductDTO
-	merchantProductList, err = merchantService.GetProductPageByProductType(productType, info)
+	merchantProductList, err = merchantService.GetProductPageByProductType(productIds, info)
 	for _, product := range merchantProductList {
 		productDTO := convertToProductDTO(product)
 		productDTO.RiskLevel, productDTO.SourceTile, productDTO.Abstract, productDTO.CoverUrl, productDTO.Src, productDTO.PermissionNames, _, err = GetProductRiskLevel(product)
 		dtoList = append(dtoList, productDTO)
 	}
+	var wg sync.WaitGroup
+	wg.Add(len(dtoList))
+	for i := 0; i < len(dtoList); i++ {
+		go func(productDTO *ProductDTO) {
+			defer wg.Done()
+			//subscibe, err := user.GetUserSubscribe(productDTO.Id, templateUserId)
+			//if
+		}(&dtoList[i])
+	}
 	return
 }
 func RangeProductList(isSignal bool) (total, latestId int64, ids []int) {

+ 4 - 0
service/report/report_service.go

@@ -430,6 +430,8 @@ func GetRandedReportByWeeklyHot(limit int, isLogin bool, userId int, pdRiskLevel
 					filterList = append(filterList, report)
 				}
 			}
+		} else {
+			filterList = dtoList
 		}
 		reports = make([]HotRankedReport, len(ids))
 		for i := 0; i < len(filterList); i++ {
@@ -478,6 +480,8 @@ func GetRandedReportByPublishTimeWeekly(limit int, week bool, isLogin bool, user
 				filterList = append(filterList, report)
 			}
 		}
+	} else {
+		filterList = dtoList
 	}
 	reports = convertToPublishRankedReportList(filterList)
 	return