info_pricing_strategy_dao.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package dao
  2. import (
  3. "fmt"
  4. log "github.com/sirupsen/logrus"
  5. "youngee_b_api/app/entity"
  6. )
  7. type InfoPricingStrategylDao struct{}
  8. func (d InfoPricingStrategylDao) GetPricingStrategy(fansLow int64, fansUp int64, feeForm int64, platForm int64) (*entity.InfoPricingStrategy, error) {
  9. // fansLow粉丝量下限 fansUp粉丝量上限 feeForm稿费形式 1产品置换 2固定稿费 3自报价 platForm平台
  10. var pricingStrategys []entity.InfoPricingStrategy
  11. whereStr := fmt.Sprintf("fee_form = %d and platform = %d and fans_low <= %d and fans_up > %d", feeForm, platForm, fansLow, fansLow)
  12. orStr := fmt.Sprintf("fee_form = %d and platform = %d and fans_low < %d and fans_up >= %d", feeForm, platForm, fansUp, fansUp)
  13. orStr1 := fmt.Sprintf("fee_form = %d and platform = %d and fans_low >= %d and fans_up <= %d", feeForm, platForm, fansLow, fansUp)
  14. orStr2 := fmt.Sprintf("fee_form = %d and platform = %d and fans_low <= %d and fans_up >= %d", feeForm, platForm, fansLow, fansUp)
  15. err := Db.Model(entity.InfoPricingStrategy{}).Where(whereStr).Or(orStr).Or(orStr1).Or(orStr2).Scan(&pricingStrategys).Error
  16. if err != nil {
  17. log.Println("DB GetLastAutoDefaultID:", err)
  18. return nil, err
  19. }
  20. fmt.Printf("PricingStrategys%+v \n", pricingStrategys)
  21. pricingStrategy := entity.InfoPricingStrategy{}
  22. if feeForm == 1 { // 如果是产品置换,则选取服务费最高时的定价策略
  23. var maxCharge float64 = 0
  24. for _, v := range pricingStrategys {
  25. if v.ServiceCharge >= maxCharge {
  26. maxCharge = v.ServiceCharge
  27. pricingStrategy = v
  28. }
  29. }
  30. } else { // 如果是固定稿费或自报价,则选取服务费率最高时的定价策略
  31. var maxRate int64 = 0
  32. for _, v := range pricingStrategys {
  33. if v.ServiceRate >= maxRate {
  34. maxRate = v.ServiceRate
  35. pricingStrategy = v
  36. }
  37. }
  38. }
  39. return &pricingStrategy, nil
  40. }