-- ----------------------------
-- Table structure for qimall_addons_bargain_active
-- ----------------------------
DROP TABLE IF EXISTS `qimall_addons_bargain_active`;
CREATE TABLE `qimall_addons_bargain_active`  (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  `cate_id` int(11) NOT NULL DEFAULT 0,
  `goods_id` int(11) NOT NULL DEFAULT 0,
  `attr_id` int(11) NOT NULL DEFAULT 0,
  `mall_id` int(11) NOT NULL DEFAULT 0,
  `min_price` decimal(11, 2) NOT NULL DEFAULT 0.00 COMMENT '最低价',
  `begin_time` int(11) NOT NULL DEFAULT 0 COMMENT '活动开始时间',
  `end_time` int(11) NOT NULL DEFAULT 0 COMMENT '活动结束时间',
  `time` tinyint(3) NOT NULL DEFAULT 0 COMMENT '砍价小时数',
  `type` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否允许中途下单 1--允许 2--不允许',
  `stock` int(11) NOT NULL DEFAULT 0 COMMENT '活动库存',
  `mode_data` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '砍价方式数据',
  `active_status` tinyint(3) NOT NULL DEFAULT 0 COMMENT '活动状态， 0--未开始，1--进行中,2--已结束',
  `initiator` int(11) NOT NULL DEFAULT 0 COMMENT '发起人数',
  `participant` int(11) NOT NULL DEFAULT 0 COMMENT '参与人数',
  `min_price_goods` int(11) NOT NULL DEFAULT 0 COMMENT '砍到最小价格数',
  `underway` int(11) NOT NULL DEFAULT 0 COMMENT '进行中的',
  `success` int(11) NOT NULL DEFAULT 0 COMMENT '成功的',
  `fail` int(11) NOT NULL DEFAULT 0 COMMENT '失败的',
  `status` tinyint(1) NOT NULL DEFAULT 1 COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(11) NOT NULL DEFAULT 0,
  `updated_at` int(11) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_mall_id_goods_id`(`mall_id`, `goods_id`) USING BTREE,
  INDEX `idx_cate_id`(`cate_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '砍价活动商品设置' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for qimall_addons_bargain_cate
-- ----------------------------
DROP TABLE IF EXISTS `qimall_addons_bargain_cate`;
CREATE TABLE `qimall_addons_bargain_cate`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `mall_id` int(11) NOT NULL COMMENT '商城id',
  `name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '名称',
  `status` tinyint(1) NOT NULL DEFAULT 1 COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(11) NOT NULL DEFAULT 0,
  `updated_at` int(11) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_mall_id`(`mall_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '砍价分类表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for qimall_addons_bargain_order
-- ----------------------------
DROP TABLE IF EXISTS `qimall_addons_bargain_order`;
CREATE TABLE `qimall_addons_bargain_order`  (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  `mall_id` int(11) NOT NULL DEFAULT 0,
  `user_id` int(11) NOT NULL DEFAULT 0,
  `order_id` int(11) NOT NULL DEFAULT 0 COMMENT '主订订单id',
  `order_no` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '订单编号',
  `bargain_active_id` int(11) NOT NULL DEFAULT 0 COMMENT '砍价活动id',
  `cover_pic` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
  `goods_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
  `token` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
  `price` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '售价',
  `min_price` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '最低价',
  `time` int(11) NOT NULL DEFAULT 0 COMMENT '砍价时间',
  `order_status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '状态 0--进行中 1--成功 2--失败',
  `is_pay` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否支付:0否；1：是',
  `bargain_goods_data` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '砍价设置',
  `mobile` varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '收货人的手机号码',
  `receiver_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '收货人姓名',
  `province` int(11) NULL DEFAULT 0 COMMENT '收货人所在省',
  `city` int(11) NULL DEFAULT 0 COMMENT '收货人所在城市',
  `area` int(11) NULL DEFAULT 0 COMMENT '收货人所在街道',
  `zip` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '收货人邮编',
  `address` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '详细地址',
  `region_name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '地区名称（省市区[乡/镇]）',
  `bargain_price` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '砍后商品价格',
  `reduce_price` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '减少价格',
  `num` int(10) NOT NULL DEFAULT 0 COMMENT '购买数量',
  `payment_type` tinyint(1) NOT NULL DEFAULT 0 COMMENT '支付方式：1.在线支付 2.货到付款 3.余额支付',
  `pay_time` int(11) NOT NULL DEFAULT 0 COMMENT '支付时间',
  `shipping_type` tinyint(1) NOT NULL DEFAULT 1 COMMENT '订单配送方式【1物流配送 2买家自提 3货到付款 4本地配送】',
  `shipping_money` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '运费',
  `total_pay_price` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '实际支付总费用(含运费）',
  `remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '用户订单备注',
  `status` tinyint(1) NOT NULL DEFAULT 1 COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(11) NOT NULL DEFAULT 0,
  `updated_at` int(11) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_bargain_active_id`(`bargain_active_id`) USING BTREE,
  INDEX `idx_mid_uid`(`mall_id`, `user_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '砍价订单表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for qimall_addons_bargain_user_order
-- ----------------------------
DROP TABLE IF EXISTS `qimall_addons_bargain_user_order`;
CREATE TABLE `qimall_addons_bargain_user_order`  (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  `mall_id` int(11) NOT NULL DEFAULT 0,
  `user_id` int(11) NOT NULL DEFAULT 0,
  `bargain_order_id` int(11) NOT NULL DEFAULT 0 COMMENT '砍价订单ID',
  `price` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '砍价的金额',
  `token` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
  `status` tinyint(1) NOT NULL DEFAULT 1 COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(11) NOT NULL DEFAULT 0,
  `updated_at` int(11) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_bargain_order_id`(`bargain_order_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '用户参与砍价所砍的金额记录表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- 插入定时任务表
-- ----------------------------
INSERT INTO `qimall_crontab_task`(`name`, `command`, `type`, `rule`, `is_warning`, `status`, `created_at`, `updated_at`) VALUES 
('砍价订单自动取消', 'bargain-order/auto-close', 2, '0 */2 * * * *', 0, 1, 1641952763, 1641968929),
('自动结束过期砍价活动', 'bargain-order/auto-finish-active', 2, '0 31 0 * * *', 0, 1, 1641952825, 1641968938);


-- ----------------------------
-- 链接分类
-- ----------------------------
INSERT INTO `qimall_link_category` (`name`, `title`, `pid`, `is_list`, `remark`, `status`, `created_at`, `updated_at`) VALUES
('bargain_active', '砍价活动', 19, 1, NULL, 1, 1641457908, 1641457908),
('bargain_cate', '砍价分类', 19, 1, NULL, 1, 1641457941, 1641457941);

-- ----------------------------
-- 装修组件
-- ----------------------------
INSERT INTO `qimall_diy_components` (`code`, `title`, `group`, `icon`, `count`, `is_top`, `permission`, `sort`, `source`, `status`, `created_at`, `updated_at`) VALUES
('bargain-goods', '砍价', 'marketing', '', 999, 0, '{\"is_drag\":\"true\",\"is_up\":\"true\",\"id_down\":\"true\",\"is_copy\":\"true\"}', 999, 'Bargain', 1, 1634538238, 1634538238);

