Browse Source

更新资源中台调用

wangchuanjin 2 năm trước cách đây
mục cha
commit
ce73e09246
4 tập tin đã thay đổi với 43 bổ sung38 xóa
  1. 3 3
      core/proxy/middleware/filterFuncs.go
  2. 36 31
      core/proxy/rpc/resourceCenter.go
  3. 2 2
      go.mod
  4. 2 2
      go.sum

+ 3 - 3
core/proxy/middleware/filterFuncs.go

@@ -45,7 +45,7 @@ func filterBefore(r *ghttp.Request) error {
 	//校验权益
 	var powerErr error
 	if rule.PowerCheck == 1 {
-		useCount, surplusCount, powerErr = rpc.CheckResourcePower(ctx.Sess.EntId, ctx.Sess.NewUid, rule.FuncCode, r.GetHeader("functionCode"), rule.AppId)
+		useCount, surplusCount, powerErr = rpc.CheckResourcePower(ctx.Sess.AccountId, ctx.Sess.EntAccountId, ctx.Sess.EntId, ctx.Sess.EntUserId, rule.FuncCode, r.GetHeader("functionCode"), rule.AppId)
 	}
 	//老剑鱼用户身份判断
 	if powerErr == nil && rule.PowerType > 0 {
@@ -100,12 +100,12 @@ func filterAfter(r *ghttp.Request) (err error) {
 		if deductNum > 0 { //资源接口异常
 			if rule.Deduct > 0 { //扣减
 				fmt.Println("扣减", deductNum, ids)
-				if err = rpc.ResourcePowerDeduct(ctx.Sess.EntId, ctx.Sess.NewUid, rule.FuncCode, rule.AppId, deductNum, ids); err != nil {
+				if err = rpc.ResourcePowerDeduct(ctx.Sess.AccountId, ctx.Sess.EntAccountId, rule.FuncCode, rule.AppId, deductNum, ids); err != nil {
 					return err
 				}
 			} else { //充值
 				fmt.Println("充值", deductNum, ids)
-				if err = rpc.ResourcePowerRecharge(ctx.Sess.EntId, ctx.Sess.NewUid, rule.FuncCode, rule.AppId, deductNum, ids); err != nil {
+				if err = rpc.ResourcePowerRecharge(ctx.Sess.AccountId, ctx.Sess.EntAccountId, rule.FuncCode, rule.AppId, deductNum, ids); err != nil {
 					return err
 				}
 			}

+ 36 - 31
core/proxy/rpc/resourceCenter.go

@@ -1,15 +1,16 @@
 package rpc
 
 import (
+	"fmt"
+	"strings"
+
 	. "bp.jydev.jianyu360.cn/BaseService/gateway/common/gatecode"
 	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
 	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/resource"
-	"fmt"
 	"github.com/gogf/gf/v2/os/gcfg"
 	"github.com/gogf/gf/v2/os/gctx"
 	"github.com/zeromicro/go-zero/core/discov"
 	"github.com/zeromicro/go-zero/zrpc"
-	"strings"
 )
 
 var ResourceCenterRpc resource.Resource
@@ -24,12 +25,14 @@ func initResourceCenterRpc() {
 }
 
 // CheckResourcePower 校验账户是否有对应权益
-// eid 企业id
-// uId 新用户id;非mongodb中user表id
+// accountId 账户id
+// entAccountId 企业账户id
+// entId 企业id
+// entUserId 企业员工id
 // funcCode 业务代码
 // reqFuncCode 	 通用结构&&需要校验权限则先判断此接口是否有此functionCode的方法
 // appid 平台标识
-func CheckResourcePower(eId, uId int64, funcCodeRule, reqFuncCode, Appid string) (UseCount, SurplusCount int64, err error) {
+func CheckResourcePower(accountId, entAccountId, entId, entUserId int64, funcCodeRule, reqFuncCode, Appid string) (UseCount, SurplusCount int64, err error) {
 	funcCode := funcCodeRule
 	funcCodeArr := strings.Split(funcCodeRule, ",")
 	if reqFuncCode != "" || len(funcCodeArr) > 1 {
@@ -41,7 +44,7 @@ func CheckResourcePower(eId, uId int64, funcCodeRule, reqFuncCode, Appid string)
 			}
 		}
 		if !checkPass {
-			err = NewErrorWithCode(GLOBAL_ERR_RESOURCE_POWERCODE_ERR, fmt.Sprintf("账户 eId:%d,uId:%d 无效funccode:%s req:%s权限", eId, uId, funcCodeRule, reqFuncCode))
+			err = NewErrorWithCode(GLOBAL_ERR_RESOURCE_POWERCODE_ERR, fmt.Sprintf("账户 accountId:%d entAccountId:%d entId:%d entUserId:%d 无效funccode:%s req:%s权限", accountId, entAccountId, entId, entUserId, funcCodeRule, reqFuncCode))
 			return
 		}
 		funcCode = reqFuncCode
@@ -50,8 +53,10 @@ func CheckResourcePower(eId, uId int64, funcCodeRule, reqFuncCode, Appid string)
 	res, err := ResourceCenterRpc.CheckPower(gctx.New(), &pb.CheckPowerReq{
 		Appid:        Appid,
 		FunctionCode: funcCode,
-		EntId:        eId,
-		UserId:       uId,
+		AccountId:    accountId,
+		EntAccountId: entAccountId,
+		EntId:        entId,
+		EntUserId:    entUserId,
 	})
 
 	if err != nil {
@@ -61,32 +66,32 @@ func CheckResourcePower(eId, uId int64, funcCodeRule, reqFuncCode, Appid string)
 	//0:失败 1:成功 -1:不在有效期内 -2:数量不足 -3:没有授权
 	switch res.Status {
 	case 0:
-		err = NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_FAIL, fmt.Sprintf("账户 eId:%d,uId:%d 无业务%s权限", eId, uId, funcCode))
+		err = NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_FAIL, fmt.Sprintf("账户 accountId:%d entAccountId:%d entId:%d entUserId:%d 无业务%s权限", accountId, entAccountId, entId, entUserId, funcCode))
 		return
 	case -1:
-		err = NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_EXPIRED, fmt.Sprintf("账户 eId:%d,uId:%d 业务%s权限已过期", eId, uId, funcCode))
+		err = NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_EXPIRED, fmt.Sprintf("账户 accountId:%d entAccountId:%d entId:%d entUserId:%d 业务%s权限已过期", accountId, entAccountId, entId, entUserId, funcCode))
 		return
 	case -2:
-		err = NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_NOTENOUGH, fmt.Sprintf("账户 eId:%d,uId:%d 业务%s权限余额不足", eId, uId, funcCode))
+		err = NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_NOTENOUGH, fmt.Sprintf("账户 accountId:%d entAccountId:%d entId:%d entUserId:%d 业务%s权限余额不足", accountId, entAccountId, entId, entUserId, funcCode))
 		return
 	case -3:
-		err = NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_NOTHAS, fmt.Sprintf("账户 eId:%d,uId:%d 业务%s权限无授权", eId, uId, funcCode))
+		err = NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_NOTHAS, fmt.Sprintf("账户 accountId:%d entAccountId:%d entId:%d entUserId:%d 业务%s权限无授权", accountId, entAccountId, entId, entUserId, funcCode))
 		return
 	}
 	return res.UseCount, res.SurplusCount, nil
 }
 
 // ResourcePowerDeduct 资源中心消费
