Compare commits
2 Commits
e4911e7732
...
3639cad484
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3639cad484 | ||
|
|
0a11372d96 |
@ -235,13 +235,14 @@ type OfficialNoticeCustomizeRequest struct {
|
||||
}
|
||||
|
||||
type RewardGroupItem struct {
|
||||
ID Int64Value `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Name string `json:"name"`
|
||||
Content string `json:"content"`
|
||||
Quantity Int64Value `json:"quantity"`
|
||||
Cover string `json:"cover"`
|
||||
Remark string `json:"remark"`
|
||||
ID Int64Value `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Name string `json:"name"`
|
||||
Content string `json:"content"`
|
||||
Quantity Int64Value `json:"quantity"`
|
||||
Cover string `json:"cover"`
|
||||
SourceURL string `json:"sourceUrl"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
|
||||
type RewardGroupDetail struct {
|
||||
|
||||
@ -76,12 +76,12 @@ func (VoiceRoomRedPacket) TableName() string { return "voice_room_red_packet" }
|
||||
|
||||
// VoiceRoomRedPacketSlice 保存红包预拆分份额。
|
||||
type VoiceRoomRedPacketSlice struct {
|
||||
ID int64 `gorm:"column:id;primaryKey"`
|
||||
PacketID int64 `gorm:"column:packet_id;uniqueIndex:uk_voice_room_red_packet_slice,priority:1;index:idx_voice_room_red_packet_slice_claim,priority:1"`
|
||||
ID int64 `gorm:"column:id;primaryKey;index:idx_voice_room_red_packet_slice_claim_order,priority:4"`
|
||||
PacketID int64 `gorm:"column:packet_id;uniqueIndex:uk_voice_room_red_packet_slice,priority:1;index:idx_voice_room_red_packet_slice_claim,priority:1;index:idx_voice_room_red_packet_slice_claim_order,priority:1"`
|
||||
PacketNo string `gorm:"column:packet_no;size:64"`
|
||||
SortNo int `gorm:"column:sort_no;uniqueIndex:uk_voice_room_red_packet_slice,priority:2"`
|
||||
SortNo int `gorm:"column:sort_no;uniqueIndex:uk_voice_room_red_packet_slice,priority:2;index:idx_voice_room_red_packet_slice_claim_order,priority:3"`
|
||||
Amount int64 `gorm:"column:amount"`
|
||||
Status string `gorm:"column:status;size:32;index:idx_voice_room_red_packet_slice_claim,priority:2"`
|
||||
Status string `gorm:"column:status;size:32;index:idx_voice_room_red_packet_slice_claim,priority:2;index:idx_voice_room_red_packet_slice_claim_order,priority:2"`
|
||||
ClaimUserID *int64 `gorm:"column:claim_user_id"`
|
||||
ClaimRecordID *int64 `gorm:"column:claim_record_id"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
|
||||
@ -124,7 +124,7 @@ func rewardItemsFromGroup(detail integration.RewardGroupDetail) []RewardItem {
|
||||
Name: strings.TrimSpace(item.Name),
|
||||
Content: strings.TrimSpace(item.Content),
|
||||
Quantity: int64(item.Quantity),
|
||||
Cover: strings.TrimSpace(item.Cover),
|
||||
Cover: firstNonEmpty(item.Cover, item.SourceURL),
|
||||
Remark: strings.TrimSpace(item.Remark),
|
||||
})
|
||||
}
|
||||
|
||||
@ -43,6 +43,43 @@ func TestSaveConfigReturnsRewardItems(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSaveConfigReturnsVipCoverFromSourceURL(t *testing.T) {
|
||||
service, gateway, _ := newTestService(t)
|
||||
gateway.groups[2001] = integration.RewardGroupDetail{
|
||||
ID: integration.Int64Value(2001),
|
||||
Name: "VIP礼包",
|
||||
RewardConfigList: []integration.RewardGroupItem{
|
||||
{
|
||||
ID: integration.Int64Value(11),
|
||||
Type: "PROPS",
|
||||
Name: "VIP 1",
|
||||
Content: "2049402425177018400",
|
||||
Quantity: integration.Int64Value(30),
|
||||
Cover: "",
|
||||
SourceURL: "https://example.com/vip-short-badge.png",
|
||||
Remark: "30 天",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := service.SaveConfig(context.Background(), mustDecodeSaveConfigRequest(t, `{
|
||||
"sysOrigin": "LIKEI",
|
||||
"enabled": true,
|
||||
"levelConfigs": [
|
||||
{"level": 1, "rechargeAmount": "9.99", "rewardGroupId": "2001", "rewardGroupName": "VIP礼包", "enabled": true}
|
||||
]
|
||||
}`))
|
||||
if err != nil {
|
||||
t.Fatalf("SaveConfig() error = %v", err)
|
||||
}
|
||||
if len(resp.LevelConfigs) != 1 || len(resp.LevelConfigs[0].RewardItems) != 1 {
|
||||
t.Fatalf("reward items = %+v", resp.LevelConfigs)
|
||||
}
|
||||
if got := resp.LevelConfigs[0].RewardItems[0].Cover; got != "https://example.com/vip-short-badge.png" {
|
||||
t.Fatalf("vip cover = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessRechargeEventFiltersAndGrantsOnce(t *testing.T) {
|
||||
service, gateway, db := newTestService(t)
|
||||
gateway.groups[1001] = testRewardGroup(1001, "首冲礼包")
|
||||
|
||||
@ -182,6 +182,12 @@ func (s *Service) completeClaimWallet(ctx context.Context, claim model.VoiceRoom
|
||||
}
|
||||
now := time.Now()
|
||||
if err := s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
var lockedPacket model.VoiceRoomRedPacket
|
||||
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).
|
||||
Where("id = ?", claim.PacketID).
|
||||
First(&lockedPacket).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Model(&model.VoiceRoomRedPacketClaim{}).
|
||||
Where("id = ?", claim.ID).
|
||||
Updates(map[string]any{
|
||||
@ -200,7 +206,7 @@ func (s *Service) completeClaimWallet(ctx context.Context, claim model.VoiceRoom
|
||||
return err
|
||||
}
|
||||
return tx.Model(&model.VoiceRoomRedPacket{}).
|
||||
Where("id = ? AND remain_count = 0 AND status = ?", claim.PacketID, packetStatusActive).
|
||||
Where("id = ? AND remain_count = 0 AND status = ?", lockedPacket.ID, packetStatusActive).
|
||||
Updates(map[string]any{
|
||||
"status": packetStatusFinished,
|
||||
"update_time": now,
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
SET @current_schema := DATABASE();
|
||||
|
||||
SET @voice_room_red_packet_slice_claim_order_idx_columns := (
|
||||
SELECT GROUP_CONCAT(column_name ORDER BY seq_in_index)
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = @current_schema
|
||||
AND table_name = 'voice_room_red_packet_slice'
|
||||
AND index_name = 'idx_voice_room_red_packet_slice_claim_order'
|
||||
);
|
||||
|
||||
SET @drop_voice_room_red_packet_slice_claim_order_idx_sql := IF(
|
||||
@voice_room_red_packet_slice_claim_order_idx_columns IS NOT NULL
|
||||
AND @voice_room_red_packet_slice_claim_order_idx_columns <> 'packet_id,status,sort_no,id',
|
||||
'ALTER TABLE `voice_room_red_packet_slice` DROP INDEX `idx_voice_room_red_packet_slice_claim_order`',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE drop_voice_room_red_packet_slice_claim_order_idx_stmt FROM @drop_voice_room_red_packet_slice_claim_order_idx_sql;
|
||||
EXECUTE drop_voice_room_red_packet_slice_claim_order_idx_stmt;
|
||||
DEALLOCATE PREPARE drop_voice_room_red_packet_slice_claim_order_idx_stmt;
|
||||
|
||||
SET @add_voice_room_red_packet_slice_claim_order_idx_sql := IF(
|
||||
@voice_room_red_packet_slice_claim_order_idx_columns IS NULL
|
||||
OR @voice_room_red_packet_slice_claim_order_idx_columns <> 'packet_id,status,sort_no,id',
|
||||
'ALTER TABLE `voice_room_red_packet_slice` ADD INDEX `idx_voice_room_red_packet_slice_claim_order` (`packet_id`, `status`, `sort_no`, `id`)',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE add_voice_room_red_packet_slice_claim_order_idx_stmt FROM @add_voice_room_red_packet_slice_claim_order_idx_sql;
|
||||
EXECUTE add_voice_room_red_packet_slice_claim_order_idx_stmt;
|
||||
DEALLOCATE PREPARE add_voice_room_red_packet_slice_claim_order_idx_stmt;
|
||||
Loading…
x
Reference in New Issue
Block a user