Преглед изворни кода

报告增加产品信息筛选

kobe6258 пре 4 месеци
родитељ
комит
251a0681b3
3 измењених фајлова са 36 додато и 18 уклоњено
  1. 2 0
      domian/report/report_service.go
  2. 3 3
      models/merchant/merchant_product.go
  3. 31 15
      service/report/report_service.go

+ 2 - 0
domian/report/report_service.go

@@ -82,6 +82,8 @@ type ReportDTO struct {
 	IsFree           bool            `json:"isFree"`
 	IsSubscribe      bool            `json:"isSubscribe"`
 	Price            string          `json:"price"`
+	ProductId        int             `json:"productId"`
+	IsPackage        bool            `json:"isPackage"`
 }
 
 type Detail struct {

+ 3 - 3
models/merchant/merchant_product.go

@@ -84,13 +84,13 @@ func GetProductListBySourceIds(ids []int, productType ...MerchantProductType) (p
 	}
 	if len(productType) > 0 {
 		if len(productType) == 1 {
-			err = db.Select(sourceIdColumn).Where("source_id in ? and type = ? and deleted =? ", ids, productType[0], false).Find(&productList).Error
+			err = db.Select(sourceIdColumn).Where("source_id in ? and type = ? and deleted =? order by created_time desc", ids, productType[0], false).Find(&productList).Error
 		} else {
-			err = db.Select(sourceIdColumn).Where("source_id in ? and type in (?) and deleted =? ", ids, productType, false).Find(&productList).Error
+			err = db.Select(sourceIdColumn).Where("source_id in ? and type in (?) and deleted =? by created_time desc", ids, productType, false).Find(&productList).Error
 		}
 
 	} else {
-		err = db.Select(sourceIdColumn).Where("source_id in ?  and deleted =? ", ids, productType, false).Find(&productList).Error
+		err = db.Select(sourceIdColumn).Where("source_id in ?  and deleted =? by created_time desc", ids, productType, false).Find(&productList).Error
 	}
 
 	return

+ 31 - 15
service/report/report_service.go

@@ -305,21 +305,48 @@ func dealReportInfo(list []reportService.ReportDTO, isLogin bool, userId int) (r
 			} else {
 				report.CoverUrl = src
 			}
-			//查询产品信息
+			//查询产品信息
 			product, pdErr := productService.GetProductBySourceId(report.ReportID, productDao.Report)
 			if pdErr != nil {
 				if errors.Is(pdErr, gorm.ErrRecordNotFound) {
-					report.Price = defaultProductPrice
-					report.IsFree = true
-					report.IsSubscribe = false
+					permissions = reportService.GetReportSecondPermissionsById(report.OrgId, report.Source)
+					var permissionIds []int
+					if len(permissions) > 0 {
+						for _, permission := range permissions {
+							permissionIds = append(permissionIds, permission.PermissionId)
+						}
+						//单品不存在的话查套餐
+						productList, prodErr := productService.GetProductListBySourceIds(permissionIds, "package")
+						if prodErr != nil || len(productList) == 0 {
+							logger.Error("获取套餐列表失败:%v", pdErr)
+							report.Price = defaultProductPrice
+							report.IsFree = true
+							report.IsSubscribe = false
+							report.IsPackage = false
+						} else {
+							report.Price = defaultProductPrice
+							report.IsFree = true
+							report.IsSubscribe = false
+							report.IsPackage = true
+							report.ProductId = productList[0].Id
+						}
+					} else {
+						report.Price = defaultProductPrice
+						report.IsFree = true
+						report.IsSubscribe = false
+						report.IsPackage = false
+					}
 				} else {
 					report.Price = defaultProductPrice
 					report.IsFree = false
 					report.IsSubscribe = false
+					report.IsPackage = false
 				}
 			} else {
 				report.Price = product.Price.String()
 				report.IsFree = false
+				report.ProductId = product.Id
+				report.IsPackage = false
 				if isLogin {
 					subscribe, subscribeErr := userService.GetUserSubscribe(product.Id, userId)
 					if subscribeErr != nil {
@@ -328,17 +355,6 @@ func dealReportInfo(list []reportService.ReportDTO, isLogin bool, userId int) (r
 						report.IsSubscribe = subscribe.Status == productDao.SubscribeValid
 					}
 				}
-				pdRiskNum, parseErr := config.ParseRiskLevel(product.RiskLevel)
-				if parseErr != nil {
-					return
-				}
-				rpRiskNum, parseErr := config.ParseRiskLevel(report.RiskLevel)
-				if parseErr != nil {
-					return
-				}
-				if rpRiskNum <= pdRiskNum {
-					report.RiskLevel = product.RiskLevel
-				}
 			}
 		}(&list[i])
 	}