Skip to content

Commit

Permalink
Merge branch 'release/v1.25.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
bububa committed Jun 12, 2024
2 parents bfa31de + 34331fb commit 3450590
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
8 changes: 4 additions & 4 deletions marketing-api/model/dpa/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ type Product struct {
Title string `json:"title,omitempty"`
// Description 商品标题
Description string `json:"description,omitempty"`
// OfflineTime 下线时间,格式"YYYY-MM-DD"
OfflineTime string `json:"offline_time,omitempty"`
// OnlineTime 上线时间,格式"YYYY-MM-DD"
OnlineTime string `json:"online_time,omitempty"`
// OfflineTime 下线时间,格式"YYYY-MM-DD" 或 格式为十位unix时间戳类型
OfflineTime model.UnixTime `json:"offline_time,omitempty"`
// OnlineTime 上线时间,格式"YYYY-MM-DD" 或 格式为十位unix时间戳类型
OnlineTime model.UnixTime `json:"online_time,omitempty"`
// PlatformID 商品库ID
PlatformID uint64 `json:"platform_id,omitempty"`
// ProductID 商品ID
Expand Down
9 changes: 1 addition & 8 deletions marketing-api/model/dpa/product_for_update.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package dpa

import "time"

// ProductForUpdate 商品详情
type ProductForUpdate struct {
// Name 商品名称
Expand Down Expand Up @@ -87,15 +85,10 @@ type ProductForUpdate struct {
}

func CopyProductForUpdateFromProduct(src *Product, dist *ProductForUpdate) {
loc := time.Now().Location()
dist.Name = src.Name
dist.Title = src.Title
dist.Description = src.Description
if src.OfflineTime != "" {
if t, err := time.ParseInLocation("2006-01-02", src.OfflineTime, loc); err == nil {
dist.OfflineTime = t.Unix()
}
}
dist.OfflineTime = src.OfflineTime.Value()
dist.Status = src.Status
dist.Stock = src.Stock
dist.FirstCategory = src.FirstCategory
Expand Down
40 changes: 39 additions & 1 deletion marketing-api/model/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package model

import "strconv"
import (
"strconv"
"time"
)

type AdVersion int

Expand Down Expand Up @@ -263,3 +266,38 @@ func (i ReverseOnOffInt) String() string {
}
return "ON"
}

var timeFormats = []string{
"2006-01-02 15:04:05",
"2006-01-02",
}

// UnixTime support number/string in json
type UnixTime int64

func (ut UnixTime) Value() int64 {
return int64(ut)
}

func (ut UnixTime) Time() time.Time {
return time.Unix(int64(ut), 0)
}

func (ut *UnixTime) UnmarshalJSON(b []byte) (err error) {
if b[0] == '"' && b[len(b)-1] == '"' {
b = b[1 : len(b)-1]
}
if i, err := strconv.ParseUint(string(b), 10, 64); err == nil {
*ut = UnixTime(i)
} else {
loc := time.Now().Location()
str := string(b)
for _, fmt := range timeFormats {
if t, err := time.ParseInLocation(fmt, str, loc); err == nil {
*ut = UnixTime(t.Unix())
break
}
}
}
return nil
}

0 comments on commit 3450590

Please sign in to comment.