-// eid 企业id
-// uId 新用户id;非mongodb中user表id
+// accountId 账户id
+// entAccountId 企业账户id
 // funcCode 业务代码
 // deductNum 扣除数量
 // ids 扣除详情id;例如数据导出信息id等数据
-func ResourcePowerDeduct(eId, uId int64, funcCode, appId string, deductNum int64, ids []string) error {
+func ResourcePowerDeduct(accountId, entAccountId int64, funcCode, appId string, deductNum int64, ids []string) error {
 	res, err := ResourceCenterRpc.Deduction(gctx.New(), &pb.DeductionReq{
 		Appid:        appId,
-		EntId:        eId,
-		UserId:       uId,
+		AccountId:    accountId,
+		EntAccountId: entAccountId,
 		FunctionCode: funcCode,
 		Count:        deductNum,
 		Ids:          ids,
@@ -97,28 +102,28 @@ func ResourcePowerDeduct(eId, uId int64, funcCode, appId string, deductNum int64
 	//0:失败 1:成功 -1:不在有效期内 -2:数量不足 -3:没有授权
 	switch res.Status {
 	case 0:
-		return NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_FAIL, fmt.Sprintf("账户 eId:%d,uId:%d 扣除业务%s权限失败", eId, uId, funcCode))
+		return NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_FAIL, fmt.Sprintf("账户 accountId:%d entAccountId:%d 扣除业务%s权限失败", accountId, entAccountId, funcCode))
 	case -1:
-		return NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_EXPIRED, fmt.Sprintf("账户 eId:%d,uId:%d 扣除业务%s权限失败,权限已过期", eId, uId, funcCode))
+		return NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_EXPIRED, fmt.Sprintf("账户 accountId:%d entAccountId:%d 扣除业务%s权限失败,权限已过期", accountId, entAccountId, funcCode))
 	case -2:
-		return NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_NOTENOUGH, fmt.Sprintf("账户 eId:%d,uId:%d 扣除业务%s权限失败,余额不足", eId, uId, funcCode))
+		return NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_NOTENOUGH, fmt.Sprintf("账户 accountId:%d entAccountId:%d 扣除业务%s权限失败,余额不足", accountId, entAccountId, funcCode))
 	case -3:
