- 同步上游 DLC (聚鑫源) 最新 GoodID 映射: - suit_shadow_gothic: 6a13aa55e3bce430aca29b01 - top_black_elite_trainer: 6a13aaeae3bce430aca29b03 - suit_romantic_destiny: 6a13ab21e3bce430aca29b04 - 更新 delivery_helpers 缺省兜底映射表与 sync_product_images 常量 - 更新 provider_test 单元测试断言与 docs/商品目录.md 文档 - 验证方式:go test 单元测试通过,go vet 校验通过
119 lines
3.4 KiB
Go
119 lines
3.4 KiB
Go
package service
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
func buildDeliveryProduct(openProduct *OpenOrderProduct, good map[string]interface{}) *DeliveryProduct {
|
|
if openProduct == nil {
|
|
return nil
|
|
}
|
|
product := &DeliveryProduct{
|
|
Name: openProduct.Name,
|
|
SKU: openProduct.SKU,
|
|
Game: openProduct.Game,
|
|
}
|
|
if title := stringFromMap(good, "title"); title != "" {
|
|
product.Name = title
|
|
}
|
|
product.Image = stringFromMap(good, "image")
|
|
return product
|
|
}
|
|
|
|
func isZeroCode(code interface{}) bool {
|
|
switch v := code.(type) {
|
|
case nil:
|
|
return true
|
|
case float64:
|
|
return v == 0
|
|
case string:
|
|
return v == "0"
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
func stringFromMap(m map[string]interface{}, key string) string {
|
|
if m == nil {
|
|
return ""
|
|
}
|
|
switch v := m[key].(type) {
|
|
case string:
|
|
return v
|
|
case float64:
|
|
return fmt.Sprintf("%.0f", v)
|
|
default:
|
|
if v != nil {
|
|
return fmt.Sprint(v)
|
|
}
|
|
return ""
|
|
}
|
|
}
|
|
|
|
func firstNonEmpty(values ...string) string {
|
|
for _, value := range values {
|
|
if strings.TrimSpace(value) != "" {
|
|
return strings.TrimSpace(value)
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func gameChannelText(account map[string]interface{}) string {
|
|
area := stringFromMap(account, "game_account_area")
|
|
plat := stringFromMap(account, "game_account_plat")
|
|
if area == "" && plat == "" {
|
|
return ""
|
|
}
|
|
return strings.Trim(strings.Join([]string{area, plat}, "-"), "-")
|
|
}
|
|
|
|
func truncateDeliveryText(value string) string {
|
|
if len(value) <= 300 {
|
|
return value
|
|
}
|
|
return value[:300]
|
|
}
|
|
|
|
func deliveryGoodID(channel, sku string) string {
|
|
if channel != "dlc" {
|
|
return ""
|
|
}
|
|
return map[string]string{
|
|
"suit_alan_walker": "682ef3c5a8f40c4234c59f47",
|
|
"suit_shadow_gothic": "6a13aa55e3bce430aca29b01",
|
|
"top_black_elite_trainer": "6a13aaeae3bce430aca29b03",
|
|
"m416_hamster_gray": "682ef3c5a8f40c4234c59f52",
|
|
"bag_cute_bear": "682ef3c5a8f40c4234c59f4a",
|
|
"suit_dual_fluffy": "682ef3c5a8f40c4234c59f49",
|
|
"suit_pink_sheep": "682ef3c5a8f40c4234c59f4d",
|
|
"suit_first_peach": "682ef3c5a8f40c4234c59f48",
|
|
"suit_romantic_destiny": "6a13ab21e3bce430aca29b04",
|
|
"pack_western_cowboy": "682ef3c5a8f40c4234c59f4c",
|
|
"smoke_pink_sheep": "682ef3c5a8f40c4234c59f50",
|
|
"frag_pink_sheep": "682ef3c5a8f40c4234c59f51",
|
|
"suit_hamster_gray": "682ef3c5a8f40c4234c59f53",
|
|
"suit_cute_bear": "682ef3c5a8f40c4234c59f4b",
|
|
"bag_pink_sheep": "682ef3c5a8f40c4234c59f4f",
|
|
"helmet_pink_sheep": "682ef3c5a8f40c4234c59f4e",
|
|
"bag_hamster_gray": "682ef3c5a8f40c4234c59f55",
|
|
"helmet_hamster_gray": "682ef3c5a8f40c4234c59f54",
|
|
"suit_western_mystery": "682ef39ca8f40c4234c59f35",
|
|
"helmet_panda_treasure": "682ef39ca8f40c4234c59f39",
|
|
"suit_panda_round": "682ef39ca8f40c4234c59f3a",
|
|
"suit_panda_tuan": "682ef39ca8f40c4234c59f3b",
|
|
"pack_lava_ranger": "682ef39ca8f40c4234c59f3c",
|
|
"suit_sand_dancer": "682ef39ca8f40c4234c59f3d",
|
|
"pack_star_roam_outfit": "682ef39ca8f40c4234c59f3e",
|
|
"pack_star_roam_weapon": "682ef39ca8f40c4234c59f3f",
|
|
"suit_cloud_bear": "682ef39ca8f40c4234c59f40",
|
|
"honor_medal_x2": "682ef39ca8f40c4234c59f45",
|
|
"honor_medal_x30": "682ef39ca8f40c4234c59f43",
|
|
"honor_medal_x90": "682ef39ca8f40c4234c59f41",
|
|
"lucky_coin_x2": "682ef39ca8f40c4234c59f46",
|
|
"lucky_coin_x30": "682ef39ca8f40c4234c59f44",
|
|
"lucky_coin_x90": "682ef39ca8f40c4234c59f42",
|
|
}[sku]
|
|
}
|