mail.pb.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. package proto
  2. import (
  3. "context"
  4. "encoding/json"
  5. "bet24.com/log"
  6. "bet24.com/servers/micros/common"
  7. item "bet24.com/servers/micros/item_inventory/proto"
  8. )
  9. type Request_mail struct {
  10. Name string
  11. UserId int
  12. Title string
  13. Content string
  14. Image string
  15. MailId int
  16. SysMailOne *SysMail
  17. Status int
  18. }
  19. type Response_mail struct {
  20. Data string
  21. Success bool
  22. RetCode int
  23. UserMails []*UserMail
  24. SysMails []*SysMail
  25. SysMailOne *SysMail
  26. Items []item.ItemPack
  27. }
  28. const (
  29. MailType_sys = iota
  30. MailType_service
  31. MailType_charge
  32. )
  33. // 发送用户邮件(客服留言)
  34. func SendUserMail(userId int, title, content, img string) (int, []*UserMail) {
  35. xclient := getClient()
  36. //defer xclient.Close()
  37. args := &Request_mail{
  38. UserId: userId,
  39. Title: title,
  40. Content: content,
  41. Image: img,
  42. }
  43. reply := &Response_mail{}
  44. err := xclient.Call(context.Background(), "SendUserMail", args, reply)
  45. if err != nil {
  46. log.Debug("mail failed to call: %v", err)
  47. common.GetClientPool().RemoveClient(ServiceName)
  48. return 0, nil
  49. }
  50. return reply.RetCode, reply.UserMails
  51. }
  52. // 获取用户邮件(客服留言)
  53. func GetUserMails(userId int, mailId int) (int, []*UserMail) {
  54. xclient := getClient()
  55. //defer xclient.Close()
  56. args := &Request_mail{
  57. UserId: userId,
  58. MailId: mailId,
  59. }
  60. reply := &Response_mail{}
  61. err := xclient.Call(context.Background(), "GetUserMails", args, reply)
  62. if err != nil {
  63. log.Debug("mail failed to call: %v", err)
  64. common.GetClientPool().RemoveClient(ServiceName)
  65. return 0, nil
  66. }
  67. return reply.RetCode, reply.UserMails
  68. }
  69. // 获取用户邮件提示(客服留言)
  70. func GetUserMailTip(userId int) bool {
  71. xclient := getClient()
  72. //defer xclient.Close()
  73. args := &Request_mail{
  74. UserId: userId,
  75. }
  76. reply := &Response_mail{}
  77. err := xclient.Call(context.Background(), "GetUserMailTip", args, reply)
  78. if err != nil {
  79. log.Debug("mail failed to call: %v", err)
  80. common.GetClientPool().RemoveClient(ServiceName)
  81. return false
  82. }
  83. return reply.Success
  84. }
  85. // 发送系统邮件(含附件)
  86. func SendSysMail(userId int, sm *SysMail) bool {
  87. xclient := getClient()
  88. //defer xclient.Close()
  89. args := &Request_mail{
  90. UserId: userId,
  91. SysMailOne: sm,
  92. }
  93. reply := &Response_mail{}
  94. err := xclient.Call(context.Background(), "SendSysMail", args, reply)
  95. if err != nil {
  96. log.Debug("mail failed to call: %v", err)
  97. common.GetClientPool().RemoveClient(ServiceName)
  98. return false
  99. }
  100. return reply.Success
  101. }
  102. // 获取系统邮件列表
  103. func GetSysMails(userId, sysMsgId int) []*SysMail {
  104. xclient := getClient()
  105. //defer xclient.Close()
  106. args := &Request_mail{
  107. UserId: userId,
  108. MailId: sysMsgId,
  109. }
  110. reply := &Response_mail{}
  111. err := xclient.Call(context.Background(), "GetSysMails", args, reply)
  112. if err != nil {
  113. log.Debug("mail failed to call: %v", err)
  114. common.GetClientPool().RemoveClient(ServiceName)
  115. return nil
  116. }
  117. return reply.SysMails
  118. }
  119. func GetSysMail(userId, sysMsgId int) *SysMail {
  120. xclient := getClient()
  121. //defer xclient.Close()
  122. args := &Request_mail{
  123. UserId: userId,
  124. MailId: sysMsgId,
  125. }
  126. reply := &Response_mail{}
  127. err := xclient.Call(context.Background(), "GetSysMail", args, reply)
  128. if err != nil {
  129. log.Debug("mail failed to call: %v", err)
  130. common.GetClientPool().RemoveClient(ServiceName)
  131. return nil
  132. }
  133. return reply.SysMailOne
  134. }
  135. // 修改系统邮件
  136. func UpdateSysMail(userId, sysMsgId, status int) (int, []item.ItemPack) {
  137. xclient := getClient()
  138. //defer xclient.Close()
  139. args := &Request_mail{
  140. UserId: userId,
  141. MailId: sysMsgId,
  142. Status: status,
  143. }
  144. reply := &Response_mail{}
  145. err := xclient.Call(context.Background(), "UpdateSysMail", args, reply)
  146. if err != nil {
  147. log.Debug("mail failed to call: %v", err)
  148. common.GetClientPool().RemoveClient(ServiceName)
  149. return 0, nil
  150. }
  151. return reply.RetCode, reply.Items
  152. }
  153. // 删除系统邮件
  154. func DelSysMail(userId, sysMsgId int) int {
  155. xclient := getClient()
  156. //defer xclient.Close()
  157. args := &Request_mail{
  158. UserId: userId,
  159. MailId: sysMsgId,
  160. }
  161. reply := &Response_mail{}
  162. err := xclient.Call(context.Background(), "DelSysMail", args, reply)
  163. if err != nil {
  164. log.Debug("mail failed to call: %v", err)
  165. common.GetClientPool().RemoveClient(ServiceName)
  166. return 0
  167. }
  168. return reply.RetCode
  169. }
  170. // 修改系统邮件
  171. func UpdateAllSysMail(userId int) string {
  172. xclient := getClient()
  173. //defer xclient.Close()
  174. args := &Request_mail{
  175. UserId: userId,
  176. }
  177. reply := &Response_mail{}
  178. err := xclient.Call(context.Background(), "UpdateAllSysMail", args, reply)
  179. if err != nil {
  180. log.Debug("mail failed to call: %v", err)
  181. common.GetClientPool().RemoveClient(ServiceName)
  182. }
  183. buf, _ := json.Marshal(reply)
  184. return string(buf)
  185. }