7 Commits

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
14 changed files with 607 additions and 66 deletions
Split View
  1. +9
    -9
      activity.go
  2. +50
    -54
      activity_test.go
  3. +45
    -0
      commission.go
  4. +18
    -0
      commission_test.go
  5. +43
    -0
      favorite.go
  6. +18
    -0
      favorite_test.go
  7. +66
    -0
      getskuinfo.go
  8. +5
    -3
      getskuinfo_test.go
  9. +1
    -0
      go.mod
  10. +2
    -0
      go.sum
  11. +73
    -0
      product.pb.go
  12. +14
    -0
      product.proto
  13. +246
    -0
      product_activity.go
  14. +17
    -0
      product_activity_test.go

+ 9
- 9
activity.go View File

@ -58,12 +58,12 @@ func GetActivity(site_id, dbname, id string, sku_id string, url ...string) ([]ma
var start int
for _, item := range res_arr {
start, err = strconv.Atoi(item["Starttime"])
start, err = strconv.Atoi(item["starttime"])
if err != nil {
log.Println(err)
}
activitys = append(activitys, Activity{
Id: item["Id"],
Id: item["id"],
Start: start,
})
}
@ -76,7 +76,7 @@ func GetActivity(site_id, dbname, id string, sku_id string, url ...string) ([]ma
if len(activitys) > 0 {
for _, v := range activitys {
for _, old := range res_arr {
if v.Id == old["Id"] {
if v.Id == old["id"] {
list = append(list, old)
break
}
@ -136,12 +136,12 @@ func GetWarmingActivity(site_id, dbname, id string, sku_id string, url ...string
var start int
for _, item := range res_arr {
start, err = strconv.Atoi(item["Starttime"])
start, err = strconv.Atoi(item["starttime"])
if err != nil {
log.Println(err)
}
activitys = append(activitys, Activity{
Id: item["Id"],
Id: item["id"],
Start: start,
})
}
@ -154,7 +154,7 @@ func GetWarmingActivity(site_id, dbname, id string, sku_id string, url ...string
if len(activitys) > 0 {
for _, v := range activitys {
for _, old := range res_arr {
if v.Id == old["Id"] {
if v.Id == old["id"] {
list = append(list, old)
break
}
@ -214,12 +214,12 @@ func GetAllActivity(site_id, dbname, id string, sku_id string, url ...string) ([
var start int
for _, item := range res_arr {
start, err = strconv.Atoi(item["Starttime"])
start, err = strconv.Atoi(item["starttime"])
if err != nil {
log.Println(err)
}
activitys = append(activitys, Activity{
Id: item["Id"],
Id: item["id"],
Start: start,
})
}
@ -232,7 +232,7 @@ func GetAllActivity(site_id, dbname, id string, sku_id string, url ...string) ([
if len(activitys) > 0 {
for _, v := range activitys {
for _, old := range res_arr {
if v.Id == old["Id"] {
if v.Id == old["id"] {
list = append(list, old)
break
}


+ 50
- 54
activity_test.go View File

@ -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)
}

+ 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)
}

+ 43
- 0
favorite.go View File

@ -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)
}

+ 18
- 0
favorite_test.go View File

@ -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)
}

+ 66
- 0
getskuinfo.go View File

@ -72,3 +72,69 @@ func GetSkuByUuid(site_id, dbname, uuid string, field string, url ...string) (ma
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
}

+ 5
- 3
getskuinfo_test.go View File

@ -4,11 +4,13 @@ import (
"testing"
)
func Test_GetSku(t *testing.T) {
func Test_GetSkuInfo(t *testing.T) {
dbname := "shop_v2"
id := "10"
product_uuid := "39034"
site_id := "1058278"
sku_id := "39814"
ret, err := GetSku(dbname, id)
ret, err := GetSkuInfo(site_id, dbname, product_uuid, sku_id, "")
t.Log(ret)
t.Log(err)


+ 1
- 0
go.mod View File

@ -5,6 +5,7 @@ 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


+ 2
- 0
go.sum View File

@ -2,6 +2,8 @@ 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=


+ 73
- 0
product.pb.go View File

@ -11,6 +11,7 @@ It is generated from these files:
It has these top-level messages:
GetRequest
GetUuidRequest
GetSkuRequest
GetResponse
Request
Response
@ -112,6 +113,54 @@ func (m *GetUuidRequest) GetField() string {
return ""
}
type GetSkuRequest struct {
SiteId *string `protobuf:"bytes,1,opt,name=site_id" json:"site_id,omitempty"`
Dbname *string `protobuf:"bytes,2,opt,name=dbname" json:"dbname,omitempty"`
ProductUuid *string `protobuf:"bytes,3,opt,name=product_uuid" json:"product_uuid,omitempty"`
SkuId *string `protobuf:"bytes,4,opt,name=sku_id" json:"sku_id,omitempty"`
Field *string `protobuf:"bytes,5,opt,name=field" json:"field,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *GetSkuRequest) Reset() { *m = GetSkuRequest{} }
func (m *GetSkuRequest) String() string { return proto.CompactTextString(m) }
func (*GetSkuRequest) ProtoMessage() {}
func (m *GetSkuRequest) GetSiteId() string {
if m != nil && m.SiteId != nil {
return *m.SiteId
}
return ""
}
func (m *GetSkuRequest) GetDbname() string {
if m != nil && m.Dbname != nil {
return *m.Dbname
}
return ""
}
func (m *GetSkuRequest) GetProductUuid() string {
if m != nil && m.ProductUuid != nil {
return *m.ProductUuid
}
return ""
}
func (m *GetSkuRequest) GetSkuId() string {
if m != nil && m.SkuId != nil {
return *m.SkuId
}
return ""
}
func (m *GetSkuRequest) GetField() string {
if m != nil && m.Field != nil {
return *m.Field
}
return ""
}
// 使用key查询响应结构
type GetResponse struct {
Value []byte `protobuf:"bytes,1,opt,name=value" json:"value,omitempty"`
@ -206,6 +255,12 @@ type ProductService interface {
GetActivity(in *Request, out *Response) error
GetAllActivity(in *Request, out *Response) error
GetWarmingActivity(in *Request, out *Response) error
FavoriteProduct(in *Request, out *Response) error
GetProductActivity(in *Request, out *Response) error
GetProductAllActivity(in *Request, out *Response) error
GetProductWarmingActivity(in *Request, out *Response) error
GetSkuInfo(in *GetSkuRequest, out *GetResponse) error
GetSkuList(in *GetSkuRequest, out *GetResponse) error
}
// AcceptProductServiceClient accepts connections on the listener and serves requests
@ -298,6 +353,24 @@ func (c *ProductServiceClient) GetAllActivity(in *Request, out *Response) error
func (c *ProductServiceClient) GetWarmingActivity(in *Request, out *Response) error {
return c.Call("ProductService.GetWarmingActivity", in, out)
}
func (c *ProductServiceClient) FavoriteProduct(in *Request, out *Response) error {
return c.Call("ProductService.FavoriteProduct", in, out)
}
func (c *ProductServiceClient) GetProductActivity(in *Request, out *Response) error {
return c.Call("ProductService.GetProductActivity", in, out)
}
func (c *ProductServiceClient) GetProductAllActivity(in *Request, out *Response) error {
return c.Call("ProductService.GetProductAllActivity", in, out)
}
func (c *ProductServiceClient) GetProductWarmingActivity(in *Request, out *Response) error {
return c.Call("ProductService.GetProductWarmingActivity", in, out)
}
func (c *ProductServiceClient) GetSkuInfo(in *GetSkuRequest, out *GetResponse) error {
return c.Call("ProductService.GetSkuInfo", in, out)
}
func (c *ProductServiceClient) GetSkuList(in *GetSkuRequest, out *GetResponse) error {
return c.Call("ProductService.GetSkuList", in, out)
}
// DialProductService connects to an ProductService at the specified network address.
func DialProductService(network, addr string) (*ProductServiceClient, *rpc.Client, error) {


+ 14
- 0
product.proto View File

@ -16,6 +16,14 @@ message GetUuidRequest {
string field = 4;
}
message GetSkuRequest {
string site_id = 1;
string dbname = 2;
string product_uuid = 3;
string sku_id = 4;
string field = 5;
}
// 使key查询响应结构
message GetResponse {
bytes value = 1;
@ -45,4 +53,10 @@ service ProductService {
rpc GetActivity(Request) returns (Response); //
rpc GetAllActivity(Request) returns (Response); //
rpc GetWarmingActivity(Request) returns (Response); //
rpc FavoriteProduct(Request) returns(Response);//
rpc GetProductActivity(Request) returns (Response); //
rpc GetProductAllActivity(Request) returns (Response); //
rpc GetProductWarmingActivity(Request) returns (Response); //
rpc GetSkuInfo (GetSkuRequest) returns (GetResponse); // 使uuid查询
rpc GetSkuList (GetSkuRequest) returns (GetResponse); // 使uuid查询
}

+ 246
- 0
product_activity.go View File

@ -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
}

+ 17
- 0
product_activity_test.go View File

@ -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)
}

Loading…
Cancel
Save