powerCheckCenter.go 2.3 KB

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