powerCheckCenter.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. res, err := PowerCheckCenterRpc.Check(gctx.New(), &pb.CheckReq{
  26. Appid: appid,
  27. Userid: userId,
  28. BaseUserId: baseUserId,
  29. AccountId: accountId,
  30. EntId: entId,
  31. PositionType: positionType,
  32. PositionId: positionId,
  33. })
  34. if err != nil {
  35. return err
  36. }
  37. /*
  38. 权益判断方式、0走资源中台
  39. 1前置代理判断,是否是付费用户
  40. 2前置代理判断,是否是超级订阅
  41. 3前置代理判断,是否是大会员
  42. 4前置代理判断,是否是商机管理
  43. */
  44. switch power_type {
  45. case 1:
  46. if res.Vip.Status <= 0 && res.Member.Status <= 0 && res.Entniche.Status <= 0 {
  47. return NewErrorWithCode(GLOBAL_ERR_NOPOWER, fmt.Sprintf("该用户非付费用户"))
  48. }
  49. case 2:
  50. if res.Vip.Status <= 0 {
  51. return NewErrorWithCode(GLOBAL_ERR_NOPOWER, fmt.Sprintf("该用户非超级订阅用户"))
  52. }
  53. case 3:
  54. if res.Member.Status <= 0 {
  55. return NewErrorWithCode(GLOBAL_ERR_NOPOWER, fmt.Sprintf("该用户非大会员用户"))
  56. }
  57. case 4:
  58. if res.Entniche.Status <= 0 {
  59. return NewErrorWithCode(GLOBAL_ERR_NOPOWER, fmt.Sprintf("该用户非商机管理用户"))
  60. }
  61. case 22: //临时加大会员专家版、商机版判断
  62. if !(res.Member.Status == 1 || res.Member.Status == 2 || res.Member.Status == 6 || res.Member.Status == 7) {
  63. return NewErrorWithCode(GLOBAL_ERR_NOPOWER, fmt.Sprintf("该用户非大会员专家版、商机版用户"))
  64. }
  65. }
  66. return nil
  67. }