蛋蛋星球-客户端
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

hdl_im.go 7.3 KiB

4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
4 hafta önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. package hdl
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/db"
  5. "applet/app/e"
  6. "applet/app/md"
  7. "applet/app/pkg/pb"
  8. "applet/app/svc"
  9. "applet/app/utils"
  10. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  11. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  12. "github.com/gin-gonic/gin"
  13. "github.com/tidwall/gjson"
  14. )
  15. // SendRedPackageDetail
  16. // @Summary 蛋蛋星球-即时通讯-发送红包详情
  17. // @Tags 即时通讯
  18. // @Description 发送红包详情
  19. // @Accept json
  20. // @Produce json
  21. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  22. // @Param req body md.SendRedPackageDetailReq true "红包的订单 ID"
  23. // @Success 200 {object} md.SendRedPackageDetailResp "具体数据"
  24. // @Failure 400 {object} md.Response "具体错误"
  25. // @Router /api/v1/im/user/sendRedPackageDetail [POST]
  26. func SendRedPackageDetail(c *gin.Context) {
  27. var req *md.SendRedPackageDetailReq
  28. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  29. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  30. return
  31. }
  32. //1、查找红包
  33. redPackageOrdDb := implement.NewImSendRedPackageOrdDb(db.Db)
  34. imSendRedPackageOrd, err := redPackageOrdDb.ImSendRedPackageOrdGetOneByParams(map[string]interface{}{
  35. "key": "ord_no",
  36. "value": req.OrderId,
  37. })
  38. if err != nil {
  39. e.OutErr(c, e.ERR_DB_ORM, nil)
  40. return
  41. }
  42. var redPackageID int64
  43. im := md.SeqType{
  44. Seq: 0,
  45. }
  46. if imSendRedPackageOrd != nil {
  47. im.Seq = int(gjson.Get(imSendRedPackageOrd.ImData, "seq").Int())
  48. redPackageID = imSendRedPackageOrd.Id
  49. }
  50. resp := md.SendRedPackageDetailResp{
  51. Im: im,
  52. RedPackageID: redPackageID,
  53. }
  54. e.OutSuc(c, resp, nil)
  55. return
  56. }
  57. // GrabRedPackage
  58. // @Summary 蛋蛋星球-即时通讯-领取红包
  59. // @Tags 即时通讯
  60. // @Description 领取红包
  61. // @Accept json
  62. // @Produce json
  63. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  64. // @Param req body md.GrabRedPackageReq true "领取红包信息"
  65. // @Success 200 {object} md.GrabRedPackageResp "具体数据"
  66. // @Failure 400 {object} md.Response "具体错误"
  67. // @Router /api/v1/im/user/grabRedPackage [POST]
  68. func GrabRedPackage(c *gin.Context) {
  69. var req *md.GrabRedPackageReq
  70. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  71. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  72. return
  73. }
  74. val, exists := c.Get("user")
  75. if !exists {
  76. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  77. return
  78. }
  79. user, ok := val.(*model.User)
  80. if !ok {
  81. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  82. return
  83. }
  84. redPackageContent, grabAmount, err := svc.DelGrabRedPackage(req, user)
  85. if err != nil {
  86. e.OutErr(c, e.ERR, err.Error())
  87. return
  88. }
  89. resp := md.GrabRedPackageResp{
  90. Im: &pb.SendRedPacketResp{Seq: 0},
  91. GrabAmount: grabAmount,
  92. }
  93. if redPackageContent == nil {
  94. e.OutSuc(c, resp, nil)
  95. return
  96. }
  97. //TODO::调用im GRPC 接口
  98. res, err := utils.GetLogicExtClient(cfg.ImLogicRpc.URL, cfg.ImLogicRpc.PORT).SendRedPacket(utils.GetCtx(req.Token, req.UserId, req.DeviceId), &pb.SendRedPacketReq{
  99. ReceiverType: pb.ReceiverType(req.ReceiverType),
  100. ReceiverId: req.ReceiverId,
  101. MessageType: pb.MessageType_MT_RED_PACKAGE,
  102. MessageContent: redPackageContent,
  103. SendTime: req.SendTime,
  104. //ToUserIds: args.ToUserIds,
  105. MessageContentBack: "",
  106. })
  107. if err != nil {
  108. e.OutErr(c, e.ERR_IS_GRPC, err.Error())
  109. return
  110. }
  111. resp.Im = res
  112. e.OutSuc(c, resp, nil)
  113. return
  114. }
  115. // RedPackageDetail
  116. // @Summary 蛋蛋星球-即时通讯-红包详情(获取)
  117. // @Tags 即时通讯
  118. // @Description 红包详情(获取)
  119. // @Accept json
  120. // @Produce json
  121. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  122. // @Param red_package_id query string true "红包 ID"
  123. // @Success 200 {object} md.RedPackageDetailResp "具体数据"
  124. // @Failure 400 {object} md.Response "具体错误"
  125. // @Router /api/v1/im/redPackageDetail [GET]
  126. func RedPackageDetail(c *gin.Context) {
  127. redPackageId := c.DefaultQuery("red_package_id", "")
  128. res, imSendRedPackageOrd, err := svc.DetailGrabRedPackage(redPackageId)
  129. if err != nil {
  130. e.OutErr(c, e.ERR, err.Error())
  131. return
  132. }
  133. resp := md.RedPackageDetailResp{
  134. List: res,
  135. Detail: model.ImSendRedPackageOrd{
  136. OrdNo: imSendRedPackageOrd.OrdNo,
  137. Uid: imSendRedPackageOrd.Uid,
  138. ImUid: imSendRedPackageOrd.ImUid,
  139. Amount: imSendRedPackageOrd.Amount,
  140. RedPacketBalanceAmount: imSendRedPackageOrd.RedPacketBalanceAmount,
  141. RedPacketType: imSendRedPackageOrd.RedPacketType,
  142. RedPacketNums: imSendRedPackageOrd.RedPacketNums,
  143. RedPacketBalanceNums: imSendRedPackageOrd.RedPacketBalanceNums,
  144. State: imSendRedPackageOrd.State,
  145. WaitDrawUserIds: imSendRedPackageOrd.WaitDrawUserIds,
  146. WaitDrawImUserIds: imSendRedPackageOrd.WaitDrawImUserIds,
  147. ReceivedUserIds: imSendRedPackageOrd.ReceivedUserIds,
  148. ReceivedImUserIds: imSendRedPackageOrd.ReceivedImUserIds,
  149. ReceivedUserAmount: imSendRedPackageOrd.ReceivedUserAmount,
  150. ReceivedTimes: imSendRedPackageOrd.ReceivedTimes,
  151. CreateTime: imSendRedPackageOrd.CreateTime,
  152. UpdateTime: imSendRedPackageOrd.UpdateTime,
  153. },
  154. }
  155. e.OutSuc(c, resp, nil)
  156. return
  157. }
  158. // SendRedPackage
  159. // @Summary 蛋蛋星球-即时通讯-发送红包
  160. // @Tags 即时通讯
  161. // @Description 发送红包
  162. // @Accept json
  163. // @Produce json
  164. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  165. // @Param req body md.SendRedPackageReq true "发送红包信息"
  166. // @Success 200 {object} md.SendRedPackageResp "具体数据"
  167. // @Failure 400 {object} md.Response "具体错误"
  168. // @Router /api/v1/im/user/sendRedPackage [POST]
  169. func SendRedPackage(c *gin.Context) {
  170. var args md.SendRedPackageReq
  171. if err := c.ShouldBindJSON(&args); err != nil {
  172. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  173. return
  174. }
  175. if args.RedPacketNums <= 0 || utils.StrToFloat64(args.Amount)*100 <= 0 || utils.StrToFloat64(args.Amount)*100 < float64(args.RedPacketNums)*utils.RED_PACKET_MIN_MONEY {
  176. e.OutErr(c, e.ERR, "传参有误")
  177. return
  178. }
  179. val, exists := c.Get("user")
  180. if !exists {
  181. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  182. return
  183. }
  184. user, ok := val.(*model.User)
  185. if !ok {
  186. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  187. return
  188. }
  189. redPackageContent, redPackageId, err := svc.BalancePayForRedPackage(user, args.Amount, args)
  190. if err != nil {
  191. e.OutErr(c, e.ERR, err)
  192. return
  193. }
  194. //TODO::调用im GRPC 接口
  195. res, err := utils.GetLogicExtClient(cfg.ImLogicRpc.URL, cfg.ImLogicRpc.PORT).SendRedPacket(utils.GetCtx(args.Token, args.UserId, args.DeviceId), &pb.SendRedPacketReq{
  196. ReceiverType: pb.ReceiverType(args.ReceiverType),
  197. ReceiverId: args.ReceiverId,
  198. MessageType: pb.MessageType_MT_RED_PACKAGE,
  199. MessageContent: redPackageContent,
  200. SendTime: args.SendTime,
  201. ToUserIds: args.ToUserIds,
  202. MessageContentBack: "",
  203. })
  204. if err != nil {
  205. e.OutErr(c, e.ERR_IS_GRPC, err)
  206. return
  207. }
  208. resp := md.SendRedPackageResp{
  209. Im: res,
  210. RedPackageId: redPackageId,
  211. }
  212. // 处理统计发红包数 推到 mq 处理
  213. go svc.AddSendRedPackageTimesPushToMQ(user.Id)
  214. e.OutSuc(c, resp, nil)
  215. return
  216. }