Author | SHA1 | Message | Date |
---|---|---|---|
guzeng | 4708e7d381 | 增加sku缓存查询 | 3 years ago |
guzeng | 709392fb99 | 增加取sku方法 | 3 years ago |
guzeng | ac0960b854 | 增加商品佣金计算方法 | 3 years ago |
guzeng | acd68471a5 | 增加商品活动查询 | 3 years ago |
guzeng | 490d89b078 | 增加商品的所有活动 | 3 years ago |
@ -1,73 +1,69 @@ | |||
package productrpc | |||
import ( | |||
"log" | |||
"sort" | |||
"strconv" | |||
"testing" | |||
) | |||
func Test_GetAllActivity(t *testing.T) { | |||
// dbname := "shop_v2" | |||
// id := "10248" | |||
// site_id := "10248" | |||
// sku_id := "10248" | |||
dbname := "shop_v2" | |||
id := "122" | |||
site_id := "1058278" | |||
// ret, err := GetAllActivity(site_id, dbname, id, sku_id) | |||
ret, err := GetAllActivity(site_id, dbname, id, "0") | |||
// t.Log(ret) | |||
// t.Log(err) | |||
t.Log(ret) | |||
t.Log(err) | |||
res_arr := []map[string]string{ | |||
map[string]string{ | |||
"Id": "55", | |||
"Starttime": "19852365", | |||
}, | |||
map[string]string{ | |||
"Id": "22", | |||
"Starttime": "17852365", | |||
}, | |||
map[string]string{ | |||
"Id": "11", | |||
"Starttime": "18852365", | |||
}, | |||
} | |||
t.Log(res_arr) | |||
// res_arr := []map[string]string{ | |||
// map[string]string{ | |||
// "Id": "55", | |||
// "Starttime": "19852365", | |||
// }, | |||
// map[string]string{ | |||
// "Id": "22", | |||
// "Starttime": "17852365", | |||
// }, | |||
// map[string]string{ | |||
// "Id": "11", | |||
// "Starttime": "18852365", | |||
// }, | |||
// } | |||
// t.Log(res_arr) | |||
var activitys Activitys | |||
var err error | |||
// var activitys Activitys | |||
// var err error | |||
if len(res_arr) > 0 { | |||
var start int | |||
// if len(res_arr) > 0 { | |||
// var start int | |||
for _, item := range res_arr { | |||
start, err = strconv.Atoi(item["Starttime"]) | |||
if err != nil { | |||
log.Println(err) | |||
} | |||
activitys = append(activitys, Activity{ | |||
Id: item["Id"], | |||
Start: start, | |||
}) | |||
} | |||
} | |||
// for _, item := range res_arr { | |||
// start, err = strconv.Atoi(item["Starttime"]) | |||
// if err != nil { | |||
// log.Println(err) | |||
// } | |||
// activitys = append(activitys, Activity{ | |||
// Id: item["Id"], | |||
// Start: start, | |||
// }) | |||
// } | |||
// } | |||
sort.Sort(activitys) | |||
// sort.Sort(activitys) | |||
t.Log(activitys) | |||
// t.Log(activitys) | |||
var list []map[string]string = make([]map[string]string, 0) | |||
// var list []map[string]string = make([]map[string]string, 0) | |||
if len(activitys) > 0 { | |||
for _, v := range activitys { | |||
for _, old := range res_arr { | |||
if v.Id == old["Id"] { | |||
list = append(list, old) | |||
break | |||
} | |||
} | |||
} | |||
} | |||
// if len(activitys) > 0 { | |||
// for _, v := range activitys { | |||
// for _, old := range res_arr { | |||
// if v.Id == old["Id"] { | |||
// list = append(list, old) | |||
// break | |||
// } | |||
// } | |||
// } | |||
// } | |||
t.Log(list) | |||
// t.Log(list) | |||
} |
@ -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 | |||
} |
@ -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) | |||
} |
@ -0,0 +1,246 @@ | |||
package productrpc | |||
import ( | |||
"encoding/json" | |||
"log" | |||
"sort" | |||
"strconv" | |||
// "strconv" | |||
// "time" | |||
"git.tetele.net/tgo/helper" | |||
) | |||
/** | |||
* 获取商品进行中活动 | |||
* 2021/10/06 | |||
* GZ | |||
*/ | |||
func GetProductActivity(site_id, dbname, id string, url ...string) ([]map[string]string, error) { | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return nil, err | |||
} | |||
defer conn.Close() | |||
arg := GetActivityParam{site_id, dbname, id, "0"} | |||
req, err := SetReqData(arg) | |||
if err != nil { | |||
return nil, err | |||
} | |||
res := &Response{} | |||
err = conn.GetProductActivity(req, res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
res_data_de, err := GetResData(res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if res_data_de == "" { | |||
return nil, nil | |||
} | |||
var res_arr []map[string]string | |||
err = json.Unmarshal([]byte(res_data_de), &res_arr) | |||
if err != nil { | |||
return nil, err | |||
} | |||
var activitys Activitys | |||
if len(res_arr) > 0 { | |||
var start int | |||
for _, item := range res_arr { | |||
start, err = strconv.Atoi(item["Starttime"]) | |||
if err != nil { | |||
log.Println(err) | |||
} | |||
activitys = append(activitys, Activity{ | |||
Id: item["Id"], | |||
Start: start, | |||
}) | |||
} | |||
} | |||
sort.Sort(activitys) | |||
var list []map[string]string = make([]map[string]string, 0) | |||
if len(activitys) > 0 { | |||
for _, v := range activitys { | |||
for _, old := range res_arr { | |||
if v.Id == old["Id"] { | |||
list = append(list, old) | |||
break | |||
} | |||
} | |||
} | |||
} | |||
return list, nil | |||
} | |||
/** | |||
* 获取商品预热中活动 | |||
* 2021/10/06 | |||
* GZ | |||
*/ | |||
func GetProductWarmingActivity(site_id, dbname, id string, url ...string) ([]map[string]string, error) { | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return nil, err | |||
} | |||
defer conn.Close() | |||
arg := GetActivityParam{site_id, dbname, id, "0"} | |||
req, err := SetReqData(arg) | |||
if err != nil { | |||
return nil, err | |||
} | |||
res := &Response{} | |||
err = conn.GetProductWarmingActivity(req, res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
res_data_de, err := GetResData(res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if res_data_de == "" { | |||
return nil, nil | |||
} | |||
var res_arr []map[string]string | |||
err = json.Unmarshal([]byte(res_data_de), &res_arr) | |||
if err != nil { | |||
return nil, err | |||
} | |||
var activitys Activitys | |||
if len(res_arr) > 0 { | |||
var start int | |||
for _, item := range res_arr { | |||
start, err = strconv.Atoi(item["Starttime"]) | |||
if err != nil { | |||
log.Println(err) | |||
} | |||
activitys = append(activitys, Activity{ | |||
Id: item["Id"], | |||
Start: start, | |||
}) | |||
} | |||
} | |||
sort.Sort(activitys) | |||
var list []map[string]string = make([]map[string]string, 0) | |||
if len(activitys) > 0 { | |||
for _, v := range activitys { | |||
for _, old := range res_arr { | |||
if v.Id == old["Id"] { | |||
list = append(list, old) | |||
break | |||
} | |||
} | |||
} | |||
} | |||
return list, nil | |||
} | |||
/** | |||
* 获取商品进行中活动 | |||
* 2021/10/06 | |||
* GZ | |||
*/ | |||
func GetProductAllActivity(site_id, dbname, id string, url ...string) ([]map[string]interface{}, error) { | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return nil, err | |||
} | |||
defer conn.Close() | |||
arg := GetActivityParam{site_id, dbname, id, "0"} | |||
req, err := SetReqData(arg) | |||
if err != nil { | |||
return nil, err | |||
} | |||
res := &Response{} | |||
err = conn.GetProductAllActivity(req, res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
res_data_de, err := GetResData(res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if res_data_de == "" { | |||
return nil, nil | |||
} | |||
var res_arr []map[string]interface{} | |||
err = json.Unmarshal([]byte(res_data_de), &res_arr) | |||
if err != nil { | |||
log.Println(err) | |||
return nil, err | |||
} | |||
var activitys Activitys | |||
if len(res_arr) > 0 { | |||
var start int | |||
for _, item := range res_arr { | |||
start = helper.ToInt(item["starttime"]) | |||
activitys = append(activitys, Activity{ | |||
Id: helper.ToStr(item["id"]), | |||
Start: start, | |||
}) | |||
} | |||
} | |||
sort.Sort(activitys) | |||
var list []map[string]interface{} = make([]map[string]interface{}, 0) | |||
if len(activitys) > 0 { | |||
for _, v := range activitys { | |||
for _, old := range res_arr { | |||
if v.Id == helper.ToStr(old["id"]) { | |||
list = append(list, old) | |||
break | |||
} | |||
} | |||
} | |||
} | |||
return list, nil | |||
} |
@ -0,0 +1,17 @@ | |||
package productrpc | |||
import ( | |||
"testing" | |||
) | |||
func Test_GetProductAllActivity(t *testing.T) { | |||
dbname := "shop_v2" | |||
id := "187" | |||
site_id := "1058278" | |||
ret, err := GetProductAllActivity(site_id, dbname, id, "0", "") | |||
t.Log(ret) | |||
t.Log(err) | |||
} |