CREATE TABLE `qimall_addons_smart_form_components` (
  `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `code` varchar(30) NOT NULL DEFAULT '' COMMENT '标识',
  `title` varchar(50) NOT NULL DEFAULT '' COMMENT '标题',
  `group` varchar(30) NOT NULL DEFAULT '' COMMENT '组件分组',
  `icon` varchar(300) NOT NULL DEFAULT '' COMMENT '图标',
  `permission` varchar(255) NOT NULL DEFAULT '' COMMENT '组件操作参数',
  `sort` int(10) NOT NULL DEFAULT '999' COMMENT '排序，越小排越前',
  `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '添加时间',
  `updated_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `group` (`group`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='智能装修组件表';

CREATE TABLE `qimall_addons_smart_form_decoration_form` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `mall_id` int(10) NOT NULL DEFAULT '0' COMMENT '商城id',
  `smart_form_template_id` int(10) NOT NULL DEFAULT '0' COMMENT '智能装修表单id',
  `diy_page_id` int(10) NOT NULL DEFAULT '0' COMMENT '使用页面id',
  `status` tinyint(4) DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1:启用]',
  `created_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '添加时间',
  `updated_at` int(10) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC COMMENT='智能装修-装修表单管理';

CREATE TABLE `qimall_addons_smart_form_template` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `mall_id` int(10) NOT NULL DEFAULT '0' COMMENT '商城id',
  `diy_page_id` int(10) NOT NULL DEFAULT '0' COMMENT '使用页面id',
  `title` varchar(15) CHARACTER SET utf8mb4 NOT NULL DEFAULT '' COMMENT '标题',
  `show_header` tinyint(4) DEFAULT '0' COMMENT '开启头部背景',
  `header` varchar(255) CHARACTER SET utf8mb4 DEFAULT '' COMMENT '头部背景',
  `expire_time` int(10) NOT NULL DEFAULT '-1' COMMENT '过期时间[-1:永久有效]',
  `status` tinyint(4) DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1:启用,2:已过期]',
  `link_status` tinyint(4) DEFAULT '1' COMMENT '开启跳转[0:关闭;1:开启]',
  `jump_type` tinyint(4) DEFAULT '1' COMMENT '跳转类型[0:跳转链接;1:跳转二维码]',
  `jump_link` varchar(255) CHARACTER SET utf8mb4 DEFAULT '' COMMENT '跳转链接',
  `success_link` varchar(255) CHARACTER SET utf8mb4 DEFAULT '' COMMENT '提交成功后跳转链接',
  `created_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '添加时间',
  `updated_at` int(10) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC COMMENT='智能装修表单管理';

CREATE TABLE `qimall_addons_smart_form_template_column` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `smart_form_template_id` int(10) NOT NULL DEFAULT '0' COMMENT '智能装修表单id',
  `smart_form_components_code` varchar(30) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '智能装修组件标识',
  `smart_form_components_id` int(10) NOT NULL DEFAULT '0' COMMENT '智能装修组件id',
  `title` varchar(100) CHARACTER SET utf8mb4 NOT NULL DEFAULT '' COMMENT '标题',
  `tips` varchar(100) CHARACTER SET utf8mb4 NOT NULL DEFAULT '' COMMENT '提示语',
  `placeholder` varchar(100) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '简短提示',
  `required` int(11) NOT NULL DEFAULT '1' COMMENT '是否必填(1:是;2:否)',
  `limit` int(10) NOT NULL DEFAULT '999' COMMENT '限制长度',
  `option` varchar(255) COLLATE utf8mb4_bin NOT NULL COMMENT '选项',
  `show_default` varchar(10) DEFAULT '1' COMMENT '显示默认值[0:不显示;1:显示]',
  `default` varchar(255) NOT NULL COMMENT '默认值',
  `sort` int(10) NOT NULL DEFAULT '999' COMMENT '排序，越小排越前',
  `status` tinyint(4) DEFAULT '1' COMMENT '状态[0:禁用;1:启用,2:已过期]',
  `created_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '添加时间',
  `updated_at` int(10) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `smart_form_template_id` (`smart_form_template_id`) USING BTREE,
  KEY `smart_form_components_id` (`smart_form_components_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC COMMENT='智能装修表单明细字段';

CREATE TABLE `qimall_addons_smart_form_template_user_behavior` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `smart_form_template_id` int(10) NOT NULL DEFAULT '0' COMMENT '智能装修表单管理id',
  `user_id` int(10) NOT NULL DEFAULT '0' COMMENT '用户id',
  `diy_page_id` int(10) NOT NULL DEFAULT '0' COMMENT '使用页面id',
  `behavior_type` tinyint(4) DEFAULT '0' COMMENT '提交类型[0:访问;1:提交]',
  `is_submit` tinyint(4) NOT NULL DEFAULT '0' COMMENT '访问类型是否已提交[0:否;1是]',
  `month_day` varchar(10) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '访问年月日',
  `created_at` int(10) NOT NULL DEFAULT '0',
  `updated_at` int(10) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC COMMENT='用户操作表单行为日志';

CREATE TABLE `qimall_addons_smart_form_template_user_form` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `mall_id` int(10) NOT NULL DEFAULT '0' COMMENT '商城id',
  `smart_form_template_id` int(10) NOT NULL DEFAULT '0' COMMENT '智能装修表单管理id',
  `user_id` int(10) NOT NULL DEFAULT '0' COMMENT '用户id',
  `diy_page_id` int(10) NOT NULL DEFAULT '0' COMMENT '使用页面id',
  `smart_form_template_column_id` text COLLATE utf8mb4_bin NOT NULL COMMENT '使用字段',
  `col_value` text COLLATE utf8mb4_bin NOT NULL COMMENT '字段值',
  `source` tinyint(4) DEFAULT '0' COMMENT '提交类型[0:小程序]',
  `created_at` int(10) NOT NULL DEFAULT '0',
  `updated_at` int(10) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `smart_form_template_id` (`smart_form_template_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC COMMENT='用户填写智能表单';


CREATE TABLE `qimall_addons_smart_form_template_user_form_info` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `smart_form_template_id` int(10) NOT NULL DEFAULT '0' COMMENT '智能装修表单管理id',
  `smart_form_template_user_form_id` int(10) NOT NULL DEFAULT '0' COMMENT '用户填写智能表单id',
  `user_id` int(10) NOT NULL DEFAULT '0' COMMENT '用户id',
  `smart_form_components_id` int(10) NOT NULL DEFAULT '0' COMMENT '智能装修表单明细字段id',
  `smart_form_components_code` varchar(30) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '智能装修组件标识',
  `smart_form_components_title` varchar(100) CHARACTER SET utf8mb4 NOT NULL DEFAULT '' COMMENT '标题',
  `col_value` text COLLATE utf8mb4_bin NOT NULL COMMENT '填写字段值',
  `created_at` int(10) NOT NULL DEFAULT '0',
  `updated_at` int(10) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `smart_form_template_id` (`smart_form_template_id`) USING BTREE,
  KEY `smart_form_template_user_form_id` (`smart_form_template_user_form_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC COMMENT='用户填写智能表单明细字段';

CREATE TABLE `qimall_addons_smart_form_template_statistics` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `smart_form_template_id` int(11) NOT NULL DEFAULT '0' COMMENT '智能装修表单管理id',
  `today_filling_times` int(11) NOT NULL DEFAULT '0' COMMENT '今日填写次数-当天填写次数，包含同一个ID用户填写次数',
  `today_view_times` int(11) NOT NULL DEFAULT '0' COMMENT '今日访问人次-当天访问次数，只访问未填写',
  `today_view_people` int(11) NOT NULL DEFAULT '0' COMMENT '今日填写人数-当天填写人数，一个ID用户统计一次',
  `filling_times` int(11) NOT NULL DEFAULT '0' COMMENT '总填写次数-当天填写次数，包含同一个ID用户填写次数',
  `view_times` int(11) NOT NULL DEFAULT '0' COMMENT '总访问人次-当天访问次数，只访问未填写',
  `view_people` int(11) NOT NULL DEFAULT '0' COMMENT '总填写人数-当天填写人数，一个ID用户统计一次',
  `created_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '添加时间',
  `updated_at` int(10) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC COMMENT='智能装修表单统计信息';


CREATE TABLE `qimall_addons_smart_form_setting` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `mall_id` int(11) NOT NULL COMMENT '商城ID',
  `is_export` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否开启一键导入功能：0:否;1是',
  `agree_on` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否开启协议：0:否;1是',
  `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,
  KEY `mall_id` (`mall_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='自定义表单特殊功能设置';

INSERT INTO `qimall_diy_components` (`code`, `title`, `group`, `icon`, `count`, `is_top`, `permission`, `sort`, `source`, `status`, `created_at`, `updated_at`) VALUES ( 'smart-form', '表单', 'img_text', '', 999, 0, '{\"is_drag\":\"true\",\"is_up\":\"true\",\"id_down\":\"true\",\"is_copy\":\"true\"}', 999, 'SmartForm', 1, 1634538238, 1634538238);
INSERT INTO `qimall_addons_links` ( `addons_name`, `app_id`, `title`, `route`, `icon`, `params`, `status`, `created_at`, `updated_at`) VALUES ('SmartForm', 'backend', '智能表单', '/plugins/SmartForm/SmartForm', '', '[]', 1, 0, 0);
INSERT INTO `qimall_link_category` (`name`, `title`, `pid`, `is_list`, `remark`, `status`, `created_at`, `updated_at`) VALUES ( 'smart_form', '智能表单', 8, 1, '', 1, 1649759024, 1649759024);

INSERT INTO `qimall_addons_smart_form_components` VALUES (31, 'single-link-text', '单行文本', 'input', 'resources/img/smartform/single-link-text.png', '', 999, 1, 0, 0);
INSERT INTO `qimall_addons_smart_form_components` VALUES (32, 'multi-text', '多行文本', 'input', 'resources/img/smartform/multi-text.png', '', 999, 1, 0, 0);
INSERT INTO `qimall_addons_smart_form_components` VALUES (33, 'id-card', '身份证号码', 'input', 'resources/img/smartform/id-card.png', '', 999, 1, 0, 0);
INSERT INTO `qimall_addons_smart_form_components` VALUES (34, 'drow-box', '下拉框', 'select', 'resources/img/smartform/drow-box.png', '', 999, 1, 0, 0);
INSERT INTO `qimall_addons_smart_form_components` VALUES (35, 'checked-tool', '多选框', 'select', 'resources/img/smartform/checked-tool.png', '', 999, 1, 0, 0);
INSERT INTO `qimall_addons_smart_form_components` VALUES (36, 'city-chose', '省市区', 'select', 'resources/img/smartform/city-chose.png', '', 999, 1, 0, 0);
INSERT INTO `qimall_addons_smart_form_components` VALUES (37, 'date-range', '日期范围', 'date', 'resources/img/smartform/date-range.png', '', 999, 1, 0, 0);
INSERT INTO `qimall_addons_smart_form_components` VALUES (38, 'date-tool', '日期', 'date', 'resources/img/smartform/date-tool.png', '', 999, 1, 0, 0);
INSERT INTO `qimall_addons_smart_form_components` VALUES (39, 'radio-tool', '单选框', 'checkbox', 'resources/img/smartform/radio-tool.png', '', 999, 1, 0, 0);
INSERT INTO `qimall_addons_smart_form_components` VALUES (40, 'time-range', '时间范围', 'date', 'resources/img/smartform/time-range.png', '', 999, 1, 0, 0);
INSERT INTO `qimall_addons_smart_form_components` VALUES (41, 'time-tool', '时间', 'time', 'resources/img/smartform/time-tool.png', '', 999, 1, 0, 0);
INSERT INTO `qimall_addons_smart_form_components` VALUES (42, 'upload-photo', '图片', 'upload', 'resources/img/smartform/upload-photo.png', '', 999, 1, 0, 0);

-- 2022-6-21 update
ALTER TABLE `qimall_addons_smart_form_template_column` 
ADD COLUMN `is_export` tinyint(4) NOT NULL DEFAULT 0 COMMENT '';

ALTER TABLE `qimall_addons_smart_form_template_column` 
ADD COLUMN `content_type` tinyint(4) NOT NULL DEFAULT 0 COMMENT '';

UPDATE `qimall_addons_smart_form_components` set `icon` = REPLACE(`icon`,'resources/img/smartform/','/static/addons/smartform/');

ALTER TABLE `qimall_addons_smart_form_template_statistics`
ADD COLUMN `today_filling_people` int(11) NOT NULL DEFAULT '0' COMMENT '今日填写人数-当天填写人数，包含同一个ID用户填写人数';

-- 2022-06-29
ALTER TABLE `qimall_addons_smart_form_template_user_form`
ADD COLUMN `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]';

ALTER TABLE `qimall_addons_smart_form_template_statistics`
ADD COLUMN `filling_people` int(11) NOT NULL DEFAULT '0' COMMENT '总填写人数-当天填写人数，包含同一个ID用户填写人数';


-- 2022-08-10
CREATE TABLE `qimall_addons_smart_form_template_goods` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `mall_id` int(11) NOT NULL COMMENT '商城ID',
  `template_id` int(11) NOT NULL DEFAULT '0' COMMENT '表单ID',
  `goods_id` int(11) NOT NULL DEFAULT '0' COMMENT '商品ID',
  `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,
  KEY `mall_goods` (`mall_id`,`goods_id`) USING BTREE,
  KEY `mall_template` (`mall_id`,`template_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='智能表单关联商品表';

