A user has a shopping cart, there are multiple stores under one shopping cart, and there are multiple items under one store
linked table query
1. Check out the shopping cart data according to the user id,
2. Under a shopping cart, there are multiple stores, black box
3. There are multiple items under the store, with a blue box
4. A commodity with information about it, red box
mysql
id
id
data: [
{
cart_goods_number: 3,
goods_id: 3,
goods_name: "honor7x",
goods_img: "honor7x.png",
goods_price: 1299,
shop_id: 4,
shop_name: "honor"
},
{
cart_goods_number: 2,
goods_id: 4,
goods_name: "honor6x",
goods_img: "honor6x.png",
goods_price: 1199,
shop_id: 4,
shop_name: "honor"
},
{
cart_goods_number: 1,
goods_id: 1,
goods_name: "iPhonex",
goods_img: "iPhonex.png",
goods_price: 8888,
shop_id: 1,
shop_name: "iPhone"
}
],
< H2 > the data set I want looks like, < / H2 >
A user has a shopping cart, there are multiple stores under one shopping cart, and there are multiple items under one store
data1: [
{
shop_id: 4,
shop_name: "honor",
children: [
{
cart_goods_number: 3,
goods_id: 3,
goods_name: "honor7x",
goods_img: "honor7x.png",
goods_price: 1299
},
{
cart_goods_number: 2,
goods_id: 4,
goods_name: "honor6x",
goods_img: "honor6x.png",
goods_price: 1199
}
]
},
{
shop_id: 1,
shop_name: "iPhone",
children: [
{
cart_goods_number: 1,
goods_id: 1,
goods_name: "iPhonex",
goods_img: "iPhonex.png",
goods_price: 8888
}
]
}
]
< H2 > Database < / H2 >
Shopping cart list
user id, merchandise quantity id, merchandise
CREATE TABLE `cart` (
`cart_id` int(10) NOT NULL AUTO_INCREMENT,
`user_id` int(10) DEFAULT NULL,
`goods_id` int(10) DEFAULT NULL,
`cart_goods_number` int(10) DEFAULT NULL,
`create_time` datetime DEFAULT NULL,
`last_edit_time` datetime DEFAULT NULL,
PRIMARY KEY (`cart_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
user table
CREATE TABLE `user` (
`user_id` int(10) NOT NULL AUTO_INCREMENT,
`user_name` varchar(10) DEFAULT NULL,
`user_password` varchar(10) DEFAULT NULL,
`user_img` varchar(1024) DEFAULT NULL,
`user_phone` varchar(11) DEFAULT NULL,
`user_sex` int(2) NOT NULL DEFAULT "1" COMMENT "1:,2:",
`user_address` varchar(100) DEFAULT NULL,
`user_state` int(2) NOT NULL DEFAULT "1" COMMENT "1:,2:",
`create_time` datetime DEFAULT NULL,
`last_edit_time` datetime DEFAULT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `user_name` (`user_name`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
Commodity list
CREATE TABLE `goods` (
`goods_id` int(10) NOT NULL AUTO_INCREMENT,
`goods_name` varchar(10) DEFAULT NULL,
`goods_img` varchar(1024) DEFAULT NULL,
`goods_price` double DEFAULT NULL,
`goods_number` int(10) DEFAULT NULL,
`goods_priority` int(2) NOT NULL DEFAULT "1",
`goods_state` int(2) NOT NULL DEFAULT "1" COMMENT "1:,2:",
`shop_id` int(10) DEFAULT NULL,
`create_time` datetime DEFAULT NULL,
`last_edit_time` datetime DEFAULT NULL,
`goods_desc` varchar(1024) DEFAULT NULL,
PRIMARY KEY (`goods_id`),
UNIQUE KEY `goods_name` (`goods_name`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
Store table
CREATE TABLE `shop` (
`shop_id` int(10) NOT NULL AUTO_INCREMENT,
`shop_name` varchar(10) DEFAULT NULL,
`shop_phone` varchar(11) DEFAULT NULL,
`shop_img` varchar(1024) DEFAULT NULL,
`shop_category_id` int(10) DEFAULT NULL,
`shop_priority` int(2) NOT NULL DEFAULT "1",
`shop_state` int(2) NOT NULL DEFAULT "1" COMMENT "1:,2:",
`create_time` datetime DEFAULT NULL,
`last_edit_time` datetime DEFAULT NULL,
`shop_desc` varchar(1024) DEFAULT NULL,
PRIMARY KEY (`shop_id`),
UNIQUE KEY `shop_name` (`shop_name`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;