powerCheckCenter.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package rpc
  2. import (
  3. "fmt"
  4. "github.com/gogf/gf/v2/net/gtrace"
  5. . "bp.jydev.jianyu360.cn/BaseService/gateway/common/gatecode"
  6. "bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/pb"
  7. "bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/powercheck"
  8. "github.com/gogf/gf/v2/os/gcfg"
  9. "github.com/gogf/gf/v2/os/gctx"
  10. "github.com/zeromicro/go-zero/core/discov"
  11. "github.com/zeromicro/go-zero/zrpc"
  12. )
  13. var PowerCheckCenterRpc powercheck.PowerCheck
  14. func initPowerCheckCenterRpcRpc() {
  15. PowerCheckCenterRpc = powercheck.NewPowerCheck(zrpc.MustNewClient(zrpc.RpcClientConf{
  16. Etcd: discov.EtcdConf{
  17. Key: gcfg.Instance().MustGet(gctx.New(), "etcd.baseserver.powerCheckCenter.key", nil).String(),
  18. Hosts: gcfg.Instance().MustGet(gctx.New(), "etcd.baseserver.powerCheckCenter.address", nil).Strings(),
  19. },
  20. }))
  21. }
  22. func CheckUserPower(ctx gctx.Ctx, power_type int, appid, userId string, baseUserId, accountId, entId, positionType, positionId int64) error {
  23. ctx, span := gtrace.NewSpan(ctx, "CheckUserPower")
  24. defer span.End()
  25. fmt.Println("PowerCheckCenterRpc value", PowerCheckCenterRpc)
  26. res, err := PowerCheckCenterRpc.Check(gctx.New(), &pb.CheckReq{
  27. Appid: appid,
  28. Userid: userId,
  29. BaseUserId: baseUserId,
  30. AccountId: accountId,
  31. EntId: entId,
  32. PositionType: positionType,
  33. PositionId: positionId,
  34. })
  35. fmt.Println("CheckUserPower", res, err)
  36. if err != nil {
  37. return err
  38. }
  39. /*
  40. 权益判断方式、0走资源中台
  41. 1前置代理判断,是否是付费用户
  42. 2前置代理判断,是否是超级订阅
  43. 3前置代理判断,是否是大会员
  44. 4前置代理判断,是否是商机管理
  45. */
  46. switch power_type {
  47. case 1:
  48. if res.Vip.Status <= 0 && res.Member.Status <= 0 && res.Entniche.Status <= 0 {
  49. return NewErrorWithCode(GLOBAL_ERR_NOPOWER, fmt.Sprintf("该用户非付费用户"))
  50. }
  51. case 2:
  52. if res.Vip.Status <= 0 {
  53. return NewErrorWithCode(GLOBAL_ERR_NOPOWER, fmt.Sprintf("该用户非超级订阅用户"))
  54. }
  55. case 3:
  56. if res.Member.Status <= 0 {
  57. return NewErrorWithCode(GLOBAL_ERR_NOPOWER, fmt.Sprintf("该用户非大会员用户"))
  58. }
  59. case 4:
  60. if res.Entniche.Status <= 0 {
  61. return NewErrorWithCode(GLOBAL_ERR_NOPOWER, fmt.Sprintf("该用户非商机管理用户"))
  62. }
  63. case 22: //临时加大会员专家版、商机版判断
  64. if !(res.Member.Status == 1 || res.Member.Status == 2 || res.Member.Status == 6 || res.Member.Status == 7) {
  65. return NewErrorWithCode(GLOBAL_ERR_NOPOWER, fmt.Sprintf("该用户非大会员专家版、商机版用户"))
  66. }
  67. }
  68. return nil
  69. }