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 |
guzeng | 763913d263 | 增加收藏商品公共调用 | 3 years ago |
guzeng | 64d2e84c2c | 增加收藏商品方法 | 3 years ago |
guzeng | 0f65ef66f2 | 增加参数 | 3 years ago |
guzeng | f2db689215 | 商品活动增加排序 | 3 years ago |
guzeng | 5dcf931741 | 增加活动查询方法 | 3 years ago |
guzeng | cc4c94cb0c | 增加查询所有活动方法 | 3 years ago |
guzeng | 811ce7be22 | 增加变量文件 | 3 years ago |
guzeng | 5184632ae6 | 增加GetActivity方法 | 3 years ago |
guzeng | eb17040cd7 | 修改请求参数 | 3 years ago |
guzeng | 0fb3adbb73 | 增加请求参数 | 3 years ago |
guzeng | e426c81793 | 查询增加自定义字段 | 3 years ago |
guzeng | c21c056b1b | 增加状态检测方法 | 3 years ago |
guzeng | 82750124cd | 增加uuid取信息方法 | 3 years ago |
guzeng | 9b2f51de66 | 增加sku查询方法 | 3 years ago |
guzeng | ccd5780795 | 增加sku查询方法 | 3 years ago |
guzeng | 9535059463 | 连接服务器增加参数设置 | 3 years ago |
guzeng | b62d2623f0 | 修改README | 3 years ago |
guzeng | eb66d73ffa | 增加id获取商品信息方法 | 3 years ago |
@ -1,3 +1,7 @@ | |||
# productrpc | |||
商品rpc数据格式及调用方法 | |||
商品rpc数据格式及调用方法 | |||
## Get(dbname, id string, rpc_url ...string) | |||
根据id取商品信息 |
@ -0,0 +1,261 @@ | |||
package productrpc | |||
import ( | |||
"encoding/json" | |||
"log" | |||
"sort" | |||
"strconv" | |||
// "strconv" | |||
// "time" | |||
) | |||
/** | |||
* 获取商品进行中活动 | |||
* 2021/10/06 | |||
* GZ | |||
*/ | |||
func GetActivity(site_id, dbname, id string, sku_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, sku_id} | |||
req, err := SetReqData(arg) | |||
if err != nil { | |||
return nil, err | |||
} | |||
res := &Response{} | |||
err = conn.GetActivity(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 GetWarmingActivity(site_id, dbname, id string, sku_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, sku_id} | |||
req, err := SetReqData(arg) | |||
if err != nil { | |||
return nil, err | |||
} | |||
res := &Response{} | |||
err = conn.GetWarmingActivity(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 GetAllActivity(site_id, dbname, id string, sku_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, sku_id} | |||
req, err := SetReqData(arg) | |||
if err != nil { | |||
return nil, err | |||
} | |||
res := &Response{} | |||
err = conn.GetAllActivity(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 | |||
} | |||
type Activity struct { | |||
Id string | |||
Start int | |||
} | |||
type Activitys []Activity | |||
func (s Activitys) Len() int { | |||
return len(s) | |||
} | |||
func (s Activitys) Swap(i, j int) { | |||
s[i], s[j] = s[j], s[i] | |||
} | |||
func (s Activitys) Less(i, j int) bool { | |||
return s[i].Start < s[j].Start | |||
} |
@ -0,0 +1,69 @@ | |||
package productrpc | |||
import ( | |||
"testing" | |||
) | |||
func Test_GetAllActivity(t *testing.T) { | |||
dbname := "shop_v2" | |||
id := "122" | |||
site_id := "1058278" | |||
ret, err := GetAllActivity(site_id, dbname, id, "0") | |||
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) | |||
// var activitys Activitys | |||
// var err error | |||
// 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) | |||
// t.Log(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 | |||
// } | |||
// } | |||
// } | |||
// } | |||
// t.Log(list) | |||
} |
@ -0,0 +1,81 @@ | |||
package productrpc | |||
import ( | |||
"strconv" | |||
"time" | |||
) | |||
/* | |||
* 检查商品状态 | |||
* 2020/09/16 | |||
*/ | |||
func CheckStatus(productInfo map[string]string, arrival_time string) (int, string) { | |||
if productInfo["Status"] == "0" { //是否在售 | |||
return 8405, "商品已下架" | |||
if productInfo["Status"] == "2" { //是否在售 | |||
return 8405, "商品已售罄" | |||
} | |||
} | |||
if productInfo["Status"] != "1" { //是否在售 | |||
return 8405, "商品未上架" | |||
} | |||
if productInfo["AutoOnSale"] == "1" { | |||
if productInfo["EndSaleTime"] != "0" && productInfo["EndSaleTime"] != "" { //销售截止日期 | |||
end_sale_time, _ := strconv.ParseInt(productInfo["EndSaleTime"], 10, 64) | |||
if time.Unix(end_sale_time, 0).Before(time.Now()) { //截止日期在当前时间之前 | |||
return 8407, "商品已过有效期" | |||
} | |||
} | |||
if productInfo["StartSaleTime"] != "0" && productInfo["StartSaleTime"] != "" { //销售开始日期 | |||
end_sale_time, _ := strconv.ParseInt(productInfo["StartSaleTime"], 10, 64) | |||
if time.Unix(end_sale_time, 0).After(time.Now()) { //开始日期在当前时间之后 | |||
return 8406, "商品未开售" | |||
} | |||
} | |||
} | |||
if productInfo["ValidityType"] == "1" { //用户选定使用日期 | |||
if arrival_time == "" { | |||
return 10005, "请选择使用日期" | |||
} else { | |||
advance, _ := strconv.Atoi(productInfo["Advance"]) //提前几天 | |||
arrival_time_int64, err := strconv.ParseInt(arrival_time, 10, 64) | |||
var release_time_int64, end_time_int64 int64 = 0, 0 | |||
now := time.Now().Unix() | |||
if err != nil { // 转换失败 | |||
return 10005, "日期错误" | |||
} | |||
if arrival_time_int64 < now { //不能在当前时间之前 | |||
return 10005, "日期选择错误" | |||
} | |||
if productInfo["Releasetime"] != "" && productInfo["Releasetime"] != "0" { | |||
release_time_int64, _ = strconv.ParseInt(productInfo["Releasetime"], 10, 64) | |||
} | |||
if productInfo["Endtime"] != "" && productInfo["Endtime"] != "0" { | |||
end_time_int64, err = strconv.ParseInt(productInfo["Endtime"], 10, 64) | |||
if err == nil { | |||
if advance > 0 { | |||
end_time_int64 = end_time_int64 - int64(advance*24*3600) //提前几天截止预约 | |||
if end_time_int64 < now { | |||
return 8409, "已截止购买" | |||
} | |||
} | |||
} | |||
} | |||
if release_time_int64 > 0 && arrival_time_int64 < release_time_int64 { //未到服务时间 | |||
return 10006, "请选择" + time.Unix(release_time_int64, 0).Format("2006-01-02") + "之后的日期" | |||
} | |||
if end_time_int64 > 0 { | |||
if arrival_time_int64 > end_time_int64 { //已过服务时间 | |||
return 10006, "请选择" + time.Unix(end_time_int64, 0).Format("2006-01-02") + "之前的日期" | |||
} | |||
} | |||
} | |||
} | |||
return 0, "" | |||
} |
@ -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,23 @@ | |||
package productrpc | |||
import ( | |||
"git.tetele.net/tgo/conf" | |||
) | |||
func rpc_server_conn(url ...string) (*ProductServiceClient, error) { | |||
var rpc_url string | |||
if len(url) > 0 && url[0] != "" { | |||
rpc_url = url[0] | |||
} else if conf.PRODUCT_RPC_URL != "" { | |||
rpc_url = conf.PRODUCT_RPC_URL | |||
} else { | |||
rpc_url = "127.0.0.1:" + conf.PRODUCT_RPC_PORT | |||
} | |||
conn, _, err := DialProductService("tcp", rpc_url) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return conn, nil | |||
} |
@ -0,0 +1,108 @@ | |||
package productrpc | |||
import ( | |||
"encoding/json" | |||
"errors" | |||
"strconv" | |||
"time" | |||
"git.tetele.net/tgo/crypter" | |||
"github.com/golang/protobuf/proto" | |||
) | |||
var DES_KEY = "pro%78gd" | |||
func SetResData(data interface{}, res *Response) { | |||
res_data_json, err := json.Marshal(data) | |||
if err == nil { | |||
encryData := crypter.DesEn(string(res_data_json), DES_KEY) | |||
now_str := strconv.FormatInt(time.Now().Unix(), 10) | |||
res_sign := Sign(encryData, now_str) | |||
res.Data = proto.String(encryData) | |||
res.Time = proto.String(now_str) | |||
res.Sign = proto.String(res_sign) | |||
} | |||
} | |||
func SetReqData(arg interface{}) (*Request, error) { | |||
data_json, err := json.Marshal(arg) | |||
if err != nil { | |||
return nil, err | |||
} | |||
now_int64 := time.Now().Unix() | |||
encryData := crypter.DesEn(string(data_json), DES_KEY) | |||
now := strconv.FormatInt(now_int64, 10) | |||
sign := Sign(encryData, now) | |||
return &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil}, nil | |||
} | |||
func GetReqData(req *Request) (string, error) { | |||
res_data := req.GetData() | |||
if res_data != "" { | |||
time_int64, err := strconv.ParseInt(req.GetTime(), 10, 64) | |||
if err != nil { | |||
return "", err | |||
} | |||
now_int64 := time.Now().Unix() | |||
if now_int64-time_int64 > 10 || time_int64-now_int64 > 10 { | |||
//时间误差前后10秒,返回 | |||
return "", errors.New("返回时间错误") | |||
} | |||
check_sign := CheckSign(req.GetSign(), res_data, req.GetTime()) | |||
if !check_sign { | |||
return "", errors.New("返回数据签名错误") | |||
} | |||
//解密 | |||
return crypter.DesDe(res_data, DES_KEY), nil | |||
} | |||
return "", nil | |||
} | |||
func GetResData(res *Response) (string, error) { | |||
res_data := res.GetData() | |||
if res_data != "" { | |||
time_int64, err := strconv.ParseInt(res.GetTime(), 10, 64) | |||
if err != nil { | |||
return "", err | |||
} | |||
now_int64 := time.Now().Unix() | |||
if now_int64-time_int64 > 10 || time_int64-now_int64 > 10 { | |||
//时间误差前后10秒,返回 | |||
return "", errors.New("返回时间错误") | |||
} | |||
check_sign := CheckSign(res.GetSign(), res_data, res.GetTime()) | |||
if !check_sign { | |||
return "", errors.New("返回数据签名错误") | |||
} | |||
//解密 | |||
return crypter.DesDe(res_data, DES_KEY), nil | |||
} | |||
return "", nil | |||
} |
@ -0,0 +1,43 @@ | |||
package productrpc | |||
import ( | |||
"strconv" | |||
) | |||
/** | |||
* 收藏 | |||
* 2021/10/14 | |||
* GZ | |||
*/ | |||
func Favorite(site_id, dbname, product_id string, user_id string, url ...string) (int64, error) { | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return 0, err | |||
} | |||
defer conn.Close() | |||
arg := FavoriteParam{site_id, dbname, product_id, user_id} | |||
req, err := SetReqData(arg) | |||
if err != nil { | |||
return 0, err | |||
} | |||
res := &Response{} | |||
err = conn.FavoriteProduct(req, res) | |||
if err != nil { | |||
return 0, err | |||
} | |||
res_data_de, err := GetResData(res) | |||
if err != nil { | |||
return 0, err | |||
} | |||
if res_data_de == "" { | |||
return 0, nil | |||
} | |||
return strconv.ParseInt(res_data_de, 10, 64) | |||
} |
@ -0,0 +1,18 @@ | |||
package productrpc | |||
import ( | |||
"testing" | |||
) | |||
func Test_Favorite(t *testing.T) { | |||
dbname := "shop_v2" | |||
product_id := "1024800" | |||
site_id := "102480" | |||
user_id := "10248" | |||
ret, err := Favorite(site_id, dbname, product_id, user_id) | |||
t.Log(ret) | |||
t.Log(err) | |||
} |
@ -0,0 +1,74 @@ | |||
package productrpc | |||
import ( | |||
"encoding/json" | |||
// "strconv" | |||
// "time" | |||
"github.com/golang/protobuf/proto" | |||
) | |||
/** | |||
* id获取商品信息 | |||
* 2021/08/20 | |||
* GZ | |||
*/ | |||
func Get(site_id, dbname, id string, field string, url ...string) (map[string]string, error) { | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return nil, err | |||
} | |||
defer conn.Close() | |||
req := &GetRequest{proto.String(site_id), proto.String(dbname), proto.String(id), proto.String(field), nil} | |||
res := &GetResponse{} | |||
err = conn.Get(req, res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
value := res.GetValue() | |||
var data map[string]string | |||
err = json.Unmarshal(value, &data) | |||
return data, err | |||
} | |||
/** | |||
* uuid获取商品sku信息 | |||
* 2021/08/20 | |||
* GZ | |||
*/ | |||
func GetByUuid(site_id, dbname, uuid string, field string, url ...string) (map[string]string, error) { | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return nil, err | |||
} | |||
defer conn.Close() | |||
req := &GetUuidRequest{proto.String(site_id), proto.String(dbname), proto.String(uuid), proto.String(field), nil} | |||
res := &GetResponse{} | |||
err = conn.GetByUuid(req, res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
value := res.GetValue() | |||
var data map[string]string | |||
err = json.Unmarshal(value, &data) | |||
return data, err | |||
} |
@ -0,0 +1,15 @@ | |||
package productrpc | |||
import ( | |||
"testing" | |||
) | |||
func Test_Get(t *testing.T) { | |||
dbname := "shop_v2" | |||
id := "10248" | |||
ret, err := GetByUuid(dbname, id) | |||
t.Log(ret) | |||
t.Log(err) | |||
} |
@ -0,0 +1,140 @@ | |||
package productrpc | |||
import ( | |||
"encoding/json" | |||
// "strconv" | |||
// "time" | |||
"github.com/golang/protobuf/proto" | |||
) | |||
/** | |||
* id获取商品sku信息 | |||
* 2021/08/20 | |||
* GZ | |||
*/ | |||
func GetSku(site_id, dbname, id string, field string, url ...string) (map[string]string, error) { | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return nil, err | |||
} | |||
defer conn.Close() | |||
req := &GetRequest{proto.String(site_id), proto.String(dbname), proto.String(id), proto.String(field), nil} | |||
res := &GetResponse{} | |||
err = conn.GetSku(req, res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
value := res.GetValue() | |||
var data map[string]string | |||
err = json.Unmarshal(value, &data) | |||
return data, err | |||
} | |||
/** | |||
* uuid获取商品sku信息 | |||
* 2021/08/20 | |||
* GZ | |||
*/ | |||
func GetSkuByUuid(site_id, dbname, uuid string, field string, url ...string) (map[string]string, error) { | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return nil, err | |||
} | |||
defer conn.Close() | |||
req := &GetUuidRequest{proto.String(site_id), proto.String(dbname), proto.String(uuid), proto.String(field), nil} | |||
res := &GetResponse{} | |||
err = conn.GetSkuByUuid(req, res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
value := res.GetValue() | |||
var data map[string]string | |||
err = json.Unmarshal(value, &data) | |||
return data, err | |||
} | |||
/** | |||
* product uuid获取商品sku信息 | |||
* 2021/11/29 | |||
* GZ | |||
*/ | |||
func GetSkuInfo(site_id, dbname, product_uuid string, sku_id string, field string, url ...string) (map[string]string, error) { | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return nil, err | |||
} | |||
defer conn.Close() | |||
req := &GetSkuRequest{proto.String(site_id), proto.String(dbname), proto.String(product_uuid), proto.String(sku_id), proto.String(field), nil} | |||
res := &GetResponse{} | |||
err = conn.GetSkuInfo(req, res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
value := res.GetValue() | |||
var data map[string]string | |||
err = json.Unmarshal(value, &data) | |||
return data, err | |||
} | |||
/** | |||
* product uuid获取商品sku信息 | |||
* 2021/11/29 | |||
* GZ | |||
*/ | |||
func GetSkuList(site_id, dbname, product_uuid string, field string, url ...string) ([]map[string]string, error) { | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return nil, err | |||
} | |||
defer conn.Close() | |||
req := &GetSkuRequest{proto.String(site_id), proto.String(dbname), proto.String(product_uuid), proto.String(""), proto.String(field), nil} | |||
res := &GetResponse{} | |||
err = conn.GetSkuList(req, res) | |||
if err != nil { | |||
return nil, err | |||
} | |||
value := res.GetValue() | |||
var data []map[string]string | |||
err = json.Unmarshal(value, &data) | |||
return data, err | |||
} |
@ -0,0 +1,17 @@ | |||
package productrpc | |||
import ( | |||
"testing" | |||
) | |||
func Test_GetSkuInfo(t *testing.T) { | |||
dbname := "shop_v2" | |||
product_uuid := "39034" | |||
site_id := "1058278" | |||
sku_id := "39814" | |||
ret, err := GetSkuInfo(site_id, dbname, product_uuid, sku_id, "") | |||
t.Log(ret) | |||
t.Log(err) | |||
} |
@ -0,0 +1,12 @@ | |||
module git.tetele.net/tgo/productrpc | |||
go 1.14 | |||
require ( | |||
git.tetele.net/tgo/conf v0.33.1 // indirect | |||
git.tetele.net/tgo/crypter v0.2.2 // indirect | |||
git.tetele.net/tgo/helper v0.1.9 // indirect | |||
github.com/chai2010/protorpc v1.1.3 // indirect | |||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect | |||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect | |||
) |
@ -0,0 +1,22 @@ | |||
git.tetele.net/tgo/conf v0.33.1 h1:ZEIv3Vq35RCv5f3T3Uz97s2mkZLl7W5OlmXvzI3/sS8= | |||
git.tetele.net/tgo/conf v0.33.1/go.mod h1:AWVIBEDE5dtotthUgR0SWaR2Qa6/f+O5WQ3s7Tj8q7A= | |||
git.tetele.net/tgo/crypter v0.2.2 h1:YMQJh2Gj5Po4ZfelJUmXBKi01UbmtiSy3bmqRfnYQMo= | |||
git.tetele.net/tgo/crypter v0.2.2/go.mod h1:vfvRLZA8+lHNgNXneOcgvVhDyuv25ZRb+C6xHOmXNx0= | |||
git.tetele.net/tgo/helper v0.1.9 h1:i1KMqWAlilnrFfkJMw1+aJVU2Mlfz1ISBLLCFGvwCHA= | |||
git.tetele.net/tgo/helper v0.1.9/go.mod h1:89mQwyfqZ+t8YXiVwzSxA70gLlUNqoZGDEUxvV46jXk= | |||
github.com/chai2010/protorpc v1.1.3 h1:VJK5hIoZn0XCGol0GmbxZkUG6FbTI5LP2Lam6RVd15w= | |||
github.com/chai2010/protorpc v1.1.3/go.mod h1:/wO0kiyVdu7ug8dCMrA2yDr2vLfyhsLEuzLa9J2HJ+I= | |||
github.com/golang/protobuf v1.0.0 h1:lsek0oXi8iFE9L+EXARyHIjU5rlWIhhTkjDz3vHhWWQ= | |||
github.com/golang/protobuf v1.0.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= | |||
github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA= | |||
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= | |||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg= | |||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= | |||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= | |||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= | |||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | |||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | |||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | |||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | |||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | |||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= |
@ -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) | |||
} |
@ -0,0 +1,37 @@ | |||
package productrpc | |||
import ( | |||
"crypto/md5" | |||
"encoding/hex" | |||
"strings" | |||
) | |||
/** | |||
* 签名 | |||
*/ | |||
func Sign(data string, salt string) string { | |||
var build strings.Builder | |||
build.WriteString(data) | |||
build.WriteString(salt) | |||
build.WriteString("sup334signlier") | |||
data_str := build.String() | |||
h := md5.New() | |||
h.Write([]byte(data_str)) // 需要加密的字符串 | |||
return hex.EncodeToString(h.Sum(nil)) // 输出加密结果 | |||
} | |||
/** | |||
* 验证签名 | |||
*/ | |||
func CheckSign(sign_str, data, salt string) bool { | |||
sign := Sign(data, salt) | |||
if strings.Compare(sign_str, sign) > -1 { | |||
return true | |||
} | |||
return false | |||
} |
@ -0,0 +1,33 @@ | |||
package productrpc | |||
type GetActivityParam struct { | |||
SiteId string `json:"site_id"` | |||
Dbname string `json:"database"` | |||
Id string `json:"id"` | |||
SkuId string `json:"sku_id"` | |||
} | |||
type GetUuidParam struct { | |||
SiteId string `json:"site_id"` | |||
Dbname string `json:"database"` | |||
Uuid string `json:"uuid"` | |||
Field string `json:"field"` | |||
} | |||
type BoolRet struct { | |||
Value bool `json:"value"` | |||
Msg string `json:"msg"` | |||
} | |||
type ReqParam struct { | |||
SiteId string `json:"site_id"` | |||
Dbname string `json:"database"` | |||
Id string `json:"id"` | |||
Field string `json:"field"` | |||
} | |||
type FavoriteParam struct { | |||
SiteId string `json:"site_id"` | |||
Dbname string `json:"database"` | |||
ProductId string `json:"product_id"` | |||
UserId string `json:"user_id"` | |||
} |