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