ALTER TABLE `shop`
ADD COLUMN `belong_type` tinyint NOT NULL DEFAULT 0 COMMENT '归属类型（0-借还柜 1-固资通）'
AFTER `corpid`;

ALTER TABLE `return_approval`
ADD COLUMN `apply_userid` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '申请人企业UserID'
AFTER `corpid`;

ALTER TABLE `return_approval`
ADD COLUMN `audit_userid` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '审批人企业UserID'
AFTER `corpid`;

ALTER TABLE `shop` 
ADD COLUMN `mode` TINYINT NOT NULL DEFAULT 0 COMMENT '运行模式（0-支付模式 1-审批模式 2-借还模式 3-会员模式 4-耗材模式）' 
AFTER `belong_type`;

ALTER TABLE `shop` 
ADD COLUMN `balance_enable` TINYINT NOT NULL DEFAULT 1 COMMENT '借呗支付（1-正常使用 0-禁止使用）' 
AFTER `mode`;

ALTER TABLE `shop` 
ADD COLUMN `cover_img` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '封面图URL' 
AFTER `balance_enable`;

ALTER TABLE `return_approval` 
ADD COLUMN `code` varchar(32) DEFAULT NULL COMMENT '审批码' 
AFTER `external_approval_id`;

ALTER TABLE `return_approval` 
ADD COLUMN `code_check` TINYINT NOT NULL DEFAULT 0 COMMENT '审批码校验 0未核销 1已核销' 
AFTER `code`;

ALTER TABLE `return_approval` 
ADD COLUMN `apply_user_name` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '申请人' 
AFTER `apply_userid`;

ALTER TABLE `approval_goods` 
ADD COLUMN `approval_quantity` int DEFAULT NULL COMMENT '审批数量' 
AFTER `apply_quantity`;


CREATE TABLE `approval_goods_cell` (
  `approval_goods_cell_id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `approval_id` bigint NOT NULL COMMENT '审批ID',
  `approval_goods_id` bigint NOT NULL COMMENT '申请领用商品ID',
  `shop_id` bigint NULL COMMENT '商店ID',
  `cabinet_id` bigint NOT NULL COMMENT '柜机ID',
  `cell_id` bigint NOT NULL COMMENT '格口ID',
  `allocate_quantity` int NOT NULL COMMENT '分配数量',
  `shop_name` varchar(100) NULL COMMENT '商店名称',
  `cabinet_name` varchar(100) NULL COMMENT '柜机名称',
  `cell_no` int NULL COMMENT '格口号',
  `creator_id` bigint NULL DEFAULT '0' COMMENT '创建者ID',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updater_id` bigint NULL DEFAULT '0' COMMENT '更新者ID',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '删除标志（0存在 1删除）',
  PRIMARY KEY (`approval_goods_cell_id`),
  UNIQUE KEY `uk_approval_goods_cell` (`approval_goods_id`, `cell_id`),
  KEY `idx_approval_id` (`approval_id`),
  KEY `idx_approval_goods_id` (`approval_goods_id`),
  KEY `idx_shop_id` (`shop_id`),
  KEY `idx_cabinet_id` (`cabinet_id`),
  KEY `idx_cell_id` (`cell_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='申请领用商品格口分配表';