kobe6258 hace 4 meses
padre
commit
d0a9e4afa8

+ 7 - 4
common/exception/exc_enums.go

@@ -126,6 +126,8 @@ const (
 	IllegalProductOrderId
 
 	MerchantInfoNotConfig
+
+	GetProductListInfoFailed
 )
 const (
 	WebhookErrCode int = iota + 80000
@@ -238,10 +240,11 @@ var ErrorMap = map[int]string{
 	GetAnalystMediaListFailed: "查询研究员媒体列表失败",
 	BindMobileFailed:          "绑定手机号失败",
 	//商户
-	ProductInfoError:      "获取商品信息失败",
-	IllegalProductId:      "非法的产品ID",
-	IllegalProductOrderId: "非法的产品订单ID",
-	MerchantInfoNotConfig: "商户信息未配置",
+	ProductInfoError:         "获取商品信息失败",
+	IllegalProductId:         "非法的产品ID",
+	IllegalProductOrderId:    "非法的产品订单ID",
+	MerchantInfoNotConfig:    "商户信息未配置",
+	GetProductListInfoFailed: "获取产品列表失败",
 	//webhook
 	SyncRiskError:               "同步风险等级失败",
 	GetCapTokenFailed:           "获取cap token失败",

+ 3 - 3
controllers/order/order_controller.go

@@ -48,16 +48,16 @@ func (o *OrderController) PreviewProductOrder(productId int) {
 // @Description  获取订单详情
 // @Success 200 {object} controllers.BaseResponse
 // @router /orderDetail [get]
-func (sc *SubscribeController) GetOrderDetail(orderId int) {
+func (sc *SubscribeController) GetOrderDetail(orderNo string) {
 	controllers.Wrap(&sc.BaseController, func() (result *controllers.WrapData, err error) {
 		result = sc.InitWrapData("获取订单号失败")
 		userInfo := sc.Data["user"].(user.User)
-		if orderId <= 0 {
+		if orderNo == "" {
 			err = exception.New(exception.IllegalProductOrderId)
 			sc.FailedResult("获取订单详情失败,产品编号非法", result)
 			return
 		}
-		orderDetail, err := order.GetOrderDetail(orderId, userInfo.Id)
+		orderDetail, err := order.GetOrderDetail(orderNo, userInfo.Id)
 		if err != nil {
 			sc.FailedResult("获取订单详情失败", result)
 			err = exception.NewWithException(exception.GetOrderListFailed, err.Error())

+ 1 - 2
controllers/order/subscribe_controller.go

@@ -195,7 +195,6 @@ func (sc *SubscribeController) SubscribeList(productType string) {
 	controllers.Wrap(&sc.BaseController, func() (result *controllers.WrapData, err error) {
 		result = sc.InitWrapData("分页查询订阅列表失败")
 		userInfo := sc.Data["user"].(user.User)
-		result = sc.InitWrapData("分页查询订阅列表失败")
 		if productType == "" || !sc.CheckProductType(productType) {
 			err = exception.New(exception.ProductTypeError)
 			sc.FailedResult("分页查询订阅列表失败", result)
@@ -205,7 +204,7 @@ func (sc *SubscribeController) SubscribeList(productType string) {
 			Current:  sc.PageInfo.Current,
 			PageSize: sc.PageInfo.PageSize,
 		}
-		pageRes.Total, pageRes.LatestId = product.GetTotalPageCountByProductType(productType, userInfo.Id)
+		pageRes.Total, pageRes.LatestId = product.GetTotalUserPageCountByProductType(productType, userInfo.Id)
 		if err != nil {
 			logger.Error("分页查询订阅列表失败:%v", err)
 			sc.FailedResult("分页查询订阅列表失败", result)

+ 57 - 5
controllers/product/product_controller.go

@@ -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
+	})
+}

+ 19 - 0
domian/merchant/merchant_product.go

@@ -3,6 +3,7 @@ package merchant
 import (
 	"errors"
 	logger "eta/eta_mini_ht_api/common/component/log"
+	"eta/eta_mini_ht_api/common/utils/page"
 	merchantDao "eta/eta_mini_ht_api/models/merchant"
 	"github.com/shopspring/decimal"
 	"gorm.io/gorm"
@@ -99,3 +100,21 @@ func GetProductListBySourceIds(ids []int, productType string) (productDTOS []Mer
 	}
 	return
 }
+
+func GetTotalPageCountByProductType(productType string) (total int64, latestId int64) {
+	return merchantDao.GetTotalPageCountByProductType(typeKindTransfer[productType])
+}
+
+func GetProductListByProductType(productType string, info page.PageInfo) (dtoList []MerchantProductDTO, err error) {
+	offset := page.StartIndex(info.Current, info.PageSize)
+	productList, err := merchantDao.GetProductListByProductType(typeKindTransfer[productType], info.LatestId, offset, info.PageSize)
+	if err != nil {
+		logger.Error("获取商品列表失败[productType:%v,pageInfo:%v],err:%v", productType, info, err)
+		return
+	}
+	for _, product := range productList {
+		productDTO := convertToDTO(product)
+		dtoList = append(dtoList, productDTO)
+	}
+	return
+}

+ 2 - 2
domian/merchant/user_access_service.go

@@ -62,6 +62,6 @@ func SubscribeList(templateUserId int, productType string, pageInfo page.PageInf
 	return
 }
 
-func GetTotalPageCountByProductType(productType string, id int) (int64, int64) {
-	return merchant.GetTotalPageCountByProductType(productType, id)
+func GetTotalUserPageCountByProductType(productType string, id int) (int64, int64) {
+	return merchant.GetTotalUserPageCountByProductType(productType, id)
 }

+ 1 - 1
domian/order/product_order.go

@@ -190,7 +190,7 @@ func GetOrderPage(pageInfo page.PageInfo, userId int, orderStatus string) (order
 	return
 }
 
-func GetOrderDetail(orderId int, userId int) (orderDTO ProductOrderDetailDTO, err error) {
+func GetOrderDetail(orderId string, userId int) (orderDTO ProductOrderDetailDTO, err error) {
 	order, err := orderDao.GetOrderDetail(orderId, userId)
 	if err != nil {
 		logger.Error("查询订单详情失败:%v", err)

+ 0 - 20
models/merchant/merchant_package.go

@@ -1,20 +0,0 @@
-package merchant
-
-import (
-	"time"
-)
-
-// MerchantPackage 商户套餐信息结构体
-type MerchantPackage struct {
-	ID              int       `gorm:"column:id;primary_key;autoIncrement;comment:主键"`
-	ReportSourceIds string    `gorm:"column:report_source_ids;type:varchar(255);comment:报告来源"`
-	VideoSourceIds  string    `gorm:"column:video_source_ids;type:varchar(255);comment:视频来源"`
-	AudioSourceIds  string    `gorm:"column:audio_source_ids;type:varchar(255);comment:音频来源"`
-	CreatedTime     time.Time `gorm:"column:created_time;type:datetime;comment:创建时间"`
-	UpdatedTime     time.Time `gorm:"column:updated_time;type:datetime;comment:更新时间"`
-}
-
-// TableName 指定表名
-func (MerchantPackage) TableName() string {
-	return "merchant_packages"
-}

+ 17 - 0
models/merchant/merchant_product.go

@@ -102,3 +102,20 @@ func GetProductListBySourceIds(ids []int, detail bool, productType ...MerchantPr
 
 	return
 }
+
+func GetTotalPageCountByProductType(productType MerchantProductType) (total int64, latestId int64) {
+	db := models.Main()
+	_ = db.Select("count(*)").Where("type=? and deleted =?", productType, false).Scan(&total).Error
+	_ = db.Select("max(id)").Where("type=? and deleted =?", productType, false).Scan(&latestId).Error
+	return
+}
+
+func GetProductListByProductType(productType MerchantProductType, 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 =? limit ?,? order by created_time desc", id, productType, false, offset, limit).Find(&list).Error
+	return
+}

+ 1 - 1
models/merchant/user_subscription_access_list.go

@@ -99,7 +99,7 @@ func SubscribeList(templateUserId int, productType string, latestId int64, offse
 	return
 }
 
-func GetTotalPageCountByProductType(productType string, templateUserId int) (count int64, latestId int64) {
+func GetTotalUserPageCountByProductType(productType string, templateUserId int) (count int64, latestId int64) {
 	db := models.Main()
 	err := db.Model(&UserSubscriptionAccessList{}).Select("count(*)").Where("template_user_id=? AND product_type=? and status=?", templateUserId, productType, SubscribeValid).Scan(&count).Error
 	if err != nil {

+ 2 - 2
models/order/product_order.go

@@ -112,9 +112,9 @@ func GetOrderPage(latestId int64, offset int, size int, userId int, status Order
 	return
 }
 
-func GetOrderDetail(orderId int, userId int) (order ProductOrder, err error) {
+func GetOrderDetail(orderId string, userId int) (order ProductOrder, err error) {
 	db := models.Main()
-	err = db.Model(&ProductOrder{}).Select("*").Where("id = ? and template_user_id = ? and is_deleted=0 ", orderId, userId).First(&order).Error
+	err = db.Model(&ProductOrder{}).Select("*").Where("order_id = ? and template_user_id = ? and is_deleted=0 ", orderId, userId).First(&order).Error
 	return
 }
 

+ 12 - 1
routers/commentsRouter.go

@@ -78,7 +78,7 @@ func init() {
             Router: `/orderDetail`,
             AllowHTTPMethods: []string{"get"},
             MethodParams: param.Make(
-				param.New("orderId"),
+				param.New("orderNo"),
 			),
             Filters: nil,
             Params: nil})
@@ -132,6 +132,17 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_mini_ht_api/controllers/product:ProductController"] = append(beego.GlobalControllerRouter["eta/eta_mini_ht_api/controllers/product:ProductController"],
+        beego.ControllerComments{
+            Method: "ProductList",
+            Router: `/ProductList`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(
+				param.New("productType"),
+			),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_mini_ht_api/controllers/product:ProductController"] = append(beego.GlobalControllerRouter["eta/eta_mini_ht_api/controllers/product:ProductController"],
         beego.ControllerComments{
             Method: "GetProductInfo",

+ 2 - 2
service/order/order_service.go

@@ -179,8 +179,8 @@ func GetOrderPage(pageInfo page.PageInfo, userId int, orderStatus string) (order
 	return
 }
 
-func GetOrderDetail(productId int, userId int) (order orderService.ProductOrderDetailDTO, err error) {
-	order, err = orderService.GetOrderDetail(productId, userId)
+func GetOrderDetail(orderId string, userId int) (order orderService.ProductOrderDetailDTO, err error) {
+	order, err = orderService.GetOrderDetail(orderId, userId)
 	return
 }
 

+ 16 - 0
service/product/product_service.go

@@ -3,6 +3,7 @@ package product
 import (
 	logger "eta/eta_mini_ht_api/common/component/log"
 	"eta/eta_mini_ht_api/common/exception"
+	"eta/eta_mini_ht_api/common/utils/page"
 	permissionService "eta/eta_mini_ht_api/domian/config"
 	merchantService "eta/eta_mini_ht_api/domian/merchant"
 	reportDomain "eta/eta_mini_ht_api/domian/report"
@@ -222,3 +223,18 @@ func GetRelatePackage(info ProductDTO) (prodList []ProductDTO, err error) {
 		return
 	}
 }
+
+func GetTotalPageCountByProductType(productType string) (total int64, latestId int64) {
+	return merchantService.GetTotalPageCountByProductType(productType)
+
+}
+
+func ProductList(productType string, info page.PageInfo) (dtoList []ProductDTO, err error) {
+	var merchantProductList []merchantService.MerchantProductDTO
+	merchantProductList, err = merchantService.GetProductListByProductType(productType, info)
+	for _, product := range merchantProductList {
+		productDTO := convertToProductDTO(product)
+		dtoList = append(dtoList, productDTO)
+	}
+	return
+}

+ 2 - 2
service/product/subscribe_servcie.go

@@ -63,6 +63,6 @@ func convertToSubscribeDTO(product merchant.MerchantProductDTO) SubscribeDTO {
 		CreatedDate: product.CreatedTime.Format(time.DateOnly),
 	}
 }
-func GetTotalPageCountByProductType(productType string, templateUserId int) (int64, int64) {
-	return merchant.GetTotalPageCountByProductType(productType, templateUserId)
+func GetTotalUserPageCountByProductType(productType string, templateUserId int) (int64, int64) {
+	return merchant.GetTotalUserPageCountByProductType(productType, templateUserId)
 }

+ 2 - 0
service/report/report_service.go

@@ -64,6 +64,7 @@ type HotRankedReport struct {
 	RiskLevel         string         `json:"riskLevel"`
 	IsFree            bool           `json:"isFree"`
 	Price             string         `json:"price"`
+	ProductId         int            `json:"productId"`
 	IsSubscribe       bool           `json:"isSubscribe"`
 	Login             bool           `json:"login"`
 }
@@ -539,6 +540,7 @@ func convertToHotRankedReport(dto reportService.ReportDTO) (report HotRankedRepo
 		Price:             dto.Price,
 		RiskLevel:         dto.RiskLevel,
 		Login:             dto.Login,
+		ProductId:         dto.ProductId,
 	}
 	return
 }