-- ******************************************************************
-- 表 kku_farm_crops 的创建SQL
-- 对应的Model: App\Module\Farm\Models\FarmCrop
-- 警告: 此文件由系统自动生成，禁止修改！
-- ******************************************************************

CREATE TABLE `kku_farm_crops` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `land_id` bigint(20) unsigned NOT NULL COMMENT '土地ID',
  `user_id` bigint(20) NOT NULL COMMENT '用户ID',
  `seed_id` bigint(20) unsigned NOT NULL COMMENT '种子ID',
  `land_level` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '种植时的土地等级，用于产出计算',
  `plant_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '种植时间',
  `growth_stage` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '生长阶段:1种子期,20发芽期,30生长期,35果实期,40成熟期,50枯萎期',
  `stage_start_time` timestamp NULL DEFAULT NULL COMMENT '当前阶段结束时间',
  `stage_end_time` timestamp NULL DEFAULT NULL COMMENT '当前阶段结束时间',
  `disasters` json DEFAULT NULL COMMENT '灾害情况',
  `fertilized` tinyint(1) NOT NULL DEFAULT '0' COMMENT '当前阶段是否已使用化肥',
  `last_disaster_check_time` timestamp NULL DEFAULT NULL COMMENT '上次灾害检查时间',
  `can_disaster` tinyint(1) NOT NULL DEFAULT '1' COMMENT '当前阶段是否可以产生灾害:0否,1是',
  `final_output_item_id` bigint(20) unsigned DEFAULT NULL COMMENT '最终产出果实ID(发芽期确定)',
  `final_output_amount` int(11) DEFAULT NULL COMMENT '最终产出数量（成熟期确定）',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `deleted_at` timestamp NULL DEFAULT NULL COMMENT '删除时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `idx_land_id_deleted_at` (`land_id`,`deleted_at`) USING BTREE,
  KEY `idx_user_id` (`user_id`) USING BTREE,
  KEY `idx_seed_id` (`seed_id`) USING BTREE,
  KEY `idx_growth_stage` (`growth_stage`) USING BTREE,
  KEY `idx_stage_end_time` (`stage_end_time`) USING BTREE,
  KEY `idx_last_disaster_check_time` (`last_disaster_check_time`) USING BTREE,
  KEY `idx_disaster_check` (`can_disaster`,`last_disaster_check_time`) USING BTREE,
  KEY `idx_can_disaster` (`can_disaster`) USING BTREE,
  KEY `idx_final_output_item_id` (`final_output_item_id`) USING BTREE,
  KEY `idx_deleted_at` (`deleted_at`) USING BTREE,
  KEY `idx_land_level` (`land_level`) USING BTREE,
  CONSTRAINT `fk_farm_crops_land_id` FOREIGN KEY (`land_id`) REFERENCES `kku_farm_land_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='作物信息表';
