api.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package im
  2. import (
  3. "context"
  4. "sportfitness/base/global"
  5. im "sportfitness/base/repository/grpc/bsw/im/im"
  6. "google.golang.org/grpc/status"
  7. "git.beswell.com/gframe/application"
  8. "google.golang.org/grpc/metadata"
  9. )
  10. func handleErr(err error) {
  11. if err == nil {
  12. return
  13. }
  14. s, _ := status.FromError(err)
  15. panic(application.ErrorBusinessF(application.ErrorCode(s.Code()), s.Message()))
  16. }
  17. func getClient() im.ApiClient {
  18. conn, err := application.GetServiceGrpcConn("bsw/im")
  19. if err != nil {
  20. panic(err)
  21. }
  22. client := im.NewApiClient(conn)
  23. return client
  24. }
  25. func ctx() context.Context {
  26. md := metadata.Pairs("sys_token", global.SysToken)
  27. return metadata.NewOutgoingContext(context.Background(), md)
  28. }
  29. func SignUpUserCode(params *im.SignUpRequest) (userId int64) {
  30. r, err := getClient().SignUpUserCode(ctx(), params)
  31. handleErr(err)
  32. userId = r.GetId()
  33. return
  34. }
  35. func GenVerifyImage(height, width int32) (id, imageBase64 string) {
  36. r, err := getClient().GenVerifyImage(ctx(), &im.GenVerifyImageRequest{
  37. Height: int32(height),
  38. Width: int32(width),
  39. })
  40. handleErr(err)
  41. id = r.CodeId
  42. imageBase64 = r.ImageBase64
  43. return
  44. }
  45. func SignInUserCodePassword(userCode, password, ip, ClientInfo, codeId, verifyCode string) (token string, userId int) {
  46. r, err := getClient().SignInUserCode(ctx(), &im.SignInPasswordRequest{
  47. Credential: userCode,
  48. Password: password,
  49. ExpirationSec: global.TokenExpireSec,
  50. Ip: ip,
  51. ClientInfo: ClientInfo,
  52. CodeId: codeId,
  53. VerifyCode: verifyCode,
  54. })
  55. handleErr(err)
  56. token = r.Token
  57. userId = int(r.UserId)
  58. return
  59. }
  60. func RegisterServiceList(servicePathList []string) {
  61. request := &im.SaveServiceListRequest{}
  62. for _, p := range servicePathList {
  63. request.List = append(request.List, &im.Service{
  64. Path: p,
  65. Memo: "自动添加",
  66. })
  67. }
  68. _, err := getClient().SubServiceSaveList(ctx(), request)
  69. if err != nil {
  70. panic(err)
  71. }
  72. }
  73. func SignOut(token string) {
  74. request := &im.TokenParam{Token: token}
  75. _, err := getClient().SubSignOut(ctx(), request)
  76. handleErr(err)
  77. }
  78. func SubSessionCheck(token string) int64 {
  79. request := &im.TokenParam{Token: token}
  80. rs, err := getClient().SubSessionCheck(ctx(), request)
  81. handleErr(err)
  82. return rs.UserId
  83. }
  84. func SubPermissionListCheck(token string, shopId int64, servicePathList []string) *im.PermissionCheckReply {
  85. rs, err := getClient().SubPermissionListCheck(ctx(), &im.PermissionCheck{
  86. Token: token,
  87. ShopId: shopId,
  88. ServicePathList: servicePathList,
  89. })
  90. handleErr(err)
  91. return rs
  92. }
  93. func ShopListRequest(name string, status im.Status, sId int64) *im.ShopListReply {
  94. request := &im.ShopListRequest{SysId: 0, Name: name, Status: status, SId: sId}
  95. rs, err := getClient().ShopList(ctx(), request)
  96. handleErr(err)
  97. return rs
  98. }
  99. // ShopDetail 查询商家信息
  100. func ShopDetail(shopId int64) *im.ShopInfo {
  101. request := &im.ShopDetailRequest{ShopId: shopId}
  102. rs, err := getClient().ShopDetail(ctx(), request)
  103. handleErr(err)
  104. return rs
  105. }
  106. // ShopLicenseList 商户许可列表
  107. func ShopLicenseList(shopId int64) *im.LicenseList {
  108. request := &im.ShopDetailRequest{ShopId: shopId}
  109. rs, err := getClient().ShopLicenseList(ctx(), request)
  110. handleErr(err)
  111. return rs
  112. }
  113. // LicenseTypeMap 许可类型字典
  114. func LicenseTypeMap(idList []int64) *im.LicenseTypeMapReply {
  115. request := &im.IdList{IdList: idList}
  116. rs, err := getClient().LicenseTypeMap(ctx(), request)
  117. handleErr(err)
  118. return rs
  119. }
  120. func GetShopNavi(userId, shopId int64, parentId int64, status im.Status) *im.UserGetColumnListReply {
  121. request := &im.UserGetColumnListRequest{UserId: userId, ShopId: shopId, ParentId: parentId, Status: status}
  122. rs, err := getClient().UserGetColumnList(ctx(), request)
  123. handleErr(err)
  124. return rs
  125. }