ALTER TABLE `zh_tender`
ADD COLUMN `has_rela`  tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否有关联台账' AFTER `had_map`;

CREATE TABLE `zh_stage_rela` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
  `tid` int(11) unsigned NOT NULL COMMENT '标段id',
  `sid` int(11) unsigned NOT NULL COMMENT '期id',
  `sorder` tinyint(4) unsigned NOT NULL COMMENT '期序号',
  `rela_tid` int(11) unsigned NOT NULL COMMENT '关联标段id',
  `rela_tname` varchar(255) CHARACTER SET utf8 NOT NULL COMMENT '关联标段-名称',
  `rela_sid` int(11) unsigned NOT NULL COMMENT '关联期id',
  `rela_sorder` tinyint(4) unsigned NOT NULL COMMENT '关联期序号',
  `add_time` datetime NOT NULL COMMENT '添加时间',
  `update_time` datetime NOT NULL COMMENT '更新时间',
  `total_price` decimal(28,6) DEFAULT NULL,
  `cache_tp` text CHARACTER SET utf8 COMMENT '缓存金额(当前标段单价计算)',
  `cache_org_tp` text CHARACTER SET utf8 COMMENT '缓存金额(原关联标段单价计算)',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='计量期-关联台账（含缓存数据）';

CREATE TABLE `zh_stage_rela_bills` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `tid` int(11) unsigned NOT NULL COMMENT '标段id',
  `sid` int(11) unsigned NOT NULL COMMENT '期id',
  `sorder` tinyint(4) unsigned NOT NULL COMMENT '期序号',
  `rela_tid` int(11) unsigned NOT NULL COMMENT '关联标段id',
  `rela_sid` int(11) unsigned NOT NULL COMMENT '关联期id',
  `rela_sorder` tinyint(4) unsigned NOT NULL COMMENT '关联期序号',
  `lid` varchar(36) CHARACTER SET ascii NOT NULL COMMENT '台账id',
  `contract_qty` decimal(24,8) DEFAULT NULL COMMENT '合同计量-数量',
  `contract_tp` decimal(24,8) DEFAULT NULL COMMENT '合同计量-金额',
  `contract_expr` varchar(255) CHARACTER SET utf8 DEFAULT NULL COMMENT '合同计量-公式',
  `qc_qty` decimal(24,8) DEFAULT NULL COMMENT '数量变更-数量',
  `qc_tp` decimal(24,8) DEFAULT NULL COMMENT '数量变更-金额',
  `postil` varchar(1000) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '本期批注',
  `unit_price` decimal(24,8) DEFAULT NULL COMMENT '单价',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=81 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE `zh_stage_rela_pos` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `tid` int(11) unsigned NOT NULL COMMENT '标段id',
  `sid` int(11) unsigned NOT NULL COMMENT '期id',
  `sorder` tinyint(4) unsigned NOT NULL COMMENT '期序号',
  `rela_tid` int(11) unsigned NOT NULL COMMENT '关联标段id',
  `rela_sid` int(11) unsigned NOT NULL COMMENT '关联期id',
  `rela_sorder` tinyint(4) unsigned NOT NULL COMMENT '关联期序号',
  `lid` varchar(36) CHARACTER SET ascii NOT NULL COMMENT '台账id',
  `pid` varchar(36) CHARACTER SET ascii NOT NULL COMMENT '计量单元id',
  `contract_qty` decimal(24,8) DEFAULT NULL COMMENT '合同计量-数量',
  `contract_expr` varchar(255) CHARACTER SET utf8 DEFAULT NULL COMMENT '合同计量-公式',
  `qc_qty` decimal(24,8) DEFAULT NULL COMMENT '数量变更-数量',
  `postil` varchar(1000) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '本期批注',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=81 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE `zh_stage_rela_bills_final` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `tid` int(11) unsigned NOT NULL COMMENT '标段id',
  `sid` int(11) unsigned NOT NULL COMMENT '期id',
  `sorder` tinyint(4) unsigned NOT NULL COMMENT '期序号',
  `rela_tid` int(11) unsigned NOT NULL COMMENT '关联标段id',
  `rela_sid` int(11) unsigned NOT NULL COMMENT '关联期id',
  `rela_sorder` tinyint(4) unsigned NOT NULL COMMENT '关联期序号',
  `lid` varchar(36) CHARACTER SET ascii NOT NULL COMMENT '台账id',
  `contract_qty` decimal(24,8) DEFAULT NULL COMMENT '合同计量-数量',
  `contract_tp` decimal(24,8) DEFAULT NULL COMMENT '合同计量-金额',
  `qc_qty` decimal(24,8) DEFAULT NULL COMMENT '数量变更-数量',
  `qc_tp` decimal(24,8) DEFAULT NULL COMMENT '数量变更-金额',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=81 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE `zh_stage_rela_pos_final` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `tid` int(11) unsigned NOT NULL COMMENT '标段id',
  `sid` int(11) unsigned NOT NULL COMMENT '期id',
  `sorder` tinyint(4) unsigned NOT NULL COMMENT '期序号',
  `rela_tid` int(11) unsigned NOT NULL COMMENT '关联标段id',
  `rela_sid` int(11) unsigned NOT NULL COMMENT '关联期id',
  `rela_sorder` tinyint(4) unsigned NOT NULL COMMENT '关联期序号',
  `lid` varchar(36) CHARACTER SET ascii NOT NULL COMMENT '台账id',
  `pid` varchar(36) CHARACTER SET ascii NOT NULL COMMENT '计量单元id',
  `contract_qty` decimal(24,8) DEFAULT NULL COMMENT '合同计量-数量',
  `qc_qty` decimal(24,8) DEFAULT NULL COMMENT '数量变更-数量',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=81 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

ALTER TABLE `zh_rpt_archive`
CHANGE COLUMN `content` `content` JSON NULL DEFAULT NULL ;