-- ----------------------------
-- 合同支付，新增字段
-- ----------------------------
ALTER TABLE `zh_stage_pay`
ADD COLUMN `start_stage_order`  tinyint(4) NULL COMMENT '第几期开始计量' AFTER `pre_finish`;

-- ----------------------------
-- 权限控制表，新增部分权限
-- ----------------------------
INSERT INTO `calculation`.`zh_permission` (`id`, `name`, `controller`, `action`, `pid`, `icon_class`, `create_time`, `isshow`) VALUES ('60', '上传二维码', 'project', 'uploadQrCode', '38', '', NULL, '1');
INSERT INTO `calculation`.`zh_permission` (`id`, `name`, `controller`, `action`, `pid`, `icon_class`, `create_time`, `isshow`) VALUES ('62', '升级说明', 'version', '', '31', '', NULL, '1');
INSERT INTO `calculation`.`zh_permission` (`id`, `name`, `controller`, `action`, `pid`, `icon_class`, `create_time`, `isshow`) VALUES ('63', '添加版本', 'version', 'add', '62', '', NULL, '1');
INSERT INTO `calculation`.`zh_permission` (`id`, `name`, `controller`, `action`, `pid`, `icon_class`, `create_time`, `isshow`) VALUES ('64', '修改版本', 'version', 'add', '62', '', NULL, '1');
INSERT INTO `calculation`.`zh_permission` (`id`, `name`, `controller`, `action`, `pid`, `icon_class`, `create_time`, `isshow`) VALUES ('65', '删除版本', 'version', 'delete', '62', '', NULL, '1');

UPDATE zh_role_rpt_rel AS role SET role.sid = source.sid
  FROM (
     SELECT s.tid AS tid, s.id AS sid, s.`order` AS sorder
       FROM (SELECT MAX(`order`) As `order`, tid FROM zh_stage GROUP BY tid) AS ls
         LEFT JOIN zh_stage AS s ON s.tid = ls.tid AND ls.`order` = s.`order`
  ) As source
  WHERE role.tid = source.tid And ISNULL(role.sid);
