393e227de5
后端: - 新增 product_images 表,支持每商品最多5张图(服务端压缩至1200px/JPEG85%) - products 表新增 public_id(UUID)、description 字段 - 新增商品详情接口、二维码接口、公开商品接口(无鉴权) - 修复 XLS 导入:OLE2 magic bytes 检测 + 临时文件解析,兼容 extrame/xls - 修复商品/名称/系列/规格三张表导入数据为0(LastCol()=0 bug) - 所有导入接口返回 total/imported/skipped 统计 - config 新增 StorageConfig,支持 STORAGE_* 环境变量覆盖 - 种子数据修复:products 补 public_id、新增 product_images TRUNCATE、schema.sql 表名修正 前端: - 商品详情页:图片上传/删除、描述内联编辑、二维码弹窗、公开链接复制 - 公开商品页:无鉴权路由 /product/:public_id,Flutter Web SPA - 商品详情列表(批次追踪)商品名超链接跳转详情页 - 导航「商品管理」改名「商品详情」 - 所有列表表格新增每页条数选择(10/20/50/100) - 表格列头内嵌筛选(FilterableColumnHeader) - 导出 Excel 功能(入库/出库/库存/财务/批次/往来单位) - 网络恢复自动刷新 + 离线缓存展示 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
139 lines
4.4 KiB
Go
139 lines
4.4 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"gorm.io/gorm"
|
|
|
|
"github.com/wangjia/jiu/backend/internal/middleware"
|
|
"github.com/wangjia/jiu/backend/internal/model"
|
|
)
|
|
|
|
type ProductOptionHandler struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewProductOptionHandler(db *gorm.DB) *ProductOptionHandler {
|
|
return &ProductOptionHandler{db: db}
|
|
}
|
|
|
|
// ── 商品名称 ──────────────────────────────────────────────────
|
|
|
|
func (h *ProductOptionHandler) ListNames(c *gin.Context) {
|
|
shopID := middleware.GetShopID(c)
|
|
var items []model.ProductNameOption
|
|
h.db.Where("shop_id = ?", shopID).Order("id ASC").Find(&items)
|
|
c.JSON(http.StatusOK, gin.H{"data": items})
|
|
}
|
|
|
|
func (h *ProductOptionHandler) CreateName(c *gin.Context) {
|
|
shopID := middleware.GetShopID(c)
|
|
var req struct {
|
|
Code string `json:"code"`
|
|
Name string `json:"name" binding:"required"`
|
|
Remark string `json:"remark"`
|
|
}
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
item := model.ProductNameOption{
|
|
TenantBase: model.TenantBase{ShopID: shopID},
|
|
Code: req.Code,
|
|
Name: req.Name,
|
|
Remark: req.Remark,
|
|
}
|
|
if err := h.db.Create(&item).Error; err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusCreated, gin.H{"data": item})
|
|
}
|
|
|
|
func (h *ProductOptionHandler) DeleteName(c *gin.Context) {
|
|
shopID := middleware.GetShopID(c)
|
|
h.db.Where("id = ? AND shop_id = ?", c.Param("id"), shopID).Delete(&model.ProductNameOption{})
|
|
c.JSON(http.StatusOK, gin.H{"message": "deleted"})
|
|
}
|
|
|
|
// ── 商品系列 ──────────────────────────────────────────────────
|
|
|
|
func (h *ProductOptionHandler) ListSeries(c *gin.Context) {
|
|
shopID := middleware.GetShopID(c)
|
|
var items []model.ProductSeriesOption
|
|
h.db.Where("shop_id = ?", shopID).Order("id ASC").Find(&items)
|
|
c.JSON(http.StatusOK, gin.H{"data": items})
|
|
}
|
|
|
|
func (h *ProductOptionHandler) CreateSeries(c *gin.Context) {
|
|
shopID := middleware.GetShopID(c)
|
|
var req struct {
|
|
Code string `json:"code"`
|
|
Name string `json:"name" binding:"required"`
|
|
Remark string `json:"remark"`
|
|
}
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
item := model.ProductSeriesOption{
|
|
TenantBase: model.TenantBase{ShopID: shopID},
|
|
Code: req.Code,
|
|
Name: req.Name,
|
|
Remark: req.Remark,
|
|
}
|
|
if err := h.db.Create(&item).Error; err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusCreated, gin.H{"data": item})
|
|
}
|
|
|
|
func (h *ProductOptionHandler) DeleteSeries(c *gin.Context) {
|
|
shopID := middleware.GetShopID(c)
|
|
h.db.Where("id = ? AND shop_id = ?", c.Param("id"), shopID).Delete(&model.ProductSeriesOption{})
|
|
c.JSON(http.StatusOK, gin.H{"message": "deleted"})
|
|
}
|
|
|
|
// ── 商品规格 ──────────────────────────────────────────────────
|
|
|
|
func (h *ProductOptionHandler) ListSpecs(c *gin.Context) {
|
|
shopID := middleware.GetShopID(c)
|
|
var items []model.ProductSpecOption
|
|
h.db.Where("shop_id = ?", shopID).Order("id ASC").Find(&items)
|
|
c.JSON(http.StatusOK, gin.H{"data": items})
|
|
}
|
|
|
|
func (h *ProductOptionHandler) CreateSpec(c *gin.Context) {
|
|
shopID := middleware.GetShopID(c)
|
|
var req struct {
|
|
Code string `json:"code"`
|
|
Name string `json:"name" binding:"required"`
|
|
Quantity int `json:"quantity"`
|
|
Remark string `json:"remark"`
|
|
}
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
item := model.ProductSpecOption{
|
|
TenantBase: model.TenantBase{ShopID: shopID},
|
|
Code: req.Code,
|
|
Name: req.Name,
|
|
Quantity: req.Quantity,
|
|
Remark: req.Remark,
|
|
}
|
|
if err := h.db.Create(&item).Error; err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusCreated, gin.H{"data": item})
|
|
}
|
|
|
|
func (h *ProductOptionHandler) DeleteSpec(c *gin.Context) {
|
|
shopID := middleware.GetShopID(c)
|
|
h.db.Where("id = ? AND shop_id = ?", c.Param("id"), shopID).Delete(&model.ProductSpecOption{})
|
|
c.JSON(http.StatusOK, gin.H{"message": "deleted"})
|
|
}
|