Forráskód Böngészése

feat:增加功能类型

wangchuanjin 2 éve
szülő
commit
9aef1f62bd

+ 47 - 0
Makefile

@@ -0,0 +1,47 @@
+SHELL=cmd
+
+#首行.PHONY命令忽略之前执行命令的结果
+.PHONY: all genRpc genApi clean fmt tidy lint cover help
+
+#生成rpc代码
+genRpc:
+	cd rpc && goctl rpc protoc resource.proto --go_out=./ --go-grpc_out=./ --zrpc_out=.
+	
+#生成api代码
+genApi:
+	cd api && goctl api go -api resource.api -dir .
+
+#清理
+clean:
+	go clean
+	rm -f ./api/api ./api/api.exe ./api/logs ./rpc/rpc ./rpc/rpc.exe ./rpc/logs
+    
+#格式化代码
+fmt:
+	golines ./
+	go fmt ./
+	go vet ./
+	go fix ./
+    
+#拉取依赖包
+tidy:
+	go mod tidy
+	
+#静态分析
+lint:
+	golangci-lint run --enable-all
+	
+#单元测试覆盖率
+cover:
+	go test -v -covermode=set -coverprofile=cover.out bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service
+	go tool cover -html=cover.out
+	
+#显示帮助
+help:
+	@echo "make genRpc 生成rpc代码"
+	@echo "make genApi 生成api代码"
+	@echo "make clean 清理"
+	@echo "make fmt 格式化代码"
+	@echo "make tidy 拉取依赖包"
+	@echo "make lint 静态分析"
+	@echo "make cover 单元测试覆盖率"

+ 73 - 0
cover.out

@@ -0,0 +1,73 @@
+mode: set
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:15.84,18.18 3 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:28.2,28.15 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:18.18,19.28 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:19.28,25.9 6 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:39.75,43.16 4 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:54.2,54.15 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:43.16,44.26 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:44.26,45.124 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:45.124,46.27 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:49.5,50.45 2 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:46.27,47.14 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:65.86,67.18 2 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:70.2,71.27 2 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:74.2,74.30 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:77.2,77.75 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:80.2,80.10 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:67.18,69.3 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:71.27,73.3 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:74.30,76.3 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:77.75,79.3 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:91.90,92.79 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:95.2,95.10 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:92.79,94.3 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:108.105,112.17 4 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:126.2,126.22 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:112.17,113.53 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:113.53,115.4 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:115.9,116.28 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:121.4,121.21 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:116.28,120.5 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/power.go:121.21,123.5 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:22.108,24.21 2 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:27.2,28.44 2 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:31.2,31.30 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:39.2,39.30 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:94.2,94.21 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:24.21,26.3 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:28.44,30.3 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:31.30,32.31 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:37.3,37.22 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:32.31,33.100 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:33.100,35.5 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:39.30,41.31 2 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:48.3,48.24 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:41.31,42.100 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:45.4,46.36 2 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:42.100,44.5 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:48.24,50.4 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:50.9,52.4 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:53.8,53.37 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:53.37,54.31 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:54.31,55.100 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:58.4,59.18 2 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:64.4,65.18 2 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:68.4,69.45 2 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:55.100,57.5 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:59.18,61.5 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:61.10,61.25 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:61.25,63.5 1 1
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:65.18,67.5 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:69.45,70.113 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:70.113,71.31 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:71.31,73.7 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:73.12,75.7 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:76.11,78.6 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:79.10,79.52 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:79.52,80.79 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:80.79,81.31 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:81.31,83.7 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:83.12,85.7 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:86.11,88.6 1 0
+bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service/surplus.go:89.10,91.5 1 0

+ 10 - 9
public/entity/base_function.go

@@ -9,15 +9,16 @@ var Base_function = base_function{}
 
 //功能原始表
 type base_function struct {
-	Id         int64
-	Appid      string
-	Name       string //功能名称
-	Code       string //功能代码
-	Status     int64  //0:不可用 1:可用
-	Haspower   int64  //能否生成用户权益;0:否 1:是
-	Version    string //版本号
-	Power_rule int64  //校验权限规则;1:仅周期 2:周期+数量 3:周期+频率+数量
-	Power_type int64  //权限类型;1:互斥 2:兼容
+	Id            int64
+	Appid         string
+	Name          string //功能名称
+	Code          string //功能代码
+	Status        int64  //0:不可用 1:可用
+	Haspower      int64  //能否生成用户权益;0:否 1:是
+	Version       string //版本号
+	Function_type int64  //1:消耗型(比如:信息发布,需要扣减) 2:固额型(比如:关注条数,不需要扣减) 3:配额型(比如:搜索结果条数)
+	Power_rule    int64  //校验权限规则;1:仅周期 2:周期+数量 3:周期+频率+数量
+	Power_type    int64  //权限类型;1:互斥 2:兼容
 }
 
 //根据代码查找功能详情

+ 15 - 15
public/entity/base_power.go

@@ -48,17 +48,17 @@ func (b *base_power) OpenPower(goods_spec_id int64, appid, goods_code string, us
 		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 b.goods_code=? and a.function_code=b.function_code) 
+			ok1 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_spec_power b 
+				on (a.appid=? and a.power_type=2 and a.power_ofid=? and b.appid=? and b.goods_code=? and b.spec_id=? and a.function_code=b.function_code) 
 				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, ent_id, appid, goods_code, appid) > -1
