create.sql 5.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. -- 创建商店分类表
  2. CREATE TABLE IF NOT EXISTS `kku_shop_categories` (
  3. `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '分类ID,主键',
  4. `name` varchar(50) NOT NULL COMMENT '分类名称',
  5. `code` varchar(50) NOT NULL COMMENT '分类编码(唯一)',
  6. `icon` varchar(255) DEFAULT NULL COMMENT '分类图标',
  7. `sort_order` int(11) NOT NULL DEFAULT '0' COMMENT '排序权重',
  8. `parent_id` int(10) unsigned DEFAULT NULL COMMENT '父分类ID(可为空,用于实现分类层级)',
  9. `is_active` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否激活(0:否, 1:是)',
  10. `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  11. `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间',
  12. PRIMARY KEY (`id`),
  13. UNIQUE KEY `shop_categories_code_unique` (`code`),
  14. KEY `shop_categories_parent_id_index` (`parent_id`)
  15. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商店分类表';
  16. -- 创建商店商品表
  17. CREATE TABLE IF NOT EXISTS `kku_shop_items` (
  18. `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '商品ID,主键',
  19. `name` varchar(100) NOT NULL COMMENT '商品名称',
  20. `description` text COMMENT '商品描述',
  21. `category_id` int(10) unsigned NOT NULL COMMENT '分类ID,外键关联kku_shop_categories表',
  22. `item_id` int(10) unsigned NOT NULL COMMENT '关联的物品ID,外键关联kku_item_items表',
  23. `item_quantity` int(11) NOT NULL DEFAULT '1' COMMENT '物品数量',
  24. `price` int(11) NOT NULL COMMENT '价格',
  25. `currency_id` int(10) unsigned NOT NULL COMMENT '货币类型ID',
  26. `max_buy` int(11) NOT NULL DEFAULT '0' COMMENT '最大购买数量(0表示无限制)',
  27. `is_active` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否激活(0:否, 1:是)',
  28. `sort_order` int(11) NOT NULL DEFAULT '0' COMMENT '排序权重',
  29. `image` varchar(255) DEFAULT NULL COMMENT '商品图片',
  30. `start_time` timestamp NULL DEFAULT NULL COMMENT '上架时间',
  31. `end_time` timestamp NULL DEFAULT NULL COMMENT '下架时间',
  32. `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  33. `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间',
  34. PRIMARY KEY (`id`),
  35. KEY `shop_items_category_id_index` (`category_id`),
  36. KEY `shop_items_item_id_index` (`item_id`),
  37. KEY `shop_items_currency_id_index` (`currency_id`),
  38. KEY `shop_items_is_active_index` (`is_active`),
  39. KEY `shop_items_sort_order_index` (`sort_order`)
  40. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商店商品表';
  41. -- 创建商店购买记录表
  42. CREATE TABLE IF NOT EXISTS `kku_shop_purchase_logs` (
  43. `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '记录ID,主键',
  44. `user_id` int(10) unsigned NOT NULL COMMENT '用户ID',
  45. `shop_item_id` int(10) unsigned NOT NULL COMMENT '商品ID,外键关联kku_shop_items表',
  46. `item_id` int(10) unsigned NOT NULL COMMENT '物品ID,外键关联kku_item_items表',
  47. `quantity` int(11) NOT NULL COMMENT '购买数量',
  48. `price` int(11) NOT NULL COMMENT '单价',
  49. `total_price` int(11) NOT NULL COMMENT '总价',
  50. `currency_id` int(10) unsigned NOT NULL COMMENT '货币类型ID',
  51. `purchase_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '购买时间',
  52. `ip_address` varchar(45) DEFAULT NULL COMMENT '购买IP地址',
  53. `device_info` varchar(255) DEFAULT NULL COMMENT '设备信息',
  54. `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  55. `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间',
  56. PRIMARY KEY (`id`),
  57. KEY `shop_purchase_logs_user_id_index` (`user_id`),
  58. KEY `shop_purchase_logs_shop_item_id_index` (`shop_item_id`),
  59. KEY `shop_purchase_logs_item_id_index` (`item_id`),
  60. KEY `shop_purchase_logs_purchase_time_index` (`purchase_time`)
  61. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商店购买记录表';
  62. -- 创建商店促销活动表
  63. CREATE TABLE IF NOT EXISTS `kku_shop_promotions` (
  64. `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '促销ID,主键',
  65. `name` varchar(100) NOT NULL COMMENT '促销名称',
  66. `description` text COMMENT '促销描述',
  67. `banner` varchar(255) DEFAULT NULL COMMENT '促销横幅图片',
  68. `discount_type` tinyint(4) NOT NULL DEFAULT '1' COMMENT '折扣类型(1:固定折扣, 2:百分比折扣)',
  69. `discount_value` int(11) NOT NULL COMMENT '折扣值(固定折扣为具体金额,百分比折扣为1-100的整数)',
  70. `is_active` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否激活(0:否, 1:是)',
  71. `sort_order` int(11) NOT NULL DEFAULT '0' COMMENT '排序权重',
  72. `start_time` timestamp NULL DEFAULT NULL COMMENT '开始时间',
  73. `end_time` timestamp NULL DEFAULT NULL COMMENT '结束时间',
  74. `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  75. `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间',
  76. PRIMARY KEY (`id`),
  77. KEY `shop_promotions_is_active_index` (`is_active`),
  78. KEY `shop_promotions_sort_order_index` (`sort_order`),
  79. KEY `shop_promotions_start_time_index` (`start_time`),
  80. KEY `shop_promotions_end_time_index` (`end_time`)
  81. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商店促销活动表';
  82. -- 创建商店促销商品关联表
  83. CREATE TABLE IF NOT EXISTS `kku_shop_promotion_items` (
  84. `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '关联ID,主键',
  85. `promotion_id` int(10) unsigned NOT NULL COMMENT '促销ID,外键关联kku_shop_promotions表',
  86. `shop_item_id` int(10) unsigned NOT NULL COMMENT '商品ID,外键关联kku_shop_items表',
  87. `custom_discount_value` int(11) DEFAULT NULL COMMENT '自定义折扣值(可为空,优先于促销活动的折扣值)',
  88. `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  89. `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间',
  90. PRIMARY KEY (`id`),
  91. UNIQUE KEY `shop_promotion_items_promotion_id_shop_item_id_unique` (`promotion_id`,`shop_item_id`),
  92. KEY `shop_promotion_items_promotion_id_index` (`promotion_id`),
  93. KEY `shop_promotion_items_shop_item_id_index` (`shop_item_id`)
  94. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商店促销商品关联表';