123456 3 年 前
コミット
4026f68193

+ 2 - 2
go.mod

@@ -57,9 +57,9 @@ require (
 	go.uber.org/multierr v1.8.0 // indirect
 	go.uber.org/zap v1.21.0 // indirect
 	golang.org/x/crypto v0.0.0-20210920023735-84f357641f63 // indirect
-	golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
+	golang.org/x/net v0.0.0-20220531201128-c960675eff93 // indirect
 	golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
-	golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect
+	golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
 	golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
 	golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 // indirect
 	golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect

+ 4 - 2
go.sum

@@ -621,8 +621,9 @@ golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qx
 golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
-golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
 golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
+golang.org/x/net v0.0.0-20220531201128-c960675eff93 h1:MYimHLfoXEpOhqd/zgoA/uoXzHB86AEky4LAx5ij9xA=
+golang.org/x/net v0.0.0-20220531201128-c960675eff93/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
 golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -700,8 +701,9 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
 golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 h1:nhht2DYV/Sn3qOayu8lM+cU1ii9sTLUeBQwQQfUHtrs=
 golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
+golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=

+ 0 - 49
public/entity/base_goods_function.go

@@ -1,49 +0,0 @@
-package entity
-
-import (
-	"strings"
-
-	. "app.yhyue.com/moapp/jybase/common"
-	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/db"
-)
-
-var Base_goods_function = base_goods_function{}
-
-//商品功能表
-type base_goods_function struct {
-	Id             int64
-	Appid          string
-	Goods_code     string //商品代码
-	Function_code  string //功能代码
-	Limit_strategy string //限制频率;1d:1天 1m:1个月
-	Strategy_count int64  //频率数量
-	Power_type     int64  //权益所属类型;1:个人 2:企业
-	Use_count      int64  //使用数量
-	Power_count    int64  //授权数量;-1:默认对企业下所有人授权 0:不授权
-	Base_function  *base_function
-}
-
-//根据商品代码查找商品的功能明细
-func (b *base_goods_function) FindByGoodsCode(appid, goods_code string) *[]*base_goods_function {
-	list := Mysql_BaseService.SelectBySql(`select a.id as a_id,a.appid as a_appid,a.goods_code as a_goods_code,a.function_code as a_function_code,a.limit_strategy as a_limit_strategy,a.strategy_count as a_strategy_count,a.power_type as a_power_type,a.use_count as a_use_count,a.power_count as a_power_count,
-		b.id as b_id,b.appid as b_appid,b.name as b_name,b.code as b_code,b.status as b_status,b.haspower as b_haspower,b.version as b_version,b.power_rule as b_power_rule,b.power_type as b_power_type  
-		from base_goods_function a inner join base_function b on (a.appid=? and a.goods_code=? and b.appid=? and a.function_code=b.code)`, appid, goods_code, appid)
-	l := []*base_goods_function{}
-	if list != nil {
-		for _, v := range *list {
-			a, b := map[string]interface{}{}, map[string]interface{}{}
-			for kk, vv := range v {
-				if strings.HasPrefix(kk, "a_") {
-					a[strings.TrimPrefix(kk, "a_")] = vv
-				} else if strings.HasPrefix(kk, "b_") {
-					b[strings.TrimPrefix(kk, "b_")] = vv
-				}
-			}
-			aa := JsonUnmarshal(a, &base_goods_function{}).(*base_goods_function)
-			bb := JsonUnmarshal(b, &base_function{}).(*base_function)
-			aa.Base_function = bb
-			l = append(l, aa)
-		}
-	}
-	return &l
-}

+ 24 - 0
public/entity/base_goods_spec.go

@@ -0,0 +1,24 @@
+package entity
+
+import (
+	. "app.yhyue.com/moapp/jybase/common"
+	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/db"
+)
+
+var Base_goods_spec = base_goods_spec{}
+
+//商品规格表
+type base_goods_spec struct {
+	Id                     int64
+	Appid                  string
+	Name                   string //规格名称
+	Cycle                  string //周期
+	Calculation_type       int64  //权益计算类型
+	Base_goods_spec_powers []*base_goods_spec_power
+}
+
+//根据代码查找功能详情
+func (b *base_goods_spec) FindById(id int64, appid, goodsCode string) *[]*base_goods_spec {
+	bgss := Mysql_BaseService.SelectBySql(`select * from base_goods_spec where id=? and appid=? and goods_code=? limit 1`, id, appid, goodsCode)
+	return JsonUnmarshal((*bgss)[0], &[]*base_goods_spec{}).(*[]*base_goods_spec)
+}

+ 41 - 0
public/entity/base_goods_spec_power.go

@@ -0,0 +1,41 @@
+package entity
+
+import (
+	. "app.yhyue.com/moapp/jybase/common"
+	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/db"
+)
+
+var Base_goods_spec_power = base_goods_spec_power{}
+
+//商品功能表
+type base_goods_spec_power struct {
+	Id                     int64
+	Appid                  string
+	Goods_spec_id          int64  //商品规格表id
+	Goods_code             string //商品代码
+	Function_code          string //功能代码
+	Cycle                  string //周期 d、m、y;比如:1d 7d 3m 1y
+	Limit_strategy         string //限制频率;1d:1天 1m:1个月
+	Strategy_count         int64  //频率数量
+	Power_type             int64  //权益所属类型;1:个人 2:企业
+	Use_count              int64  //使用数量
+	Power_count            int64  //授权数量;-1:默认对企业下所有人授权 0:不授权
+	Judge_repeat_mechanism int64  //判重机制;0:无 1:通用判重 2:应用判重
+	Judge_repeat_scope     int64  //判重范围;1:个人 2:部门(上一级) 3:企业
+	Judge_repeat_flag      string //判重标识;_id、projectid
+	Judge_repeat_strategy  int64  //判重策略;0:无需判重 1:通用判重 2:应用自己判重
+	Base_function          *base_function
+}
+
+//根据商品代码查找商品的功能明细
+func (b *base_goods_spec_power) FindByGoodsCode(goods_spec_id int64, appid, goods_code string) *[]*base_goods_spec_power {
+	list := Mysql_BaseService.SelectBySql(`select * from base_goods_spec_power where goods_spec_id=? and appid=? and goods_code=?`, goods_spec_id, appid, goods_code)
+	if list != nil && len(*list) > 0 {
+		bgsps := JsonUnmarshal(list, &[]*base_goods_spec_power{}).(*[]*base_goods_spec_power)
+		for _, v := range *bgsps {
+			b.Base_function = Base_function.FindByCode(appid, v.Function_code)
+		}
+		return bgsps
+	}
+	return nil
+}

+ 56 - 27
public/entity/base_power.go

@@ -2,6 +2,8 @@ package entity
 
 import (
 	"database/sql"
+	"strings"
+	"time"
 
 	. "app.yhyue.com/moapp/jybase/common"
 	. "app.yhyue.com/moapp/jybase/date"
@@ -34,7 +36,7 @@ func (b *base_power) FindMyPower(appid, function_code string, user_id, ent_id in
 }
 
 //开通权益
-func (b *base_power) OpenPower(appid, goods_code string, user_id, ent_id int64, start_time, end_time string, use_count int64, bgfs *[]*base_goods_function) bool {
+func (b *base_power) OpenPower(goods_spec_id int64, appid, goods_code string, user_id, ent_id int64, buy_num int64, bgss *[]*base_goods_spec) bool {
 	return Mysql_BaseService.ExecTx("开通权益", func(tx *sql.Tx) bool {
 		ok1, ok2 := true, true
 		//企业互斥的功能失效掉
@@ -51,36 +53,58 @@ func (b *base_power) OpenPower(appid, goods_code string, user_id, ent_id int64,
 				inner join base_function c on (c.appid=? and c.status=1 and c.power_type=1 and c.code=a.function_code) 
 				set a.status=0`, appid, user_id, appid, goods_code, appid) > -1
 		}
-		power_values, empower_values := []interface{}{}, []interface{}{}
-		for _, v := range *bgfs {
-			if v.Base_function == nil {
+		power_values, empower_values, wait_empower_values := []interface{}{}, []interface{}{}, []interface{}{}
+		for _, bgs := range *bgss {
+			if bgs.Base_goods_spec_powers == nil {
 				continue
-			} else if v.Base_function.Haspower == 0 {
-				continue
-			}
-			power_values = append(power_values, appid, v.Function_code, v.Power_type)
-			if v.Power_type == 1 {
-				power_values = append(power_values, user_id)
-			} else if v.Power_type == 2 {
-				power_values = append(power_values, ent_id)
-			} else {
-				logx.Error(appid, goods_code, v.Function_code, "无效的power_type", v.Power_type)
-				return false
 			}
-			power_values = append(power_values, start_time, end_time)
-			if v.Use_count > 0 {
-				power_values = append(power_values, v.Use_count)
-			} else {
-				power_values = append(power_values, use_count)
-			}
-			power_values = append(power_values, v.Limit_strategy, v.Strategy_count, 1, NowFormat(Date_Full_Layout))
-			//
-			if v.Power_type == 2 && v.Power_count == -1 && Base_ent_empower.Count(appid, v.Function_code, ent_id) == 0 {
-				empower_values = append(empower_values, appid, ent_id, 0, v.Function_code, NowFormat(Date_Full_Layout))
+			for _, v := range bgs.Base_goods_spec_powers {
+				if v.Base_function == nil {
+					continue
+				} else if v.Base_function.Haspower == 0 {
+					continue
+				}
+				power_values = append(power_values, appid, v.Function_code, v.Power_type)
+				if v.Power_type == 1 {
+					power_values = append(power_values, user_id)
+				} else if v.Power_type == 2 {
+					power_values = append(power_values, ent_id)
+				} else {
+					logx.Error(appid, goods_code, goods_spec_id, v.Function_code, "无效的power_type", v.Power_type)
+					continue
+				}
+				now := time.Now()
+				end := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
+				if strings.HasSuffix(v.Cycle, "d") {
+					cycle := IntAll(strings.TrimSuffix(v.Cycle, "d"))
+					end = end.AddDate(0, 0, cycle)
+				} else if strings.HasSuffix(v.Cycle, "m") {
+					cycle := IntAll(strings.TrimSuffix(v.Cycle, "m"))
+					end = end.AddDate(0, cycle, 0)
+				} else if strings.HasSuffix(v.Cycle, "y") {
+					cycle := IntAll(strings.TrimSuffix(v.Cycle, "y"))
+					end = end.AddDate(cycle, 0, 0)
+				} else {
+					logx.Error(appid, goods_code, goods_spec_id, v.Function_code, "无效的cycle", v.Cycle)
+					continue
+				}
+				starat_time, end_time := NowFormat(Date_Full_Layout), FormatDate(&end, Date_Full_Layout)
+				power_values = append(power_values, start_time, end_time)
+				use_count := buy_num
+				if bgs.Calculation_type == 2 {
+					use_count = buy_num * v.Use_count
+				}
+				power_values = append(power_values, use_count, v.Limit_strategy, v.Strategy_count, 1, NowFormat(Date_Full_Layout))
+				//
+				if v.Power_type == 2 && v.Power_count == -1 && Base_ent_empower.Count(appid, v.Function_code, ent_id) == 0 {
+					empower_values = append(empower_values, appid, ent_id, 0, v.Function_code, NowFormat(Date_Full_Layout))
+				} else if v.Power_type == 2 && v.Power_count > 0 {
+					wait_empower_values = append(wait_empower_values, appid, v.Id, ent_id, starat_time, end_time, use_count, v.Power_count, v.Limit_strategy, NowFormat(Date_Full_Layout))
+				}
 			}
 		}
 		if len(power_values) == 0 {
-			logx.Error(appid, goods_code, user_id, ent_id, "没有找到需要开通的权益")
+			logx.Error(appid, goods_code, goods_spec_id, user_id, ent_id, "没有找到需要开通的权益")
 			return false
 		}
 		v1, v2 := Mysql_BaseService.InsertBatchByTx(tx, "base_power", []string{"appid", "function_code", "power_type", "power_ofid", "start_time", "end_time", "use_count", "limit_strategy", "strategy_count", "status", "create_time"}, power_values)
@@ -89,7 +113,12 @@ func (b *base_power) OpenPower(appid, goods_code string, user_id, ent_id int64,
 			v3, v4 := Mysql_BaseService.InsertBatchByTx(tx, "base_ent_empower", []string{"appid", "ent_id", "ent_user_id", "function_code", "create_time"}, empower_values)
 			ok3 = v3 > 0 && v4 > 0
 		}
-		return ok1 && ok2 && v1 > 0 && v2 > 0 && ok3
+		ok4 := true
+		if len(wait_empower_values) > 0 {
+			v5, v6 := Mysql_BaseService.InsertBatchByTx(tx, "base_ent_wait_empower", []string{"appid", "goods_spec_power_id", "ent_id", "start_time", "end_time", "use_count", "empower_count", "limit_strategy", "create_time"}, wait_empower_values)
+			ok4 = v5 > 0 && v6 > 0
+		}
+		return ok1 && ok2 && v1 > 0 && v2 > 0 && ok3 && ok4
 	})
 }
 

+ 6 - 10
rpc/internal/logic/powerhandlelogic.go

@@ -38,18 +38,14 @@ func (l *PowerHandleLogic) PowerHandle(in *pb.PowerReq) (*pb.Resp, error) {
 		return resp, nil
 	}
 	if in.Type == 1 { //开通
-		if in.StartTime == "" {
-			l.Error(fmt.Sprintf("%+v", in), "无效的参数start_time")
-			return resp, nil
-		} else if in.EndTime == "" {
-			l.Error(fmt.Sprintf("%+v", in), "无效的参数end_time")
-			return resp, nil
-		}
-		list := Base_goods_function.FindByGoodsCode(in.Appid, in.GoodsCode)
+		list := Base_goods_spec.FindById(in.GoodsSpecId, in.Appid, in.GoodsCode)
 		if list != nil {
-			if Base_power.OpenPower(in.Appid, in.GoodsCode, in.UserId, in.EntId, in.StartTime, in.EndTime, in.UseCount, list) {
+			if Base_power.OpenPower(in.GoodsSpecId, in.Appid, in.GoodsCode, in.UserId, in.EntId, in.BuyNum, list) {
 				return &pb.Resp{Status: 1}, nil
 			}
+		} else {
+			l.Error(fmt.Sprintf("%+v", in), "没有找到该商品规格")
+			return resp, nil
 		}
 	} else if in.Type == -1 { //取消
 		if Base_power.CancelPower(in.Appid, in.GoodsCode, in.UserId, in.EntId) {
@@ -59,5 +55,5 @@ func (l *PowerHandleLogic) PowerHandle(in *pb.PowerReq) (*pb.Resp, error) {
 		l.Error(fmt.Sprintf("%+v", in), "无效的参数type")
 		return resp, nil
 	}
-	return &pb.Resp{}, nil
+	return resp, nil
 }

+ 56 - 66
rpc/pb/resource.pb.go

@@ -25,14 +25,13 @@ type PowerReq struct {
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 
-	Appid     string `protobuf:"bytes,1,opt,name=appid,proto3" json:"appid,omitempty"`
-	GoodsCode string `protobuf:"bytes,2,opt,name=goods_code,json=goodsCode,proto3" json:"goods_code,omitempty"` //商品代码
-	EntId     int64  `protobuf:"varint,3,opt,name=ent_id,json=entId,proto3" json:"ent_id,omitempty"`            //企业id
-	UserId    int64  `protobuf:"varint,4,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`         //用户id
-	UseCount  int64  `protobuf:"varint,5,opt,name=use_count,json=useCount,proto3" json:"use_count,omitempty"`   //数量
-	StartTime string `protobuf:"bytes,6,opt,name=start_time,json=startTime,proto3" json:"start_time,omitempty"` //开始时间
-	EndTime   string `protobuf:"bytes,7,opt,name=end_time,json=endTime,proto3" json:"end_time,omitempty"`       //结束时间
-	Type      int64  `protobuf:"varint,8,opt,name=type,proto3" json:"type,omitempty"`                           //操作类型 1:开通权益 -1:取消权益
+	Appid       string `protobuf:"bytes,1,opt,name=appid,proto3" json:"appid,omitempty"`
+	GoodsCode   string `protobuf:"bytes,2,opt,name=goods_code,json=goodsCode,proto3" json:"goods_code,omitempty"`          //商品代码
+	GoodsSpecId int64  `protobuf:"varint,3,opt,name=goods_spec_id,json=goodsSpecId,proto3" json:"goods_spec_id,omitempty"` //商品规格id
+	EntId       int64  `protobuf:"varint,4,opt,name=ent_id,json=entId,proto3" json:"ent_id,omitempty"`                     //企业id
+	UserId      int64  `protobuf:"varint,5,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`                  //用户id
+	BuyNum      int64  `protobuf:"varint,6,opt,name=buy_num,json=buyNum,proto3" json:"buy_num,omitempty"`                  //购买的数量或者购买的份数
+	Type        int64  `protobuf:"varint,7,opt,name=type,proto3" json:"type,omitempty"`                                    //操作类型 1:开通权益 -1:取消权益
 }
 
 func (x *PowerReq) Reset() {
@@ -81,39 +80,32 @@ func (x *PowerReq) GetGoodsCode() string {
 	return ""
 }
 
-func (x *PowerReq) GetEntId() int64 {
+func (x *PowerReq) GetGoodsSpecId() int64 {
 	if x != nil {
-		return x.EntId
+		return x.GoodsSpecId
 	}
 	return 0
 }
 
-func (x *PowerReq) GetUserId() int64 {
+func (x *PowerReq) GetEntId() int64 {
 	if x != nil {
-		return x.UserId
+		return x.EntId
 	}
 	return 0
 }
 
-func (x *PowerReq) GetUseCount() int64 {
+func (x *PowerReq) GetUserId() int64 {
 	if x != nil {
-		return x.UseCount
+		return x.UserId
 	}
 	return 0
 }
 
-func (x *PowerReq) GetStartTime() string {
+func (x *PowerReq) GetBuyNum() int64 {
 	if x != nil {
-		return x.StartTime
+		return x.BuyNum
 	}
-	return ""
-}
-
-func (x *PowerReq) GetEndTime() string {
-	if x != nil {
-		return x.EndTime
-	}
-	return ""
+	return 0
 }
 
 func (x *PowerReq) GetType() int64 {
@@ -340,51 +332,49 @@ var File_resource_proto protoreflect.FileDescriptor
 
 var file_resource_proto_rawDesc = []byte{
 	0x0a, 0x0e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
-	0x22, 0xda, 0x01, 0x0a, 0x08, 0x50, 0x6f, 0x77, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x14, 0x0a,
+	0x22, 0xc0, 0x01, 0x0a, 0x08, 0x50, 0x6f, 0x77, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x14, 0x0a,
 	0x05, 0x61, 0x70, 0x70, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x70,
 	0x70, 0x69, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x67, 0x6f, 0x6f, 0x64, 0x73, 0x5f, 0x63, 0x6f, 0x64,
 	0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x67, 0x6f, 0x6f, 0x64, 0x73, 0x43, 0x6f,
-	0x64, 0x65, 0x12, 0x15, 0x0a, 0x06, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01,
-	0x28, 0x03, 0x52, 0x05, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65,
-	0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72,
-	0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x75, 0x73, 0x65, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18,
-	0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x75, 0x73, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12,
-	0x1d, 0x0a, 0x0a, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20,
-	0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x19,
-	0x0a, 0x08, 0x65, 0x6e, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09,
-	0x52, 0x07, 0x65, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70,
-	0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x9a, 0x01,
-	0x0a, 0x0d, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x50, 0x6f, 0x77, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12,
-	0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05,
-	0x61, 0x70, 0x70, 0x69, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f,
-	0x6e, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x66, 0x75,
-	0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73,
-	0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x75, 0x73, 0x65,
-	0x72, 0x49, 0x64, 0x12, 0x15, 0x0a, 0x06, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20,
-	0x01, 0x28, 0x03, 0x52, 0x05, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0b, 0x65, 0x6e,
-	0x74, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52,
-	0x09, 0x65, 0x6e, 0x74, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0xa1, 0x01, 0x0a, 0x0c, 0x44,
-	0x65, 0x64, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x14, 0x0a, 0x05, 0x61,
-	0x70, 0x70, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x70, 0x70, 0x69,
-	0x64, 0x12, 0x23, 0x0a, 0x0d, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x63, 0x6f,
-	0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69,
-	0x6f, 0x6e, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x15, 0x0a, 0x06, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64,
-	0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x17, 0x0a,
-	0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06,
-	0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18,
-	0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x10, 0x0a, 0x03,
-	0x69, 0x64, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x09, 0x52, 0x03, 0x69, 0x64, 0x73, 0x22, 0x1e,
-	0x0a, 0x04, 0x52, 0x65, 0x73, 0x70, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73,
-	0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x32, 0x73,
-	0x0a, 0x08, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x50, 0x6f,
-	0x77, 0x65, 0x72, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x12, 0x09, 0x2e, 0x50, 0x6f, 0x77, 0x65,
-	0x72, 0x52, 0x65, 0x71, 0x1a, 0x05, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x12, 0x23, 0x0a, 0x0a, 0x43,
-	0x68, 0x65, 0x63, 0x6b, 0x50, 0x6f, 0x77, 0x65, 0x72, 0x12, 0x0e, 0x2e, 0x43, 0x68, 0x65, 0x63,
-	0x6b, 0x50, 0x6f, 0x77, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x05, 0x2e, 0x52, 0x65, 0x73, 0x70,
-	0x12, 0x21, 0x0a, 0x09, 0x44, 0x65, 0x64, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x0d, 0x2e,
-	0x44, 0x65, 0x64, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x1a, 0x05, 0x2e, 0x52,
-	0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f,
-	0x74, 0x6f, 0x33,
+	0x64, 0x65, 0x12, 0x22, 0x0a, 0x0d, 0x67, 0x6f, 0x6f, 0x64, 0x73, 0x5f, 0x73, 0x70, 0x65, 0x63,
+	0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x67, 0x6f, 0x6f, 0x64, 0x73,
+	0x53, 0x70, 0x65, 0x63, 0x49, 0x64, 0x12, 0x15, 0x0a, 0x06, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64,
+	0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x17, 0x0a,
+	0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06,
+	0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x62, 0x75, 0x79, 0x5f, 0x6e, 0x75,
+	0x6d, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x62, 0x75, 0x79, 0x4e, 0x75, 0x6d, 0x12,
+	0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74,
+	0x79, 0x70, 0x65, 0x22, 0x9a, 0x01, 0x0a, 0x0d, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x50, 0x6f, 0x77,
+	0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x69, 0x64, 0x18, 0x01,
+	0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x70, 0x70, 0x69, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x66,
+	0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01,
+	0x28, 0x09, 0x52, 0x0c, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x64, 0x65,
+	0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28,
+	0x03, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x15, 0x0a, 0x06, 0x65, 0x6e, 0x74,
+	0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x65, 0x6e, 0x74, 0x49, 0x64,
+	0x12, 0x1e, 0x0a, 0x0b, 0x65, 0x6e, 0x74, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18,
+	0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x65, 0x6e, 0x74, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64,
+	0x22, 0xa1, 0x01, 0x0a, 0x0c, 0x44, 0x65, 0x64, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65,
+	0x71, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
+	0x52, 0x05, 0x61, 0x70, 0x70, 0x69, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x66, 0x75, 0x6e, 0x63, 0x74,
+	0x69, 0x6f, 0x6e, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c,
+	0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x15, 0x0a, 0x06,
+	0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x65, 0x6e,
+	0x74, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04,
+	0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05,
+	0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x6f, 0x75,
+	0x6e, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x69, 0x64, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x09, 0x52,
+	0x03, 0x69, 0x64, 0x73, 0x22, 0x1e, 0x0a, 0x04, 0x52, 0x65, 0x73, 0x70, 0x12, 0x16, 0x0a, 0x06,
+	0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74,
+	0x61, 0x74, 0x75, 0x73, 0x32, 0x73, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65,
+	0x12, 0x1f, 0x0a, 0x0b, 0x50, 0x6f, 0x77, 0x65, 0x72, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x12,
+	0x09, 0x2e, 0x50, 0x6f, 0x77, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x05, 0x2e, 0x52, 0x65, 0x73,
+	0x70, 0x12, 0x23, 0x0a, 0x0a, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x50, 0x6f, 0x77, 0x65, 0x72, 0x12,
+	0x0e, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x50, 0x6f, 0x77, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a,
+	0x05, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x12, 0x21, 0x0a, 0x09, 0x44, 0x65, 0x64, 0x75, 0x63, 0x74,
+	0x69, 0x6f, 0x6e, 0x12, 0x0d, 0x2e, 0x44, 0x65, 0x64, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52,
+	0x65, 0x71, 0x1a, 0x05, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70,
+	0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (

+ 6 - 7
rpc/resource.proto

@@ -4,13 +4,12 @@ option go_package="./pb";
 
 message PowerReq {
   string appid = 1;
-  string goods_code = 2; //商品代码
-  int64 ent_id = 3;      //企业id
-  int64 user_id = 4;     //用户id
-  int64 use_count = 5;   //数量
-  string start_time = 6; //开始时间
-  string end_time = 7;   //结束时间
-  int64 type = 8;        //操作类型 1:开通权益 -1:取消权益
+  string goods_code = 2; 	//商品代码
+  int64 goods_spec_id = 3;  //商品规格id
+  int64 ent_id = 4;         //企业id
+  int64 user_id = 5;     	//用户id
+  int64 buy_num = 6;     	//购买的数量或者购买的份数
+  int64 type = 7;        	//操作类型 1:开通权益 -1:取消权益
 }
 
 message CheckPowerReq {

BIN
rpc/rpc


BIN
rpc/rpc.exe


+ 17 - 4
test/resource.go

@@ -21,8 +21,10 @@ var c = resource.NewResource(zrpc.MustNewClient(zrpc.RpcClientConf{
 func main() {
 	m := flag.Int("m", 0, "")
 	flag.Parse()
-	if *m == 1 {
-		PowerHandle()
+	if *m == -1 {
+		CancelPowerHandle()
+	} else if *m == 1 {
+		OpenPowerHandle()
 	} else if *m == 2 {
 		CheckPower()
 	} else if *m == 3 {
@@ -31,7 +33,7 @@ func main() {
 }
 
 //开通或者取消用户/企业权益
-func PowerHandle() {
+func OpenPowerHandle() {
 	r, err := c.PowerHandle(context.Background(), &pb.PowerReq{
 		Appid:     "10000",
 		GoodsCode: "xxfb_gyxx",
@@ -43,12 +45,23 @@ func PowerHandle() {
 	log.Println("----------", r.Status, err)
 }
 
+//开通或者取消用户/企业权益
+func CancelPowerHandle() {
+	r, err := c.PowerHandle(context.Background(), &pb.PowerReq{
+		Appid:     "10000",
+		GoodsCode: "xxfb_gyxx",
+		EntId:     55,
+		Type:      -1,
+	})
+	log.Println("----------", r.Status, err)
+}
+
 //检查用户/企业权益
 func CheckPower() {
 	r, err := c.CheckPower(context.Background(), &pb.CheckPowerReq{
 		Appid:        "10000",
 		FunctionCode: "xxfb_gyxx_add",
-		EntId:        55,
+		EntId:        14829,
 	})
 	log.Println("----------", r.Status, err)
 }

BIN
test/test.exe