+				set a.status=0`, appid, ent_id, appid, goods_code, goods_spec_id, appid) > -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 b.goods_code=? and a.function_code=b.function_code) 
+			ok2 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_spec_power b 
+				on (a.appid=? and a.power_type=2 and a.power_ofid=? and b.appid=? and b.goods_code=? and b.spec_id=? and a.function_code=b.function_code) 
 				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
+				set a.status=0`, appid, user_id, appid, goods_code, goods_spec_id, appid) > -1
 		}
 		power_values, empower_values, wait_empower_values := []interface{}{}, []interface{}{}, []interface{}{}
 		for _, bgs := range *bgss {
@@ -71,7 +71,7 @@ func (b *base_power) OpenPower(goods_spec_id int64, appid, goods_code string, us
 				} else if v.Base_function.Haspower == 0 {
 					continue
 				}
-				power_values = append(power_values, appid, v.Function_code, v.Power_type)
+				power_values = append(power_values, appid, v.Id, v.Function_code, v.Power_type)
 				if v.Power_type == 1 {
 					power_values = append(power_values, user_id)
 				} else if v.Power_type == 2 {
@@ -114,7 +114,7 @@ func (b *base_power) OpenPower(goods_spec_id int64, appid, goods_code string, us
 			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)
+		v1, v2 := Mysql_BaseService.InsertBatchByTx(tx, "base_power", []string{"appid", "goods_spec_power_id", "function_code", "power_type", "power_ofid", "start_time", "end_time", "use_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)
@@ -130,18 +130,18 @@ func (b *base_power) OpenPower(goods_spec_id int64, appid, goods_code string, us
 }
 
 //取消权益
-func (b *base_power) CancelPower(appid, goods_code string, user_id, ent_id int64) bool {
+func (b *base_power) CancelPower(appid, goods_code string, spec_id, user_id, ent_id int64) bool {
 	return Mysql_BaseService.ExecTx("取消权益", func(tx *sql.Tx) bool {
 		ok1, ok2 := false, false
 		if user_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 b.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
+			ok1 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_spec_power b 
+				on (a.appid=? and a.power_type=1 and a.power_ofid=? and b.appid=? and b.goods_code=? and b.spec_id=? and b.power_type=1 and a.function_code=b.function_code) 
+				set a.status=-1`, appid, user_id, appid, goods_code, spec_id) > 0
 		}
 		if ent_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 b.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
+			ok2 = Mysql_BaseService.UpdateOrDeleteBySqlByTx(tx, `update base_power a inner join base_goods_spec_power b 
+				on (a.appid=? and a.power_type=2 and a.power_ofid=? and b.appid=? and b.goods_code=? and b.spec_id=? and b.power_type=2 and a.function_code=b.function_code) 
+				set a.status=-1`, appid, ent_id, appid, goods_code, spec_id) > 0
 		}
 		return ok1 || ok2
 	})

+ 1 - 1
public/entity/base_resource_use.go

@@ -54,7 +54,7 @@ func (b *base_resource_use) FindLastOne(appid, function_code string, user_id, en
 //新增扣减记录
 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", "deduct_count", "create_time"}, use_values)
+		v1, v2 := Mysql_BaseService.InsertBatchByTx(tx, "base_resource_use", []string{"appid", "ent_id", "user_id", "function_code", "add_count", "surplus_count", "deduct_count", "business_id", "create_time"}, use_values)
 		array := []interface{}{}
 		for _, v := range detail_values {
 			array = append(array, v...)

+ 120 - 0
public/service/deduction.go

@@ -0,0 +1,120 @@
+package service
+
+import (
+	"errors"
+	"strings"
+	"time"
+
+	. "app.yhyue.com/moapp/jybase/date"
+	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/entity"
+)
+
+/*
+ * 资源扣减
+ * @param appid
+ * @param function_code 功能代码
+ * @param userId 用户id
+ * @param entId 企业id
+ * @param count 扣减数量
+ * @param ids 业务id
+ * @return 状态 0:失败 1:成功 -1:不在有效期内 -2:数量不足 -3:没有授权
+ */
+func Deduction(appid, function_code string, user_id, ent_id int64, count int64, ids []string) (int64, error) {
+	function := Base_function.FindByCode(appid, function_code)
+	if function == nil {
+		return 0, errors.New("功能原始表中没有找到该功能")
+	}
+	myPowers := Base_power.FindMyPower(appid, function_code, user_id, ent_id)
+	if myPowers == nil || len(*myPowers) == 0 {
+		return -1, errors.New("功能权益表中没有找到权益记录")
+	}
+	use_values, detail_values := []interface{}{}, [][]interface{}{}
+	update := [][]interface{}{}
+	surplus_count := int64(-1)
+	deduct_count := count
+	userId, entId := 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 {
+					userId = v.Power_ofid
+				} else if v.Power_type == 2 {
+					entId = 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{}{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(appid, function_code, user_id, ent_id, v.Power_type)
+			if err != nil {
+				return 0, errors.New("查询资源使用记录失败," + err.Error())
+			}
+			if use != nil {
+				create_time, err := time.ParseInLocation(Date_Full_Layout, use.Create_time, time.Local)
+				if err != nil {
+					return 0, errors.New("资源充值/消耗表创建时间错误," + use.Create_time + "," + err.Error())
+				}
+				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 - count
+					} else {
+						surplus_count = v.Strategy_count - count
+					}
+				} else if v.Limit_strategy == "1m" {
+					if create_time.Year() == now.Year() && create_time.Month() == now.Month() {
+						surplus_count = use.Surplus_count - count
+					} else {
+						surplus_count = v.Strategy_count - count
+					}
+				} else {
+					return 0, errors.New("limit_strategy格式错误," + v.Limit_strategy)
+				}
+			} else {
+				surplus_count = v.Strategy_count - count
+			}
+			if v.Power_type == 1 {
+				userId = v.Power_ofid
+			} else if v.Power_type == 2 {
+				entId = v.Power_ofid
+			} else {
+				continue
+			}
+			if surplus_count >= 0 {
+				detail_values = append(detail_values, []interface{}{appid, v.Id, surplus_count, count, NowFormat(Date_Full_Layout)})
+				break
+			}
+		}
+	}
+	if surplus_count < 0 {
+		return -2, nil
+	} else {
+		use_values = append(use_values, appid, entId, userId, function_code, 0, surplus_count, count, strings.Join(ids, ","), NowFormat(Date_Full_Layout))
+	}
+	if len(use_values) > 0 && len(detail_values) > 0 && Base_resource_use.Deduction(use_values, detail_values, update) {
+		return 1, nil
+	}
+	return 0, nil
+}

+ 14 - 0
public/service/deduction_test.go

@@ -0,0 +1,14 @@
+package service
+
+import (
+	"testing"
+
+	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/entity"
+	"github.com/stretchr/testify/assert"
+)
+
+func TestDeduction(t *testing.T) {
+	status, err := Deduction("10000", "xxfb_gyxx", 0, 14184, 1, []string{"test"})
+	assert.Nil(t, err)
+	assert.Equal(t, 1, status)
+}

+ 29 - 0
public/service/recharge.go

@@ -0,0 +1,29 @@
+package service
+
+import (
+	"errors"
+
+	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/entity"
+)
+
+/*
+ * 资源充值
+ * @param appid
+ * @param function_code 功能代码
+ * @param userId 用户id
+ * @param entId 企业id
+ * @param count 充值数量
+ * @param ids 业务id
+ * @return 状态 0:失败 1:成功 -1:不在有效期内 -2:数量不足 -3:没有授权 -4:超额
+ */
+func Recharge(appid, function_code string, user_id, ent_id int64, count int64, ids []string) (int64, error) {
+	function := Base_function.FindByCode(appid, function_code)
+	if function == nil {
+		return 0, errors.New("功能原始表中没有找到该功能")
+	}
+	myPowers := Base_power.FindMyPower(appid, function_code, user_id, ent_id)
+	if myPowers == nil || len(*myPowers) == 0 {
+		return -1, errors.New("功能权益表中没有找到权益记录")
+	}
+	return 0, nil
+}

+ 14 - 0
public/service/recharge_test.go

@@ -0,0 +1,14 @@
+package service
+
+import (
+	"testing"
+
+	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/entity"
+	"github.com/stretchr/testify/assert"
+)
+
+func TestRecharge(t *testing.T) {
+	status, err := Recharge("10000", "xxfb_gyxx", 0, 0, 1, []string{"test"})
+	assert.Nil(t, err)
+	assert.Equal(t, 1, status)
+}

+ 1 - 2
public/service/surplus.go

@@ -35,8 +35,7 @@ func Surplus(appid, function_code string, user_id, ent_id, ent_user_id int64) (i
 			}
 		}
 		return 1, 0, 0, nil
-	}
-	if function.Power_rule == 2 { //周期+数量校验
+	} else if function.Power_rule == 2 { //周期+数量校验
 		use_count, surplus_count := int64(0), int64(0)
 		for _, v := range *myPowers {
 			if v.Power_type == 2 && !Base_ent_empower.HasEmpower(appid, function_code, ent_id, ent_user_id) {

+ 3 - 1
rpc/internal/logic/checkpowerlogic.go

@@ -44,8 +44,10 @@ func (l *CheckPowerLogic) CheckPower(in *pb.CheckPowerReq) (*pb.Resp, error) {
 		l.Error(fmt.Sprintf("%+v", in), "功能原始表中没有找到该功能")
 		return resp, nil
 	}
-	status, _, _, err := Surplus(in.Appid, in.FunctionCode, in.UserId, in.EntId, in.EntUserId)
+	status, use_count, surplus_count, err := Surplus(in.Appid, in.FunctionCode, in.UserId, in.EntId, in.EntUserId)
 	resp.Status = status
+	resp.UseCount = use_count
+	resp.SurplusCount = surplus_count
 	if err != nil {
 		l.Error(fmt.Sprintf("%+v", in), err.Error())
 	}

+ 5 - 107
rpc/internal/logic/deductionlogic.go

@@ -3,13 +3,10 @@ package logic
 import (
 	"context"
 	"fmt"
-	"time"
 
-	. "app.yhyue.com/moapp/jybase/date"
-	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/entity"
+	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service"
 	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/svc"
 	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
-
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
@@ -43,109 +40,10 @@ func (l *DeductionLogic) Deduction(in *pb.DeductionReq) (*pb.Resp, error) {
 		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
+	status, err := Deduction(in.Appid, in.FunctionCode, in.UserId, in.EntId, in.Count, in.Ids)
+	if err != nil {
+		l.Error(fmt.Sprintf("%+v", in), err)
 	}
+	resp.Status = status
 	return resp, nil
 }

+ 1 - 1
rpc/internal/logic/powerhandlelogic.go

@@ -48,7 +48,7 @@ func (l *PowerHandleLogic) PowerHandle(in *pb.PowerReq) (*pb.Resp, error) {
 			return resp, nil
 		}
 	} else if in.Type == -1 { //取消
-		if Base_power.CancelPower(in.Appid, in.GoodsCode, in.UserId, in.EntId) {
+		if Base_power.CancelPower(in.Appid, in.GoodsCode, in.GoodsSpecId, in.UserId, in.EntId) {
 			return &pb.Resp{Status: 1}, nil
 		}
 	} else {

+ 49 - 0
rpc/internal/logic/rechargelogic.go

@@ -0,0 +1,49 @@
+package logic
+
+import (
+	"context"
+	"fmt"
+
+	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service"
+	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/svc"
+	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type RechargeLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewRechargeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RechargeLogic {
+	return &RechargeLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+// 资源充值
+func (l *RechargeLogic) Recharge(in *pb.RechargeReq) (*pb.Resp, error) {
+	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
+	}
+	status, err := Deduction(in.Appid, in.FunctionCode, in.UserId, in.EntId, in.Count, in.Ids)
+	if err != nil {
+		l.Error(fmt.Sprintf("%+v", in), err)
+	}
+	resp.Status = status
+	return resp, nil
+}

+ 6 - 0
rpc/internal/server/resourceserver.go

@@ -40,6 +40,12 @@ func (s *ResourceServer) Deduction(ctx context.Context, in *pb.DeductionReq) (*p
 	return l.Deduction(in)
 }
 
+// 资源充值
+func (s *ResourceServer) Recharge(ctx context.Context, in *pb.RechargeReq) (*pb.Resp, error) {
+	l := logic.NewRechargeLogic(ctx, s.svcCtx)
+	return l.Recharge(in)
+}
+
 // 重新授权
 func (s *ResourceServer) ReEmpower(ctx context.Context, in *pb.EmpowerReq) (*pb.Resp, error) {
 	l := logic.NewReEmpowerLogic(ctx, s.svcCtx)

+ 209 - 75
rpc/pb/resource.pb.go

@@ -328,6 +328,93 @@ func (x *DeductionReq) GetIds() []string {
 	return nil
 }
 
+type RechargeReq struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	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
+	Count        int64    `protobuf:"varint,5,opt,name=count,proto3" json:"count,omitempty"`                                  //扣除数量
+	Ids          []string `protobuf:"bytes,6,rep,name=ids,proto3" json:"ids,omitempty"`                                       //id列表
+}
+
+func (x *RechargeReq) Reset() {
+	*x = RechargeReq{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_resource_proto_msgTypes[4]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *RechargeReq) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*RechargeReq) ProtoMessage() {}
+
+func (x *RechargeReq) ProtoReflect() protoreflect.Message {
+	mi := &file_resource_proto_msgTypes[4]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use RechargeReq.ProtoReflect.Descriptor instead.
+func (*RechargeReq) Descriptor() ([]byte, []int) {
+	return file_resource_proto_rawDescGZIP(), []int{4}
+}
+
+func (x *RechargeReq) GetAppid() string {
+	if x != nil {
+		return x.Appid
+	}
+	return ""
+}
+
+func (x *RechargeReq) GetFunctionCode() string {
+	if x != nil {
+		return x.FunctionCode
+	}
+	return ""
+}
+
+func (x *RechargeReq) GetEntId() int64 {
+	if x != nil {
+		return x.EntId
+	}
+	return 0
+}
+
+func (x *RechargeReq) GetUserId() int64 {
+	if x != nil {
+		return x.UserId
+	}
+	return 0
+}
+
+func (x *RechargeReq) GetCount() int64 {
+	if x != nil {
+		return x.Count
+	}
+	return 0
+}
+
+func (x *RechargeReq) GetIds() []string {
+	if x != nil {
+		return x.Ids
+	}
+	return nil
+}
+
 type EmpowerReq struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
@@ -342,7 +429,7 @@ type EmpowerReq struct {
 func (x *EmpowerReq) Reset() {
 	*x = EmpowerReq{}
 	if protoimpl.UnsafeEnabled {
-		mi := &file_resource_proto_msgTypes[4]
+		mi := &file_resource_proto_msgTypes[5]
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		ms.StoreMessageInfo(mi)
 	}
@@ -355,7 +442,7 @@ func (x *EmpowerReq) String() string {
 func (*EmpowerReq) ProtoMessage() {}
 
 func (x *EmpowerReq) ProtoReflect() protoreflect.Message {
-	mi := &file_resource_proto_msgTypes[4]
+	mi := &file_resource_proto_msgTypes[5]
 	if protoimpl.UnsafeEnabled && x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		if ms.LoadMessageInfo() == nil {
@@ -368,7 +455,7 @@ func (x *EmpowerReq) ProtoReflect() protoreflect.Message {
 
 // Deprecated: Use EmpowerReq.ProtoReflect.Descriptor instead.
 func (*EmpowerReq) Descriptor() ([]byte, []int) {
-	return file_resource_proto_rawDescGZIP(), []int{4}
+	return file_resource_proto_rawDescGZIP(), []int{5}
 }
 
 func (x *EmpowerReq) GetAppid() string {
@@ -414,7 +501,7 @@ type EmpowerListReq struct {
 func (x *EmpowerListReq) Reset() {
 	*x = EmpowerListReq{}
 	if protoimpl.UnsafeEnabled {
-		mi := &file_resource_proto_msgTypes[5]
+		mi := &file_resource_proto_msgTypes[6]
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		ms.StoreMessageInfo(mi)
 	}
@@ -427,7 +514,7 @@ func (x *EmpowerListReq) String() string {
 func (*EmpowerListReq) ProtoMessage() {}
 
 func (x *EmpowerListReq) ProtoReflect() protoreflect.Message {
-	mi := &file_resource_proto_msgTypes[5]
+	mi := &file_resource_proto_msgTypes[6]
 	if protoimpl.UnsafeEnabled && x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		if ms.LoadMessageInfo() == nil {
@@ -440,7 +527,7 @@ func (x *EmpowerListReq) ProtoReflect() protoreflect.Message {
 
 // Deprecated: Use EmpowerListReq.ProtoReflect.Descriptor instead.
 func (*EmpowerListReq) Descriptor() ([]byte, []int) {
-	return file_resource_proto_rawDescGZIP(), []int{5}
+	return file_resource_proto_rawDescGZIP(), []int{6}
 }
 
 func (x *EmpowerListReq) GetAppid() string {
@@ -484,13 +571,13 @@ type EmpowerListResp struct {
 	unknownFields protoimpl.UnknownFields
 
 	Count int64      `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` //总条数,只有第一页的时候才返回, 如果企业下所有人都有权限返回-1
-	List  []*Empower `protobuf:"bytes,2,rep,name=list,proto3" json:"list,omitempty"`    //企业用户id,如果企业下所有人都有权限,返回空数组
+	List  []*Empower `protobuf:"bytes,2,rep,name=list,proto3" json:"list,omitempty"`    //列表,如果企业下所有人都有权限,返回空数组
 }
 
 func (x *EmpowerListResp) Reset() {
 	*x = EmpowerListResp{}
 	if protoimpl.UnsafeEnabled {
-		mi := &file_resource_proto_msgTypes[6]
+		mi := &file_resource_proto_msgTypes[7]
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		ms.StoreMessageInfo(mi)
 	}
@@ -503,7 +590,7 @@ func (x *EmpowerListResp) String() string {
 func (*EmpowerListResp) ProtoMessage() {}
 
 func (x *EmpowerListResp) ProtoReflect() protoreflect.Message {
-	mi := &file_resource_proto_msgTypes[6]
+	mi := &file_resource_proto_msgTypes[7]
 	if protoimpl.UnsafeEnabled && x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		if ms.LoadMessageInfo() == nil {
@@ -516,7 +603,7 @@ func (x *EmpowerListResp) ProtoReflect() protoreflect.Message {
 
 // Deprecated: Use EmpowerListResp.ProtoReflect.Descriptor instead.
 func (*EmpowerListResp) Descriptor() ([]byte, []int) {
-	return file_resource_proto_rawDescGZIP(), []int{6}
+	return file_resource_proto_rawDescGZIP(), []int{7}
 }
 
 func (x *EmpowerListResp) GetCount() int64 {
@@ -538,13 +625,15 @@ type Resp struct {
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 
-	Status int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` //0:失败 1:成功 -1:不在有效期内 -2:数量不足 -3:没有授权
+	Status       int64 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"`                                 //0:失败 1:成功 -1:不在有效期内 -2:数量不足 -3:没有授权
+	UseCount     int64 `protobuf:"varint,2,opt,name=use_count,json=useCount,proto3" json:"use_count,omitempty"`             //使用数量
+	SurplusCount int64 `protobuf:"varint,3,opt,name=surplus_count,json=surplusCount,proto3" json:"surplus_count,omitempty"` //剩余数量
 }
 
 func (x *Resp) Reset() {
 	*x = Resp{}
 	if protoimpl.UnsafeEnabled {
-		mi := &file_resource_proto_msgTypes[7]
+		mi := &file_resource_proto_msgTypes[8]
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		ms.StoreMessageInfo(mi)
 	}
@@ -557,7 +646,7 @@ func (x *Resp) String() string {
 func (*Resp) ProtoMessage() {}
 
 func (x *Resp) ProtoReflect() protoreflect.Message {
-	mi := &file_resource_proto_msgTypes[7]
+	mi := &file_resource_proto_msgTypes[8]
 	if protoimpl.UnsafeEnabled && x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		if ms.LoadMessageInfo() == nil {
@@ -570,7 +659,7 @@ func (x *Resp) ProtoReflect() protoreflect.Message {
 
 // Deprecated: Use Resp.ProtoReflect.Descriptor instead.
 func (*Resp) Descriptor() ([]byte, []int) {
-	return file_resource_proto_rawDescGZIP(), []int{7}
+	return file_resource_proto_rawDescGZIP(), []int{8}
 }
 
 func (x *Resp) GetStatus() int64 {
@@ -580,6 +669,20 @@ func (x *Resp) GetStatus() int64 {
 	return 0
 }
 
+func (x *Resp) GetUseCount() int64 {
+	if x != nil {
+		return x.UseCount
+	}
+	return 0
+}
+
+func (x *Resp) GetSurplusCount() int64 {
+	if x != nil {
+		return x.SurplusCount
+	}
+	return 0
+}
+
 var File_resource_proto protoreflect.FileDescriptor
 
 var file_resource_proto_rawDesc = []byte{
@@ -619,47 +722,63 @@ var file_resource_proto_rawDesc = []byte{
 	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,
-	0x7e, 0x0a, 0x0a, 0x45, 0x6d, 0x70, 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,
-	0x1e, 0x0a, 0x0b, 0x65, 0x6e, 0x74, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04,
-	0x20, 0x03, 0x28, 0x03, 0x52, 0x09, 0x65, 0x6e, 0x74, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22,
-	0x9a, 0x01, 0x0a, 0x0e, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 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, 0x19, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x5f, 0x6e, 0x75, 0x6d,
-	0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x70, 0x61, 0x67, 0x65, 0x4e, 0x75, 0x6d, 0x12,
-	0x1b, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x05, 0x20, 0x01,
-	0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x22, 0x45, 0x0a, 0x0f,
-	0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12,
-	0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05,
-	0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x1c, 0x0a, 0x04, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x02, 0x20,
-	0x03, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x52, 0x04, 0x6c,
-	0x69, 0x73, 0x74, 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, 0xeb, 0x01, 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, 0x12, 0x1f, 0x0a, 0x09, 0x52, 0x65, 0x45,
-	0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x12, 0x0b, 0x2e, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72,
-	0x52, 0x65, 0x71, 0x1a, 0x05, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x12, 0x23, 0x0a, 0x0d, 0x43, 0x61,
-	0x6e, 0x63, 0x65, 0x6c, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x12, 0x0b, 0x2e, 0x45, 0x6d,
-	0x70, 0x6f, 0x77, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x05, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x12,
-	0x30, 0x0a, 0x0b, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x0f,
-	0x2e, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x1a,
-	0x10, 0x2e, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73,
-	0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
-	0x33,
+	0xa0, 0x01, 0x0a, 0x0b, 0x52, 0x65, 0x63, 0x68, 0x61, 0x72, 0x67, 0x65, 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, 0x7e, 0x0a, 0x0a, 0x45, 0x6d, 0x70, 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, 0x1e, 0x0a, 0x0b, 0x65, 0x6e, 0x74, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69,
+	0x64, 0x18, 0x04, 0x20, 0x03, 0x28, 0x03, 0x52, 0x09, 0x65, 0x6e, 0x74, 0x55, 0x73, 0x65, 0x72,
+	0x49, 0x64, 0x22, 0x9a, 0x01, 0x0a, 0x0e, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x4c, 0x69,
+	0x73, 0x74, 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, 0x19, 0x0a, 0x08, 0x70, 0x61, 0x67, 0x65, 0x5f,
+	0x6e, 0x75, 0x6d, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x70, 0x61, 0x67, 0x65, 0x4e,
+	0x75, 0x6d, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x18,
+	0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x22,
+	0x45, 0x0a, 0x0f, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65,
+	0x73, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28,
+	0x03, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x1c, 0x0a, 0x04, 0x6c, 0x69, 0x73, 0x74,
+	0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72,
+	0x52, 0x04, 0x6c, 0x69, 0x73, 0x74, 0x22, 0x60, 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, 0x12, 0x1b, 0x0a, 0x09, 0x75, 0x73, 0x65, 0x5f, 0x63, 0x6f,
+	0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x75, 0x73, 0x65, 0x43, 0x6f,
+	0x75, 0x6e, 0x74, 0x12, 0x23, 0x0a, 0x0d, 0x73, 0x75, 0x72, 0x70, 0x6c, 0x75, 0x73, 0x5f, 0x63,
+	0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x73, 0x75, 0x72, 0x70,
+	0x6c, 0x75, 0x73, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x32, 0x8c, 0x02, 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, 0x12, 0x1f,
+	0x0a, 0x08, 0x52, 0x65, 0x63, 0x68, 0x61, 0x72, 0x67, 0x65, 0x12, 0x0c, 0x2e, 0x52, 0x65, 0x63,
+	0x68, 0x61, 0x72, 0x67, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x05, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x12,
+	0x1f, 0x0a, 0x09, 0x52, 0x65, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x12, 0x0b, 0x2e, 0x45,
+	0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x05, 0x2e, 0x52, 0x65, 0x73, 0x70,
+	0x12, 0x23, 0x0a, 0x0d, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65,
+	0x72, 0x12, 0x0b, 0x2e, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x05,
+	0x2e, 0x52, 0x65, 0x73, 0x70, 0x12, 0x30, 0x0a, 0x0b, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72,
+	0x4c, 0x69, 0x73, 0x74, 0x12, 0x0f, 0x2e, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x4c, 0x69,
+	0x73, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x10, 0x2e, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x4c,
+	0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62,
+	0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (
@@ -674,33 +793,36 @@ func file_resource_proto_rawDescGZIP() []byte {
 	return file_resource_proto_rawDescData
 }
 
-var file_resource_proto_msgTypes = make([]protoimpl.MessageInfo, 8)
+var file_resource_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
 var file_resource_proto_goTypes = []interface{}{
 	(*Empower)(nil),         // 0: Empower
 	(*PowerReq)(nil),        // 1: PowerReq
 	(*CheckPowerReq)(nil),   // 2: CheckPowerReq
 	(*DeductionReq)(nil),    // 3: DeductionReq
-	(*EmpowerReq)(nil),      // 4: EmpowerReq
-	(*EmpowerListReq)(nil),  // 5: EmpowerListReq
-	(*EmpowerListResp)(nil), // 6: EmpowerListResp
-	(*Resp)(nil),            // 7: Resp
+	(*RechargeReq)(nil),     // 4: RechargeReq
+	(*EmpowerReq)(nil),      // 5: EmpowerReq
+	(*EmpowerListReq)(nil),  // 6: EmpowerListReq
+	(*EmpowerListResp)(nil), // 7: EmpowerListResp
+	(*Resp)(nil),            // 8: Resp
 }
 var file_resource_proto_depIdxs = []int32{
 	0, // 0: EmpowerListResp.list:type_name -> Empower
 	1, // 1: Resource.PowerHandle:input_type -> PowerReq
 	2, // 2: Resource.CheckPower:input_type -> CheckPowerReq
 	3, // 3: Resource.Deduction:input_type -> DeductionReq
-	4, // 4: Resource.ReEmpower:input_type -> EmpowerReq
-	4, // 5: Resource.CancelEmpower:input_type -> EmpowerReq
-	5, // 6: Resource.EmpowerList:input_type -> EmpowerListReq
-	7, // 7: Resource.PowerHandle:output_type -> Resp
-	7, // 8: Resource.CheckPower:output_type -> Resp
-	7, // 9: Resource.Deduction:output_type -> Resp
-	7, // 10: Resource.ReEmpower:output_type -> Resp
-	7, // 11: Resource.CancelEmpower:output_type -> Resp
-	6, // 12: Resource.EmpowerList:output_type -> EmpowerListResp
-	7, // [7:13] is the sub-list for method output_type
-	1, // [1:7] is the sub-list for method input_type
+	4, // 4: Resource.Recharge:input_type -> RechargeReq
+	5, // 5: Resource.ReEmpower:input_type -> EmpowerReq
+	5, // 6: Resource.CancelEmpower:input_type -> EmpowerReq
+	6, // 7: Resource.EmpowerList:input_type -> EmpowerListReq
+	8, // 8: Resource.PowerHandle:output_type -> Resp
+	8, // 9: Resource.CheckPower:output_type -> Resp
+	8, // 10: Resource.Deduction:output_type -> Resp
+	8, // 11: Resource.Recharge:output_type -> Resp
+	8, // 12: Resource.ReEmpower:output_type -> Resp
+	8, // 13: Resource.CancelEmpower:output_type -> Resp
+	7, // 14: Resource.EmpowerList:output_type -> EmpowerListResp
+	8, // [8:15] is the sub-list for method output_type
+	1, // [1:8] is the sub-list for method input_type
 	1, // [1:1] is the sub-list for extension type_name
 	1, // [1:1] is the sub-list for extension extendee
 	0, // [0:1] is the sub-list for field type_name
@@ -761,7 +883,7 @@ func file_resource_proto_init() {
 			}
 		}
 		file_resource_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
-			switch v := v.(*EmpowerReq); i {
+			switch v := v.(*RechargeReq); i {
 			case 0:
 				return &v.state
 			case 1:
@@ -773,7 +895,7 @@ func file_resource_proto_init() {
 			}
 		}
 		file_resource_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
-			switch v := v.(*EmpowerListReq); i {
+			switch v := v.(*EmpowerReq); i {
 			case 0:
 				return &v.state
 			case 1:
@@ -785,7 +907,7 @@ func file_resource_proto_init() {
 			}
 		}
 		file_resource_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
-			switch v := v.(*EmpowerListResp); i {
+			switch v := v.(*EmpowerListReq); i {
 			case 0:
 				return &v.state
 			case 1:
@@ -797,6 +919,18 @@ func file_resource_proto_init() {
 			}
 		}
 		file_resource_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*EmpowerListResp); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
+		file_resource_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Resp); i {
 			case 0:
 				return &v.state
@@ -815,7 +949,7 @@ func file_resource_proto_init() {
 			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
 			RawDescriptor: file_resource_proto_rawDesc,
 			NumEnums:      0,
-			NumMessages:   8,
+			NumMessages:   9,
 			NumExtensions: 0,
 			NumServices:   1,
 		},

+ 38 - 0
rpc/pb/resource_grpc.pb.go

@@ -28,6 +28,8 @@ type ResourceClient interface {
 	CheckPower(ctx context.Context, in *CheckPowerReq, opts ...grpc.CallOption) (*Resp, error)
 	//资源扣减
 	Deduction(ctx context.Context, in *DeductionReq, opts ...grpc.CallOption) (*Resp, error)
+	//资源充值
+	Recharge(ctx context.Context, in *RechargeReq, opts ...grpc.CallOption) (*Resp, error)
 	//重新授权
 	ReEmpower(ctx context.Context, in *EmpowerReq, opts ...grpc.CallOption) (*Resp, error)
 	//取消授权
@@ -71,6 +73,15 @@ func (c *resourceClient) Deduction(ctx context.Context, in *DeductionReq, opts .
 	return out, nil
 }
 
+func (c *resourceClient) Recharge(ctx context.Context, in *RechargeReq, opts ...grpc.CallOption) (*Resp, error) {
+	out := new(Resp)
+	err := c.cc.Invoke(ctx, "/Resource/Recharge", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
 func (c *resourceClient) ReEmpower(ctx context.Context, in *EmpowerReq, opts ...grpc.CallOption) (*Resp, error) {
 	out := new(Resp)
 	err := c.cc.Invoke(ctx, "/Resource/ReEmpower", in, out, opts...)
@@ -108,6 +119,8 @@ type ResourceServer interface {
 	CheckPower(context.Context, *CheckPowerReq) (*Resp, error)
 	//资源扣减
 	Deduction(context.Context, *DeductionReq) (*Resp, error)
+	//资源充值
+	Recharge(context.Context, *RechargeReq) (*Resp, error)
 	//重新授权
 	ReEmpower(context.Context, *EmpowerReq) (*Resp, error)
 	//取消授权
@@ -130,6 +143,9 @@ func (UnimplementedResourceServer) CheckPower(context.Context, *CheckPowerReq) (
 func (UnimplementedResourceServer) Deduction(context.Context, *DeductionReq) (*Resp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method Deduction not implemented")
 }
+func (UnimplementedResourceServer) Recharge(context.Context, *RechargeReq) (*Resp, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method Recharge not implemented")
+}
 func (UnimplementedResourceServer) ReEmpower(context.Context, *EmpowerReq) (*Resp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method ReEmpower not implemented")
 }
@@ -206,6 +222,24 @@ func _Resource_Deduction_Handler(srv interface{}, ctx context.Context, dec func(
 	return interceptor(ctx, in, info, handler)
 }
 
+func _Resource_Recharge_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(RechargeReq)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(ResourceServer).Recharge(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/Resource/Recharge",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(ResourceServer).Recharge(ctx, req.(*RechargeReq))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
 func _Resource_ReEmpower_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
 	in := new(EmpowerReq)
 	if err := dec(in); err != nil {
@@ -279,6 +313,10 @@ var Resource_ServiceDesc = grpc.ServiceDesc{
 			MethodName: "Deduction",
 			Handler:    _Resource_Deduction_Handler,
 		},
+		{
+			MethodName: "Recharge",
+			Handler:    _Resource_Recharge_Handler,
+		},
 		{
 			MethodName: "ReEmpower",
 			Handler:    _Resource_ReEmpower_Handler,

+ 14 - 1
rpc/resource.proto

@@ -33,6 +33,15 @@ message DeductionReq {
   repeated string ids = 6;  //id列表
 }
 
+message RechargeReq {
+  string appid = 1;
+  string function_code = 2; //功能代码
+  int64 ent_id = 3;         //企业id
+  int64 user_id = 4;        //用户id
+  int64 count = 5;          //扣除数量
+  repeated string ids = 6;  //id列表
+}
+
 message EmpowerReq {
   string appid = 1;
   string function_code = 2; //功能代码
@@ -54,7 +63,9 @@ message EmpowerListResp {
 }
 
 message Resp {
-  int64 status = 1;        //0:失败 1:成功 -1:不在有效期内 -2:数量不足 -3:没有授权
+  int64 status = 1;        //0:失败 1:成功 -1:不在有效期内 -2:数量不足 -3:没有授权 -4:超额
+  int64 use_count = 2;     //使用数量
+  int64 surplus_count = 3; //剩余数量
 }
 
 service Resource {
@@ -64,6 +75,8 @@ service Resource {
   rpc CheckPower(CheckPowerReq) returns(Resp);
   //资源扣减
   rpc Deduction(DeductionReq) returns(Resp);
+  //资源充值
+  rpc Recharge(RechargeReq) returns(Resp);
   //重新授权
   rpc ReEmpower(EmpowerReq) returns(Resp);
   //取消授权

+ 9 - 0
rpc/resource/resource.go

@@ -20,6 +20,7 @@ type (
 	EmpowerListResp = pb.EmpowerListResp
 	EmpowerReq      = pb.EmpowerReq
 	PowerReq        = pb.PowerReq
+	RechargeReq     = pb.RechargeReq
 	Resp            = pb.Resp
 
 	Resource interface {
@@ -29,6 +30,8 @@ type (
 		CheckPower(ctx context.Context, in *CheckPowerReq, opts ...grpc.CallOption) (*Resp, error)
 		// 资源扣减
 		Deduction(ctx context.Context, in *DeductionReq, opts ...grpc.CallOption) (*Resp, error)
+		// 资源充值
+		Recharge(ctx context.Context, in *RechargeReq, opts ...grpc.CallOption) (*Resp, error)
 		// 重新授权
 		ReEmpower(ctx context.Context, in *EmpowerReq, opts ...grpc.CallOption) (*Resp, error)
 		// 取消授权
@@ -66,6 +69,12 @@ func (m *defaultResource) Deduction(ctx context.Context, in *DeductionReq, opts
 	return client.Deduction(ctx, in, opts...)
 }
 
+// 资源充值
+func (m *defaultResource) Recharge(ctx context.Context, in *RechargeReq, opts ...grpc.CallOption) (*Resp, error) {
+	client := pb.NewResourceClient(m.cli.Conn())
+	return client.Recharge(ctx, in, opts...)
+}
+
 // 重新授权
 func (m *defaultResource) ReEmpower(ctx context.Context, in *EmpowerReq, opts ...grpc.CallOption) (*Resp, error) {
 	client := pb.NewResourceClient(m.cli.Conn())