|
@@ -84,6 +84,59 @@ func CreatePricingStrategy(ctx context.Context, req *http_model.AddPricingReques
|
|
return "创建成功", monthAndDay + numString, nil
|
|
return "创建成功", monthAndDay + numString, nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func CreateYoungeeStrategy(ctx context.Context, req *http_model.AddYoungeeRequest) (string, string, error) {
|
|
|
|
+ db := GetReadDB(ctx)
|
|
|
|
+ project_type, task_type, platform, content_type, reason, cash := req.ProjectType, req.TaskType, req.Platform, req.ContentType, req.Reason, req.Cash
|
|
|
|
+ var IsExclusive gorm_model.InfoYoungeeStrategy
|
|
|
|
+ err := db.Where(" platform = ? ").First(&IsExclusive).Error
|
|
|
|
+ if err == nil {
|
|
|
|
+ return "该策略与已经运行的策略互斥,请修改相关字段后重新创建", "", nil
|
|
|
|
+ }
|
|
|
|
+ var newStrategy gorm_model.InfoYoungeeStrategy
|
|
|
|
+ var strategyInfo gorm_model.InfoYoungeeStrategy
|
|
|
|
+ getMonth := time.Now().Format("01") //获取月
|
|
|
|
+ getDay := time.Now().Day() //获取日
|
|
|
|
+ dayString := ""
|
|
|
|
+ if getDay < 10 {
|
|
|
|
+ dayString = conv.MustString(getDay, "")
|
|
|
|
+ dayString = "0" + dayString
|
|
|
|
+ } else {
|
|
|
|
+ dayString = conv.MustString(getDay, "")
|
|
|
|
+ }
|
|
|
|
+ monthAndDay := conv.MustString(getMonth, "") + dayString
|
|
|
|
+ err = db.Where(fmt.Sprintf(" strategyId like '%s%%'", monthAndDay)).Last(&strategyInfo).Error
|
|
|
|
+
|
|
|
|
+ num := 1
|
|
|
|
+ if strategyInfo.StrategyId != "" {
|
|
|
|
+ num = conv.MustInt(strategyInfo.StrategyId[4:6], 0)
|
|
|
|
+ num = num + 1 //获取日
|
|
|
|
+ } else {
|
|
|
|
+ num = 1
|
|
|
|
+ }
|
|
|
|
+ numString := ""
|
|
|
|
+ if num < 10 {
|
|
|
|
+ numString = conv.MustString(num, "")
|
|
|
|
+ numString = "0" + numString
|
|
|
|
+ } else {
|
|
|
|
+ numString = conv.MustString(num, "")
|
|
|
|
+ }
|
|
|
|
+ newStrategy.StrategyId = monthAndDay + numString
|
|
|
|
+ newStrategy.Status = 0
|
|
|
|
+ newStrategy.ProjectType = conv.MustInt64(project_type, 0)
|
|
|
|
+ newStrategy.TaskType = conv.MustInt64(task_type, 0)
|
|
|
|
+ newStrategy.Platform = conv.MustInt64(platform, 0)
|
|
|
|
+ newStrategy.ContentType = conv.MustInt(content_type, 0)
|
|
|
|
+ newStrategy.Reason = conv.MustInt(reason, 0)
|
|
|
|
+ //newStrategy.Points = conv.MustFloat64(points, 0)
|
|
|
|
+ newStrategy.Cash = conv.MustFloat64(cash, 0)
|
|
|
|
+ newStrategy.CreateAt = time.Now()
|
|
|
|
+ err = db.Create(&newStrategy).Error
|
|
|
|
+ if err != nil {
|
|
|
|
+ return "创建失败", "", err
|
|
|
|
+ }
|
|
|
|
+ return "创建成功", monthAndDay + numString, nil
|
|
|
|
+}
|
|
|
|
+
|
|
func SearchPricing(ctx context.Context, pageSize, pageNum int32, conditions *common_model.PricingConditions) ([]*gorm_model.InfoPricingStrategy, int64, error) {
|
|
func SearchPricing(ctx context.Context, pageSize, pageNum int32, conditions *common_model.PricingConditions) ([]*gorm_model.InfoPricingStrategy, int64, error) {
|
|
db := GetReadDB(ctx)
|
|
db := GetReadDB(ctx)
|
|
db = db.Model(gorm_model.InfoPricingStrategy{})
|
|
db = db.Model(gorm_model.InfoPricingStrategy{})
|
|
@@ -118,6 +171,39 @@ func SearchPricing(ctx context.Context, pageSize, pageNum int32, conditions *com
|
|
return PricingDatas, total, nil
|
|
return PricingDatas, total, nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func SearchYoungee(ctx context.Context, pageSize, pageNum int32, conditions *common_model.YoungeeConditions) ([]*gorm_model.InfoYoungeeStrategy, int64, error) {
|
|
|
|
+ db := GetReadDB(ctx)
|
|
|
|
+ db = db.Model(gorm_model.InfoYoungeeStrategy{})
|
|
|
|
+ // 根据 查询条件过滤
|
|
|
|
+ conditionType := reflect.TypeOf(conditions).Elem()
|
|
|
|
+ conditionValue := reflect.ValueOf(conditions).Elem()
|
|
|
|
+ for i := 0; i < conditionType.NumField(); i++ {
|
|
|
|
+ field := conditionType.Field(i)
|
|
|
|
+ tag := field.Tag.Get("condition")
|
|
|
|
+ value := conditionValue.FieldByName(field.Name)
|
|
|
|
+ if !util.IsBlank(value) {
|
|
|
|
+ fmt.Println("tag:", tag)
|
|
|
|
+ db = db.Debug().Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 查询总数
|
|
|
|
+ var total int64
|
|
|
|
+ var YoungeeDatas []*gorm_model.InfoYoungeeStrategy
|
|
|
|
+ if err := db.Count(&total).Error; err != nil {
|
|
|
|
+ logrus.WithContext(ctx).Errorf("[SearchYoungee] error query mysql total, err:%+v", err)
|
|
|
|
+ return nil, 0, err
|
|
|
|
+ }
|
|
|
|
+ // 查询该页数据
|
|
|
|
+ limit := pageSize
|
|
|
|
+ offset := pageSize * pageNum // assert pageNum start with 0
|
|
|
|
+ err := db.Order("content_type desc").Limit(int(limit)).Offset(int(offset)).Find(&YoungeeDatas).Error
|
|
|
|
+ if err != nil {
|
|
|
|
+ logrus.WithContext(ctx).Errorf("[SearchYoungee] error query mysql find, err:%+v", err)
|
|
|
|
+ return nil, 0, err
|
|
|
|
+ }
|
|
|
|
+ return YoungeeDatas, total, nil
|
|
|
|
+}
|
|
|
|
+
|
|
func ModifyPricing(ctx context.Context, req *http_model.ModifyPricingRequest) (int, error) {
|
|
func ModifyPricing(ctx context.Context, req *http_model.ModifyPricingRequest) (int, error) {
|
|
db := GetReadDB(ctx)
|
|
db := GetReadDB(ctx)
|
|
strategyId := req.StrategyId
|
|
strategyId := req.StrategyId
|