蛋蛋星球-客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

hdl_im.go 7.3 KiB

5日前
4日前
4日前
4日前
4日前
4日前
5日前
4日前
5日前
4日前
5日前
4日前
5日前
4日前
5日前
4日前
5日前
4日前
5日前
4日前
5日前
4日前
5日前
4日前
5日前
4日前
5日前
4日前
5日前
4日前
5日前
4日前
5日前
4日前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. // masterID := c.GetHeader("master_id")
  99. res, err := utils.GetLogicExtClient(cfg.ImLogicRpc.URL, cfg.ImLogicRpc.PORT).SendRedPacket(utils.GetCtx(req.Token, req.UserId, req.DeviceId), &pb.SendRedPacketReq{
  100. ReceiverType: pb.ReceiverType(req.ReceiverType),
  101. ReceiverId: req.ReceiverId,
  102. MessageType: pb.MessageType_MT_RED_PACKAGE,
  103. MessageContent: redPackageContent,
  104. SendTime: req.SendTime,
  105. //ToUserIds: args.ToUserIds,
  106. MessageContentBack: "",
  107. })
  108. if err != nil {
  109. e.OutErr(c, e.ERR_IS_GRPC, err.Error())
  110. return
  111. }
  112. resp.Im = res
  113. e.OutSuc(c, resp, nil)
  114. return
  115. }
  116. // RedPackageDetail
  117. // @Summary 蛋蛋星球-即时通讯-红包详情(获取)
  118. // @Tags 即时通讯
  119. // @Description 红包详情(获取)
  120. // @Accept json
  121. // @Produce json
  122. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  123. // @Param red_package_id query string true "红包 ID"
  124. // @Success 200 {object} md.RedPackageDetailResp "具体数据"
  125. // @Failure 400 {object} md.Response "具体错误"
  126. // @Router /api/v1/im/redPackageDetail [GET]
  127. func RedPackageDetail(c *gin.Context) {
  128. redPackageId := c.DefaultQuery("red_package_id", "")
  129. res, imSendRedPackageOrd, err := svc.DetailGrabRedPackage(redPackageId)
  130. if err != nil {
  131. e.OutErr(c, e.ERR, err.Error())
  132. return
  133. }
  134. resp := md.RedPackageDetailResp{
  135. List: res,
  136. Detail: model.ImSendRedPackageOrd{
  137. OrdNo: imSendRedPackageOrd.OrdNo,
  138. Uid: imSendRedPackageOrd.Uid,
  139. ImUid: imSendRedPackageOrd.ImUid,
  140. Amount: imSendRedPackageOrd.Amount,
  141. RedPacketBalanceAmount: imSendRedPackageOrd.RedPacketBalanceAmount,
  142. RedPacketType: imSendRedPackageOrd.RedPacketType,
  143. RedPacketNums: imSendRedPackageOrd.RedPacketNums,
  144. RedPacketBalanceNums: imSendRedPackageOrd.RedPacketBalanceNums,
  145. State: imSendRedPackageOrd.State,
  146. WaitDrawUserIds: imSendRedPackageOrd.WaitDrawUserIds,
  147. WaitDrawImUserIds: imSendRedPackageOrd.WaitDrawImUserIds,
  148. ReceivedUserIds: imSendRedPackageOrd.ReceivedUserIds,
  149. ReceivedImUserIds: imSendRedPackageOrd.ReceivedImUserIds,
  150. ReceivedUserAmount: imSendRedPackageOrd.ReceivedUserAmount,
  151. ReceivedTimes: imSendRedPackageOrd.ReceivedTimes,
  152. CreateTime: imSendRedPackageOrd.CreateTime,
  153. UpdateTime: imSendRedPackageOrd.UpdateTime,
  154. },
  155. }
  156. e.OutSuc(c, resp, nil)
  157. return
  158. }
  159. // SendRedPackage
  160. // @Summary 蛋蛋星球-即时通讯-发送红包
  161. // @Tags 即时通讯
  162. // @Description 发送红包
  163. // @Accept json
  164. // @Produce json
  165. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  166. // @Param req body md.SendRedPackageReq true "发送红包信息"
  167. // @Success 200 {object} md.SendRedPackageResp "具体数据"
  168. // @Failure 400 {object} md.Response "具体错误"
  169. // @Router /api/v1/im/user/sendRedPackage [POST]
  170. func SendRedPackage(c *gin.Context) {
  171. var args md.SendRedPackageReq
  172. if err := c.ShouldBindJSON(&args); err != nil {
  173. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  174. return
  175. }
  176. if args.RedPacketNums <= 0 || utils.StrToFloat64(args.Amount)*100 <= 0 || utils.StrToFloat64(args.Amount)*100 < float64(args.RedPacketNums)*utils.RED_PACKET_MIN_MONEY {
  177. e.OutErr(c, e.ERR, "传参有误")
  178. return
  179. }
  180. val, exists := c.Get("user")
  181. if !exists {
  182. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  183. return
  184. }
  185. user, ok := val.(*model.User)
  186. if !ok {
  187. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  188. return
  189. }
  190. redPackageContent, redPackageId, err := svc.BalancePayForRedPackage(user, args.Amount, args)
  191. if err != nil {
  192. e.OutErr(c, e.ERR, err)
  193. return
  194. }
  195. //TODO::调用im GRPC 接口
  196. res, err := utils.GetLogicExtClient(cfg.ImLogicRpc.URL, cfg.ImLogicRpc.PORT).SendRedPacket(utils.GetCtx(args.Token, args.UserId, args.DeviceId), &pb.SendRedPacketReq{
  197. ReceiverType: pb.ReceiverType(args.ReceiverType),
  198. ReceiverId: args.ReceiverId,
  199. MessageType: pb.MessageType_MT_RED_PACKAGE,
  200. MessageContent: redPackageContent,
  201. SendTime: args.SendTime,
  202. ToUserIds: args.ToUserIds,
  203. MessageContentBack: "",
  204. })
  205. if err != nil {
  206. e.OutErr(c, e.ERR_IS_GRPC, err)
  207. return
  208. }
  209. resp := md.SendRedPackageResp{
  210. Im: res,
  211. RedPackageId: redPackageId,
  212. }
  213. e.OutSuc(c, resp, nil)
  214. return
  215. }