CREATE TABLE `qimall_addons_higo_goods_setting` (
                                                    `id` int(11) NOT NULL AUTO_INCREMENT,
                                                    `mall_id` int(11) NOT NULL COMMENT '商城ID',
                                                    `goods_id` int(11) NOT NULL DEFAULT '0' COMMENT '商品id',
                                                    `wallet_type` varchar(20) DEFAULT '' COMMENT '钱包类型[hi_bei:嗨贝，hi_value:嗨值]',
                                                    `is_enable` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否开启：0:否，1是',
                                                    `is_percent` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否百分比：0:否(固定金额)，1是',
                                                    `give` decimal(32,20) NOT NULL DEFAULT '0.00000000000000000000' COMMENT '赠送金额',
                                                    `deduct_type` tinyint(1) NOT NULL DEFAULT '0' COMMENT '商品抵扣类型[1:单件抵扣，2:多件抵扣]',
                                                    `deduct_money` decimal(32,20) NOT NULL DEFAULT '0.00000000000000000000' COMMENT '商品抵扣金额',
                                                    `settlement_method` tinyint(1) NOT NULL DEFAULT '1' COMMENT '结算方式[;0:支付完成后;1:订单完成后]',
                                                    `source` varchar(20) NOT NULL DEFAULT '' COMMENT '来源标识; 主商城[Main], 插件对应插件标识',
                                                    `source_id` int(11) unsigned 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_id+goods_id` (`mall_id`,`goods_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='嗨购商品赠送抵扣设置';


CREATE TABLE `qimall_addons_higo_hibei_log` (
                                                `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
                                                `mall_id` int(11) unsigned NOT NULL DEFAULT '0',
                                                `change_type` char(12) NOT NULL DEFAULT '' COMMENT '操作类型：add-增加，sub-减少',
                                                `change_num` decimal(32,10) unsigned NOT NULL DEFAULT '0.0000000000' COMMENT '操作数量',
                                                `desc` varchar(255) NOT NULL DEFAULT '' COMMENT '变动说明',
                                                `from_type` varchar(255) NOT NULL DEFAULT '' COMMENT '来源类型',
                                                `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态，-1：失效，1：正常，2：冻结',
                                                `created_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '添加时间戳',
                                                `updated_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间戳',
                                                `setting` text COMMENT '系统设置',
                                                PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='嗨呗变动记录表';

CREATE TABLE `qimall_addons_higo_mall` (
                                           `id` int(11) NOT NULL AUTO_INCREMENT,
                                           `mall_id` int(11) NOT NULL DEFAULT '0' COMMENT '商城id',
                                           `hi_bei` decimal(23,10) NOT NULL DEFAULT '0.0000000000' COMMENT '已发放嗨呗数量',
                                           `available_hi_bei` decimal(23,10) unsigned NOT NULL DEFAULT '0.0000000000' COMMENT '当前可用嗨呗数量',
                                           `hi_value` decimal(23,10) NOT NULL DEFAULT '0.0000000000' COMMENT '当前发放嗨值数量',
                                           `status` tinyint(1) 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 `idx_mall` (`mall_id`) USING BTREE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='嗨购商城数量表';

CREATE TABLE `qimall_addons_higo_recharge_orders` (
                                                      `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
                                                      `mall_id` int(11) NOT NULL,
                                                      `order_no` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
                                                      `user_id` int(11) NOT NULL,
                                                      `pay_price` decimal(32,20) NOT NULL DEFAULT '0.00000000000000000000' COMMENT '充值金额',
                                                      `hi_bei` decimal(32,20) NOT NULL DEFAULT '0.00000000000000000000' COMMENT '嗨贝数额',
                                                      `pay_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '支付方式 1.线上支付',
                                                      `price_setting_method` tinyint(4) NOT NULL DEFAULT '0' COMMENT '充值计算方式 0阶梯，1比例',
                                                      `is_pay` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否支付 0--未支付 1--支付',
                                                      `pay_at` int(11) NOT NULL DEFAULT '0',
                                                      `status` tinyint(4) NOT NULL,
                                                      `created_at` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
                                                      `deleted_at` int(11) NOT NULL DEFAULT '0' COMMENT '删除时间',
                                                      `updated_at` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
                                                      PRIMARY KEY (`id`) USING BTREE,
                                                      KEY `index_user_id` (`user_id`) USING BTREE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='嗨购充值订单表';

CREATE TABLE `qimall_addons_higo_store_goods_mode` (
                                                       `id` int(11) NOT NULL AUTO_INCREMENT,
                                                       `mall_id` int(11) NOT NULL COMMENT '商城ID',
                                                       `source` varchar(30) NOT NULL DEFAULT '' COMMENT '来源，插件名称',
                                                       `source_id` int(11) NOT NULL DEFAULT '0' COMMENT '来源id',
                                                       `goods_id` int(11) NOT NULL DEFAULT '0' COMMENT '商品id',
                                                       `is_enable` 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+goods_id` (`mall_id`,`goods_id`) USING BTREE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='嗨购商家商品参与设置';

CREATE TABLE `qimall_addons_higo_wallet` (
                                             `id` int(11) NOT NULL AUTO_INCREMENT,
                                             `mall_id` int(11) NOT NULL DEFAULT '0' COMMENT '商城id',
                                             `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '会员id',
                                             `hi_bei` decimal(32,10) NOT NULL DEFAULT '0.0000000000' COMMENT '当前嗨呗数量',
                                             `hi_value` decimal(32,10) NOT NULL DEFAULT '0.0000000000' COMMENT '当前嗨值数量',
                                             `status` tinyint(1) 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 `idx_uid` (`mall_id`,`user_id`) USING BTREE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='嗨购钱包表';

CREATE TABLE `qimall_addons_higo_wallet_frozen_log` (
                                                        `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
                                                        `mall_id` int(11) unsigned NOT NULL DEFAULT '0',
                                                        `user_id` int(11) unsigned NOT NULL DEFAULT '0',
                                                        `wallet_type` varchar(20) NOT NULL DEFAULT '' COMMENT '类型[hi_bei:嗨呗，hi_value:嗨值]',
                                                        `change_type` char(12) NOT NULL DEFAULT '' COMMENT '操作类型：add-增加，sub-减少',
                                                        `change_num` decimal(32,10) unsigned NOT NULL DEFAULT '0.0000000000' COMMENT '操作数量',
                                                        `after_num` decimal(32,10) NOT NULL DEFAULT '0.0000000000' COMMENT '变动后数量',
                                                        `desc` varchar(255) NOT NULL DEFAULT '' COMMENT '变动说明',
                                                        `source_table` varchar(255) NOT NULL DEFAULT '' COMMENT '来源表',
                                                        `source_table_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '操作来源业务id',
                                                        `from_type` varchar(255) NOT NULL DEFAULT '' COMMENT '来源类型',
                                                        `status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '状态：0:未结算，1:已结算，-1:无效',
                                                        `created_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '添加时间戳',
                                                        `updated_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间戳',
                                                        `addon_name` varchar(64) NOT NULL DEFAULT 'HiGo' COMMENT '来源插件名称',
                                                        `is_send` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否发放嗨呗',
                                                        `setting` text COMMENT '相关设置',
                                                        PRIMARY KEY (`id`) USING BTREE,
                                                        KEY `idx_mall_user` (`mall_id`,`user_id`) USING BTREE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='嗨呗/嗨值钱包冻结记录表';


CREATE TABLE `qimall_addons_higo_wallet_log` (
                                                 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
                                                 `mall_id` int(11) unsigned NOT NULL DEFAULT '0',
                                                 `user_id` int(11) unsigned NOT NULL DEFAULT '0',
                                                 `wallet_type` varchar(20) NOT NULL DEFAULT '' COMMENT '类型[hi_bei:嗨呗，hi_value:嗨值]',
                                                 `change_type` char(12) NOT NULL DEFAULT '' COMMENT '操作类型：add-增加，sub-减少',
                                                 `change_num` decimal(32,10) unsigned NOT NULL DEFAULT '0.0000000000' COMMENT '操作数量',
                                                 `after_num` decimal(32,10) NOT NULL DEFAULT '0.0000000000' COMMENT '变动后数量',
                                                 `desc` varchar(255) NOT NULL DEFAULT '' COMMENT '变动说明',
                                                 `source_table` varchar(255) NOT NULL DEFAULT '' COMMENT '来源表',
                                                 `source_table_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '操作来源业务id',
                                                 `from_type` varchar(255) NOT NULL DEFAULT '' COMMENT '来源类型',
                                                 `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态，-1：失效，1：正常，2：冻结',
                                                 `created_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '添加时间戳',
                                                 `updated_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间戳',
                                                 `addon_name` varchar(64) NOT NULL DEFAULT 'HiGo' COMMENT '来源插件名称',
                                                 PRIMARY KEY (`id`) USING BTREE,
                                                 KEY `idx_mall_user` (`mall_id`,`user_id`) USING BTREE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='嗨呗/嗨值钱包记录表';

CREATE TABLE `qimall_addons_higo_withdraw_log` (
                                                   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
                                                   `mall_id` int(11) NOT NULL,
                                                   `user_id` int(11) NOT NULL,
                                                   `order_no` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '提现订单号',
                                                   `num` decimal(32,20) NOT NULL DEFAULT '0.00000000000000000000' COMMENT '提现金额',
                                                   `actual_num` decimal(32,20) NOT NULL DEFAULT '0.00000000000000000000' COMMENT '实际到账金额',
                                                   `poundage_num` decimal(32,20) NOT NULL DEFAULT '0.00000000000000000000' COMMENT '手续费扣除金额',
                                                   `poundage_ratio` float NOT NULL DEFAULT '0' COMMENT '手续费比例',
                                                   `from` tinyint(1) NOT NULL DEFAULT '1' COMMENT '提现来源1用户2商户',
                                                   `type` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '提现方式 auto--自动打款 wechat--微信打款 alipay--支付宝打款 bank--银行转账 balance--打款到余额',
                                                   `extra` longtext COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '额外信息 例如微信账号、支付宝账号等',
                                                   `content` longtext COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '用户额外输入信息',
                                                   `status` int(11) NOT NULL DEFAULT '0' COMMENT '提现状态 0--申请 1--同意 2--已打款 3--驳回  4--失败',
                                                   `transfer` text COLLATE utf8mb4_unicode_ci COMMENT '支付宝打款信息',
                                                   `created_at` int(11) DEFAULT '0' COMMENT '添加时间戳',
                                                   `updated_at` int(11) DEFAULT '0' COMMENT '更新时间戳',
                                                   PRIMARY KEY (`id`) USING BTREE,
                                                   KEY `index_mall_id` (`mall_id`) USING BTREE,
                                                   KEY `index_user_id` (`user_id`) USING BTREE,
                                                   KEY `index_status` (`status`) USING BTREE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='嗨购提现申请记录';

INSERT INTO `qimall_crontab_task` ( `name`, `command`, `type`, `rule`, `is_warning`, `status`, `created_at`, `updated_at`) VALUES ( '嗨购-嗨值销毁', 'hi-go/hi-value-crontab/destroy', '2', '0 */10 * * * *', '0', '1', '1666753337', '1666753337');

INSERT INTO `qimall_crontab_task` ( `name`, `command`, `type`, `rule`, `is_warning`, `status`, `created_at`, `updated_at`) VALUES ( '嗨购-嗨呗空投', 'hi-go/hi-bei-crontab/airdrop', 2, '0 */10 * * * *', 0, 1, 1668756633, 1668756633);

CREATE TABLE `qimall_addons_higo_merchant_reward_log` (
                                                          `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
                                                          `mall_id` int(11) unsigned NOT NULL DEFAULT '0',
                                                          `source_table` varchar(255) NOT NULL DEFAULT '' COMMENT '来源表',
                                                          `source_table_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '操作来源业务id',
                                                          `profit_price` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '商家让利价格',
                                                          `profit` decimal(22,10) unsigned NOT NULL DEFAULT '0.0000000000' COMMENT '商家让利嗨呗数量',
                                                          `destroy` decimal(22,10) unsigned NOT NULL DEFAULT '0.0000000000' COMMENT '销毁嗨呗数量',
                                                          `platform_account_uid` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '平台指定会员ID',
                                                          `platform_account_reward` decimal(22,10) unsigned NOT NULL DEFAULT '0.0000000000' COMMENT '平台指定会员嗨呗数量',
                                                          `remaining_rewards` decimal(22,10) unsigned NOT NULL DEFAULT '0.0000000000' COMMENT '剩余模式嗨呗数量',
                                                          `handle_status` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '记录状态：0-等待处理，1-已处理',
                                                          `mch_name` varchar(128) NOT NULL DEFAULT '' COMMENT '商家名称',
                                                          `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态，-1：失效，1：正常，2：冻结',
                                                          `created_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '添加时间戳',
                                                          `updated_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间戳',
                                                          `user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
                                                          `mode_status` tinyint(3) NOT NULL DEFAULT '0' COMMENT '是否分佣：0-否，1-冻结，2-完成',
                                                          `consumer_hi_value` decimal(22,10) NOT NULL DEFAULT '0.0000000000' COMMENT '消费者奖励嗨值基数',
                                                          `merchant_hi_value` decimal(22,10) NOT NULL DEFAULT '0.0000000000' COMMENT '商家奖励嗨值基数',
                                                          PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='打赏记录表';


ALTER TABLE `qimall_addons_higo_wallet`
ADD COLUMN `freeze_hi_value`  decimal(22,10) NOT NULL DEFAULT 0 COMMENT '冻结嗨值' AFTER `updated_at`,
ADD COLUMN `freeze_hi_bei`  decimal(22,10) NOT NULL DEFAULT 0 COMMENT '冻结嗨呗' AFTER `freeze_hi_value`;


ALTER TABLE `qimall_addons_higo_wallet_frozen_log` COMMENT='嗨呗/嗨值钱包等待处理记录表';


CREATE TABLE `qimall_addons_higo_wallet_freeze_log` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `mall_id` int(11) unsigned NOT NULL DEFAULT '0',
  `user_id` int(11) unsigned NOT NULL DEFAULT '0',
  `wallet_type` varchar(20) NOT NULL DEFAULT '' COMMENT '类型[hi_bei:嗨呗，hi_value:嗨值]',
  `change_type` char(12) NOT NULL DEFAULT '' COMMENT '操作类型：add-增加，sub-减少',
  `change_num` decimal(32,10) unsigned NOT NULL DEFAULT '0.0000000000' COMMENT '操作数量',
  `after_num` decimal(32,10) NOT NULL DEFAULT '0.0000000000' COMMENT '变动后数量',
  `desc` varchar(255) NOT NULL DEFAULT '' COMMENT '变动说明',
  `source_table` varchar(255) NOT NULL DEFAULT '' COMMENT '来源表',
  `source_table_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '操作来源业务id',
  `from_type` varchar(255) NOT NULL DEFAULT '' COMMENT '来源类型',
  `status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '状态：0:未结算，1:已结算，-1:无效',
  `created_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '添加时间戳',
  `updated_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间戳',
  `addon_name` varchar(64) NOT NULL DEFAULT 'HiGo' COMMENT '来源插件名称',
  `is_send` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否发放嗨呗',
  `setting` text COMMENT '相关设置',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_mall_user` (`mall_id`,`user_id`) USING BTREE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='嗨呗/嗨值钱包冻结记录表，对应wallet表中freeze字段';

INSERT INTO `qimall_crontab_task` ( `name`, `command`, `type`, `rule`, `is_warning`, `status`, `created_at`, `updated_at`) VALUES ( '检测会员上笔订单，超出时间，冻结账户嗨值', 'hi-go/repurchase-crontab/index', '2', '0 0 */2 * * *', '0', '1', '1666753337', '1668657630');

ALTER TABLE `qimall_addons_higo_hibei_log`
ADD INDEX `idx_from_type` (`from_type`) USING BTREE ;


ALTER TABLE `qimall_addons_higo_merchant_reward_log`
ADD COLUMN `send_profit`  decimal(22,10) NOT NULL DEFAULT 0 COMMENT '已发放的嗨呗奖励' AFTER `merchant_hi_value`;
