商品 分类 属性 表设计 库存

根据不同的商品分类选择,特殊商品出现不同 扩展属性/规格,如:衣服出现尺码,颜色

private function getCategoryTreeAndLevel($id, $parent_id) {
    $level = 1;
    $current_cate_tree = $id;
    if ($parent_id > 0) {
        $pInfo = $this->getInfo($parent_id);
        if ($pInfo) {
            $current_cate_tree = "{$pInfo['cate_tree']}-{$current_cate_tree}";
            $level = $pInfo['level'] + 1;
        }
    }
    return ['cate_tree' => $current_cate_tree, 'level' => $level];
}

模糊查询

 (cate_tree LIKE 'pid-%' or cate_tree LIKE '%-pid-%')

 1.商品分类表:一次性把数据读出来(id做key)然后递归处理,不要递归取数据库

Array
(
    [758] => Array
        (
            [id] => 758
            [name] => 综合开单
            [pid] => 99
        )

    [738] => Array
        (
            [id] => 738
            [name] => 商家首页
            [pid] => 92
        )
CREATE TABLE `category` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '分类ID',
  `pid` int(11) DEFAULT '0' COMMENT '分类父ID',
  `level` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '层数',
  `name` varchar(100) DEFAULT NULL COMMENT '分类名称',
  `seo_title` varchar(20) DEFAULT NULL COMMENT 'SEO标题',
  `seo_keyword` varchar(20) DEFAULT NULL COMMENT 'SEO关键字',
  `seo_desc` varchar(50) DEFAULT NULL COMMENT 'SEO描述',
  `cate_tree` varchar(100) DEFAULT NULL COMMENT '分类树形结构',
  `listorder` int(11) DEFAULT '0' COMMENT '排序',
  PRIMARY KEY (`id`),
  KEY `pid` (`pid`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;

INSERT INTO `category` (`id`, `pid`, `level`, `name`, `seo_title`, `seo_keyword`, `seo_desc`, `cate_tree`, `listorder`)
VALUES
(1, 0, 1, '日常所需', '', '', '', '1', 0),
(2, 1, 2, '注册公司', '', '', '', '1-2', 0),
(3, 2, 3, '国内游', '', '', '', '1-2-3', 0),
(4, 3, 4, '上海游', '', '', '', '1-2-3-4', 0),
(5, 1, 2, '企业开户', '', '', '', '1-5', 0),
(6, 0, 1, '办公硬件', '', '', '', '6', 0);

分隔符要用 ‘-’,不要用下划线 ‘_’

2.分类属性表(核心)

CREATE TABLE `category_fields` (
  `field_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '分类属性表',
  `category_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '分类ID',
  `field_name` varchar(100) NOT NULL DEFAULT '' COMMENT '属性code',
  `title` varchar(255) NOT NULL DEFAULT '' COMMENT '名称',
  `description` varchar(255) NOT NULL DEFAULT '' COMMENT '描叙',
  `required` enum('no','yes') NOT NULL DEFAULT 'no' COMMENT '是否必填',
  `formtype` varchar(255) NOT NULL DEFAULT '' COMMENT '表单类型',
  `choices` text NOT NULL COMMENT '值选项',
  `sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序',
  `unit` varchar(10) DEFAULT NULL COMMENT '单位',
  `min` int(11) unsigned DEFAULT NULL COMMENT '文本框时的最小值',
  `max` int(11) unsigned DEFAULT NULL COMMENT '文本框时的最大值',
  PRIMARY KEY (`field_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

INSERT INTO `category_fields` (`field_id`, `category_id`, `field_name`, `title`, `description`, `required`, `formtype`, `choices`, `sort`, `unit`, `min`, `max`)
VALUES
(1, 1, 'renjunyusuan', '人均预算', '', 'no', 'text', '', 0, '元', 1, 2),
(2, 1, 'renshu', '旅游人数', '', 'no', 'text', '', 0, '', NULL, NULL),
(3, 1, 'daogou', '允许导购', '', 'no', 'radio', '是 否', 0, '', NULL, NULL),
(4, 1, 'days', '预计天数', '', 'no', 'checkbox', '2天1夜 3天2夜', 0, '', NULL, NULL);


 3.商品属性值表

CREATE TABLE `mall_product_field_value` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '商品属性值',
  `product_id` int(11) NOT NULL DEFAULT '0' COMMENT '商品ID',
  `field_id` int(11) NOT NULL DEFAULT '0' COMMENT '属性ID',
  `value` text COMMENT '属性值',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

二规格表

CREATE TABLE `catalog_standard` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '分类规格表',
  `pid` int(11) NOT NULL DEFAULT '0',
  `level` int(11) NOT NULL DEFAULT '1',
  `catalog_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '分类ID',
  `name` varchar(100) NOT NULL DEFAULT '' COMMENT '规格code',
  `value` varchar(100) NOT NULL DEFAULT '' COMMENT '值选项',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

INSERT INTO `catalog_standard` (`id`, `pid`, `level`, `catalog_id`, `name`, `value`)
VALUES
(1, 0, 1, 35, 'color', '颜色'),
(2, 0, 1, 35, 'size', '尺码'),
(3, 1, 2, 35, 'red', '红色'),
(4, 1, 2, 35, 'black', '黑色'),
(5, 2, 2, 35, 'S', 'S'),
(6, 2, 2, 35, 'M', 'M'),
(7, 2, 2, 35, 'L', 'L');

规格checkbox勾选值表

CREATE TABLE `mall_product_standard_value` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '商品规格值',
  `product_id` int(11) NOT NULL DEFAULT '0' COMMENT '产品ID',
  `root_standard_id` int(11) NOT NULL DEFAULT '0' COMMENT 'level=1的StandardID',
  `standard_id` varchar(100) NOT NULL DEFAULT '0' COMMENT '规格ID',
  `value` varchar(100) NOT NULL DEFAULT '' COMMENT '值',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

INSERT INTO `mall_product_standard_value` (`id`, `product_id`, `root_standard_id`, `standard_id`, `value`)
VALUES
(1, 1, 1, '3', '红色1'),
(2, 1, 1, '4', '黑色'),
(3, 1, 2, '5', 'S222')

规格勾选后,js生成不同规格组合的表单(价格/库存/货号),修改勾选规格名称,表单的规格名称也随之变化商品的基础属性库存不允许填写,库存是自动加和的

 

不同规则选项组合表

CREATE TABLE `mall_product_standard_value_group` (
    `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '商品规则组合值',
    `product_id` int(11) NOT NULL DEFAULT '0' COMMENT '产品ID',
    `standard_ids` varchar(100) DEFAULT NULL COMMENT '规格组合standard_value_ids',
    `inventory` int(11) NOT NULL DEFAULT '0' COMMENT '库存',
    `price` int(11) NOT NULL DEFAULT '0.00' COMMENT '价格(分)',
    `sku` varchar(60) DEFAULT NULL COMMENT '货号',
    `bar_code` varchar(32) DEFAULT NULL COMMENT '商品条形码',
    PRIMARY KEY (`id`),
    UNIQUE KEY `standard_group` (`standard_ids`,`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

猜你喜欢

转载自hudeyong926.iteye.com/blog/2064023