Skip to content

Commit

Permalink
重构: 商品模块——修改字段添加注释等
Browse files Browse the repository at this point in the history
  • Loading branch information
longyue0521 authored Mar 21, 2024
2 parents 7b02908 + 949f0bf commit cf6bfec
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
47 changes: 22 additions & 25 deletions .script/mysql/product_insert.sql
Original file line number Diff line number Diff line change
@@ -1,46 +1,43 @@
CREATE TABLE IF NOT EXISTS `product_spus` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT 'SPU ID',
`sn` varchar(255) NOT NULL COMMENT 'SPU 对外展示ID',
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '商品SPU自增ID',
`sn` varchar(255) NOT NULL COMMENT '商品SPU序列号',
`name` varchar(255) NOT NULL COMMENT '商品名称',
`description` longtext NOT NULL COMMENT '商品描述',
`status` tinyint unsigned NOT NULL DEFAULT '0' COMMENT '状态 0=下架 1=上架',
`status` tinyint unsigned NOT NULL DEFAULT '1' COMMENT '状态 1=下架 2=上架',
`ctime` bigint DEFAULT NULL,
`utime` bigint DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_code` (`sn`)
UNIQUE KEY `uniq_product_spu_sn` (`sn`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

INSERT INTO `product_spus` (sn, name, description, status, ctime, utime)
VALUES ('SPU001', '会员服务', '提供不同期限的会员服务', 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('SPU002', '面试项目', '提供不同规模的面试项目', 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP());
VALUES ('SPU001', '会员服务', '提供不同期限的会员服务', 2, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('SPU002', '面试项目', '提供不同规模的面试项目', 2, UNIX_TIMESTAMP(), UNIX_TIMESTAMP());

CREATE TABLE IF NOT EXISTS `product_skus` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT 'SKU ID',
`sn` varchar(255) NOT NULL COMMENT 'SKU 对外展示ID',
`product_spu_id` bigint NOT NULL,
CREATE TABLE IF NOT EXISTS `product_skus` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '商品SKU自增ID',
`sn` varchar(255) NOT NULL COMMENT '商品SKU序列号',
`product_spu_id` bigint NOT NULL COMMENT '商品SPU自增ID',
`name` varchar(255) NOT NULL COMMENT 'SKU名称',
`description` longtext NOT NULL COMMENT 'SKU描述',
`price` bigint NOT NULL COMMENT '价格,单位为分;999表示9.99元',
`description` longtext NOT NULL COMMENT '商品描述',
`price` bigint NOT NULL COMMENT '商品单价',
`stock` bigint NOT NULL COMMENT '库存数量',
`stock_limit` bigint NOT NULL COMMENT '库存限制',
`sale_type` tinyint unsigned NOT NULL DEFAULT '1' COMMENT '销售类型: 1=无限期 2=限时促销 3=预售',
`status` tinyint unsigned NOT NULL DEFAULT '0' COMMENT '状态 0=下架 1=上架',
`status` tinyint unsigned NOT NULL DEFAULT '1' COMMENT '状态 1=下架 2=上架',
`ctime` bigint DEFAULT NULL,
`utime` bigint DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_code` (`sn`)
UNIQUE KEY `uniq_product_sku_sn` (`sn`),
KEY `idx_product_spu_id` (`product_spu_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;


INSERT INTO `product_skus` (sn, product_spu_id, name, description, price, stock, stock_limit, sale_type, status, ctime, utime)
VALUES
('SKU001', 1, '星期会员', '提供一周的会员服务', 799, 1000, 100000000, 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('SKU002', 1, '月会员', '提供一个月的会员服务', 990, 1000, 100000000, 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('SKU003', 1, '季度会员', '提供一个季度的会员服务', 2970, 1000, 100000000, 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('SKU004', 1, '年会员', '提供一年的会员服务', 11880, 1000, 100000000, 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('SKU005', 2, '用户项目', '中小型面试项目', 9999, 1000, 100000000, 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('SKU006', 2, '权限项目', '中大型面试项目', 19999, 1000, 100000000, 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP());





('SKU001', 1, '星期会员', '提供一周的会员服务', 799, 1000, 100000000, 1, 2, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('SKU002', 1, '月会员', '提供一个月的会员服务', 990, 1000, 100000000, 1, 2, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('SKU003', 1, '季度会员', '提供一个季度的会员服务', 2970, 1000, 100000000, 1, 2, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('SKU004', 1, '年会员', '提供一年的会员服务', 11880, 1000, 100000000, 1, 2, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('SKU005', 2, '用户项目', '中小型面试项目', 9999, 1000, 100000000, 1, 2, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
('SKU006', 2, '权限项目', '中大型面试项目', 19999, 1000, 100000000, 1, 2, UNIX_TIMESTAMP(), UNIX_TIMESTAMP());
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,33 @@ func (d *ProductGORMDAO) CreateSKU(ctx context.Context, sku ProductSKU) (int64,
}

type ProductSPU struct {
Id int64 `gorm:"primaryKey;autoIncrement;comment:SPU ID"`
SN string `gorm:"type:varchar(255);not null;uniqueIndex:uniq_code;comment:SPU 对外展示ID"`
Id int64 `gorm:"primaryKey;autoIncrement;comment:商品SPU自增ID"`
SN string `gorm:"type:varchar(255);not null;uniqueIndex:uniq_product_spu_sn;comment:商品SPU序列号"`
Name string `gorm:"type:varchar(255);not null;comment:商品名称"`
Description string `gorm:"not null; comment:商品描述"`
Status int64 `gorm:"type:tinyint unsigned;not null;default:0;comment:状态 0=下架 1=上架"`
Status int64 `gorm:"type:tinyint unsigned;not null;default:1;comment:状态 1=下架 2=上架"`
Ctime int64
Utime int64
}

type ProductSKU struct {
Id int64 `gorm:"primaryKey;autoIncrement;comment:SKU ID"`
SN string `gorm:"type:varchar(255);not null;uniqueIndex:uniq_code;comment:SKU 对外展示ID"`
ProductSPUID int64 `gorm:"column:product_spu_id;not null;index:idx_product_spu_id,comment:所属SPU的ID不是SN"`
Id int64 `gorm:"primaryKey;autoIncrement;comment:商品SKU自增ID"`
SN string `gorm:"type:varchar(255);not null;uniqueIndex:uniq_product_sku_sn;comment:商品SKU序列号"`
ProductSPUID int64 `gorm:"column:product_spu_id;not null;index:idx_product_spu_id;comment:商品SPU自增ID"`
Name string `gorm:"type:varchar(255);not null;comment:SKU名称"`
Description string `gorm:"not null;comment:SKU描述"`
Price int64 `gorm:"not null;comment:价格单位为分, 999表示9.99元"`
Description string `gorm:"not null;comment:商品描述"`
Price int64 `gorm:"not null;comment:商品单价;单位为分, 999表示9.99元"`
Stock int64 `gorm:"not null;comment:库存数量"`
StockLimit int64 `gorm:"not null;comment:库存限制"`
SaleType int64 `gorm:"type:tinyint unsigned;not null;default:1;comment:销售类型: 1=无限期 2=限时促销 3=预售"`
// SaleStart sql.NullInt64 `gorm:"comment:销售开始时间,无限期销售为NULL"`
// SaleEnd sql.NullInt64 `gorm:"comment:销售结束时间,无限期和预售为NULL"`
Status int64 `gorm:"type:tinyint unsigned;not null;default:0;comment:状态 0=下架 1=上架"`
Status int64 `gorm:"type:tinyint unsigned;not null;default:1;comment:状态 1=下架 2=上架"`
Ctime int64
Utime int64
}

const (
StatusOffShelf = iota // 下架
StatusOnShelf // 上架
StatusOffShelf = iota + 1 // 下架
StatusOnShelf // 上架
)

0 comments on commit cf6bfec

Please sign in to comment.