新增摸大红业务并修复后台链接按钮白字
支持分类筛选、搜索、下单支付建群与固定二维码;合并迁移种子数据;后台表格编辑/详情链接恢复主题色可见。
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
package mohong
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/pkg/money"
|
||||
)
|
||||
|
||||
func toProductDTO(row model.MohongProduct, includeAdminFields bool) ProductDTO {
|
||||
images := decodeStringList(row.ImageURLs)
|
||||
dto := ProductDTO{
|
||||
ID: row.ID,
|
||||
CategoryID: row.CategoryID,
|
||||
Title: row.Title,
|
||||
CoverURL: row.CoverURL,
|
||||
ImageURLs: images,
|
||||
Description: row.Description,
|
||||
PriceCent: row.PriceCent,
|
||||
Price: money.Format(row.PriceCent),
|
||||
OriginalPriceCent: row.OriginalPriceCent,
|
||||
Unit: row.Unit,
|
||||
Stock: row.Stock,
|
||||
SortOrder: row.SortOrder,
|
||||
Status: row.Status,
|
||||
CreatedAt: row.CreatedAt,
|
||||
UpdatedAt: row.UpdatedAt,
|
||||
}
|
||||
if row.OriginalPriceCent > 0 {
|
||||
dto.OriginalPrice = money.Format(row.OriginalPriceCent)
|
||||
}
|
||||
if includeAdminFields {
|
||||
dto.QrcodeImageURL = row.QrcodeImageURL
|
||||
}
|
||||
return dto
|
||||
}
|
||||
|
||||
func toProductDTOWithCategory(row model.MohongProduct, categoryName string, includeAdminFields bool) ProductDTO {
|
||||
dto := toProductDTO(row, includeAdminFields)
|
||||
dto.CategoryName = categoryName
|
||||
return dto
|
||||
}
|
||||
|
||||
func toOrderDTO(row model.MohongOrder, snap productSnapshot, buyerNickname, buyerPhone string, includeAdmin bool) OrderDTO {
|
||||
dto := OrderDTO{
|
||||
ID: row.ID,
|
||||
OrderNo: row.OrderNo,
|
||||
UserID: row.UserID,
|
||||
ProductID: row.ProductID,
|
||||
Quantity: row.Quantity,
|
||||
UnitPriceCent: row.UnitPriceCent,
|
||||
UnitPrice: money.Format(row.UnitPriceCent),
|
||||
AmountCent: row.AmountCent,
|
||||
Amount: money.Format(row.AmountCent),
|
||||
Status: row.Status,
|
||||
ProductTitle: snap.Title,
|
||||
ProductCoverURL: snap.CoverURL,
|
||||
ProductUnit: snap.Unit,
|
||||
QrcodeURLSnapshot: row.QrcodeURLSnapshot,
|
||||
CopyText: row.CopyText,
|
||||
ConversationID: row.ConversationID,
|
||||
CancelReason: row.CancelReason,
|
||||
PaidAt: row.PaidAt,
|
||||
CompletedAt: row.CompletedAt,
|
||||
CancelledAt: row.CancelledAt,
|
||||
CreatedAt: row.CreatedAt,
|
||||
UpdatedAt: row.UpdatedAt,
|
||||
}
|
||||
if includeAdmin {
|
||||
dto.BuyerNickname = buyerNickname
|
||||
dto.BuyerPhone = maskPhone(buyerPhone)
|
||||
dto.AdminRemark = row.AdminRemark
|
||||
} else {
|
||||
dto.BuyerNickname = buyerNickname
|
||||
dto.BuyerPhone = maskPhone(buyerPhone)
|
||||
}
|
||||
return dto
|
||||
}
|
||||
|
||||
func decodeStringList(raw []byte) []string {
|
||||
if len(raw) == 0 {
|
||||
return []string{}
|
||||
}
|
||||
var list []string
|
||||
if err := json.Unmarshal(raw, &list); err != nil {
|
||||
return []string{}
|
||||
}
|
||||
out := make([]string, 0, len(list))
|
||||
for _, item := range list {
|
||||
item = strings.TrimSpace(item)
|
||||
if item != "" {
|
||||
out = append(out, item)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func encodeStringList(list []string) []byte {
|
||||
clean := make([]string, 0, len(list))
|
||||
for _, item := range list {
|
||||
item = strings.TrimSpace(item)
|
||||
if item != "" {
|
||||
clean = append(clean, item)
|
||||
}
|
||||
}
|
||||
if len(clean) == 0 {
|
||||
return []byte("[]")
|
||||
}
|
||||
raw, err := json.Marshal(clean)
|
||||
if err != nil {
|
||||
return []byte("[]")
|
||||
}
|
||||
return raw
|
||||
}
|
||||
|
||||
func decodeProductSnapshot(raw []byte) productSnapshot {
|
||||
var snap productSnapshot
|
||||
if len(raw) == 0 {
|
||||
return snap
|
||||
}
|
||||
_ = json.Unmarshal(raw, &snap)
|
||||
return snap
|
||||
}
|
||||
|
||||
func maskPhone(phone string) string {
|
||||
phone = strings.TrimSpace(phone)
|
||||
if len(phone) < 7 {
|
||||
return phone
|
||||
}
|
||||
return phone[:3] + "****" + phone[len(phone)-4:]
|
||||
}
|
||||
Reference in New Issue
Block a user