修复(#126): 修复家庭组邀请记录漏查验收分支
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -23,8 +23,9 @@ type InviteRelation struct {
|
||||
}
|
||||
|
||||
type paidOrderRow struct {
|
||||
UserId int64 `gorm:"column:user_id"`
|
||||
OrderNo string `gorm:"column:order_no"`
|
||||
UserId int64 `gorm:"column:user_id"`
|
||||
SubscriptionUserId int64 `gorm:"column:subscription_user_id"`
|
||||
OrderNo string `gorm:"column:order_no"`
|
||||
}
|
||||
|
||||
type systemLogRow struct {
|
||||
@@ -81,7 +82,7 @@ func QueryBenefits(ctx context.Context, db *gorm.DB, relations []InviteRelation)
|
||||
var paidOrders []paidOrderRow
|
||||
if err := db.WithContext(ctx).
|
||||
Table("`order`").
|
||||
Select("user_id, order_no").
|
||||
Select("user_id, subscription_user_id, order_no").
|
||||
Where("user_id IN ? AND status IN ?", inviteeIds, []int{2, 5}).
|
||||
Scan(&paidOrders).Error; err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query invitee paid orders failed: %v", err)
|
||||
@@ -92,11 +93,16 @@ func QueryBenefits(ctx context.Context, db *gorm.DB, relations []InviteRelation)
|
||||
|
||||
orderNos := make([]string, 0, len(paidOrders))
|
||||
orderToInvitee := make(map[string]int64, len(paidOrders))
|
||||
orderToSubscriptionUser := make(map[string]int64, len(paidOrders))
|
||||
inviterIds := make([]int64, 0, len(relations))
|
||||
inviteeAndInviterSet := make(map[int64]struct{}, len(relations)*2)
|
||||
for _, order := range paidOrders {
|
||||
orderNos = append(orderNos, order.OrderNo)
|
||||
orderToInvitee[order.OrderNo] = order.UserId
|
||||
if order.SubscriptionUserId > 0 && order.SubscriptionUserId != order.UserId {
|
||||
orderToSubscriptionUser[order.OrderNo] = order.SubscriptionUserId
|
||||
inviteeAndInviterSet[order.SubscriptionUserId] = struct{}{}
|
||||
}
|
||||
}
|
||||
for _, relation := range relations {
|
||||
inviterIds = append(inviterIds, relation.InviterId)
|
||||
@@ -111,7 +117,7 @@ func QueryBenefits(ctx context.Context, db *gorm.DB, relations []InviteRelation)
|
||||
if err := fillCommissionBenefits(ctx, db, result, orderToInvitee, inviteeToInviter, orderNos, inviterIds); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := fillGiftBenefits(ctx, db, result, orderToInvitee, inviteeToInviter, orderNos, inviteeAndInviterIds); err != nil {
|
||||
if err := fillGiftBenefits(ctx, db, result, orderToInvitee, inviteeToInviter, orderToSubscriptionUser, orderNos, inviteeAndInviterIds); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -143,7 +149,7 @@ func fillCommissionBenefits(ctx context.Context, db *gorm.DB, benefits map[int64
|
||||
return nil
|
||||
}
|
||||
|
||||
func fillGiftBenefits(ctx context.Context, db *gorm.DB, benefits map[int64]Benefits, orderToInvitee map[string]int64, inviteeToInviter map[int64]int64, orderNos []string, userIds []int64) error {
|
||||
func fillGiftBenefits(ctx context.Context, db *gorm.DB, benefits map[int64]Benefits, orderToInvitee map[string]int64, inviteeToInviter map[int64]int64, orderToSubscriptionUser map[string]int64, orderNos []string, userIds []int64) error {
|
||||
var rows []systemLogRow
|
||||
if err := db.WithContext(ctx).
|
||||
Table("system_logs").
|
||||
@@ -170,6 +176,8 @@ func fillGiftBenefits(ctx context.Context, db *gorm.DB, benefits map[int64]Benef
|
||||
benefit.InviterGiftDays += content.Amount
|
||||
case inviteeId:
|
||||
benefit.InviteeGiftDays += content.Amount
|
||||
case orderToSubscriptionUser[content.OrderNo]:
|
||||
benefit.InviteeGiftDays += content.Amount
|
||||
default:
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user