wangchuanjin 3 роки тому
батько
коміт
5ecb3acc10

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module bp.jydev.jianyu360.cn/BaseService/resourceCenter
 go 1.18
 
 require (
-	app.yhyue.com/moapp/jybase v0.0.0-20220415064050-37ce64b3e2d4
+	app.yhyue.com/moapp/jybase v0.0.0-20220418104200-46c3fff161c7
 	github.com/zeromicro/go-zero v1.3.2
 	google.golang.org/grpc v1.45.0
 	google.golang.org/protobuf v1.28.0

+ 2 - 2
go.sum

@@ -1,6 +1,6 @@
 app.yhyue.com/moapp/esv1 v0.0.0-20220414031211-3da4123e648d/go.mod h1:91/lSD/hS+ckMVP3WdidRzDhC60lLMdyce9QHy0cSMA=
-app.yhyue.com/moapp/jybase v0.0.0-20220415064050-37ce64b3e2d4 h1:da6H5iMYf7aQ2CtO5pXSN9hDul1w1CvkjnsDgh9S3+o=
-app.yhyue.com/moapp/jybase v0.0.0-20220415064050-37ce64b3e2d4/go.mod h1:qNRA0sHuYqcLoYoP8irpaWnW9YsXixe6obBIkwaXpD0=
+app.yhyue.com/moapp/jybase v0.0.0-20220418104200-46c3fff161c7 h1:LqxpxJvesxVSlXW+kgRntHd35wkw490TaKQXcLbDJfw=
+app.yhyue.com/moapp/jybase v0.0.0-20220418104200-46c3fff161c7/go.mod h1:qNRA0sHuYqcLoYoP8irpaWnW9YsXixe6obBIkwaXpD0=
 cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
 cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
 cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=

+ 1 - 1
rpc/internal/entity/base_ent_empower.go

@@ -9,7 +9,7 @@ var Base_ent_empower = base_ent_empower{}
 
 //企业授权表
 type base_ent_empower struct {
-	Id            int
+	Id            int64
 	Appid         string
 	Ent_id        int64  //企业id
 	Ent_user_id   int64  //企业员工id

+ 5 - 3
rpc/internal/entity/base_function.go

@@ -9,13 +9,15 @@ var Base_function = base_function{}
 
 //功能原始表
 type base_function struct {
-	Id         int
+	Id         int64
 	Appid      string
 	Name       string //功能名称
 	Code       string //功能代码
-	Status     int    //0:不可用 1:可用
+	Status     int64  //0:不可用 1:可用
+	Haspower   int64  //能否生成用户权益;0:否 1:是
 	Version    string //版本号
-	Power_rule int    //校验权限规则;1:仅周期 2:周期+数量 3:周期+频率+数量
+	Power_rule int64  //校验权限规则;1:仅周期 2:周期+数量 3:周期+频率+数量
+	Power_type int64  //权限类型;1:互斥 2:兼容
 }
 
 //根据代码查找功能详情

+ 28 - 6
rpc/internal/entity/base_goods_function.go

@@ -1,6 +1,8 @@
 package entity
 
 import (
+	"strings"
+
 	. "app.yhyue.com/moapp/jybase/common"
 	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/db"
 )
@@ -9,17 +11,37 @@ var Base_goods_function = base_goods_function{}
 
 //商品功能表
 type base_goods_function struct {
-	Id             int
+	Id             int64
 	Appid          string
 	Goods_code     string //商品代码
 	Function_code  string //功能代码
-	Limit_strategy string //限制频率;7d:7天 1m:1个月
-	Strategy_count string //频率数量
-	Power_type     string //权益所属类型;1:个人 2:企业
+	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 * from base_goods_function where appid=? and goods_code=?`, appid, goods_code)
-	return JsonUnmarshal(list, &[]base_goods_function{}).(*[]*base_goods_function)
+	list := Mysql_BaseService.SelectBySql(`select a.*,b.* 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(list, &base_function{}).(*base_function)
+			aa.Base_function = bb
+			l = append(l, aa)
+		}
+	}
+	return &l
 }