-		return NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_NOTHAS, fmt.Sprintf("账户 eId:%d,uId:%d 扣除业务%s权限失败", eId, uId, funcCode))
+		return NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_NOTHAS, fmt.Sprintf("账户 accountId:%d entAccountId:%d 扣除业务%s权限失败", accountId, entAccountId, funcCode))
 	}
 	return nil
 }
 
 // ResourcePowerRecharge 资源中心充值
-// eid 企业id
-// uId 新用户id;非mongodb中user表id
+// accountId 账户id
+// entAccountId 企业账户id
 // funcCode 业务代码
 // deductNum 扣除数量
 // ids 扣除详情id;例如数据导出信息id等数据
-func ResourcePowerRecharge(eId, uId int64, funcCode, appId string, deductNum int64, ids []string) error {
+func ResourcePowerRecharge(accountId, entAccountId int64, funcCode, appId string, deductNum int64, ids []string) error {
 	res, err := ResourceCenterRpc.Recharge(gctx.New(), &pb.RechargeReq{
 		Appid:        appId,
-		EntId:        eId,
-		UserId:       uId,
+		AccountId:    accountId,
+		EntAccountId: entAccountId,
 		FunctionCode: funcCode,
 		Count:        deductNum,
 		Ids:          ids,
@@ -128,15 +133,15 @@ func ResourcePowerRecharge(eId, uId int64, funcCode, appId string, deductNum int
 	}
 	switch res.Status {
 	case 0:
-		return NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_FAIL, fmt.Sprintf("账户 eId:%d,uId:%d 充值业务%s权限失败", eId, uId, funcCode))
+		return NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_FAIL, fmt.Sprintf("账户 accountId:%d entAccountId:%d 充值业务%s权限失败", accountId, entAccountId, funcCode))
 	case -1:
-		return NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_EXPIRED, fmt.Sprintf("账户 eId:%d,uId:%d 充值业务%s权限失败,权限已过期", eId, uId, funcCode))
+		return NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_EXPIRED, fmt.Sprintf("账户 accountId:%d entAccountId:%d 充值业务%s权限失败,权限已过期", accountId, entAccountId, funcCode))
 	case -2:
-		return NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_NOTENOUGH, fmt.Sprintf("账户 eId:%d,uId:%d 充值业务%s权限失败,余额不足", eId, uId, funcCode))
+		return NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_NOTENOUGH, fmt.Sprintf("账户 accountId:%d entAccountId:%d 充值业务%s权限失败,余额不足", accountId, entAccountId, funcCode))
 	case -3:
