在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/PHP  數(shù)據庫  網絡安全  電子商務/ 類似淘寶的sku

類似淘寶的sku

首先數(shù)據庫的設計我在百度上找了一大堆,可以說得上是眾說紛紜??!我看到一個中間表是這樣設計的,商品ID sku屬性,單價庫存,看到中間屬性存的是json然后就懵了,請各位大神告知什么操作能把這些屬性還有值扔到一起,并且全部塞到指定的商品下邊?

回答
編輯回答
有點壞

json_encode了解一下

2018年9月13日 12:23
編輯回答
寫榮

關于SKU的概念應該先谷歌了解下
sku是屬性and規(guī)格組成的,而屬性規(guī)格又需要相互獨立,為了避免未來業(yè)務擴展,實際一個屬性屬性鏈接另一個規(guī)格屬性則就是一個sku,例如:

規(guī)格:顏色 屬性:紅色
規(guī)格:尺碼 屬性:xl
規(guī)格:尺碼 屬性:xxl

那么它的sku就又二個,(紅色+xl)(紅色+xxl)

下面是我的數(shù)據表設計

商品表

CREATE TABLE `product` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '商品標題',
  `category_id` int(11) NOT NULL COMMENT '商品分類編號',
  `mer_id` int(11) NOT NULL COMMENT '商家編號',
  `type_id` tinyint(4) NOT NULL COMMENT '類型編號',
  `sketch` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '簡述',
  `intro` text COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '商品描述',
  `keywords` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '商品關鍵字',
  `marque` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '商品型號',
  `barcode` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '倉庫條碼',
  `brand_id` int(11) NOT NULL COMMENT '品牌編號',
  `virtual` int(11) NOT NULL DEFAULT '0' COMMENT '虛擬購買量',
  `price` decimal(8,2) NOT NULL COMMENT '商品價格',
  `market_price` decimal(8,2) NOT NULL COMMENT '市場價格',
  `integral` int(11) NOT NULL DEFAULT '0' COMMENT '可使用積分抵消',
  `stock` int(11) NOT NULL COMMENT '庫存量',
  `warning_stock` int(11) NOT NULL COMMENT '庫存警告',
  `picture_url` varchar(125) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '封面圖',
  `status` tinyint(4) NOT NULL COMMENT '狀態(tài) -1=>下架,1=>上架,2=>預售,0=>未上架',
  `is_package` enum('0','1') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '0' COMMENT '是否是套餐',
  `is_integral` enum('0','1') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '0' COMMENT '是否是積分產品',
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=136 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

sku表

CREATE TABLE `product_sku` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `product_id` int(11) NOT NULL COMMENT '商品編碼',
  `name` varchar(125) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'sku名稱',
  `img` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '主圖',
  `price` decimal(8,2) NOT NULL COMMENT '價格',
  `stock` int(11) NOT NULL DEFAULT '0' COMMENT '庫存',
  `code` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '商品編碼',
  `barcode` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '商品條形碼',
  PRIMARY KEY (`id`),
  KEY `product_sku_name_product_id_index` (`name`,`product_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1125 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

規(guī)格表

CREATE TABLE `product_attribute` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `category_id` int(11) NOT NULL COMMENT '商品類別編號',
  `name` varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '屬性名稱',
  `sort` int(11) NOT NULL DEFAULT '999' COMMENT '排列次序',
  PRIMARY KEY (`id`),
  KEY `product_attribute_category_id_name_index` (`category_id`,`name`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

屬性表

CREATE TABLE `product_attribute_option` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(125) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '選項名稱',
  `attr_id` int(11) NOT NULL COMMENT '屬性編碼',
  `sort` int(11) NOT NULL DEFAULT '999' COMMENT '排序',
  PRIMARY KEY (`id`),
  KEY `product_attribute_option_name_attr_id_index` (`name`,`attr_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

規(guī)格屬性綁定SKU的表

CREATE TABLE `product_attribute_and_option` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `sku_id` int(11) NOT NULL COMMENT 'sku編碼',
  `option_id` int(11) NOT NULL DEFAULT '0' COMMENT '屬性選項編碼',
  `attribute_id` int(11) NOT NULL COMMENT '屬性編碼',
  `sort` int(11) NOT NULL DEFAULT '999' COMMENT '排序',
  `supplier_option_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `product_attribute_and_option_sku_id_option_id_attribute_id_index` (`sku_id`,`option_id`,`attribute_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4819 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2017年9月16日 10:15