Browse Source

设置产品

kobe6258 4 months ago
parent
commit
df178a6c82
7 changed files with 483 additions and 173 deletions
  1. 122 124
      controllers/merchant.go
  2. 241 9
      controllers/product.go
  3. 1 0
      models/db.go
  4. 27 2
      models/merchant_product.go
  5. 6 12
      models/request/product.go
  6. 27 18
      routers/commentsRouter.go
  7. 59 8
      services/product.go

+ 122 - 124
controllers/merchant.go

@@ -1,138 +1,136 @@
 package controllers
 
 import (
-	"encoding/json"
 	"errors"
 	"eta/eta_mini_crm_ht/models"
-	"eta/eta_mini_crm_ht/models/request"
-	"github.com/shopspring/decimal"
 )
 
 type MerchantController struct {
 	BaseAuthController
 }
 
-// AddProduct
-// @Title 新增产品
-// @Description 获取报告作者
-// @Success 200 {object} models.ReportAuthorResp
-// @router /addProduct [post]
-func (this *MerchantController) AddProduct() {
-	br := new(models.BaseResponse).Init()
-	defer func() {
-		this.Data["json"] = br
-		this.ServeJSON()
-	}()
-
-	var req request.ProductReq
-	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
-		br.Msg = "参数解析失败"
-		br.ErrMsg = "参数解析失败,Err:" + err.Error()
-		return
-	}
-	if !checkProductRiskLevel(req.RiskLevel) {
-		br.Msg = "产品风险等级不合法"
-		br.ErrMsg = "产品风险等级不合法:" + req.RiskLevel
-		return
-	}
-	if !checkProductType(req.Type) {
-		br.Msg = "产品类型不合法"
-		br.ErrMsg = "产品类型不合法:" + req.Type
-		return
-	}
-	if req.ProductName == "" {
-		br.Msg = "产品名称不能为空"
-		br.ErrMsg = "产品名称不能为空"
-		return
-	}
-	price, err := decimal.NewFromString(req.Price)
-	if err != nil {
-		br.Msg = "产品价格格式不正确"
-		br.ErrMsg = "产品价格格式不正确,err:" + err.Error()
-		return
-	}
-	productType, err := transProductType(req.Type)
-	if err != nil {
-		br.Msg = "产品类型不正确"
-		br.ErrMsg = "产品类型不正确,err:" + err.Error()
-		return
-	}
-	product := models.MerchantProduct{
-		Deleted:     false,
-		SourceId:    req.SourceId,
-		Title:       req.ProductName,
-		Price:       price,
-		RiskLevel:   req.RiskLevel,
-		Type:        productType,
-		IsPermanent: true,
-		SaleStatus:  models.OnSale,
-	}
-	err = product.Insert()
-	if err != nil {
-		br.Msg = "新增产品失败"
-		br.ErrMsg = "新增产品失败,err:" + err.Error()
-		return
-	}
-	br.Msg = "新增产品成功"
-	br.Ret = 200
-	br.Success = true
-}
-
-// AddPackage
-// @Title 新增产品
-// @Description 获取报告作者
-// @Success 200 {object} models.ReportAuthorResp
-// @router /addPackage [post]
-func (this *MerchantController) AddPackage() {
-	br := new(models.BaseResponse).Init()
-	defer func() {
-		this.Data["json"] = br
-		this.ServeJSON()
-	}()
-
-	var req request.PackageReq
-	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
-		br.Msg = "参数解析失败"
-		br.ErrMsg = "参数解析失败,Err:" + err.Error()
-		return
-	}
-	if !checkProductRiskLevel(req.RiskLevel) {
-		br.Msg = "产品风险等级不合法"
-		br.ErrMsg = "产品风险等级不合法:" + req.RiskLevel
-		return
-	}
-	if req.ProductName == "" {
-		br.Msg = "产品名称不能为空"
-		br.ErrMsg = "产品名称不能为空"
-		return
-	}
-	price, err := decimal.NewFromString(req.Price)
-	if err != nil {
-		br.Msg = "产品价格格式不正确"
-		br.ErrMsg = "产品价格格式不正确,err:" + err.Error()
-		return
-	}
-	//开始事务
-	product := models.MerchantProduct{
-		Deleted:     false,
-		Title:       req.ProductName,
-		Price:       price,
-		RiskLevel:   req.RiskLevel,
-		Type:        models.ProductPackage,
-		IsPermanent: false,
-		ValidDays:   req.ValidDays,
-		SaleStatus:  models.OnSale,
-	}
-	err = product.Insert()
-	if err != nil {
-		br.Msg = "新增产品失败"
-		br.ErrMsg = "新增产品失败,err:" + err.Error()
-		return
-	}
-	br.Msg = "新增产品成功"
-	br.Ret = 200
-	br.Success = true
-}
+//
+//// AddProduct
+//// @Title 新增产品
+//// @Description 获取报告作者
+//// @Success 200 {object} models.ReportAuthorResp
+//// @router /addProduct [post]
+//func (this *MerchantController) AddProduct() {
+//	br := new(models.BaseResponse).Init()
+//	defer func() {
+//		this.Data["json"] = br
+//		this.ServeJSON()
+//	}()
+//
+//	var req request.ProductReq
+//	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
+//		br.Msg = "参数解析失败"
+//		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+//		return
+//	}
+//	if !checkProductRiskLevel(req.RiskLevel) {
+//		br.Msg = "产品风险等级不合法"
+//		br.ErrMsg = "产品风险等级不合法:" + req.RiskLevel
+//		return
+//	}
+//	if !checkProductType(req.Type) {
+//		br.Msg = "产品类型不合法"
+//		br.ErrMsg = "产品类型不合法:" + req.Type
+//		return
+//	}
+//	if req.ProductName == "" {
+//		br.Msg = "产品名称不能为空"
+//		br.ErrMsg = "产品名称不能为空"
+//		return
+//	}
+//	price, err := decimal.NewFromString(req.Price)
+//	if err != nil {
+//		br.Msg = "产品价格格式不正确"
+//		br.ErrMsg = "产品价格格式不正确,err:" + err.Error()
+//		return
+//	}
+//	productType, err := transProductType(req.Type)
+//	if err != nil {
+//		br.Msg = "产品类型不正确"
+//		br.ErrMsg = "产品类型不正确,err:" + err.Error()
+//		return
+//	}
+//	product := models.MerchantProduct{
+//		Deleted:     false,
+//		SourceId:    req.SourceId,
+//		Title:       req.ProductName,
+//		Price:       price,
+//		RiskLevel:   req.RiskLevel,
+//		Type:        productType,
+//		IsPermanent: true,
+//		SaleStatus:  models.OnSale,
+//	}
+//	err = product.Insert()
+//	if err != nil {
+//		br.Msg = "新增产品失败"
+//		br.ErrMsg = "新增产品失败,err:" + err.Error()
+//		return
+//	}
+//	br.Msg = "新增产品成功"
+//	br.Ret = 200
+//	br.Success = true
+//}
+//
+//// AddPackage
+//// @Title 新增产品
+//// @Description 获取报告作者
+//// @Success 200 {object} models.ReportAuthorResp
+//// @router /addPackage [post]
+//func (this *MerchantController) AddPackage() {
+//	br := new(models.BaseResponse).Init()
+//	defer func() {
+//		this.Data["json"] = br
+//		this.ServeJSON()
+//	}()
+//
+//	var req request.PackageReq
+//	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
+//		br.Msg = "参数解析失败"
+//		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+//		return
+//	}
+//	if !checkProductRiskLevel(req.RiskLevel) {
+//		br.Msg = "产品风险等级不合法"
+//		br.ErrMsg = "产品风险等级不合法:" + req.RiskLevel
+//		return
+//	}
+//	if req.ProductName == "" {
+//		br.Msg = "产品名称不能为空"
+//		br.ErrMsg = "产品名称不能为空"
+//		return
+//	}
+//	price, err := decimal.NewFromString(req.Price)
+//	if err != nil {
+//		br.Msg = "产品价格格式不正确"
+//		br.ErrMsg = "产品价格格式不正确,err:" + err.Error()
+//		return
+//	}
+//	//开始事务
+//	product := models.MerchantProduct{
+//		Deleted:     false,
+//		Title:       req.ProductName,
+//		Price:       price,
+//		RiskLevel:   req.RiskLevel,
+//		Type:        models.ProductPackage,
+//		IsPermanent: false,
+//		ValidDays:   req.ValidDays,
+//		SaleStatus:  models.OnSale,
+//	}
+//	err = product.Insert()
+//	if err != nil {
+//		br.Msg = "新增产品失败"
+//		br.ErrMsg = "新增产品失败,err:" + err.Error()
+//		return
+//	}
+//	br.Msg = "新增产品成功"
+//	br.Ret = 200
+//	br.Success = true
+//}
 func checkProductType(productType string) bool {
 	if productType == "" {
 		return false

+ 241 - 9
controllers/product.go

@@ -1,14 +1,20 @@
 package controllers
 
 import (
+	"encoding/json"
+	"errors"
 	"eta/eta_mini_crm_ht/models"
+	"eta/eta_mini_crm_ht/models/request"
 	"eta/eta_mini_crm_ht/models/response"
 	"eta/eta_mini_crm_ht/services"
 	"eta/eta_mini_crm_ht/utils"
+	"github.com/go-sql-driver/mysql"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"github.com/shopspring/decimal"
 	"strconv"
 	"strings"
 	"sync"
+	"time"
 )
 
 type ProductController struct {
@@ -93,16 +99,15 @@ func (this *ProductController) UnSetProductList() {
 	for _, product := range list {
 		go func(product *services.ProductView) {
 			defer wg.Done()
-
 			switch product.ProductType {
 			case "report":
-				product.RiskLevel = product.GetRiskLevel("report", product.SourceId)
+				product.RiskLevel, _, _ = services.GetRiskLevel("report", product.SourceId)
 				product.ProductType = "报告"
 			case "video":
-				product.RiskLevel = product.GetRiskLevel("media", product.SourceId)
+				product.RiskLevel, _, _ = services.GetRiskLevel("media", product.SourceId)
 				product.ProductType = "视频"
 			case "audio":
-				product.RiskLevel = product.GetRiskLevel("media", product.SourceId)
+				product.RiskLevel, _, _ = services.GetRiskLevel("media", product.SourceId)
 				product.ProductType = "音频"
 			}
 		}(product)
@@ -118,13 +123,240 @@ func (this *ProductController) UnSetProductList() {
 	br.Msg = "获取成功"
 }
 
+// AddProduct @Title 新增单品
+// @Description 新增单品
+// @Param   File   query   file  true       "文件"
+// @Success 200 {object} models.ReportAuthorResp
+// @router /addProduct [post]
+func (this *ProductController) AddProduct() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req request.ProductReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	var product models.MerchantProduct
+	if req.Type == "package" {
+		if req.ValidDays <= 0 {
+			br.Msg = "套餐有效期非法"
+			br.ErrMsg = "套餐有效期非法,天数不能是负数"
+			return
+		}
+		if req.ProductName == "" {
+			br.Msg = "套餐名称不能为空"
+			br.ErrMsg = "套餐名称不能为空"
+			return
+		}
+		product.Title = req.ProductName
+		product.ValidDays = req.ValidDays
+		product.Description = req.Description
+		product.CoverSrc = req.CoverSrc
+	}
+	switch req.Type {
+	case "report":
+		product.RiskLevel, product.Title, err = services.GetRiskLevel("report", req.SourceId)
+	case "audio":
+		product.RiskLevel, product.Title, err = services.GetRiskLevel("audio", req.SourceId)
+	case "video":
+		product.RiskLevel, product.Title, err = services.GetRiskLevel("video", req.SourceId)
+	case "package":
+		product.RiskLevel, _, err = services.GetRiskLevel("package", req.SourceId)
+	default:
+		br.Msg = "产品类型错误"
+		br.ErrMsg = "获取产品列表失败,Err:产品类型错误"
+		return
+	}
+
+	if err != nil {
+		utils.FileLog.Error("新增单品失败", err.Error())
+		br.Msg = "新增产品错误"
+		if strings.Contains(err.Error(), "<QuerySeter> no row found") {
+			br.Msg = "新增产品错误,产品信息不存在"
+		} else {
+			br.Msg = "新增产品错误" + err.Error()
+		}
+		return
+	}
+	if product.RiskLevel == "" {
+		br.Msg = "新增产品错误"
+		br.ErrMsg = "未获取到风险等级"
+		return
+	}
+	if !checkProductRiskLevel(product.RiskLevel) {
+		br.Msg = "产品风险等级不合法"
+		br.ErrMsg = "产品风险等级不合法:" + product.RiskLevel
+		return
+	}
+	if product.Title == "" {
+		br.Msg = "产品名称不能为空"
+		br.ErrMsg = "产品名称不能为空"
+		return
+	}
+	var price decimal.Decimal
+	price, err = decimal.NewFromString(req.Price)
+	if err != nil {
+		br.Msg = "产品价格格式不正确"
+		br.ErrMsg = "产品价格格式不正确,err:" + err.Error() + "price:" + product.Price
+		return
+	}
+	if price.Cmp(decimal.New(0, 0)) <= 0 {
+		br.Msg = "产品价格不能小于0"
+		br.ErrMsg = "产品价格不能小于0"
+		return
+	}
+	product.SaleStatus = models.OnSale
+	product.CreatedTime = time.Now()
+	product.Price = req.Price
+	product.SourceId = req.SourceId
+	product.Type = models.MerchantProductType(req.Type)
+	if product.Type == "" {
+		br.Msg = "新增产品错误"
+		br.ErrMsg = "产品类型为空"
+		return
+	}
+
+	err = product.AddProduct()
+	if err != nil {
+		var mysqlErr *mysql.MySQLError
+		if errors.As(err, &mysqlErr) {
+			if mysqlErr.Number == 1062 {
+				br.Msg = "该产品已设置付费,请刷新后重试"
+				br.ErrMsg = "该产品已设置付费,请刷新后重试"
+			} else {
+				utils.FileLog.Error("新增产品失败,err:" + err.Error())
+				br.Msg = "新增产品失败"
+				br.ErrMsg = "新增产品失败,err:" + err.Error()
+			}
+		} else {
+			utils.FileLog.Error("新增产品失败,err:" + err.Error())
+			br.Msg = "新增产品失败"
+			br.ErrMsg = "新增产品失败,err:" + err.Error()
+		}
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "新增产品成功"
+	return
+}
+
+// UpdateSaleStatus @Title 上下架产品
+// @Description 上下架产品
+// @Param   File   query   file  true       "文件"
+// @Success 200 {object} models.ReportAuthorResp
+// @router /updateSaleStatus [post]
+func (this *ProductController) UpdateSaleStatus() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req request.ProductSaleStatusReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.ProductId <= 0 {
+		br.Msg = "产品编号非法!"
+		br.ErrMsg = "产品编号非法,不能小于0"
+		return
+	}
+	if req.SaleStatus != "onSale" && req.SaleStatus != "offSale" {
+		br.Msg = "产品销售状态非法!"
+		br.ErrMsg = "产品销售状态非法,未知的上下架类型:" + req.SaleStatus
+		return
+	}
+	var saleStatus models.SaleStatus
+	var messageStatus string
+	switch req.SaleStatus {
+	case "onSale":
+		saleStatus = models.OnSale
+		messageStatus = "上架"
+	case "offSale":
+		saleStatus = models.OffSale
+		messageStatus = "下架"
+	}
+	product := models.MerchantProduct{
+		Id:          req.ProductId,
+		SaleStatus:  saleStatus,
+		UpdatedTime: time.Now(),
+	}
+	err = product.UpdateProductSaleStatus()
+	if err != nil {
+		br.Msg = messageStatus + "失败"
+		br.ErrMsg = messageStatus + "失败,err:" + err.Error()
+		return
+	}
+
+	br.Msg = messageStatus + "成功"
+	br.Ret = 200
+	br.Success = true
+}
+
+// DeleteProduct @Title 删除产品
+// @Description 删除产品
+// @Param   File   query   file  true       "文件"
+// @Success 200 {object} models.ReportAuthorResp
+// @router /deleteProduct [post]
+func (this *ProductController) DeleteProduct() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req request.ProductSaleStatusReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.ProductId <= 0 {
+		br.Msg = "产品编号非法!"
+		br.ErrMsg = "产品编号非法,不能小于0"
+		return
+	}
+	product := models.MerchantProduct{
+		Id:          req.ProductId,
+		Deleted:     true,
+		UpdatedTime: time.Now(),
+	}
+	err = product.Delete()
+	if err != nil {
+		br.Msg = "删除产品失败"
+		br.ErrMsg = "删除产品失败,err:" + err.Error()
+		return
+	}
+
+	br.Msg = "删除产品成功"
+	br.Ret = 200
+	br.Success = true
+}
+
 //
-//// UploadFile @Title 上传图片
-//// @Description 上传视频
+//// OnSale @Title 上架产品
+//// @Description 上架产品
 //// @Param   File   query   file  true       "文件"
 //// @Success 200 {object} models.ReportAuthorResp
-//// @router /uploadFile [post]
-//func (this *VideoController) UploadFile() {
+//// @router /onSale [post]
+//func (this *ProductController) OnSale() {
 //	br := new(models.BaseResponse).Init()
 //	defer func() {
 //		this.Data["json"] = br
@@ -195,7 +427,7 @@ func (this *ProductController) UnSetProductList() {
 //	resp.Url = mp3Url
 //	resp.FileName = base
 //	br.Data = resp
-//	br.Msg = "上成功"
+//	br.Msg = "上成功"
 //	br.Ret = 200
 //	br.Success = true
 //}

+ 1 - 0
models/db.go

@@ -52,5 +52,6 @@ func init() {
 		new(Permission),
 		new(CustomerProductRiskMapping),
 		new(UserSourceClickFlow),
+		new(MerchantProduct),
 	)
 }

+ 27 - 2
models/merchant_product.go

@@ -3,7 +3,6 @@ package models
 import (
 	"errors"
 	"github.com/beego/beego/v2/client/orm"
-	"github.com/shopspring/decimal"
 	"time"
 )
 
@@ -25,7 +24,7 @@ type MerchantProduct struct {
 	Title       string              `gorm:"column:title;type:varchar(255);comment:标题"`
 	CoverSrc    string              `gorm:"column:cover_src;type:varchar(255);comment:封面图片"`
 	Description string              `gorm:"column:description;type:varchar(255);comment:描述"`
-	Price       decimal.Decimal     `gorm:"column:price;type:decimal(10,2);comment:价格"`
+	Price       string              `gorm:"column:price;type:decimal(10,2);comment:价格"`
 	RiskLevel   string              `gorm:"column:risk_level;type:varchar(255);not null;comment:风险等级"`
 	Type        MerchantProductType `gorm:"column:type;type:enum('report','video','audio','package');not null;comment:类型"`
 	IsPermanent bool                `gorm:"column:is_permanent;type:int(1);not null;default:0;comment:是否永久"`
@@ -71,3 +70,29 @@ func GetProductSourceIdsByProductType(productType string) (ids []int, err error)
 	_, err = o.Raw("select source_id from merchant_products where deleted = 0 " + condition).QueryRows(&ids)
 	return
 }
+
+func (mp *MerchantProduct) AddProduct() (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(mp)
+	return
+}
+
+func (mp *MerchantProduct) UpdateProductSaleStatus() (err error) {
+	o := orm.NewOrm()
+	var dbProduct MerchantProduct
+	err = o.Raw("select * from merchant_products where id =? and deleted=0", mp.Id).QueryRow(&dbProduct)
+	if err != nil {
+		if err.Error() == "<QuerySeter> no row found" {
+			return errors.New("产品不存在")
+		}
+		return
+	}
+	_, err = o.Update(mp, "sale_status", "updated_time")
+	return
+}
+
+func (mp *MerchantProduct) Delete() (err error) {
+	o := orm.NewOrm()
+	_, err = o.Update(mp, "deleted", "updated_time")
+	return
+}

+ 6 - 12
models/request/product.go

@@ -5,17 +5,11 @@ type ProductReq struct {
 	SourceId    int
 	Type        string
 	Price       string
-	RiskLevel   string
+	CoverSrc    string
+	ValidDays   int
+	Description string
 }
-
-type PackageReq struct {
-	ProductName     string
-	CoverSrc        string
-	ValidDays       int
-	Description     string
-	Price           string
-	RiskLevel       string
-	ReportSourceIds string
-	VideoSourceIds  string
-	AudioSourceIds  string
+type ProductSaleStatusReq struct {
+	ProductId  int
+	SaleStatus string
 }

+ 27 - 18
routers/commentsRouter.go

@@ -297,24 +297,6 @@ func init() {
             Filters: nil,
             Params: nil})
 
-    beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:MerchantController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:MerchantController"],
-        beego.ControllerComments{
-            Method: "AddPackage",
-            Router: `/addPackage`,
-            AllowHTTPMethods: []string{"post"},
-            MethodParams: param.Make(),
-            Filters: nil,
-            Params: nil})
-
-    beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:MerchantController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:MerchantController"],
-        beego.ControllerComments{
-            Method: "AddProduct",
-            Router: `/addProduct`,
-            AllowHTTPMethods: []string{"post"},
-            MethodParams: param.Make(),
-            Filters: nil,
-            Params: nil})
-
     beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:MessageController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:MessageController"],
         beego.ControllerComments{
             Method: "AudioList",
@@ -351,6 +333,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:ProductController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:ProductController"],
+        beego.ControllerComments{
+            Method: "AddProduct",
+            Router: `/addProduct`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:ProductController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:ProductController"],
+        beego.ControllerComments{
+            Method: "DeleteProduct",
+            Router: `/deleteProduct`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:ProductController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:ProductController"],
         beego.ControllerComments{
             Method: "UnSetProductList",
@@ -360,6 +360,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:ProductController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:ProductController"],
+        beego.ControllerComments{
+            Method: "UpdateSaleStatus",
+            Router: `/updateSaleStatus`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:RiskConfigController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:RiskConfigController"],
         beego.ControllerComments{
             Method: "GetCustomerRiskList",

+ 59 - 8
services/product.go

@@ -166,10 +166,11 @@ type ProductView struct {
 	PublishedTime string
 }
 
-func (v ProductView) GetRiskLevel(productType string, id int) (risklevel string) {
+func GetRiskLevel(productType string, id int) (riskLevel string, productName string, err error) {
 	switch productType {
 	case "report":
-		report, err := models.GetReportById(id)
+		var report *models.Report
+		report, err = models.GetReportById(id)
 		if err != nil {
 			utils.FileLog.Error("获取报告失败,无法确认风险等级", err.Error())
 			return
@@ -182,7 +183,7 @@ func (v ProductView) GetRiskLevel(productType string, id int) (risklevel string)
 				utils.FileLog.Error("获取品种信息,无法确认风险等级", err.Error())
 				return
 			}
-			return permission.RiskLevel
+			return permission.RiskLevel, report.Title, nil
 		case models.SourceETA:
 			var permissionIds []int
 			permissionIds, err = models.GetByPermissionIdsByClassifyId(report.ClassifyId)
@@ -211,22 +212,25 @@ func (v ProductView) GetRiskLevel(productType string, id int) (risklevel string)
 				}
 			}
 			if riskNum > 0 {
-				return fmt.Sprintf("R%d", riskNum)
+				return fmt.Sprintf("R%d", riskNum), report.Title, nil
 			}
 			return
 		}
 	case "media":
-		media, err := models.GetMediaById("", id)
+		var media *models.Media
+		media, err = models.GetMediaById("", id)
 		if err != nil {
 			utils.FileLog.Error("获取媒体信息,无法确认风险等级", err.Error())
 			return
 		}
-		permissionsIds, err := models.GetPermissionIdsByMediaId(media.MediaType, id)
+		var permissionsIds []int
+		permissionsIds, err = models.GetPermissionIdsByMediaId(media.MediaType, id)
 		if err != nil {
 			utils.FileLog.Error("获取媒体信息,无法确认风险等级", err.Error())
 			return
 		}
-		permissions, err := models.GetPermissionsWithRiskLevel(permissionsIds)
+		var permissions []models.Permission
+		permissions, err = models.GetPermissionsWithRiskLevel(permissionsIds)
 		if err != nil {
 			utils.FileLog.Error("获取媒体信息,无法确认风险等级", err.Error())
 			return
@@ -247,10 +251,57 @@ func (v ProductView) GetRiskLevel(productType string, id int) (risklevel string)
 			}
 		}
 		if riskNum > 0 {
-			return fmt.Sprintf("R%d", riskNum)
+			return fmt.Sprintf("R%d", riskNum), media.MediaName, nil
 		}
 		return
+	case "package":
+		var permission *models.Permission
+		permission, err = models.GetPermissionByPermissionId(id)
+		if err != nil {
+			utils.FileLog.Error("获取套餐品种信息,无法确认风险等级", err.Error())
+			return
+		}
+		if permission.RiskLevel == "" {
+			return "", "", errors.New("当前品种未设置风测等级")
+		}
+		return permission.RiskLevel, "", nil
 	default:
+		var media *models.Media
+		media, err = models.GetMediaById(models.MediaType(productType), id)
+		if err != nil {
+			utils.FileLog.Error("获取媒体信息,无法确认风险等级", err.Error())
+			return
+		}
+		var permissionsIds []int
+		permissionsIds, err = models.GetPermissionIdsByMediaId(media.MediaType, id)
+		if err != nil {
+			utils.FileLog.Error("获取媒体信息,无法确认风险等级", err.Error())
+			return
+		}
+		var permissions []models.Permission
+		permissions, err = models.GetPermissionsWithRiskLevel(permissionsIds)
+		if err != nil {
+			utils.FileLog.Error("获取媒体信息,无法确认风险等级", err.Error())
+			return
+		}
+		var riskNum int
+		for _, permission := range permissions {
+
+			if permission.RiskLevel == "" {
+				continue
+			}
+			var parseErr error
+			currentNum, parseErr := strconv.Atoi(permission.RiskLevel[1:])
+			if parseErr != nil {
+				continue
+			}
+			if currentNum > riskNum {
+				riskNum = currentNum
+			}
+		}
+		if riskNum > 0 {
+			return fmt.Sprintf("R%d", riskNum), media.MediaName, nil
+		}
 		return
 	}
 	return