# 10:47 2021/8/17
ALTER TABLE `categories`
    CHANGE COLUMN `template` `template` VARCHAR(50) NOT NULL DEFAULT '' COMMENT '产品模板' COLLATE 'utf8_general_ci' AFTER `sort`;

# 12:47 2021/8/17
ALTER TABLE `users`
    CHANGE COLUMN `mobile` `mobile` VARCHAR(15) NOT NULL DEFAULT '' COMMENT '手机号' COLLATE 'utf8mb4_unicode_ci' AFTER `id`;

# 18:09 2021/8/17
ALTER TABLE `agents`
	ADD COLUMN `type` TINYINT NOT NULL DEFAULT '0' COMMENT '1、计调版旅行社；2、供应商旅行社；3、组团版旅行社' AFTER `remember_token`;

# 23:25 2021/08/17
ALTER TABLE `agent_products`
    ADD COLUMN `guide_id` INT NOT NULL DEFAULT 0 COMMENT '绑定地接（组团版旅行社才能绑定）' AFTER `category_id`;

ALTER TABLE `agents`
    CHANGE COLUMN `type` `type` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '1、计调版旅行社；2、供应商旅行社；3、组团版旅行社' AFTER `status`;

ALTER TABLE `agent_products`
    ADD COLUMN `verifier` INT NOT NULL DEFAULT '0' COMMENT '核销人员的user_id' AFTER `status`,
    CHANGE COLUMN `product_id` `product_id` INT(11) NOT NULL COMMENT '供应商产品ID，组合产品时为第一个ID' AFTER `agent_id`,
    ADD COLUMN `product_ids` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '供应商产品ID，主要用于组合产品，可能会有多个ID' COLLATE 'utf8_general_ci' AFTER `product_id`;

ALTER TABLE `orders`
    CHANGE COLUMN `product_id` `product_id` INT(11) NOT NULL COMMENT '供应商产品ID，组合产品时为第一个ID' AFTER `agent_product_id`,
    ADD COLUMN `product_ids` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '供应商产品ID，主要用于组合产品，可能会有多个ID' COLLATE 'utf8_general_ci' AFTER `product_id`;

# 9:37 2021/8/18
ALTER TABLE `orders`
    CHANGE COLUMN `paid_at` `paid_at` TIMESTAMP NULL DEFAULT NULL COMMENT '付款时间' AFTER `paid_money`,
    CHANGE COLUMN `status` `status` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '订单状态，-1:已取消；0:待付款；1:已付订金/定金/首付款；2:已付全款；3:已付尾款；4:线下未支付；5:线下已支付；6:退款中；7:已退款；16:已完成；' AFTER `picture`,
    CHANGE COLUMN `pay_type` `pay_type` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '支付方式，0:在线支付，1:线下支付，2:订金支付，3:定金支付，4:首款支付；5:追加/尾款支付；【注：订单生成后不应该再修改此项的值】' AFTER `status`;

# 11:27 2021/8/18
ALTER TABLE `agents`
	ADD COLUMN `rate` FLOAT(10,2) NOT NULL DEFAULT 0 COMMENT '平台分成比率' AFTER `contact_phone`;

ALTER TABLE `suppliers`
	ADD COLUMN `rate` FLOAT(10,2) NOT NULL DEFAULT '0.00' COMMENT '平台分成比率' AFTER `contact_phone`;

ALTER TABLE `guides`
	ADD COLUMN `rate` FLOAT(10,2) NOT NULL DEFAULT '0.00' COMMENT '平台分成比率' AFTER `status`;

# 17:54 2021/8/18
ALTER TABLE `agent_products`
	DROP INDEX `agent_id_product_id`,
	ADD INDEX `agent_id_product_id` (`agent_id`, `product_id`);

# 18:03 2021/8/19
ALTER TABLE `advertisings`
    CHANGE COLUMN `agent_id` `agent_id` INT(10) NOT NULL COMMENT '发布者ID' AFTER `id`,
    ADD INDEX `agent_id` (`agent_id`);

# 0:01 ‎2021/‎08/‎20
ALTER TABLE `orders`
	ADD COLUMN `guide_id` INT NOT NULL DEFAULT '0' COMMENT '地接ID' AFTER `refund_info`,
	ADD INDEX `guide_id` (`guide_id`);

# 14:27 2021/8/20
ALTER TABLE `orders`
	CHANGE COLUMN `status` `status` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '订单状态，-1:已取消；0:待付款；1:已付订金/定金/首付款；2:已付全款；3:已付尾款；4:线下未支付；5:线下已支付；6:退款中；7:已退款；8:拒绝退款；16:已完成；' AFTER `picture`,
	CHANGE COLUMN `refund_info` `refund_info` TEXT NULL DEFAULT NULL COMMENT '退款信息["desc":"退款说明","refund_no":"退款号，用于微信申请退款","pictures":"退款图片凭据","old_status":"申请退款前的订单状态"]' COLLATE 'utf8_general_ci' AFTER `paid_at`;