-		return NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_NOTHAS, fmt.Sprintf("账户 eId:%d,uId:%d 充值业务%s权限失败", eId, uId, funcCode))
+		return NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_NOTHAS, fmt.Sprintf("账户 accountId:%d entAccountId:%d 充值业务%s权限失败", accountId, entAccountId, funcCode))
 	case -4: //超出可拥有最大限额
-		return NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_RECHARGE_FULL, fmt.Sprintf("账户 eId:%d,uId:%d 充值业务%s权限失败", eId, uId, funcCode))
+		return NewErrorWithCode(GLOBAL_ERR_RESOURCE_PORWE_RECHARGE_FULL, fmt.Sprintf("账户 accountId:%d entAccountId:%d 充值业务%s权限失败", accountId, entAccountId, funcCode))
 	}
 
 	return nil

+ 2 - 2
go.mod

@@ -1,11 +1,11 @@
 module bp.jydev.jianyu360.cn/BaseService/gateway
 
-go 1.19
+go 1.18
 
 require (
 	app.yhyue.com/moapp/jybase v0.0.0-20230117032034-ad7c00ffe11a
 	bp.jydev.jianyu360.cn/BP/jynsq v0.0.0-20220424062752-50170a93c431
-	bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.4
+	bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.7
 	bp.jydev.jianyu360.cn/BaseService/userCenter v0.0.0-20220905055615-8540037e1b06
 	github.com/go-redis/redis v6.15.9+incompatible
 	github.com/gogf/gf/v2 v2.3.1

+ 2 - 2
go.sum

@@ -19,8 +19,8 @@ bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.0-20220419023723-0b32d4a41
 bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.0-20220419063004-233fc7ce006c/go.mod h1:6KL5LMEku83uRbre0W/bj5kXG2I6pJGBFtktmtp51yM=
 bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.0-20220420075831-0b59892e9982/go.mod h1:wsHNO91h37H+xE4ZNny0yd7mtpODeDJxbVYhIRMR+qw=
 bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.3/go.mod h1:Z353aucNO5hH4ZYjeKST3kE1PN3W8/uPc4J8s0Upz40=
-bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.4 h1:LXD8woSkDDtqCQ19S9TGvx7GVir300nGszoIidBTlGM=
-bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.4/go.mod h1:rRiGzKG4F/fmkNxXQCxrkxNWc8yf1SmW8qWCKfGIQSM=
+bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.7 h1:G6PHMWAHfYEuY6kbl7OM/KnCQf1Xa54mdhuP7JzK8/I=
+bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.7/go.mod h1:rRiGzKG4F/fmkNxXQCxrkxNWc8yf1SmW8qWCKfGIQSM=
 bp.jydev.jianyu360.cn/BaseService/userCenter v0.0.0-20220418072311-2062bed1e700/go.mod h1:KjcrxTzM96tBc6G4B8tlLBn1lrVy5UJYF8+eTdP4xAE=
 bp.jydev.jianyu360.cn/BaseService/userCenter v0.0.0-20220421015128-4a36f3eac5c5/go.mod h1:GT0QC4aaKDuXxAvaU4G02XjCc31TU1ctqBGqxQYOfC4=
 bp.jydev.jianyu360.cn/BaseService/userCenter v0.0.0-20220905055615-8540037e1b06 h1:tHDv+gN34UmgiJvIqEa1lXQnYz20HgJeJJCW0qFM3PE=