3 Commits

Author SHA1 Message Date
  guzeng 4708e7d381 增加sku缓存查询 2 years ago
  guzeng 709392fb99 增加取sku方法 2 years ago
  guzeng ac0960b854 增加商品佣金计算方法 2 years ago
8 changed files with 205 additions and 7 deletions
Split View
  1. +45
    -0
      commission.go
  2. +18
    -0
      commission_test.go
  3. +2
    -2
      favorite.go
  4. +66
    -0
      getskuinfo.go
  5. +5
    -3
      getskuinfo_test.go
  6. +57
    -0
      product.pb.go
  7. +10
    -0
      product.proto
  8. +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
*/
func Favorite(site_id, dbname, product_id string, user_id string, url ...string) (int64, error) {


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


+ 57
- 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"`
@ -210,6 +259,8 @@ type ProductService interface {
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
@ -314,6 +365,12 @@ func (c *ProductServiceClient) GetProductAllActivity(in *Request, out *Response)
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) {


+ 10
- 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;
@ -49,4 +57,6 @@ service ProductService {
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查询
}

+ 2
- 2
product_activity_test.go View File

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


Loading…
Cancel
Save