拆分 service 与前端大文件,修复 CORS 配置与格式问题
- 后端 internal/service 按职责拆分: fulfillment.go(1397→527)拆出 wallet/timeout/data/order/query/dashboard/shipnotify delivery.go(1124→801)拆出 upstream/link/state/helpers merchant.go(855→251)拆出 member/product/api_client/catalog/helpers - 前端 MerchantCenter.tsx(1327→606)拆出 merchantCenterTabs/merchantCenterUtils - docker-compose backend 透传 CORS_ALLOWED_ORIGINS - CORS 白名单实现(config/router/README/.env.example 配套) - 修复 gofmt 与文件尾部多余空行
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
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]
|
||||
}
|
||||
Reference in New Issue
Block a user