|
@@ -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 {
|