rpc.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. package server
  2. import (
  3. col "go-common/app/service/main/coupon/model"
  4. "go-common/app/service/main/vip/conf"
  5. "go-common/app/service/main/vip/model"
  6. "go-common/app/service/main/vip/service"
  7. "go-common/library/log"
  8. "go-common/library/net/rpc"
  9. "go-common/library/net/rpc/context"
  10. )
  11. // RPC represent rpc server
  12. type RPC struct {
  13. svc *service.Service
  14. }
  15. // New init rpc.
  16. func New(c *conf.Config, s *service.Service) (svr *rpc.Server) {
  17. r := &RPC{svc: s}
  18. svr = rpc.NewServer(c.RPCServer)
  19. if err := svr.Register(r); err != nil {
  20. panic(err)
  21. }
  22. return
  23. }
  24. // Ping check connection success.
  25. func (r *RPC) Ping(c context.Context, arg *struct{}, res *struct{}) (err error) {
  26. return
  27. }
  28. // VipInfo vipinfo.
  29. func (r *RPC) VipInfo(c context.Context, arg *model.ArgRPCMid, res *model.VipInfoResp) (err error) {
  30. var v *model.VipInfoResp
  31. if v, err = r.svc.ByMid(c, arg.Mid); err != nil {
  32. log.Error("RPC.VipInfo(%d) err(%+v)", arg.Mid, err)
  33. return
  34. }
  35. if v != nil {
  36. *res = *v
  37. }
  38. return
  39. }
  40. // VipInfos vipinfo list.
  41. func (r *RPC) VipInfos(c context.Context, arg *model.ArgRPCMids, res *map[int64]*model.VipInfoResp) (err error) {
  42. if *res, err = r.svc.VipInfos(c, arg.Mids); err != nil {
  43. log.Error("RPC.VipInfos(%v) err(%+v)", arg.Mids, err)
  44. }
  45. return
  46. }
  47. // BcoinList bcoin list.
  48. func (r *RPC) BcoinList(c context.Context, arg *model.ArgRPCMid, res *model.BcoinSalaryResp) (err error) {
  49. var b *model.BcoinSalaryResp
  50. if b, err = r.svc.BcoinGive(c, arg.Mid); err != nil {
  51. log.Error("RPC.BcoinGive(%d) err(%+v)", arg.Mid, err)
  52. return
  53. }
  54. if b != nil {
  55. *res = *b
  56. }
  57. return
  58. }
  59. // History user change history.
  60. func (r *RPC) History(c context.Context, arg *model.ArgChangeHistory, res *[]*model.VipChangeHistoryVo) (err error) {
  61. if *res, err = r.svc.H5History(c, arg); err != nil {
  62. log.Error("RPC.History(%v) err(%+v)", arg, err)
  63. }
  64. return
  65. }
  66. // CreateOrder create order.
  67. func (r *RPC) CreateOrder(c context.Context, arg *model.ArgCreateOrder, res *map[string]interface{}) (err error) {
  68. if *res, err = r.svc.CreateOrder(c, arg, arg.IP); err != nil {
  69. log.Error("RPC.CreateOrder(%v) err(%+v)", arg, err)
  70. }
  71. return
  72. }
  73. // OrderInfo vipinfo.
  74. func (r *RPC) OrderInfo(c context.Context, arg *model.ArgRPCOrderNo, res *model.OrderInfo) (err error) {
  75. var v *model.OrderInfo
  76. if v, err = r.svc.OrderInfo(c, arg.OrderNo); err != nil {
  77. log.Error("RPC.OrderInfo(%s) err(%+v)", arg.OrderNo, err)
  78. return
  79. }
  80. if v != nil {
  81. *res = *v
  82. }
  83. return
  84. }
  85. // Tips info.
  86. func (r *RPC) Tips(c context.Context, arg *model.ArgTips, res *[]*model.TipsResp) (err error) {
  87. if *res, err = r.svc.Tips(c, arg); err != nil {
  88. log.Error("RPC.Tips(%v) err(%+v)", arg, err)
  89. }
  90. return
  91. }
  92. // CouponBySuitID coupon by suit id.
  93. func (r *RPC) CouponBySuitID(c context.Context, arg *model.ArgCouponPanel, res *col.CouponAllowancePanelInfo) (err error) {
  94. var v *col.CouponAllowancePanelInfo
  95. if v, err = r.svc.CouponBySuitID(c, arg); err == nil && v != nil {
  96. *res = *v
  97. }
  98. if err != nil {
  99. log.Error("rpc.CouponBySuitID(%+v) err(%+v)", arg, err)
  100. }
  101. return
  102. }
  103. // CouponBySuitIDV2 coupon by suit id.
  104. func (r *RPC) CouponBySuitIDV2(c context.Context, arg *model.ArgCouponPanelV2, res *col.CouponAllowancePanelInfo) (err error) {
  105. var v *col.CouponAllowancePanelInfo
  106. arg1 := &model.ArgCouponPanel{
  107. Mid: arg.Mid,
  108. Sid: arg.Sid,
  109. }
  110. if v, err = r.svc.CouponBySuitID(c, arg1); err == nil && v != nil {
  111. *res = *v
  112. }
  113. if err != nil {
  114. log.Error("rpc.CouponBySuitID(%+v) err(%+v)", arg, err)
  115. }
  116. return
  117. }
  118. // CouponsForPanel coupon by suit id.
  119. func (r *RPC) CouponsForPanel(c context.Context, arg *model.ArgCouponPanel, res *col.CouponAllowancePanelResp) (err error) {
  120. var v *col.CouponAllowancePanelResp
  121. if v, err = r.svc.CouponsForPanel(c, arg); err == nil && v != nil {
  122. *res = *v
  123. }
  124. if err != nil {
  125. log.Error("rpc.CouponsForPanel(%+v) err(%+v)", arg, err)
  126. }
  127. return
  128. }
  129. // CouponsForPanelV2 coupon by suit id.
  130. func (r *RPC) CouponsForPanelV2(c context.Context, arg *model.ArgCouponPanelV2, res *col.CouponAllowancePanelResp) (err error) {
  131. var v *col.CouponAllowancePanelResp
  132. arg1 := &model.ArgCouponPanel{
  133. Mid: arg.Mid,
  134. Sid: arg.Sid,
  135. }
  136. if v, err = r.svc.CouponsForPanel(c, arg1); err == nil && v != nil {
  137. *res = *v
  138. }
  139. if err != nil {
  140. log.Error("rpc.CouponsForPanel(%+v) err(%+v)", arg, arg1)
  141. }
  142. return
  143. }
  144. // CancelUseCoupon cancel use coupon.
  145. func (r *RPC) CancelUseCoupon(c context.Context, arg *model.ArgCouponCancel, res *struct{}) (err error) {
  146. if err = r.svc.CancelUseCoupon(c, arg.Mid, arg.CouponToken, arg.IP); err != nil {
  147. log.Error("rpc.CancelUseCoupon(%+v) err(%+v)", arg, err)
  148. }
  149. return
  150. }
  151. // PrivilegeBySid privilege by sid.
  152. func (r *RPC) PrivilegeBySid(c context.Context, arg *model.ArgPrivilegeBySid, res *model.PrivilegesResp) (err error) {
  153. var v *model.PrivilegesResp
  154. if v, err = r.svc.PrivilegesBySid(c, arg); err == nil && v != nil {
  155. *res = *v
  156. }
  157. return
  158. }
  159. // PrivilegeByType privilege by type.
  160. func (r *RPC) PrivilegeByType(c context.Context, arg *model.ArgPrivilegeDetail, res *[]*model.PrivilegeDetailResp) (err error) {
  161. *res, err = r.svc.PrivilegesByType(c, arg)
  162. return
  163. }
  164. // PanelExplain panel explain.
  165. func (r *RPC) PanelExplain(c context.Context, arg *model.ArgPanelExplain, res *model.VipPanelExplain) (err error) {
  166. var v *model.VipPanelExplain
  167. if v, err = r.svc.VipPanelExplain(c, arg); err == nil && v != nil {
  168. *res = *v
  169. }
  170. return
  171. }
  172. // Jointly jointly info.
  173. func (r *RPC) Jointly(c context.Context, arg *struct{}, res *[]*model.JointlyResp) (err error) {
  174. *res, err = r.svc.Jointly(c)
  175. return
  176. }
  177. //SurplusFrozenTime surplus frozen time.
  178. func (r *RPC) SurplusFrozenTime(c context.Context, arg *model.ArgRPCMid, stime *int64) (err error) {
  179. *stime, err = r.svc.SurplusFrozenTime(c, arg.Mid)
  180. return
  181. }
  182. //Unfrozen unfrozen.
  183. func (r *RPC) Unfrozen(c context.Context, arg *model.ArgRPCMid, res *struct{}) (err error) {
  184. err = r.svc.Unfrozen(c, arg.Mid)
  185. return
  186. }
  187. //ResourceBatchOpenVip resource batch open vip.
  188. func (r *RPC) ResourceBatchOpenVip(c context.Context, arg *model.ArgUseBatch, res *struct{}) (err error) {
  189. err = r.svc.ResourceBatchOpenVip(c, arg)
  190. return
  191. }
  192. //OrderPayResult .
  193. func (r *RPC) OrderPayResult(c context.Context, arg *model.ArgDialog, res *model.OrderResult) (err error) {
  194. var o *model.OrderResult
  195. if o, err = r.svc.OrderPayResult(c, arg.OrderNo, arg.Mid, arg.AppID, arg.Platform, arg.Device, arg.MobiApp, arg.Build, arg.PanelType); err == nil && o != nil {
  196. *res = *o
  197. }
  198. return
  199. }
  200. // AssociateVips get all associate vip infos
  201. func (r *RPC) AssociateVips(c context.Context, arg *model.ArgAssociateVip, res *[]*model.AssociateVipResp) (err error) {
  202. *res = r.svc.AssociateVips(c, arg)
  203. return
  204. }