90a195c9ca
CI / changes (push) Successful in 13s
CI / ad (push) Successful in 3s
CI / admin (push) Successful in 2s
CI / bff (push) Successful in 2s
CI / chore (push) Successful in 1s
CI / express (push) Successful in 2s
CI / product (push) Successful in 31s
CI / sale (push) Successful in 2s
CI / user (push) Successful in 2s
CI / wecom (push) Successful in 2s
93 lines
2.5 KiB
Go
93 lines
2.5 KiB
Go
package logic
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
|
|
"lone-services/pkg/utils"
|
|
product "lone-services/rpc/product/pb"
|
|
"lone-services/services/product/internal/dao"
|
|
|
|
jsoniter "github.com/json-iterator/go"
|
|
)
|
|
|
|
func toProductItem(row dao.Info) *product.Item {
|
|
publishTime := ""
|
|
if !row.PublishTime.IsZero() {
|
|
publishTime = row.PublishTime.Format(time.DateTime)
|
|
}
|
|
return &product.Item{
|
|
Id: int64(row.Id),
|
|
Name: row.Name,
|
|
Subhead: row.Subhead,
|
|
Content: row.Content,
|
|
ModelCode: row.ModelCode,
|
|
Price: utils.RoundFloat(float64(row.Price)),
|
|
StorePrice: utils.RoundFloat(float64(row.StorePrice)),
|
|
SalePrice: utils.RoundFloat(float64(row.SalePrice)),
|
|
SharePrice: utils.RoundFloat(float64(row.SharePrice)),
|
|
AgentPrice: utils.RoundFloat(float64(row.AgentPrice)),
|
|
SaleReward: row.SaleReward,
|
|
SalesModel: uint32(row.SalesModel),
|
|
Waybill: row.Waybill,
|
|
Status: uint32(row.Status),
|
|
Weight: utils.RoundFloat(float64(row.Weight)),
|
|
IsIndex: uint32(row.IsIndex),
|
|
IndexImage: row.IndexImage,
|
|
Cubage: row.Cubage,
|
|
Label: row.Label,
|
|
Images: splitImages(row.Images),
|
|
IsBuy: uint32(row.IsBuy),
|
|
PeriodValidity: int32(row.PeriodValidity),
|
|
PublishTime: publishTime,
|
|
Type: uint32(row.Type),
|
|
NormsNumber: uint32(row.NormsNumber),
|
|
BoxNumber: row.BoxNumber,
|
|
Sort: uint32(row.Sort),
|
|
Number: uint32(row.Number),
|
|
VerifyStatus: uint32(row.VerifyStatus),
|
|
VerifyId: int64(row.VerifyId),
|
|
VerifyName: row.VerifyName,
|
|
VerifySecondId: int64(row.VerifySecondId),
|
|
VerifySecondName: row.VerifySecondName,
|
|
Reason: row.Reason,
|
|
AdminName: row.AdminName,
|
|
Edit: uint32(row.Edit),
|
|
}
|
|
}
|
|
|
|
func joinImages(images []string) string {
|
|
list := cleanImages(images)
|
|
if len(list) == 0 {
|
|
return "[]"
|
|
}
|
|
buf, err := jsoniter.Marshal(list)
|
|
if err != nil {
|
|
return "[]"
|
|
}
|
|
return string(buf)
|
|
}
|
|
|
|
func splitImages(images string) []string {
|
|
images = strings.TrimSpace(images)
|
|
if images == utils.StringEmpty {
|
|
return []string{}
|
|
}
|
|
var list []string
|
|
if err := jsoniter.Unmarshal([]byte(images), &list); err != nil {
|
|
return []string{}
|
|
}
|
|
return cleanImages(list)
|
|
}
|
|
|
|
func cleanImages(images []string) []string {
|
|
out := make([]string, 0, len(images))
|
|
for _, img := range images {
|
|
img = strings.TrimSpace(img)
|
|
if img != utils.StringEmpty {
|
|
out = append(out, img)
|
|
}
|
|
}
|
|
return out
|
|
}
|