ALTER TABLE `user_money_logs`
    ADD INDEX `agent_id` (`agent_id`);

CREATE TABLE `agent_product_items` (
    `id` INT(10) NOT NULL AUTO_INCREMENT,
    `agent_product_id` INT(10) NOT NULL,
    `agent_id` INT(10) NOT NULL,
    `supplier_id` INT(10) NOT NULL,
    `product_id` INT(10) NOT NULL,
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `agent_product_id` (`agent_product_id`) USING BTREE,
    INDEX `agent_id` (`agent_id`) USING BTREE,
    INDEX `supplier_id` (`supplier_id`) USING BTREE,
    INDEX `product_id` (`product_id`) USING BTREE
)
COMMENT='代理商产品-组合产品明细'
COLLATE='utf8_general_ci'
ENGINE=InnoDB
;

ALTER TABLE `agent_products`
    ADD COLUMN `stock` INT(10) NOT NULL DEFAULT '0' COMMENT '库存' AFTER `sale`;

# 10:42 ‎2021/‎08/‎21
ALTER TABLE `orders`
    CHANGE COLUMN `order_no` `order_no` CHAR(22) NOT NULL COMMENT '订单号' COLLATE 'utf8_general_ci' AFTER `agent_id`;

ALTER TABLE `orders`
    ADD COLUMN verify_code CHAR(13) NOT NULL DEFAULT '' COMMENT '核销码' AFTER `guide_id`;

# 10:35 ‎2021/‎08/‎22
ALTER TABLE `slides`
	CHANGE COLUMN `url` `picture` VARCHAR(255) NOT NULL COMMENT '轮播图地址' COLLATE 'utf8_general_ci' AFTER `title`,
	ADD COLUMN `type` TINYINT NOT NULL DEFAULT '0' COMMENT '链接类型，0:链接到内部页面；1:链接到webview url' AFTER `sort`,
	ADD COLUMN `url` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '链接地址' AFTER `type`;

# 23:43 ‎2021/‎08/‎22
CREATE TABLE `waterfall_ads` (
	`id` INT(10) NOT NULL AUTO_INCREMENT,
	`agent_id` INT(10) NOT NULL COMMENT '代理商ID',
	`title` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '广告名称' COLLATE 'utf8_general_ci',
	`picture` VARCHAR(255) NOT NULL COMMENT '广告图片' COLLATE 'utf8_general_ci',
	`type` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '链接类型，0:链接到内部页面；1:链接到外部url',
	`url` VARCHAR(50) NOT NULL COMMENT '链接' COLLATE 'utf8_general_ci',
	`status` TINYINT(3) NOT NULL DEFAULT '1' COMMENT '0:未启用，1:启用',
	`sort` SMALLINT(5) NOT NULL DEFAULT '255' COMMENT '排序，越小越靠前',
	`created_at` TIMESTAMP NULL DEFAULT NULL,
	`updated_at` TIMESTAMP NULL DEFAULT NULL,
	PRIMARY KEY (`id`) USING BTREE,
	INDEX `agent_id` (`agent_id`) USING BTREE
)
COMMENT='瀑布流内嵌广告'
COLLATE='utf8_general_ci'
ENGINE=InnoDB;

#################################################################
# 12:39 2021/8/24
ALTER TABLE `notices`
	ADD COLUMN `sort` SMALLINT NOT NULL DEFAULT '255' COMMENT '排序，越小越靠前' AFTER `content`;

ALTER TABLE `users`
    CHANGE COLUMN `verifier` `is_verify` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '是否是核销人员，1:是；0:否' AFTER `status`;

# 15:51 2021/8/24
ALTER TABLE `articles`
	ADD COLUMN `type` TINYINT NOT NULL DEFAULT 0 COMMENT '0:普通列表显示；1:大图显示；' AFTER `content`,
	ADD COLUMN `sort` SMALLINT NOT NULL DEFAULT 255 COMMENT '排序，越小越靠前' AFTER `type`;

# 18:16 2021/8/24
ALTER TABLE `slides`
	COMMENT='广告图、轮播图等';
RENAME TABLE `slides` TO `advertisings`;

# 23:05 ‎2021/‎08/‎24
ALTER TABLE `advertisings`
	CHANGE COLUMN `agent_id` `agent_id` INT(11) NOT NULL COMMENT '发布者ID' AFTER `id`,
	ADD COLUMN `display` TINYINT NOT NULL DEFAULT 0 COMMENT '显示位置，0:轮播图；1:首页横屏广告；2:瀑布流内嵌广告；' AFTER `url`;

# 23:56 ‎2021/‎08/‎24
ALTER TABLE `agent_products`
	ADD INDEX `sale` (`sale`),
	ADD INDEX `category_id` (`category_id`);

# 0:24 ‎2021/‎08/‎25
ALTER TABLE `specials`
	DROP COLUMN `picture_ad`;

# 14:15 2021/8/25
ALTER TABLE `messages`
	DROP COLUMN `is_read`;
