|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- package hdl
-
- import (
- "applet/app/cfg"
- "applet/app/db"
- "applet/app/e"
- "applet/app/md"
- "applet/app/pkg/pb"
- "applet/app/svc"
- "applet/app/utils"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
- "github.com/gin-gonic/gin"
- "github.com/tidwall/gjson"
- )
-
- // SendRedPackageDetail
- // @Summary 蛋蛋星球-即时通讯-发送红包详情
- // @Tags 即时通讯
- // @Description 发送红包详情
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.SendRedPackageDetailReq true "红包的订单 ID"
- // @Success 200 {object} md.SendRedPackageDetailResp "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/v1/im/user/sendRedPackageDetail [POST]
- func SendRedPackageDetail(c *gin.Context) {
- var req *md.SendRedPackageDetailReq
- if err1 := c.ShouldBindJSON(&req); err1 != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
- return
- }
-
- //1、查找红包
- redPackageOrdDb := implement.NewImSendRedPackageOrdDb(db.Db)
- imSendRedPackageOrd, err := redPackageOrdDb.ImSendRedPackageOrdGetOneByParams(map[string]interface{}{
- "key": "ord_no",
- "value": req.OrderId,
- })
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, nil)
- return
- }
- var redPackageID int64
- im := md.SeqType{
- Seq: 0,
- }
- if imSendRedPackageOrd != nil {
- im.Seq = int(gjson.Get(imSendRedPackageOrd.ImData, "seq").Int())
- redPackageID = imSendRedPackageOrd.Id
- }
- resp := md.SendRedPackageDetailResp{
- Im: im,
- RedPackageID: redPackageID,
- }
- e.OutSuc(c, resp, nil)
- return
- }
-
- // GrabRedPackage
- // @Summary 蛋蛋星球-即时通讯-领取红包
- // @Tags 即时通讯
- // @Description 领取红包
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.GrabRedPackageReq true "领取红包信息"
- // @Success 200 {object} md.GrabRedPackageResp "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/v1/im/user/grabRedPackage [POST]
- func GrabRedPackage(c *gin.Context) {
- var req *md.GrabRedPackageReq
- if err1 := c.ShouldBindJSON(&req); err1 != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
- return
- }
-
- val, exists := c.Get("user")
- if !exists {
- e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
- return
- }
- user, ok := val.(*model.User)
- if !ok {
- e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
- return
- }
-
- redPackageContent, grabAmount, err := svc.DelGrabRedPackage(req, user)
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
-
- resp := md.GrabRedPackageResp{
- Im: &pb.SendRedPacketResp{Seq: 0},
- GrabAmount: grabAmount,
- }
-
- if redPackageContent == nil {
- e.OutSuc(c, resp, nil)
- return
- }
-
- //TODO::调用im GRPC 接口
- res, err := utils.GetLogicExtClient(cfg.ImLogicRpc.URL, cfg.ImLogicRpc.PORT).SendRedPacket(utils.GetCtx(req.Token, req.UserId, req.DeviceId), &pb.SendRedPacketReq{
- ReceiverType: pb.ReceiverType(req.ReceiverType),
- ReceiverId: req.ReceiverId,
- MessageType: pb.MessageType_MT_RED_PACKAGE,
- MessageContent: redPackageContent,
- SendTime: req.SendTime,
- //ToUserIds: args.ToUserIds,
- MessageContentBack: "",
- })
- if err != nil {
- e.OutErr(c, e.ERR_IS_GRPC, err.Error())
- return
- }
-
- resp.Im = res
- e.OutSuc(c, resp, nil)
- return
- }
-
- // RedPackageDetail
- // @Summary 蛋蛋星球-即时通讯-红包详情(获取)
- // @Tags 即时通讯
- // @Description 红包详情(获取)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param red_package_id query string true "红包 ID"
- // @Success 200 {object} md.RedPackageDetailResp "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/v1/im/redPackageDetail [GET]
- func RedPackageDetail(c *gin.Context) {
- redPackageId := c.DefaultQuery("red_package_id", "")
-
- res, imSendRedPackageOrd, err := svc.DetailGrabRedPackage(redPackageId)
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
- resp := md.RedPackageDetailResp{
- List: res,
- Detail: model.ImSendRedPackageOrd{
- OrdNo: imSendRedPackageOrd.OrdNo,
- Uid: imSendRedPackageOrd.Uid,
- ImUid: imSendRedPackageOrd.ImUid,
- Amount: imSendRedPackageOrd.Amount,
- RedPacketBalanceAmount: imSendRedPackageOrd.RedPacketBalanceAmount,
- RedPacketType: imSendRedPackageOrd.RedPacketType,
- RedPacketNums: imSendRedPackageOrd.RedPacketNums,
- RedPacketBalanceNums: imSendRedPackageOrd.RedPacketBalanceNums,
- State: imSendRedPackageOrd.State,
- WaitDrawUserIds: imSendRedPackageOrd.WaitDrawUserIds,
- WaitDrawImUserIds: imSendRedPackageOrd.WaitDrawImUserIds,
- ReceivedUserIds: imSendRedPackageOrd.ReceivedUserIds,
- ReceivedImUserIds: imSendRedPackageOrd.ReceivedImUserIds,
- ReceivedUserAmount: imSendRedPackageOrd.ReceivedUserAmount,
- ReceivedTimes: imSendRedPackageOrd.ReceivedTimes,
- CreateTime: imSendRedPackageOrd.CreateTime,
- UpdateTime: imSendRedPackageOrd.UpdateTime,
- },
- }
- e.OutSuc(c, resp, nil)
- return
- }
-
- // SendRedPackage
- // @Summary 蛋蛋星球-即时通讯-发送红包
- // @Tags 即时通讯
- // @Description 发送红包
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.SendRedPackageReq true "发送红包信息"
- // @Success 200 {object} md.SendRedPackageResp "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/v1/im/user/sendRedPackage [POST]
- func SendRedPackage(c *gin.Context) {
- var args md.SendRedPackageReq
- if err := c.ShouldBindJSON(&args); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- if args.RedPacketNums <= 0 || utils.StrToFloat64(args.Amount)*100 <= 0 || utils.StrToFloat64(args.Amount)*100 < float64(args.RedPacketNums)*utils.RED_PACKET_MIN_MONEY {
- e.OutErr(c, e.ERR, "传参有误")
- return
- }
-
- val, exists := c.Get("user")
- if !exists {
- e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
- return
- }
- user, ok := val.(*model.User)
- if !ok {
- e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
- return
- }
-
- redPackageContent, redPackageId, err := svc.BalancePayForRedPackage(user, args.Amount, args)
- if err != nil {
- e.OutErr(c, e.ERR, err)
- return
- }
-
- //TODO::调用im GRPC 接口
- res, err := utils.GetLogicExtClient(cfg.ImLogicRpc.URL, cfg.ImLogicRpc.PORT).SendRedPacket(utils.GetCtx(args.Token, args.UserId, args.DeviceId), &pb.SendRedPacketReq{
- ReceiverType: pb.ReceiverType(args.ReceiverType),
- ReceiverId: args.ReceiverId,
- MessageType: pb.MessageType_MT_RED_PACKAGE,
- MessageContent: redPackageContent,
- SendTime: args.SendTime,
- ToUserIds: args.ToUserIds,
- MessageContentBack: "",
- })
- if err != nil {
- e.OutErr(c, e.ERR_IS_GRPC, err)
- return
- }
-
- resp := md.SendRedPackageResp{
- Im: res,
- RedPackageId: redPackageId,
- }
-
- // 处理统计发红包数 推到 mq 处理
- go svc.AddSendRedPackageTimesPushToMQ(user.Id)
-
- e.OutSuc(c, resp, nil)
- return
- }
|