inventory.pb.go 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. package proto
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/micros/common"
  5. "context"
  6. )
  7. type Request_User struct {
  8. UserId int
  9. IpAddress string
  10. }
  11. func AddUser(userId int, ipAddress string) {
  12. xclient := getClient()
  13. //defer xclient.Close()
  14. args := &Request_User{
  15. UserId: userId,
  16. IpAddress: ipAddress,
  17. }
  18. err := xclient.Call(context.Background(), "AddUser", args, nil)
  19. if err != nil {
  20. common.GetClientPool().RemoveClient(ServiceName)
  21. log.Debug("item_invenroty failed to call: %v", err)
  22. }
  23. }
  24. func RemoveUser(userId int) {
  25. xclient := getClient()
  26. //defer xclient.Close()
  27. args := &Request_User{
  28. UserId: userId,
  29. }
  30. err := xclient.Call(context.Background(), "RemoveUser", args, nil)
  31. if err != nil {
  32. common.GetClientPool().RemoveClient(ServiceName)
  33. log.Debug("item_invenroty failed to call: %v", err)
  34. }
  35. }
  36. type Request_Consume struct {
  37. UserId int
  38. ItemId int
  39. BulletId int
  40. Count int
  41. IsGift int
  42. }
  43. type Response_Consume struct {
  44. Success bool
  45. ErrorMsg string
  46. }
  47. func Consume(userId, itemId, bulletId, count, isGift int) (bool, string) {
  48. xclient := getClient()
  49. //defer xclient.Close()
  50. args := &Request_Consume{
  51. UserId: userId,
  52. ItemId: itemId,
  53. BulletId: bulletId,
  54. Count: count,
  55. IsGift: isGift,
  56. }
  57. reply := &Response_Consume{}
  58. err := xclient.Call(context.Background(), "Consume", args, reply)
  59. if err != nil {
  60. log.Debug("item_invenroty failed to call: %v", err)
  61. common.GetClientPool().RemoveClient(ServiceName)
  62. return false, "Comsume failed rpc call"
  63. }
  64. return reply.Success, reply.ErrorMsg
  65. }
  66. type Request_Sell struct {
  67. UserId int
  68. ItemId int
  69. Count int
  70. LogType int
  71. }
  72. type Response_Sell struct {
  73. Success bool
  74. ErrorMsg string
  75. }
  76. func Sell(userId, itemId, count, logType int) (bool, string) {
  77. xclient := getClient()
  78. //defer xclient.Close()
  79. args := &Request_Sell{
  80. UserId: userId,
  81. ItemId: itemId,
  82. Count: count,
  83. LogType: logType,
  84. }
  85. reply := &Response_Sell{}
  86. err := xclient.Call(context.Background(), "Sell", args, reply)
  87. if err != nil {
  88. log.Debug("item_invenroty failed to call: %v", err)
  89. common.GetClientPool().RemoveClient(ServiceName)
  90. return false, "Sell failed rpc call"
  91. }
  92. return reply.Success, reply.ErrorMsg
  93. }
  94. type Request_ConsumeBulk struct {
  95. UserId int
  96. Items []ItemPack
  97. LogType int
  98. }
  99. type Response_ConsumeBulk struct {
  100. Success bool
  101. }
  102. func ConsumeBulk(userId int, items []ItemPack, logType int) bool {
  103. xclient := getClient()
  104. //defer xclient.Close()
  105. args := &Request_ConsumeBulk{
  106. UserId: userId,
  107. Items: items,
  108. LogType: logType,
  109. }
  110. reply := &Response_ConsumeBulk{}
  111. err := xclient.Call(context.Background(), "ConsumeBulk", args, reply)
  112. if err != nil {
  113. log.Debug("item_invenroty failed to call: %v", err)
  114. common.GetClientPool().RemoveClient(ServiceName)
  115. return false
  116. }
  117. return reply.Success
  118. }
  119. type Request_ConsumeLottery struct {
  120. UserId int
  121. Count int
  122. }
  123. type Response_ConsumeLottery struct {
  124. Success bool
  125. ErrorMsg string
  126. }
  127. func ConsumeLottery(userId, itemId, count, logType int) (bool, string) {
  128. xclient := getClient()
  129. //defer xclient.Close()
  130. args := &Request_ConsumeLottery{
  131. UserId: userId,
  132. Count: count,
  133. }
  134. reply := &Response_ConsumeLottery{}
  135. err := xclient.Call(context.Background(), "ConsumeLottery", args, reply)
  136. if err != nil {
  137. log.Debug("item_invenroty failed to call: %v", err)
  138. common.GetClientPool().RemoveClient(ServiceName)
  139. return false, "failed rpc call"
  140. }
  141. return reply.Success, reply.ErrorMsg
  142. }
  143. type Request_AddItems struct {
  144. UserId int
  145. Items []ItemPack
  146. LogType int
  147. Desc string
  148. ExpireTime int
  149. }
  150. type Response_AddItems struct {
  151. Success bool
  152. }
  153. func AddItems(userId int, items []ItemPack, desc string, logType int) bool {
  154. xclient := getClient()
  155. //defer xclient.Close()
  156. args := &Request_AddItems{
  157. UserId: userId,
  158. Items: items,
  159. LogType: logType,
  160. Desc: desc,
  161. }
  162. reply := &Response_AddItems{}
  163. err := xclient.Call(context.Background(), "AddItems", args, reply)
  164. if err != nil {
  165. log.Debug("item_invenroty failed to call: %v", err)
  166. common.GetClientPool().RemoveClient(ServiceName)
  167. return false
  168. }
  169. return reply.Success
  170. }
  171. // vip激活或升级时,根据vip时效添加时效道具
  172. func AddItemsWithExpireTime(userId int, items []ItemPack, desc string, logType int, expireTime int) bool {
  173. xclient := getClient()
  174. //defer xclient.Close()
  175. args := &Request_AddItems{
  176. UserId: userId,
  177. Items: items,
  178. LogType: logType,
  179. Desc: desc,
  180. ExpireTime: expireTime,
  181. }
  182. reply := &Response_AddItems{}
  183. err := xclient.Call(context.Background(), "AddItemsWithExpireTime", args, reply)
  184. if err != nil {
  185. log.Debug("item_invenroty.AddItemsWithExpireTime failed to call: %v", err)
  186. common.GetClientPool().RemoveClient(ServiceName)
  187. return false
  188. }
  189. return reply.Success
  190. }
  191. type Response_GetUserItems struct {
  192. Itms []UserItem
  193. }
  194. func GetUserItems(userId int) []UserItem {
  195. xclient := getClient()
  196. //defer xclient.Close()
  197. args := &Request{
  198. UserId: userId,
  199. }
  200. reply := &Response_GetUserItems{}
  201. err := xclient.Call(context.Background(), "GetUserItems", args, reply)
  202. if err != nil {
  203. log.Debug("item_invenroty failed to call: %v", err)
  204. common.GetClientPool().RemoveClient(ServiceName)
  205. return nil
  206. }
  207. return reply.Itms
  208. }
  209. type Response_GetUserLottery struct {
  210. Itm *UserItem
  211. }
  212. func GetUserLottery(userId int) *UserItem {
  213. xclient := getClient()
  214. //defer xclient.Close()
  215. args := &Request{
  216. UserId: userId,
  217. }
  218. reply := &Response_GetUserLottery{}
  219. err := xclient.Call(context.Background(), "GetUserLottery", args, reply)
  220. if err != nil {
  221. log.Debug("item_invenroty failed to call: %v", err)
  222. common.GetClientPool().RemoveClient(ServiceName)
  223. return nil
  224. }
  225. return reply.Itm
  226. }
  227. type Request_GetItemCount struct {
  228. UserId int
  229. ItemId int
  230. }
  231. type Response_GetItemCount struct {
  232. Count int
  233. }
  234. func GetItemCount(userId int, itemId int) int {
  235. xclient := getClient()
  236. //defer xclient.Close()
  237. args := &Request_GetItemCount{
  238. UserId: userId,
  239. ItemId: itemId,
  240. }
  241. reply := &Response_GetItemCount{}
  242. err := xclient.Call(context.Background(), "GetItemCount", args, reply)
  243. if err != nil {
  244. log.Debug("item_invenroty failed to call: %v", err)
  245. common.GetClientPool().RemoveClient(ServiceName)
  246. return 0
  247. }
  248. return reply.Count
  249. }
  250. type Request_Gift struct {
  251. UserId int
  252. ToUserId int
  253. ItemId int
  254. Count int
  255. }
  256. type Response_Gift struct {
  257. Success bool
  258. ErrorMsg string
  259. }
  260. func Gift(userId, toUserId, itemId, count int) (bool, string) {
  261. xclient := getClient()
  262. //defer xclient.Close()
  263. args := &Request_Gift{
  264. UserId: userId,
  265. ToUserId: toUserId,
  266. ItemId: itemId,
  267. Count: count,
  268. }
  269. reply := &Response_Gift{}
  270. err := xclient.Call(context.Background(), "Gift", args, reply)
  271. if err != nil {
  272. log.Debug("item_invenroty failed to call: %v", err)
  273. common.GetClientPool().RemoveClient(ServiceName)
  274. return false, ""
  275. }
  276. return reply.Success, reply.ErrorMsg
  277. }
  278. type Request_DeduceByAdmin struct {
  279. OpUserId int
  280. OpName string
  281. UserId int
  282. ItemId int
  283. Count int
  284. }
  285. type Response_DeduceByAdmin struct {
  286. Success bool
  287. ErrorMsg string
  288. }
  289. func ReduceItemByAdmin(opUserID int, opUserName string, userId, itemId, count int) (bool, string) {
  290. xclient := getClient()
  291. //defer xclient.Close()
  292. args := &Request_DeduceByAdmin{
  293. OpUserId: opUserID,
  294. OpName: opUserName,
  295. UserId: userId,
  296. ItemId: itemId,
  297. Count: count,
  298. }
  299. reply := &Response_DeduceByAdmin{}
  300. err := xclient.Call(context.Background(), "ReduceItemByAdmin", args, reply)
  301. if err != nil {
  302. log.Debug("item_invenroty failed to call: %v", err)
  303. common.GetClientPool().RemoveClient(ServiceName)
  304. return false, ""
  305. }
  306. return reply.Success, reply.ErrorMsg
  307. }
  308. type Request_CheckDecoration struct {
  309. UserId int
  310. ItemId int
  311. Type int
  312. }
  313. type Response_CheckDecoration struct {
  314. Success bool
  315. }
  316. func CheckDecortaionType(decorationType int, itemId, userId int) bool {
  317. xclient := getClient()
  318. //defer xclient.Close()
  319. args := &Request_CheckDecoration{
  320. UserId: userId,
  321. ItemId: itemId,
  322. Type: decorationType,
  323. }
  324. reply := &Response_CheckDecoration{}
  325. err := xclient.Call(context.Background(), "CheckDecortaionType", args, reply)
  326. if err != nil {
  327. log.Debug("item_invenroty failed to call: %v", err)
  328. common.GetClientPool().RemoveClient(ServiceName)
  329. return false
  330. }
  331. return reply.Success
  332. }