subscriobePay.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package rpc
  2. import (
  3. qu "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/go-logger/logger"
  5. "encoding/json"
  6. "fmt"
  7. "github.com/gogf/gf/v2/os/gcfg"
  8. "github.com/gogf/gf/v2/os/gctx"
  9. "github.com/gogf/gf/v2/util/gconv"
  10. "net/rpc"
  11. )
  12. //===========================================
  13. // 来源 https://bp.jydev.jianyu360.cn/BP/common/src/master/src/qfw/util/rpc/order.go
  14. //==========================================
  15. // shareUserInfo
  16. type shareUserInfo struct {
  17. UserId string `json:"userId"` //用户id
  18. TimeExpand int `json:"timeExpand"` //延长时间
  19. Remark string `json:"remark"` //备注
  20. }
  21. //分享完成 订单处理结果
  22. type JYShareResp struct {
  23. Error_code int64 `json:"error_code"`
  24. Error_msg string `json:"error_msg"`
  25. Data interface{} `json:"data"`
  26. }
  27. type JYShareUserIdsRes struct {
  28. ShareUserInfo []shareUserInfo //被分享者+分享者等用户信息
  29. }
  30. //===========================================
  31. // SubVipHarvest 超级订阅奖励发放
  32. func SubVipHarvest(userId string, num int, remark string) (err error) {
  33. defer qu.Catch()
  34. client, err := rpc.DialHTTP("tcp", gcfg.Instance().MustGet(gctx.New(), "rpc.payrpc").String())
  35. if err != nil {
  36. logger.Error("GetUserVipBaseMsgByRpc userId", userId, "err", err.Error())
  37. return err
  38. }
  39. var repl JYShareResp
  40. req := JYShareUserIdsRes{
  41. ShareUserInfo: []shareUserInfo{
  42. {
  43. UserId: userId,
  44. TimeExpand: num,
  45. Remark: remark,
  46. },
  47. },
  48. }
  49. if err = client.Call("JyPayRpc.ShareFissionNew", req, &repl); err != nil {
  50. logger.Error("JyPayRpc.ShareFissionNew userId", userId, "err", err.Error())
  51. return err
  52. }
  53. if repl.Error_code != 0 {
  54. err = fmt.Errorf(repl.Error_msg)
  55. return
  56. }
  57. return nil
  58. }
  59. type VipStatus struct {
  60. Status int `json:"status"` //大会员状态
  61. VipStatus int `json:"vip_status"` //超级订阅状态
  62. EntnicheStatus int `json:"entniche_status"` //超级订阅状态
  63. }
  64. // GetUserVipBaseMsgByRpc 获取用户Vip信息
  65. func GetUserVipBaseMsgByRpc(userId string) (vs VipStatus, err error) {
  66. defer qu.Catch()
  67. var repl JYShareResp
  68. vs = VipStatus{}
  69. client, err := rpc.DialHTTP("tcp", gcfg.Instance().MustGet(gctx.New(), "rpc.payrpc").String())
  70. if err != nil {
  71. logger.Error("GetUserVipBaseMsgByRpc userId", userId, "err", err.Error())
  72. return
  73. }
  74. req := JYShareUserIdsRes{
  75. ShareUserInfo: []shareUserInfo{
  76. shareUserInfo{
  77. UserId: userId,
  78. },
  79. },
  80. }
  81. if err = client.Call("JyPayRpc.GetUserPowerInfo", req, &repl); err != nil {
  82. logger.Error("GetUserVipBaseMsgByRpc userId", userId, "err", err.Error())
  83. return
  84. }
  85. if repl.Error_code != 0 {
  86. err = fmt.Errorf(repl.Error_msg)
  87. return
  88. }
  89. umErr := json.Unmarshal(gconv.Bytes(repl.Data), &vs)
  90. if umErr != nil {
  91. err = fmt.Errorf("格式化信息异常")
  92. }
  93. return
  94. }