浏览代码

修改定价策略bug

Ohio-HYF 2 年之前
父节点
当前提交
d994885154

+ 32 - 23
db/operate.go

@@ -18,7 +18,7 @@ import (
 
 func CreatePricingStrategy(ctx context.Context, req *http_model.AddPricingRequest) (string, string, error) {
 	db := GetReadDB(ctx)
-	project_type, fee_form, platform, fans_low, fans_up, service_charge, base_offer := req.ProjectType, req.ManuscriptForm, req.Platform, req.FansLow, req.FansHigh, req.PlatformFee, req.BaseOffer
+	project_type, fee_form, platform, fans_low, fans_up, service_charge, service_rate := req.ProjectType, req.ManuscriptForm, req.Platform, req.FansLow, req.FansHigh, req.ServiceCharge, req.ServiceRate*10
 	var IsExclusive, IsExclusive2, IsExclusive3, IsExclusive1 gorm_model.InfoPricingStrategy
 	err := db.Where(" fee_form = ? && platform = ? && fans_low <= ? && fans_up >= ?", fee_form, platform, fans_low, fans_up).First(&IsExclusive).Error
 	if err == nil {
@@ -69,10 +69,10 @@ func CreatePricingStrategy(ctx context.Context, req *http_model.AddPricingReques
 	newStrategy.FansLow = fans_low
 	newStrategy.FansUp = fans_up
 	newStrategy.ProjectType = conv.MustInt64(project_type, 0)
-	newStrategy.BaseOffer = conv.MustFloat32(base_offer, 0)
+	newStrategy.ServiceCharge = conv.MustFloat32(service_charge, 0)
 	newStrategy.Platform = conv.MustInt64(platform, 0)
 	newStrategy.FeeForm = conv.MustInt64(fee_form, 0)
-	newStrategy.ServiceCharge = conv.MustInt64(service_charge, 0)
+	newStrategy.ServiceRate = conv.MustInt64(service_rate, 0)
 	newStrategy.CreateAt = time.Now()
 	newStrategy.UpdateAt = time.Now()
 	err = db.Create(&newStrategy).Error
@@ -116,36 +116,45 @@ func SearchPricing(ctx context.Context, pageSize, pageNum int32, conditions *com
 	return PricingDatas, total, nil
 }
 
-func ModifyPricing(ctx context.Context, req *http_model.ModifyPricingRequest) (string, error) {
+func ModifyPricing(ctx context.Context, req *http_model.ModifyPricingRequest) (int, error) {
 	db := GetReadDB(ctx)
 	strategyId := req.StrategyId
 	db = db.Model(gorm_model.InfoPricingStrategy{}).Where("strategyId = ?", strategyId)
-	project_type, fee_form, platform, fans_low, fans_up, service_charge, base_offer := req.ProjectType, req.FeeForm, req.Platform, req.FansLow, req.FansHigh, req.PlatformFee, req.BaseOffer
-	var IsExclusive, IsExclusive2, IsExclusive3, IsExclusive1 gorm_model.InfoPricingStrategy
-	err := db.Where(" fee_form = ? && platform = ? && fans_low <= ? && fans_up >= ?", fee_form, platform, fans_low, fans_up).First(&IsExclusive).Error
-	if err == nil {
-		return "该策略与已经运行的策略互斥,请修改相关字段后重新创建", nil
+	project_type, fee_form, platform, fans_low, fans_up, service_charge, service_rate := req.ProjectType, req.FeeForm, req.Platform, req.FansLow, req.FansHigh, req.ServiceCharge, req.ServiceRate*10
+	var IsExclusive, IsExclusive2, IsExclusive3, IsExclusive1 int64
+	err := db.Where("strategyId <> ? && fee_form = ? && platform = ? && fans_low <= ? && fans_up >= ?", strategyId, fee_form, platform, fans_low, fans_up).Count(&IsExclusive).Error
+	if IsExclusive != 0 {
+		return 1, nil
 	}
-	err = db.Where(" fee_form = ? && platform = ? && fans_low < ? && fans_up > ?", fee_form, platform, fans_low, fans_low).First(&IsExclusive1).Error
-	if err == nil {
-		return "该策略与已经运行的策略互斥,请修改相关字段后重新创建", nil
+	err = db.Where("strategyId <> ? && fee_form = ? && platform = ? && fans_low < ? && fans_up > ?", strategyId, fee_form, platform, fans_low, fans_low).Count(&IsExclusive1).Error
+	if IsExclusive1 != 0 {
+		return 1, nil
 	}
-	err = db.Where(" fee_form = ? && platform = ? && fans_low < ? && fans_up > ?", fee_form, platform, fans_up, fans_up).First(&IsExclusive2).Error
-	if err == nil {
-		return "该策略与已经运行的策略互斥,请修改相关字段后重新创建", nil
+	err = db.Where("strategyId <> ? && fee_form = ? && platform = ? && fans_low < ? && fans_up > ?", strategyId, fee_form, platform, fans_up, fans_up).Count(&IsExclusive2).Error
+	if IsExclusive2 != 0 {
+		return 1, nil
 	}
-	err = db.Where(" fee_form = ? && platform = ? && fans_low >= ? && fans_up <= ?", fee_form, platform, fans_low, fans_up).First(&IsExclusive3).Error
-	if err == nil {
-		return "该策略与已经运行的策略互斥,请修改相关字段后重新创建", nil
+	err = db.Where("strategyId <> ? && fee_form = ? && platform = ? && fans_low >= ? && fans_up <= ?", strategyId, fee_form, platform, fans_low, fans_up).Count(&IsExclusive3).Error
+	if IsExclusive3 != 0 {
+		return 1, nil
 	}
-	err = db.Updates(map[string]interface{}{
-		"project_type": project_type, "base_offer": base_offer, "fee_form": fee_form,
+	if err != nil {
+		fmt.Printf("[ModifyPricing] error query mysql find, err:%+v", err)
+		logrus.WithContext(ctx).Errorf("[ModifyPricing] error query mysql find, err:%+v", err)
+		return 2, err
+	}
+	fmt.Printf("service_rate:%+v", service_rate)
+	db1 := GetReadDB(ctx).Model(gorm_model.InfoPricingStrategy{}).Where("strategyId = ?", strategyId)
+	err1 := db1.Updates(map[string]interface{}{
+		"project_type": project_type, "service_rate": service_rate, "fee_form": fee_form,
 		"platform": platform, "fans_low": fans_low, "fans_up": fans_up, "service_charge": service_charge,
 	}).Error
-	if err != nil {
-		return "", err
+	if err1 != nil {
+		fmt.Printf("[ModifyPricing] error query mysql update, err:%+v", err)
+		logrus.WithContext(ctx).Errorf("[ModifyPricing] error query mysql update, err:%+v", err)
+		return 2, err
 	}
-	return "修改成功", nil
+	return 0, nil
 }
 
 func UpdateAutoTaskTime(ctx context.Context, time int32, num int32) error {

+ 7 - 4
handler/operate/modify_pricing.go

@@ -1,12 +1,13 @@
 package operate
 
 import (
-	"github.com/gin-gonic/gin"
-	"github.com/sirupsen/logrus"
 	"youngee_m_api/consts"
 	"youngee_m_api/db"
 	"youngee_m_api/model/http_model"
 	"youngee_m_api/util"
+
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
 )
 
 func WrapModifyPricingHandler(ctx *gin.Context) {
@@ -49,11 +50,13 @@ func (m ModifyPricingHandler) run() {
 		logrus.Info("PricingHandler fail,req:%+v", m.req)
 		return
 	}
-	if toast == "修改成功" {
+	if toast == 0 {
 		m.resp.Message = "编号为" + m.req.StrategyId + "的策略修改成功"
-	} else if toast == "要修改策略与已经运行的策略互斥,请修改相关字段" {
+	} else if toast == 1 {
+		m.resp.Message = "该策略与已经运行的策略互斥,请修改相关字段后重新创建"
 		m.resp.Status = 1
 	} else {
+		m.resp.Message = "网络错误,修改失败"
 		m.resp.Status = 2
 	}
 }

+ 1 - 1
model/gorm_model/info_pricing_strategy.go

@@ -13,7 +13,7 @@ type InfoPricingStrategy struct {
 	Platform      int64     `gorm:"column:platform;NOT NULL"`             // 项目平台,1-7分别代表小红书、抖音、微博、快手、b站、大众点评、知乎
 	FansLow       int64     `gorm:"column:fans_low;NOT NULL"`             // 对应粉丝量下限
 	FansUp        int64     `gorm:"column:fans_up;NOT NULL"`              // 对应粉丝量上限
-	ServiceCharge int64     `gorm:"column:service_charge"`                // 服务费,稿费形式为产品置换时填写,可以为空
+	ServiceCharge float32   `gorm:"column:service_charge"`                // 服务费,稿费形式为产品置换时填写,可以为空
 	BaseOffer     float32   `gorm:"column:base_offer"`                    // 基础报价
 	Status        int64     `gorm:"column:status;NOT NULL"`               // 定价策略当前状态,0表示正常,1表示禁用
 	ServiceRate   int64     `gorm:"column:service_rate"`                  // 服务费率*1000,稿费形式为固定稿费和自报价时填写,可以为空

+ 2 - 2
model/http_model/add_pricing.go

@@ -6,8 +6,8 @@ type AddPricingRequest struct {
 	Platform       string  `json:"platform"`        //社媒平台
 	FansLow        int64   `json:"fans_low"`        //对应创作者 粉丝量
 	FansHigh       int64   `json:"fans_high"`       //对应创作者 粉丝量
-	BaseOffer      float32 `json:"base_offer"`      //基础报价
-	PlatformFee    int64   `json:"platform_fee"`    //平台服务费
+	ServiceCharge  float32 `json:"service_charge"`  //基础报价
+	ServiceRate    int64   `json:"service_rate"`    //平台服务费
 }
 
 type AddPricingResponse struct {

+ 9 - 8
model/http_model/modify_pricing.go

@@ -1,14 +1,15 @@
 package http_model
 
 type ModifyPricingRequest struct {
-	StrategyId  string `json:"strategy_id"`
-	ProjectType string `json:"project_type"` //项目类型
-	FeeForm     string `json:"fee_form"`     //稿费形式
-	Platform    string `json:"platform"`     //社媒平台
-	FansLow     int64  `json:"fans_low"`     //对应创作者 粉丝量
-	FansHigh    int64  `json:"fans_high"`    //对应创作者 粉丝量
-	BaseOffer   int64  `json:"base_offer"`   //基础报价
-	PlatformFee int64  `json:"platform_fee"` //平台服务费
+	ID            string `json:"id"`
+	StrategyId    string `json:"strategy_id"`
+	ProjectType   string `json:"project_type"`   //项目类型
+	FeeForm       string `json:"fee_form"`       //稿费形式
+	Platform      string `json:"platform"`       //社媒平台
+	FansLow       int64  `json:"fans_low"`       //对应创作者 粉丝量
+	FansHigh      int64  `json:"fans_high"`      //对应创作者 粉丝量
+	ServiceCharge int64  `json:"service_charge"` //平台服务费
+	ServiceRate   int64  `json:"service_rate"`   //平台服务费率
 }
 
 type ModifyPricingResponse struct {

+ 11 - 10
model/http_model/search_pricing.go

@@ -3,20 +3,21 @@ package http_model
 type SearchPricingRequest struct {
 	PageSize    int32  `json:"page_size"`
 	PageNum     int32  `json:"page_num"`
-	ProjectType string `json:"project_type"` //项目类型
-	FeeForm     string `json:"fee_form"`     //稿费形式
-	Platform    string `json:"platform"`     //社媒平台
+	ProjectType string `json:"project_type"` // 项目类型
+	FeeForm     string `json:"fee_form"`     // 稿费形式
+	Platform    string `json:"platform"`     // 社媒平台
 	UpdateAt    string `json:"update_at"`    // 创建时间
 }
 
 type SearchPricingPreview struct {
-	StrategyId     string `json:"strategyId"`      //定价策略编号
-	ProjectType    string `json:"project_type"`    //项目类型
-	Platform       string `json:"platform"`        //社媒平台
-	ManuscriptForm string `json:"manuscript_form"` //稿费形式
-	Fans           string `json:"fans"`            //对应创作者粉丝量
-	BaseOffer      string `json:"base_offer"`      //基础报价
-	PlatformFee    string `json:"platform_fee"`    //平台服务费
+	ID             string `json:"id"`              // 编号
+	StrategyId     string `json:"strategyId"`      // 定价策略编号
+	ProjectType    string `json:"project_type"`    // 项目类型
+	Platform       string `json:"platform"`        // 社媒平台
+	ManuscriptForm string `json:"manuscript_form"` // 稿费形式
+	Fans           string `json:"fans"`            // 对应创作者粉丝量
+	ServiceCharge  string `json:"service_charge"`  // 基础报价
+	ServiceRate    string `json:"service_rate"`    // 平台服务费
 	UpdateTime     string `json:"update_time"`     // 更新时间
 }
 

+ 9 - 7
pack/operate.go

@@ -1,12 +1,13 @@
 package pack
 
 import (
-	"github.com/caixw/lib.go/conv"
 	"youngee_m_api/consts"
 	"youngee_m_api/model/common_model"
 	"youngee_m_api/model/gorm_model"
 	"youngee_m_api/model/http_model"
 	"youngee_m_api/util"
+
+	"github.com/caixw/lib.go/conv"
 )
 
 func HttpPricingRequestToConditions(req *http_model.SearchPricingRequest) *common_model.PricingConditions {
@@ -41,20 +42,21 @@ func MGromSearchPricingDataToHttpData(gormPricing *gorm_model.InfoPricingStrateg
 	} else if gormPricing.FansLow != 0 && gormPricing.FansUp == 0 {
 		fans = util.GetNumString(gormPricing.FansLow) + "以上"
 	}
-	baseOffer := ""
-	if gormPricing.BaseOffer == 0 {
-		baseOffer = "不限"
+	serviceCharge := ""
+	if gormPricing.ServiceCharge == 0 {
+		serviceCharge = "不限"
 	} else {
-		baseOffer = conv.MustString(gormPricing.BaseOffer, "")
+		serviceCharge = conv.MustString(gormPricing.ServiceCharge, "")
 	}
 	return &http_model.SearchPricingPreview{
+		ID:             conv.MustString(gormPricing.ID, ""),
 		StrategyId:     gormPricing.StrategyId,
 		ProjectType:    consts.GetProjectType(gormPricing.ProjectType),
 		Platform:       consts.GetProjectPlatform(gormPricing.Platform),
 		ManuscriptForm: consts.GetFeeForm(gormPricing.FeeForm),
 		Fans:           fans,
-		BaseOffer:      baseOffer,
-		PlatformFee:    conv.MustString(gormPricing.ServiceCharge, "") + "%",
+		ServiceCharge:  serviceCharge,
+		ServiceRate:    conv.MustString(gormPricing.ServiceRate/10, "") + "%",
 		UpdateTime:     updatedTime,
 	}
 }