商品rpc数据格式及调用方法
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB

  1. package productrpc
  2. import (
  3. "strings"
  4. "git.tetele.net/tgo/helper"
  5. )
  6. /**
  7. * commission_rule 规则1按系统设置2单独设置
  8. * commission_value 单独佣金值
  9. * commission_rate 系统佣金比例
  10. */
  11. func ProductCommission(commission_rule, commission_value, commission_rate string, product_price, cost_price string, quantity interface{}) float64 {
  12. var commission_rule_rate float64 //佣金按比例换算成的小数
  13. var commission_type string
  14. switch commission_rule {
  15. case "1": //按系统设置
  16. commission_rule_rate = helper.FloatQuo(commission_rate, 100)
  17. commission_type = "rate"
  18. case "2": //单独设置
  19. if strings.Contains(commission_value, "%") { //百分比
  20. commission_rule_rate = helper.FloatQuo(strings.ReplaceAll(commission_value, "%", ""), 100)
  21. commission_type = "rate"
  22. } else {
  23. commission_type = "fixed"
  24. }
  25. }
  26. var commission float64
  27. switch commission_type {
  28. case "rate":
  29. commission = helper.FloatMul(helper.FloatMul(helper.FloatSub(product_price, cost_price), commission_rule_rate), quantity) //利润
  30. case "fixed":
  31. commission = helper.FloatMul(commission_value, quantity)
  32. }
  33. return commission
  34. }