Commit a5dfd4c2 by jscat

nyx sql: 数据更新

1. 完成toOrder的操作
parent 9459366e
USE rockwell_key;
USE rockwell_key;
......@@ -12,7 +12,7 @@ USE rockwell_key;
活动(activity)
问答(quiz) 为 activity 提供题目信息
商品(product) 为 activity 提供商品 price 和 stock 信息
商品(product) 为 activity 提供商品 price 和 quantity 信息
竞答(match) 用 match_id 将 activity_id 同 user_id 联系起来
竞答助力(match_bonus) 将 match_id 同 user_id 联系起来
......
USE rockwell_key;
USE rockwell_key;
......@@ -9,7 +9,7 @@ DROP VIEW IF EXISTS view_activity_detail;
CREATE VIEW view_activity_detail
AS
SELECT aa.activity_id, aa.activity_status, bb.member_name, bb.member_slogan, aa.tag, aa.title, aa.num_like, aa.content, aa.quiz, aa.point, dd.address_name, IFNULL(cc.product_id,"") as product_id, IFNULL(cc.product_desc,"") as product_desc, IFNULL(cc.product_status,"") as product_status, IFNULL(cc.default_status,"") as default_status, IFNULL(cc.unit_price,0) as unit_price, IFNULL(cc.stock, 0) as stock, aa.note_image, aa.member_id, bb.member_status, bb.member_logo, cc.start_datetime, cc.end_datetime, aa.create_datetime, aa.update_datetime
SELECT aa.activity_id, aa.activity_status, bb.member_name, bb.member_slogan, aa.tag, aa.title, aa.num_like, aa.content, aa.quiz, aa.point, dd.address_name, IFNULL(cc.product_id,"") as product_id, IFNULL(cc.product_desc,"") as product_desc, IFNULL(cc.product_status,"") as product_status, IFNULL(cc.default_status,"") as default_status, IFNULL(cc.unit_price,0) as unit_price, IFNULL(cc.quantity, 0) as quantity, aa.note_image, aa.member_id, bb.member_status, bb.member_logo, cc.start_datetime, cc.end_datetime, aa.create_datetime, aa.update_datetime
FROM tbl_activity aa
LEFT JOIN tbl_member bb ON aa.member_id=bb.id
LEFT JOIN tbl_product cc ON aa.activity_id=cc.activity_id
......
USE rockwell_key;
USE rockwell_key;
......@@ -33,6 +33,7 @@ CREATE TABLE tbl_order (
`user_id` VARCHAR(100) COMMENT '用户的id, uuid format, uid_001',
`order_status` VARCHAR(10) DEFAULT '00' COMMENT '订单状态: 00-订单取消, 10-未付款, 20-可使用, 30-已完成',
`total_price` DECIMAL(20,2) DEFAULT '0.00' COMMENT '实际付款金额,单位是元,保留两位小数',
`total_count` int DEFAULT '0' COMMENT '实际购买数量',
`payment_type` VARCHAR(10) DEFAULT '01' COMMENT '支付类型,01-在线支付',
`qrcode_url` VARCHAR(200) COMMENT 'qrcode的二维码url',
`payment_datetime` DATETIME DEFAULT NULL COMMENT '支付时间',
......@@ -40,12 +41,12 @@ CREATE TABLE tbl_order (
`create_datetime` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`update_datetime` DATETIME DEFAULT NULL,
PRIMARY KEY(`order_id`),
KEY `query_key` (`activity_id`, `user_id`, `order_status`))
KEY `query_key` (`activity_id`, `user_id`, `total_price`, `total_count`, `order_status`))
ENGINE=INNODB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT='活动预订结果';
INSERT INTO `tbl_order`(`order_id`, `activity_id`, `user_id`, `order_status`, `total_price`, `payment_type`, `qrcode_url`, `payment_datetime`, `end_datetime`, `create_datetime`,`update_datetime`)
INSERT INTO `tbl_order`(`order_id`, `activity_id`, `user_id`, `order_status`, `total_price`, `total_count`, `payment_type`, `qrcode_url`, `payment_datetime`, `end_datetime`, `create_datetime`,`update_datetime`)
VALUES
('oid_001', 'aid_005', 'uid_030e7057-e6b5-4fb0-bcbf-d8bf055e38d9', '20', 217.0, '01', 'https://930-test-sh.oss-cn-shanghai.aliyuncs.com/qrcode-dir/mid_11235813.png', '', '', '2019-11-20 11:24:45', '2019-11-20 11:24:45'),
('oid_002', 'aid_005', 'uid_030e7057-e6b5-4fb0-bcbf-d8bf055e38d9', '10', 0.0, '', '', '', '', '2019-11-20 11:24:45', '2019-11-20 11:24:45'),
('oid_003', 'aid_006', 'uid_030e7057-e6b5-4fb0-bcbf-d8bf055e38d9', '20', 119.0, '01', 'https://930-test-sh.oss-cn-shanghai.aliyuncs.com/qrcode-dir/mid_11235813.png', '', '', '2019-11-20 11:24:45', '2019-11-20 11:24:45')
('oid_001', 'aid_005', 'uid_030e7057-e6b5-4fb0-bcbf-d8bf055e38d9', '20', 217.0, 2, '01', 'https://930-test-sh.oss-cn-shanghai.aliyuncs.com/qrcode-dir/mid_11235813.png', '', '', '2019-11-20 11:24:45', '2019-11-20 11:24:45'),
('oid_002', 'aid_005', 'uid_030e7057-e6b5-4fb0-bcbf-d8bf055e38d9', '10', 0.0, 3, '', '', '', '', '2019-11-20 11:24:45', '2019-11-20 11:24:45'),
('oid_003', 'aid_006', 'uid_030e7057-e6b5-4fb0-bcbf-d8bf055e38d9', '20', 119.0, 4, '01', 'https://930-test-sh.oss-cn-shanghai.aliyuncs.com/qrcode-dir/mid_11235813.png', '', '', '2019-11-20 11:24:45', '2019-11-20 11:24:45')
;
USE rockwell_key;
USE rockwell_key;
......@@ -32,11 +32,14 @@ USE rockwell_key;
btw: 按照 in 的顺序排序
SELECT * FROM tbl_product WHERE product_id IN ('gid_002', 'gid_001') ORDER BY FIELD(product_id, 'gid_002', 'gid_001')
btw: item_id是需要的, 因为如果item未消费, 则可以退款;
*/
DROP TABLE IF EXISTS tbl_order_item;
CREATE TABLE tbl_order_item (
`item_id` VARCHAR(100) COMMENT '子项的id, uuid format, iid_001',
`id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT "item id, auto increment",
`order_id` VARCHAR(100) COMMENT '订单的id, uuid format, oid_001',
`user_id` VARCHAR(100) COMMENT '用户的id, uuid format, uid_001',
`product_id` VARCHAR(100) COMMENT '商品的id, uuid format, pid_001',
......@@ -44,19 +47,18 @@ CREATE TABLE tbl_order_item (
`product_image` VARCHAR(500) COMMENT '商品的图片地址',
`unit_price` decimal(20,2) DEFAULT '0.00' COMMENT '生成订单时的商品单价,单位是元,保留两位小数',
`quantity` int(10) DEFAULT 0 COMMENT '商品数量',
`item_price` decimal(20,2) DEFAULT '0.00' COMMENT '该item的商品总价,单位是元,保留两位小数',
`create_datetime` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`update_datetime` DATETIME DEFAULT NULL,
PRIMARY KEY(`item_id`),
PRIMARY KEY(`id`),
KEY `query_key` (`order_id`, `user_id`, `product_id`))
ENGINE=INNODB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT='活动预订结果的子项';
INSERT INTO `tbl_order_item`(`item_id`, `order_id`, `user_id`, `product_id`, `product_desc`, `unit_price`, `quantity`, `item_price`, `product_image`, `create_datetime`,`update_datetime`)
INSERT INTO `tbl_order_item`(`order_id`, `user_id`, `product_id`, `product_desc`, `unit_price`, `quantity`, `product_image`, `create_datetime`,`update_datetime`)
VALUES
('iid_001', 'oid_001', 'uid_030e7057-e6b5-4fb0-bcbf-d8bf055e38d9', 'pid_001', "会员", 59.0, 2, 118.0, 'https://930-test-sh.oss-cn-shanghai.aliyuncs.com/user-dir/sakura.jpg', '2019-11-20 11:24:45', '2019-11-20 11:24:45'),
('iid_002', 'oid_001', 'uid_030e7057-e6b5-4fb0-bcbf-d8bf055e38d9', 'pid_002', "普通用户", 99.0, 1, 99.0, 'https://930-test-sh.oss-cn-shanghai.aliyuncs.com/user-dir/sakura.jpg', '2019-11-20 11:24:45', '2019-11-20 11:24:45'),
('iid_003', 'oid_002', 'uid_030e7057-e6b5-4fb0-bcbf-d8bf055e38d9', 'pid_001', "会员", 59.0, 1, 59.0, 'https://930-test-sh.oss-cn-shanghai.aliyuncs.com/user-dir/sakura.jpg', '2019-11-20 11:24:45', '2019-11-20 11:24:45'),
('iid_004', 'oid_003', 'uid_030e7057-e6b5-4fb0-bcbf-d8bf055e38d9', 'pid_003', "意大利红酒周", 119.0, 1, 119.0, 'https://930-test-sh.oss-cn-shanghai.aliyuncs.com/user-dir/sakura.jpg', '2019-11-20 11:24:45', '2019-11-20 11:24:45')
('oid_001', 'uid_030e7057-e6b5-4fb0-bcbf-d8bf055e38d9', 'pid_001', "会员", 59.0, 2, 'https://930-test-sh.oss-cn-shanghai.aliyuncs.com/user-dir/sakura.jpg', '2019-11-20 11:24:45', '2019-11-20 11:24:45'),
('oid_001', 'uid_030e7057-e6b5-4fb0-bcbf-d8bf055e38d9', 'pid_002', "普通用户", 99.0, 1, 'https://930-test-sh.oss-cn-shanghai.aliyuncs.com/user-dir/sakura.jpg', '2019-11-20 11:24:45', '2019-11-20 11:24:45'),
('oid_002', 'uid_030e7057-e6b5-4fb0-bcbf-d8bf055e38d9', 'pid_001', "会员", 59.0, 1, 'https://930-test-sh.oss-cn-shanghai.aliyuncs.com/user-dir/sakura.jpg', '2019-11-20 11:24:45', '2019-11-20 11:24:45'),
('oid_003', 'uid_030e7057-e6b5-4fb0-bcbf-d8bf055e38d9', 'pid_003', "意大利红酒周", 119.0, 1, 'https://930-test-sh.oss-cn-shanghai.aliyuncs.com/user-dir/sakura.jpg', '2019-11-20 11:24:45', '2019-11-20 11:24:45')
;
......
USE rockwell_key;
USE rockwell_key;
......@@ -5,7 +5,7 @@ USE rockwell_key;
什么 product, 属于哪个 activity, 有多少数量,价格多少
activity 和 product 的关系 1:n 一个 activity 对于多个 product
比如 一场活动 有两个类别,一个针对会员,一个针对普通用户
注意库存管理 stock
注意库存管理 quantity
参考1: 分布式商城项目数据库设计
https://www.jianshu.com/p/7e673ffb29d8
......@@ -21,7 +21,7 @@ CREATE TABLE tbl_product(
`default_status` VARCHAR(10) DEFAULT '00' COMMENT '默认状态: 00:普通 01:默认状态; 默认是第一个product',
`product_desc` VARCHAR(100) COMMENT '类别说明',
`unit_price` DECIMAL(10,2) DEFAULT '0.00' COMMENT '价格',
`stock` INT(11) DEFAULT 0 COMMENT '库存数量',
`quantity` INT(11) DEFAULT 0 COMMENT '库存数量 stock quantity',
`start_datetime` DATETIME DEFAULT NULL,
`end_datetime` DATETIME DEFAULT NULL,
`create_datetime` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
......@@ -30,7 +30,7 @@ CREATE TABLE tbl_product(
KEY `query_key` (`activity_id`, `product_status`))
ENGINE=INNODB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT='活动所对应的商品名录';
INSERT INTO `tbl_product`(`product_id`, `activity_id`, `product_status`, `default_status`, `product_desc`, `unit_price`, `stock`,
INSERT INTO `tbl_product`(`product_id`, `activity_id`, `product_status`, `default_status`, `product_desc`, `unit_price`, `quantity`,
`start_datetime`, `end_datetime`, `create_datetime`,`update_datetime`)
VALUES
('pid_001', 'aid_005', '01', '01', '会员', 59, 10, '2020-08-30 00:00:00', '2020-08-30 00:00:00', '2020-05-20 11:24:45', '2020-05-20 11:24:45'),
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论