+ 90 - 8
rpc/internal/entity/base_power.go

@@ -1,28 +1,110 @@
 package entity
 
 import (
+	"database/sql"
+
 	. "app.yhyue.com/moapp/jybase/common"
+	. "app.yhyue.com/moapp/jybase/date"
 	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/db"
+	"github.com/zeromicro/go-zero/core/logx"
 )
 
 var Base_power = base_power{}
 
 //企业/用户权益表
 type base_power struct {
-	Id             int
+	Id             int64
 	Appid          string
 	Function_code  string //功能代码
-	Power_type     int    //权益所属类型;1:个人 2:企业
-	Power_ofid     int    //权益所属id;个人id/企业id/部门id/员工id
+	Power_type     int64  //权益所属类型;1:个人 2:企业
+	Power_ofid     int64  //权益所属id;个人id/企业id/部门id/员工id
 	Start_time     string //开始时间
 	End_time       string //结束时间
-	Count          int    //数量
-	Limit_strategy string //限制频率;7d:7天 1m:1个月
-	Strategy_count int    //频率数量
+	Use_count      int64  //使用数量
+	Surplus_count  int64  //剩余数量
+	Limit_strategy string //限制频率;1d:1天 1m:1个月
+	Strategy_count int64  //频率数量
 }
 
 //查找我的权益
