Browse Source

增加商品佣金计算方法

master v0.6.0
guzeng 3 years ago
parent
commit
ac0960b854
4 changed files with 67 additions and 4 deletions
  1. +45
    -0
      commission.go
  2. +18
    -0
      commission_test.go
  3. +2
    -2
      favorite.go
  4. +2
    -2
      product_activity_test.go

+ 45
- 0
commission.go View File

@ -0,0 +1,45 @@
package productrpc
import (
"strings"
"git.tetele.net/tgo/helper"
)
/**
* commission_rule 规则1按系统设置2单独设置
* commission_value 单独佣金值
* commission_rate 系统佣金比例
*/
func ProductCommission(commission_rule, commission_value, commission_rate string, product_price, cost_price string, quantity interface{}) float64 {
var commission_rule_rate float64 //佣金按比例换算成的小数
var commission_type string
switch commission_rule {
case "1": //按系统设置
commission_rule_rate = helper.FloatQuo(commission_rate, 100)
commission_type = "rate"
case "2": //单独设置
if strings.Contains(commission_value, "%") { //百分比
commission_rule_rate = helper.FloatQuo(strings.ReplaceAll(commission_value, "%", ""), 100)
commission_type = "rate"
} else {
commission_type = "fixed"
}
}
var commission float64
switch commission_type {
case "rate":
commission = helper.FloatMul(helper.FloatMul(helper.FloatSub(product_price, cost_price), commission_rule_rate), quantity) //利润
case "fixed":
commission = helper.FloatMul(commission_value, quantity)
}
return commission
}

+ 18
- 0
commission_test.go View File

@ -0,0 +1,18 @@
package productrpc
import (
"testing"
)
func Test_ProductCommission(t *testing.T) {
commission_rule := "2"
commission_value := "2%"
commission_rate := "35"
product_price := "105"
cost_price := "80"
quantity := "1"
ret := ProductCommission(commission_rule, commission_value, commission_rate, product_price, cost_price, quantity)
t.Log(ret)
}

+ 2
- 2
favorite.go View File

@ -5,8 +5,8 @@ import (
) )
/** /**
* 获取商品进行中活动
* 2021/10/06
* 收藏
* 2021/10/14
* GZ * GZ
*/ */
func Favorite(site_id, dbname, product_id string, user_id string, url ...string) (int64, error) { func Favorite(site_id, dbname, product_id string, user_id string, url ...string) (int64, error) {


+ 2
- 2
product_activity_test.go View File

@ -6,10 +6,10 @@ import (
func Test_GetProductAllActivity(t *testing.T) { func Test_GetProductAllActivity(t *testing.T) {
dbname := "shop_v2" dbname := "shop_v2"
id := "122"
id := "187"
site_id := "1058278" site_id := "1058278"
ret, err := GetAllActivity(site_id, dbname, id, "0")
ret, err := GetProductAllActivity(site_id, dbname, id, "0", "")
t.Log(ret) t.Log(ret)
t.Log(err) t.Log(err)


Loading…
Cancel
Save