diff --git a/commission.go b/commission.go new file mode 100644 index 0000000..9877350 --- /dev/null +++ b/commission.go @@ -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 +} diff --git a/commission_test.go b/commission_test.go new file mode 100644 index 0000000..d8e4e97 --- /dev/null +++ b/commission_test.go @@ -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) +} diff --git a/favorite.go b/favorite.go index 33af033..614c29f 100644 --- a/favorite.go +++ b/favorite.go @@ -5,8 +5,8 @@ import ( ) /** - * 获取商品进行中活动 - * 2021/10/06 + * 收藏 + * 2021/10/14 * GZ */ func Favorite(site_id, dbname, product_id string, user_id string, url ...string) (int64, error) { diff --git a/product_activity_test.go b/product_activity_test.go index 8fbd7c3..d812197 100644 --- a/product_activity_test.go +++ b/product_activity_test.go @@ -6,10 +6,10 @@ import ( func Test_GetProductAllActivity(t *testing.T) { dbname := "shop_v2" - id := "122" + id := "187" site_id := "1058278" - ret, err := GetAllActivity(site_id, dbname, id, "0") + ret, err := GetProductAllActivity(site_id, dbname, id, "0", "") t.Log(ret) t.Log(err)