-func (b *base_power) FindMyPower(appid, function_code string, ent_id, user_id int64) *[]*base_power {
-	list := Mysql_BaseService.SelectBySql(`select * from base_power where appid=? and function_code=? and (power_ofid=? or power_ofid=?) and status=1`, appid, function_code, ent_id, user_id)
+func (b *base_power) FindMyPower(appid, function_code string, user_id, ent_id int64) *[]*base_power {
+	now := NowFormat(Date_Full_Layout)
+	list := Mysql_BaseService.SelectBySql(`select * from base_power where appid=? and function_code=? and ((power_type=1 and power_ofid=?) or (power_type=2 and power_ofid=?)) and end_time>? and status=1 order by power_type`, appid, function_code, user_id, ent_id, now)
 	return JsonUnmarshal(list, &[]base_power{}).(*[]*base_power)
 }
+
+//开通权益
+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 {
+	return Mysql_BaseService.ExecTx("开通权益", func(tx *sql.Tx) bool {
+		ok1, ok2 := true, true
+		//企业互斥的功能失效掉
+		if ent_id > 0 {
+			ok1 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_function b 
+				on (a.appid=? and a.power_type=2 and a.power_ofid=? and b.appid=? and a.goods_code=? and a.function_code=b.function_code) 
+				inner join base_function c on (c.appid=? and c.status=1 and power_type=1 and code=a.function_code) 
+				set a.status=0`, appid, ent_id, appid, goods_code) > -1
+		}
+		//用户互斥的功能失效掉
+		if user_id > 0 {
+			ok2 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_function b 
+				on (a.appid=? and a.power_type=2 and a.power_ofid=? and b.appid=? and a.goods_code=? and a.function_code=b.function_code) 
+				inner join base_function c on (c.appid=? and c.status=1 and power_type=1 and code=a.function_code) 
+				set a.status=0`, appid, user_id, appid, goods_code) > -1
+		}
+		power_values, empower_values := []interface{}{}, []interface{}{}
+		for _, v := range *bgfs {
+			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 {
+				empower_values = append(empower_values, appid, ent_id, 0, v.Function_code, NowFormat(Date_Full_Layout))
+			}
+		}
+		if len(power_values) == 0 {
+			logx.Error(appid, goods_code, 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", "count", "limit_strategy", "strategy_count", "status", "create_time"}, power_values)
+		ok3 := true
+		if len(empower_values) > 0 {
+			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
+	})
+}
+
+//取消权益
+func (b *base_power) CancelPower(appid, goods_code string, user_id, ent_id int64) bool {
+	return Mysql_BaseService.ExecTx("取消权益", func(tx *sql.Tx) bool {
+		ok1, ok2 := false, false
+		if ent_id > 0 {
+			ok1 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_function b 
+				on (a.appid=? and a.power_type=1 and a.power_ofid=? and b.appid=? and a.goods_code=? and b.power_type=1 and a.function_code=b.function_code) 
+				set a.status=-1`, appid, user_id, appid, goods_code) > 0
+		}
+		if user_id > 0 {
+			ok2 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_function b 
+				on (a.appid=? and a.power_type=2 and a.power_ofid=? and b.appid=? and a.goods_code=? and b.power_type=2 and a.function_code=b.function_code) 
+				set a.status=-1`, appid, ent_id, appid, goods_code) > 0
+		}
+		return ok1 || ok2
+	})
+}

+ 49 - 13
rpc/internal/entity/base_resource_use.go

@@ -1,6 +1,7 @@
 package entity
 
 import (
+	"database/sql"
 	"errors"
 
 	. "app.yhyue.com/moapp/jybase/common"
@@ -11,24 +12,59 @@ var Base_resource_use = base_resource_use{}
 
 //资源充值/消耗表
 type base_resource_use struct {
-	Id              int
-	Appid           string
-	Ent_id          int64  //企业id
-	User_id         int64  //用户id
-	Function_code   string //功能代码
-	Add_count       int    //新增数量
-	Surplus_count   int    //剩余数量
-	Deduction_count int    //扣除数量
+	Id            int64
+	Appid         string
+	Ent_id        int64  //企业id
+	User_id       int64  //用户id
+	Function_code string //功能代码
+	Add_count     int64  //新增数量
+	Surplus_count int64  //剩余数量
+	Deduct_count  int64  //扣除数量
+	Create_time   string //创建时间
 }
 
 //查找最新一条的权益使用记录
-func (b *base_resource_use) FindLastOneByEntId(appid, function_code string, ent_id int64) (*base_resource_use, error) {
-	list := Mysql_BaseService.SelectBySql(`select * from base_resource_use where appid=? and function_code=? and ent_id=? limit 1`, appid, function_code, ent_id)
+func (b *base_resource_use) FindLastOne(appid, function_code string, user_id, ent_id, power_type int64) (*base_resource_use, error) {
+	query := `select * from base_resource_use where appid=? and function_code=?`
+	args := []interface{}{appid, function_code}
+	if power_type == 1 {
+		query += ` and user_id=?`
+		args = append(args, user_id)
+	} else if power_type == 2 {
+		query += ` and ent_id=?`
+		args = append(args, ent_id)
+	} else {
+		return nil, errors.New("power_type error")
+	}
+	query += ` order by create_time desc limit 1`
+	list := Mysql_BaseService.SelectBySql(query, args)
 	if list == nil {
 		return nil, errors.New("find error")
 	}
-	if list != nil && len(*list) == 1 {
-		return JsonUnmarshal((*list)[0], &base_resource_use{}).(*base_resource_use), nil
+	if len(*list) == 0 {
+		return nil, nil
+	}
+	r, err := JsonUnmarshalByErr((*list)[0], &base_resource_use{})
+	if err == nil {
+		return r.(*base_resource_use), nil
 	}
-	return nil, nil
+	return nil, err
+}
+
+//新增扣减记录
+func (b *base_resource_use) Deduction(use_values []interface{}, detail_values [][]interface{}, update [][]interface{}) bool {
+	return Mysql_BaseService.ExecTx("新增扣减记录", func(tx *sql.Tx) bool {
+		v1, v2 := Mysql_BaseService.InsertBatchByTx(tx, "base_resource_use", []string{"appid", "ent_id", "user_id", "function_code", "add_count", "surplus_count", "deduction_count", "create_time"}, use_values)
+		array := []interface{}{}
+		for _, v := range detail_values {
+			array = append(array, v...)
+			array = append(array, v2)
+		}
+		v3, v4 := Mysql_BaseService.InsertBatchByTx(tx, "base_resource_use_detail", []string{"appid", "power_id", "surplus_count", "deduction_count", "create_time", "use_id"}, array)
+		ok := true
+		if len(update) > 0 {
+			ok = Mysql_BaseService.UpdateBathByTx(tx, "base_power", []string{"id", "surplus_count", "update_time"}, update) == int64(len(update))
+		}
+		return v1 > 0 && v2 > 0 && v3 > 0 && v4 > 0 && ok
+	})
 }

+ 14 - 0
rpc/internal/entity/base_resource_use_detail.go

@@ -0,0 +1,14 @@
+package entity
+
+var Base_resource_use_detail = base_resource_use_detail{}
+
+//消耗明细表
+type base_resource_use_detail struct {
+	Id            int64
+	Appid         string
+	Use_id        int64  //消耗表id
+	Power_id      int64  //权益id
+	Surplus_count int64  //扣除数量
+	Deduct_count  int64  //扣除数量
+	Create_time   string //创建时间
+}

+ 78 - 53
rpc/internal/logic/checkpowerlogic.go

@@ -2,6 +2,7 @@ package logic
 
 import (
 	"context"
+	"fmt"
 	"time"
 
 	. "app.yhyue.com/moapp/jybase/date"
@@ -26,82 +27,106 @@ func NewCheckPowerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckP
 	}
 }
 
+//检查用户权益
 func (l *CheckPowerLogic) CheckPower(in *pb.CheckPowerReq) (*pb.Resp, error) {
+	l.Info("检查用户权益请求参数", fmt.Sprintf("%+v", in))
 	resp := &pb.Resp{}
+	if in.Appid == "" {
+		l.Error(fmt.Sprintf("%+v", in), "无效的参数appid")
+		return resp, nil
+	} else if in.FunctionCode == "" {
+		l.Error(fmt.Sprintf("%+v", in), "无效的参数function_code")
+		return resp, nil
+	} else if in.UserId == 0 && in.EntId == 0 && in.EntUserId == 0 {
+		l.Error(fmt.Sprintf("%+v", in), "无效的参数user_id、ent_id、ent_user_id")
+		return resp, nil
+	}
 	function := Base_function.FindByCode(in.Appid, in.FunctionCode)
 	if function == nil {
-		l.Error(in.Appid, in.FunctionCode, in.EntId, in.UserId, "功能原始表中没有找到该功能")
+		l.Error(fmt.Sprintf("%+v", in), "功能原始表中没有找到该功能")
 		return resp, nil
 	}
-	myPowers := Base_power.FindMyPower(in.Appid, in.FunctionCode, in.EntId, in.UserId)
+	myPowers := Base_power.FindMyPower(in.Appid, in.FunctionCode, in.UserId, in.EntId)
 	if myPowers == nil || len(*myPowers) == 0 {
-		l.Error(in.Appid, in.FunctionCode, in.EntId, in.UserId, "功能权益表中没有找到权益记录")
-		return resp, nil
-	}
-	isPass := false
-	for _, v := range *myPowers {
-		start, err := time.ParseInLocation(Date_Full_Layout, v.Start_time, time.Local)
-		if err != nil {
-			l.Error(in.Appid, in.FunctionCode, in.EntId, in.UserId, "开始时间转化错误", err)
-			return resp, nil
-		}
-		end, err := time.ParseInLocation(Date_Full_Layout, v.End_time, time.Local)
-		if err != nil {
-			l.Error(in.Appid, in.FunctionCode, in.EntId, in.UserId, "结束时间转化错误", err)
-			return resp, nil
-		}
-		if time.Now().After(start) && time.Now().Before(end) {
-			isPass = true
-		}
-	}
-	if !isPass {
 		resp.Status = -1
-		l.Info(in.Appid, in.FunctionCode, in.EntId, in.UserId, "不在有效期内")
+		l.Info(fmt.Sprintf("%+v", in), "不在有效期内")
 		return resp, nil
 	}
-	if function.Power_rule == 1 {
+	if function.Power_rule == 1 { //只对周期进行校验
 		resp.Status = 1
 		return resp, nil
 	} else {
-		if function.Power_rule == 3 {
-			hasEmpower := false
-			if (*myPowers)[0].Power_type == 2 {
+		for _, v := range *myPowers {
+			if v.Power_type == 2 {
+				hasEmpower := false
 				empower := Base_ent_empower.FindMyEntId(in.Appid, in.FunctionCode, in.EntId)
-				if empower == nil || len(*empower) == 0 {
+				if empower != nil {
+					if len(*empower) == 1 {
+						if (*empower)[0].Ent_user_id == 0 {
+							hasEmpower = true
+						}
+					} else {
+						for _, vv := range *empower {
+							if vv.Ent_id == in.EntId && vv.Ent_user_id == in.EntUserId {
+								hasEmpower = true
+								break
+							}
+						}
+					}
+				}
+				if !hasEmpower {
 					resp.Status = -3
-					l.Error(in.Appid, in.FunctionCode, in.EntId, in.UserId, "没有授权记录")
+					l.Info(fmt.Sprintf("%+v", in), "没有对该用户进行授权")
 					return resp, nil
 				}
-				if len(*empower) == 1 {
-					if (*empower)[0].Ent_user_id == 0 {
-						hasEmpower = true
+			}
+			if function.Power_rule == 2 { //周期+数量校验
+				if v.Surplus_count > 0 {
+					resp.Status = 1
+					return resp, nil
+				}
+			} else if function.Power_rule == 3 { //周期+频率+数量校验
+				use, err := Base_resource_use.FindLastOne(in.Appid, in.FunctionCode, in.UserId, in.EntId, v.Power_type)
+				if err != nil {
+					l.Error(fmt.Sprintf("%+v", in), "查询资源使用记录失败")
+					return resp, nil
+				} else if use == nil {
+					resp.Status = 1
+					return resp, nil
+				}
+				create_time, err := time.ParseInLocation(Date_Full_Layout, use.Create_time, time.Local)
+				if err != nil {
+					l.Error(fmt.Sprintf("%+v", in), "资源充值/消耗表创建时间错误", create_time, err)
+					return resp, nil
+				}
+				now := time.Now()
+				if (*myPowers)[0].Limit_strategy == "1d" {
+					if create_time.Year() == now.Year() && create_time.Month() == now.Month() && create_time.Day() == now.Day() {
+						if use.Surplus_count > 0 {
+							resp.Status = 1
+							return resp, nil
+						}
+					} else {
+						resp.Status = 1
+						return resp, nil
 					}
-				} else {
-					for _, v := range *empower {
-						if v.Ent_user_id == in.UserId {
-							hasEmpower = true
-							break
+				} else if (*myPowers)[0].Limit_strategy == "1m" {
+					if create_time.Year() == now.Year() && create_time.Month() == now.Month() {
+						if use.Surplus_count > 0 {
+							resp.Status = 1
+							return resp, nil
 						}
+					} else {
+						resp.Status = 1
+						return resp, nil
 					}
+				} else {
+					l.Error(fmt.Sprintf("%+v", in), "limit_strategy格式错误", (*myPowers)[0].Limit_strategy)
+					return resp, nil
 				}
-			} else {
-				hasEmpower = true
-			}
-			if !hasEmpower {
-				resp.Status = -3
-				l.Info(in.Appid, in.FunctionCode, in.EntId, in.UserId, "没有对该用户进行授权")
-				return resp, nil
-			}
-			use, err := Base_resource_use.FindLastOneByEntId(in.Appid, in.FunctionCode, in.EntId)
-			if err != nil {
-				l.Error(in.Appid, in.FunctionCode, in.EntId, in.UserId, "查询资源使用记录失败")
-				return resp, nil
-			} else if use == nil {
-				resp.Status = 1
-				return resp, nil
 			}
-			//limit_strategy := (*myPowers)[0].Limit_strategy
 		}
+		resp.Status = -2
 		return resp, nil
 	}
 	return resp, nil

+ 125 - 3
rpc/internal/logic/deductionlogic.go

@@ -2,7 +2,11 @@ package logic
 
 import (
 	"context"
+	"fmt"
+	"time"
 
+	. "app.yhyue.com/moapp/jybase/date"
+	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/entity"
 	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/svc"
 	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
 
@@ -23,8 +27,126 @@ func NewDeductionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Deducti
 	}
 }
 
+//资源扣减
 func (l *DeductionLogic) Deduction(in *pb.DeductionReq) (*pb.Resp, error) {
-	// todo: add your logic here and delete this line
-
-	return &pb.Resp{}, nil
+	l.Info("资源扣减请求参数", fmt.Sprintf("%+v", in))
+	resp := &pb.Resp{}
+	if in.Appid == "" {
+		l.Error(fmt.Sprintf("%+v", in), "无效的参数appid")
+		return resp, nil
+	} else if in.FunctionCode == "" {
+		l.Error(fmt.Sprintf("%+v", in), "无效的参数function_code")
+		return resp, nil
+	} else if in.Count <= 0 {
+		l.Error(fmt.Sprintf("%+v", in), "无效的参数count")
+		return resp, nil
+	} else if in.UserId == 0 && in.EntId == 0 {
+		l.Error(fmt.Sprintf("%+v", in), "无效的参数user_id、ent_id")
+		return resp, nil
+	}
+	function := Base_function.FindByCode(in.Appid, in.FunctionCode)
+	if function == nil {
+		l.Error(fmt.Sprintf("%+v", in), "功能原始表中没有找到该功能")
+		return resp, nil
+	}
+	myPowers := Base_power.FindMyPower(in.Appid, in.FunctionCode, in.UserId, in.EntId)
+	if myPowers == nil || len(*myPowers) == 0 {
+		resp.Status = -1
+		l.Error(fmt.Sprintf("%+v", in), "功能权益表中没有找到权益记录")
+		return resp, nil
+	}
+	use_values, detail_values := []interface{}{}, [][]interface{}{}
+	update := [][]interface{}{}
+	surplus_count := int64(-1)
+	deduct_count := in.Count
+	user_id, ent_id := int64(0), int64(0)
+	if function.Power_rule == 2 { //周期+数量
+		my_surplus_count := int64(0)
+		for _, v := range *myPowers {
+			if v.Surplus_count <= 0 {
+				continue
+			}
+			if deduct_count > 0 {
+				if v.Power_type == 1 {
+					user_id = v.Power_ofid
+				} else if v.Power_type == 2 {
+					ent_id = v.Power_ofid
+				} else {
+					continue
+				}
+				this_deduct_count := deduct_count
+				if v.Surplus_count >= deduct_count { //本次记录的数据足够扣减
+					v.Surplus_count -= deduct_count
+					deduct_count = 0
+				} else { //本次不够扣减,把本次的扣完,进入下次扣减
+					v.Surplus_count = 0
+					this_deduct_count = v.Surplus_count
+					deduct_count -= v.Surplus_count
+				}
+				update = append(update, []interface{}{v.Id, v.Surplus_count, NowFormat(Date_Full_Layout)})
+				detail_values = append(detail_values, []interface{}{in.Appid, v.Id, v.Surplus_count, this_deduct_count, NowFormat(Date_Full_Layout)})
+			}
+			my_surplus_count += v.Surplus_count
+		}
+		//剩余的总数成功完成了本次的扣减
+		if deduct_count == 0 {
+			surplus_count = my_surplus_count
+		}
+	} else if function.Power_rule == 3 { //周期+频率+数量
+		for _, v := range *myPowers {
+			use, err := Base_resource_use.FindLastOne(in.Appid, in.FunctionCode, in.UserId, in.EntId, v.Power_type)
+			if err != nil {
+				l.Error(fmt.Sprintf("%+v", in), "查询资源使用记录失败", err)
+				continue
+			}
+			if use != nil {
+				create_time, err := time.ParseInLocation(Date_Full_Layout, use.Create_time, time.Local)
+				if err != nil {
+					l.Error(fmt.Sprintf("%+v", in), "资源充值/消耗表创建时间错误", create_time, err)
+					continue
+				}
+				now := time.Now()
+				if v.Limit_strategy == "1d" {
+					if create_time.Year() == now.Year() && create_time.Month() == now.Month() && create_time.Day() == now.Day() {
+						surplus_count = use.Surplus_count - in.Count
+					} else {
+						surplus_count = v.Strategy_count - in.Count
+					}
+				} else if v.Limit_strategy == "1m" {
+					if create_time.Year() == now.Year() && create_time.Month() == now.Month() {
+						surplus_count = use.Surplus_count - in.Count
+					} else {
+						surplus_count = v.Strategy_count - in.Count
+					}
+				} else {
+					l.Error(fmt.Sprintf("%+v", in), "limit_strategy格式错误", v.Limit_strategy)
+					continue
+				}
+			} else {
+				surplus_count = v.Strategy_count - in.Count
+			}
+			if v.Power_type == 1 {
+				user_id = v.Power_ofid
+			} else if v.Power_type == 2 {
+				ent_id = v.Power_ofid
+			} else {
+				continue
+			}
+			if surplus_count >= 0 {
+				detail_values = append(detail_values, []interface{}{in.Appid, v.Id, surplus_count, in.Count, NowFormat(Date_Full_Layout)})
+				break
+			}
+		}
+	}
+	if surplus_count < 0 {
+		resp.Status = -2
+		return resp, nil
+	} else {
+		use_values = append(use_values, in.Appid, ent_id, user_id, in.FunctionCode, 0, surplus_count, in.Count, NowFormat(Date_Full_Layout))
+	}
+	if len(use_values) > 0 && len(detail_values) > 0 && Base_resource_use.Deduction(use_values, detail_values, update) {
+		resp.Status = 1
+		return resp, nil
+	}
+	return resp, nil
 }

+ 36 - 3
rpc/internal/logic/powerhandlelogic.go

@@ -2,10 +2,11 @@ package logic
 
 import (
 	"context"
+	"fmt"
 
+	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/entity"
 	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/svc"
 	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
-
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
@@ -23,8 +24,40 @@ func NewPowerHandleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Power
 	}
 }
 
+//开通或者取消权益
 func (l *PowerHandleLogic) PowerHandle(in *pb.PowerReq) (*pb.Resp, error) {
-	// todo: add your logic here and delete this line
-
+	l.Info("开通或者取消权益请求参数", fmt.Sprintf("%+v", in))
+	resp := &pb.Resp{}
+	if in.Appid == "" {
+		l.Error(fmt.Sprintf("%+v", in), "无效的参数appid")
+		return resp, nil
+	} else if in.GoodsCode == "" {
+		l.Error(fmt.Sprintf("%+v", in), "无效的参数goods_code")
+		return resp, nil
+	} else if in.UserId == 0 && in.EntId == 0 {
+		l.Error(fmt.Sprintf("%+v", in), "无效的参数user_id、ent_id")
+		return resp, nil
+	} else 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
+	} else if in.Type != 1 && in.Type != -1 {
+		l.Error(fmt.Sprintf("%+v", in), "无效的参数type")
+		return resp, nil
+	}
+	if in.Type == 1 { //开通
+		list := Base_goods_function.FindByGoodsCode(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) {
+				return &pb.Resp{Status: 1}, nil
+			}
+		}
+	} else if in.Type == -1 { //取消
+		if Base_power.CancelPower(in.Appid, in.GoodsCode, in.UserId, in.EntId) {
+			return &pb.Resp{Status: 1}, nil
+		}
+	}
 	return &pb.Resp{}, nil
 }

+ 76 - 36
rpc/pb/resource.pb.go

@@ -29,7 +29,10 @@ type PowerReq struct {
 	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
-	Type      int64  `protobuf:"varint,5,opt,name=type,proto3" json:"type,omitempty"`                           //操作类型 0:查询权益 1:开通权益 -1:取消权益
+	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:取消权益
 }
 
 func (x *PowerReq) Reset() {
@@ -92,6 +95,27 @@ func (x *PowerReq) GetUserId() int64 {
 	return 0
 }
 
+func (x *PowerReq) GetUseCount() int64 {
+	if x != nil {
+		return x.UseCount
+	}
+	return 0
+}
+
+func (x *PowerReq) GetStartTime() string {
+	if x != nil {
+		return x.StartTime
+	}
+	return ""
+}
+
+func (x *PowerReq) GetEndTime() string {
+	if x != nil {
+		return x.EndTime
+	}
+	return ""
+}
+
 func (x *PowerReq) GetType() int64 {
 	if x != nil {
 		return x.Type
@@ -106,8 +130,9 @@ type CheckPowerReq struct {
 
 	Appid        string `protobuf:"bytes,1,opt,name=appid,proto3" json:"appid,omitempty"`
 	FunctionCode string `protobuf:"bytes,2,opt,name=function_code,json=functionCode,proto3" json:"function_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
+	UserId       int64  `protobuf:"varint,3,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`                  //用户id
+	EntId        int64  `protobuf:"varint,4,opt,name=ent_id,json=entId,proto3" json:"ent_id,omitempty"`                     //企业id
+	EntUserId    int64  `protobuf:"varint,5,opt,name=ent_user_id,json=entUserId,proto3" json:"ent_user_id,omitempty"`       //企业用户id
 }
 
 func (x *CheckPowerReq) Reset() {
@@ -156,6 +181,13 @@ func (x *CheckPowerReq) GetFunctionCode() string {
 	return ""
 }
 
+func (x *CheckPowerReq) GetUserId() int64 {
+	if x != nil {
+		return x.UserId
+	}
+	return 0
+}
+
 func (x *CheckPowerReq) GetEntId() int64 {
 	if x != nil {
 		return x.EntId
@@ -163,9 +195,9 @@ func (x *CheckPowerReq) GetEntId() int64 {
 	return 0
 }
 
-func (x *CheckPowerReq) GetUserId() int64 {
+func (x *CheckPowerReq) GetEntUserId() int64 {
 	if x != nil {
-		return x.UserId
+		return x.EntUserId
 	}
 	return 0
 }
@@ -308,43 +340,51 @@ 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, 0x83, 0x01, 0x0a, 0x08, 0x50, 0x6f, 0x77, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x14, 0x0a,
+	0x22, 0xda, 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, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03,
-	0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x7a, 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, 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, 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,
+	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,
 }
 
 var (

+ 7 - 3
rpc/resource.proto

@@ -7,14 +7,18 @@ message PowerReq {
   string goods_code = 2; //商品代码
   int64 ent_id = 3;      //企业id
   int64 user_id = 4;     //用户id
-  int64 type = 5;        //操作类型 0:查询权益 1:开通权益 -1:取消权益
+  int64 use_count = 5;   //数量
+  string start_time = 6; //开始时间
+  string end_time = 7;   //结束时间
+  int64 type = 8;        //操作类型 1:开通权益 -1:取消权益
 }
 
 message CheckPowerReq {
   string appid = 1;
   string function_code = 2; //功能代码
-  int64 ent_id = 3;         //企业id
-  int64 user_id = 4;        //用户id
+  int64 user_id = 3;        //用户id
+  int64 ent_id = 4;         //企业id
+  int64 ent_user_id = 5;    //企业用户id 
 }
 
 message DeductionReq {