|
|
@@ -38,6 +38,7 @@ func DelGrabRedPackage(req *md.GrabRedPackageReq, user *model.User) (resp []byte |
|
|
|
if imSendRedPackageOrd == nil { |
|
|
|
return nil, grabAmount, errors.New("未查询到对应的红包记录") |
|
|
|
} |
|
|
|
// 剩余个数和已过期无法领取 |
|
|
|
if imSendRedPackageOrd.RedPacketBalanceNums == 0 || imSendRedPackageOrd.State == int(pb.RedPacketStatusType_RPS_EXPIRE) { |
|
|
|
return nil, "-1", nil |
|
|
|
} |
|
|
@@ -141,7 +142,8 @@ func DelGrabRedPackage(req *md.GrabRedPackageReq, user *model.User) (resp []byte |
|
|
|
imSendRedPackageOrd.RedPacketBalanceAmount = redPacketBalanceAmount |
|
|
|
imSendRedPackageOrd.ReceivedUserIds = redPacketReceivedUserIds |
|
|
|
imSendRedPackageOrd.ReceivedImUserIds = redPacketReceivedImUserIds |
|
|
|
_, err = redPackageOrdDb.ImSendRedPackageOrdUpdateBySession(session, imSendRedPackageOrd.Id, imSendRedPackageOrd, "red_packet_balance_nums", "state", "received_user_ids", "received_im_user_ids", "received_times", |
|
|
|
_, err = redPackageOrdDb.ImSendRedPackageOrdUpdateBySession(session, imSendRedPackageOrd.Id, imSendRedPackageOrd, |
|
|
|
"red_packet_balance_nums", "state", "received_user_ids", "received_im_user_ids", "received_times", |
|
|
|
"received_user_amount", "create_time", "update_time", "red_packet_balance_amount") |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
@@ -161,6 +163,7 @@ func DelGrabRedPackage(req *md.GrabRedPackageReq, user *model.User) (resp []byte |
|
|
|
session.Rollback() |
|
|
|
return nil, grabAmount, err |
|
|
|
} |
|
|
|
session.Commit() |
|
|
|
|
|
|
|
//4、组装消息参数 |
|
|
|
msg := &pb.RED_PACKAGE{ |
|
|
@@ -260,18 +263,45 @@ func BalancePayForRedPackage(user *model.User, money string, req md.SendRedPacka |
|
|
|
|
|
|
|
// 新增红包记录 |
|
|
|
var imUid int |
|
|
|
if req.UserId != "" { |
|
|
|
imUid = utils.StrToInt(req.UserId) |
|
|
|
var imUser model2.User |
|
|
|
has, err := db.DbIm.Where("phone_number = ?", user.Phone).Get(&imUser) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
return nil, 0, err |
|
|
|
} |
|
|
|
if has { |
|
|
|
imUid = int(imUser.Id) |
|
|
|
} else { |
|
|
|
//TODO::请求rpc接口,同步用户数据 |
|
|
|
resp, err := utils.GetBusinessExtClient(cfg.ImBusinessRpc.URL, cfg.ImBusinessRpc.PORT).GetUser(utils.GetCtx("", "", ""), &pb.GetUserReq{ |
|
|
|
UserId: 0, |
|
|
|
Phone: user.Phone, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
return nil, redPackageId, err |
|
|
|
if req.UserId != "" { |
|
|
|
imUid = utils.StrToInt(req.UserId) |
|
|
|
} else { |
|
|
|
//TODO::请求rpc接口,同步用户数据 |
|
|
|
resp, err := utils.GetBusinessExtClient(cfg.ImBusinessRpc.URL, cfg.ImBusinessRpc.PORT).GetUser(utils.GetCtx("", "", ""), &pb.GetUserReq{ |
|
|
|
UserId: 0, |
|
|
|
Phone: user.Phone, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
return nil, redPackageId, err |
|
|
|
} |
|
|
|
imUid = int(resp.User.UserId) |
|
|
|
now := time.Now() |
|
|
|
tempImUser := model2.User{ |
|
|
|
Id: int64(imUid), |
|
|
|
PhoneNumber: user.Phone, |
|
|
|
Nickname: user.Nickname, |
|
|
|
Sex: 0, |
|
|
|
AvatarUrl: user.Avatar, |
|
|
|
Extra: "", |
|
|
|
CreateTime: now, |
|
|
|
UpdateTime: now, |
|
|
|
IsAutoAddedFriends: 0, |
|
|
|
} |
|
|
|
_, err = db.DbIm.Insert(&tempImUser) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
return nil, 0, err |
|
|
|
} |
|
|
|
} |
|
|
|
imUid = int(resp.User.UserId) |
|
|
|
} |
|
|
|
|
|
|
|
now := time.Now() |
|
|
@@ -279,33 +309,37 @@ func BalancePayForRedPackage(user *model.User, money string, req md.SendRedPacka |
|
|
|
var waitDrawUserIds string |
|
|
|
var waitDrawImUserIds string |
|
|
|
if req.RedPacketType == int(pb.RedPacketType_RPT_GROUP_SPECIALLY) { |
|
|
|
var toUserIds []string |
|
|
|
// 构造 im 用户 id 列表 |
|
|
|
var toImUserIds []string |
|
|
|
for _, v := range req.ToUserIds { |
|
|
|
toUserIds = append(toUserIds, utils.AnyToString(v)) |
|
|
|
toImUserIds = append(toImUserIds, utils.AnyToString(v)) |
|
|
|
} |
|
|
|
waitDrawImUserIds = strings.Join(toImUserIds, ",") |
|
|
|
// 查询 im 用户信息 |
|
|
|
var imUsers []model2.User |
|
|
|
err = db.DbIm.In("id", req.ToUserIds).Find(&imUsers) |
|
|
|
if err != nil { |
|
|
|
return nil, 0, err |
|
|
|
} |
|
|
|
// 获取手机号列表 |
|
|
|
var phones []string |
|
|
|
for _, v := range imUsers { |
|
|
|
phones = append(phones, v.PhoneNumber) |
|
|
|
} |
|
|
|
waitDrawUserIds = strings.Join(toUserIds, ",") |
|
|
|
// 查询用户信息 |
|
|
|
userDb := implement.NewUserDb(db.Db) |
|
|
|
waitDrawUsers, err1 := userDb.UserFindByParams(map[string]interface{}{ |
|
|
|
"key": "id", |
|
|
|
"value": toUserIds, |
|
|
|
"key": "phone", |
|
|
|
"value": phones, |
|
|
|
}) |
|
|
|
if err1 != nil { |
|
|
|
return nil, 0, err1 |
|
|
|
} |
|
|
|
var waitDrawUserPhones []string |
|
|
|
var toUserIDs []string |
|
|
|
for _, v := range waitDrawUsers { |
|
|
|
waitDrawUserPhones = append(waitDrawUserPhones, v.Phone) |
|
|
|
} |
|
|
|
var waitDrawImUsers []model2.User |
|
|
|
err = db.DbIm.Table("user").In("phone_number", waitDrawUserPhones).Find(&waitDrawUsers) |
|
|
|
if err != nil { |
|
|
|
return nil, 0, err |
|
|
|
} |
|
|
|
var toUserIMIDs []string |
|
|
|
for _, v := range waitDrawImUsers { |
|
|
|
toUserIMIDs = append(toUserIMIDs, utils.AnyToString(v.Id)) |
|
|
|
toUserIDs = append(toUserIDs, utils.AnyToString(v.Id)) |
|
|
|
} |
|
|
|
waitDrawImUserIds = strings.Join(toUserIMIDs, ",") |
|
|
|
waitDrawUserIds = strings.Join(toUserIDs, ",") |
|
|
|
} |
|
|
|
|
|
|
|
ordDb := implement.NewImSendRedPackageOrdDb(db.Db) |
|
|
|