-- 合伙股东收益体系 V2 -- 表前缀以站点 database.prefix 为准(本仓库 .env 为 hla_) -- 手工执行:将 __PREFIX__ 替换为实际前缀后导入 -- 1. 分销商扩展字段 SET @dbname = DATABASE(); SET @prefix = ( SELECT TABLE_PREFIX FROM information_schema.TABLES WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME LIKE '%shopro_commission_agent' ORDER BY CASE WHEN TABLE_NAME LIKE 'hla_%' THEN 0 ELSE 1 END LIMIT 1 ); -- 直接按常见前缀改;执行脚本时请替换 __PREFIX__ ALTER TABLE `__PREFIX__shopro_commission_agent` ADD COLUMN `is_venue` tinyint(1) NOT NULL DEFAULT 0 COMMENT '酒道馆' AFTER `level`, ADD COLUMN `is_county` tinyint(1) NOT NULL DEFAULT 0 COMMENT '区县代理' AFTER `is_venue`, ADD COLUMN `county_code` varchar(20) NOT NULL DEFAULT '' COMMENT '区县编码' AFTER `is_county`, ADD COLUMN `direct_order_seq` int(11) NOT NULL DEFAULT 0 COMMENT '直推合格单累计(推三返一)' AFTER `county_code`, ADD COLUMN `madow` decimal(20,8) NOT NULL DEFAULT 0.00000000 COMMENT '马豆' AFTER `direct_order_seq`, ADD COLUMN `voucher_total` decimal(12,2) NOT NULL DEFAULT 0.00 COMMENT '兑换券总额' AFTER `madow`, ADD COLUMN `voucher_released` decimal(12,2) NOT NULL DEFAULT 0.00 COMMENT '兑换券已释放' AFTER `voucher_total`, ADD COLUMN `voucher_used` decimal(12,2) NOT NULL DEFAULT 0.00 COMMENT '兑换券已使用' AFTER `voucher_released`, ADD COLUMN `last_self_order_time` bigint(16) DEFAULT NULL COMMENT '本人最近合格订单时间' AFTER `voucher_used`, ADD KEY `idx_venue` (`is_venue`), ADD KEY `idx_county` (`is_county`), ADD KEY `idx_last_self_order` (`last_self_order_time`); -- 2. 收益流水 CREATE TABLE IF NOT EXISTS `__PREFIX__shopro_partner_reward` ( `id` int(11) NOT NULL AUTO_INCREMENT, `order_id` int(11) NOT NULL DEFAULT 0, `buyer_id` int(11) NOT NULL DEFAULT 0, `user_id` int(11) NOT NULL COMMENT '受益人', `role` varchar(20) NOT NULL DEFAULT '' COMMENT 'taster/maker/venue/county/system', `reward_type` varchar(32) NOT NULL, `amount` decimal(12,2) NOT NULL DEFAULT 0.00, `madow` decimal(20,8) NOT NULL DEFAULT 0.00000000, `base_amount` decimal(12,2) NOT NULL DEFAULT 0.00, `rate` decimal(16,10) NOT NULL DEFAULT 0.0000000000, `ext` text, `settle_date` date DEFAULT NULL, `status` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0待入账 1已入账 -1取消 -2退回', `createtime` bigint(16) DEFAULT NULL, `updatetime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `uk_order_user_type` (`order_id`,`user_id`,`reward_type`), UNIQUE KEY `uk_daily_user_type` (`settle_date`,`user_id`,`reward_type`), KEY `idx_user` (`user_id`,`reward_type`,`status`), KEY `idx_order` (`order_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='合伙股东收益'; -- 3. 兑换券释放计划 CREATE TABLE IF NOT EXISTS `__PREFIX__shopro_partner_voucher_plan` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `order_id` int(11) NOT NULL, `total_amount` decimal(12,2) NOT NULL, `daily_amount` decimal(12,2) NOT NULL, `released_amount` decimal(12,2) NOT NULL DEFAULT 0.00, `released_days` int(11) NOT NULL DEFAULT 0, `total_days` int(11) NOT NULL DEFAULT 365, `start_date` date NOT NULL, `status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '1释放中 2完成 0关闭', `createtime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `uk_order` (`order_id`), KEY `idx_user_status` (`user_id`,`status`,`start_date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='兑换券释放计划'; -- 4. 汇率快照 CREATE TABLE IF NOT EXISTS `__PREFIX__shopro_partner_rate_log` ( `id` int(11) NOT NULL AUTO_INCREMENT, `settle_date` date NOT NULL, `order_count_n` int(11) NOT NULL DEFAULT 0 COMMENT '历史合格单累计N', `rate` decimal(16,10) NOT NULL DEFAULT 0.0000000000, `gmv` decimal(14,2) NOT NULL DEFAULT 0.00, `madow_pool` decimal(20,8) NOT NULL DEFAULT 0.00000000, `share_user_count` int(11) NOT NULL DEFAULT 0, `venue_pool` decimal(12,2) NOT NULL DEFAULT 0.00, `county_pool` decimal(12,2) NOT NULL DEFAULT 0.00, `createtime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `uk_date` (`settle_date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='马豆汇率日志'; -- 5. 日结对账 CREATE TABLE IF NOT EXISTS `__PREFIX__shopro_partner_daily_report` ( `id` int(11) NOT NULL AUTO_INCREMENT, `settle_date` date NOT NULL, `order_count` int(11) NOT NULL DEFAULT 0, `order_count_n` int(11) NOT NULL DEFAULT 0, `gmv` decimal(14,2) NOT NULL DEFAULT 0.00, `rate` decimal(16,10) NOT NULL DEFAULT 0.0000000000, `madow_pool` decimal(20,8) NOT NULL DEFAULT 0.00000000, `share_user_count` int(11) NOT NULL DEFAULT 0, `venue_pool` decimal(12,2) NOT NULL DEFAULT 0.00, `venue_user_count` int(11) NOT NULL DEFAULT 0, `county_pool` decimal(12,2) NOT NULL DEFAULT 0.00, `county_user_count` int(11) NOT NULL DEFAULT 0, `voucher_release_total` decimal(12,2) NOT NULL DEFAULT 0.00, `status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '1成功 0失败 2重跑中', `error_msg` varchar(500) NOT NULL DEFAULT '', `createtime` bigint(16) DEFAULT NULL, `updatetime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `uk_date` (`settle_date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='合伙股东日结对账'; -- 6. 配置(挂在 shop.commission 下,sheep_config('shop.commission.partner_mode') 可读) INSERT IGNORE INTO `__PREFIX__shopro_config` (`code`, `parent_code`, `name`, `description`, `type`, `value`, `store_range`, `rule`, `weigh`) VALUES ('shop.commission.partner_mode', 'shop.commission', '关闭旧百分比分佣', '1=跳过三级百分比', 'boolean', '1', NULL, NULL, 80), ('shop.commission.partner_enable', 'shop.commission', '启用合伙股东结算', '1=新单记即时奖', 'boolean', '1', NULL, NULL, 81), ('shop.commission.partner_count_type', 'shop.commission', '合格订单口径', 'order=订单头 item=商品件数', 'string', 'order', NULL, NULL, 82), ('shop.commission.partner_active_days', 'shop.commission', '领取窗口天数', NULL, 'int', '30', NULL, NULL, 83), ('shop.commission.partner_chain_max_depth', 'shop.commission', '关系链最大深度', NULL, 'int', '50', NULL, NULL, 84), ('shop.commission.partner_push3_amounts', 'shop.commission', '推三返一循环金额', NULL, 'array', '[398,400,600]', NULL, NULL, 85), ('shop.commission.partner_madow_mode', 'shop.commission', '马豆发放模式', 'madow=马豆 cash=现金', 'string', 'madow', NULL, NULL, 86), ('shop.commission.partner_madow_base_rate', 'shop.commission', '马豆基础汇率', NULL, 'string', '0.00000075', NULL, NULL, 87), ('shop.commission.partner_madow_step_orders', 'shop.commission', '马豆步进订单数', NULL, 'int', '1', NULL, NULL, 88), ('shop.commission.partner_voucher_times', 'shop.commission', '兑换券倍数', NULL, 'float', '1.5', NULL, NULL, 89), ('shop.commission.partner_voucher_days', 'shop.commission', '兑换券释放天数', NULL, 'int', '365', NULL, NULL, 90), ('shop.commission.partner_maker_bonus', 'shop.commission', '创客级差基数', NULL, 'array', '{\"2\":20,\"3\":40,\"4\":60,\"5\":80,\"6\":100,\"7\":120}', NULL, NULL, 91), ('shop.commission.partner_maker_peer_rate', 'shop.commission', '创客平级比例', NULL, 'float', '0.10', NULL, NULL, 92), ('shop.commission.partner_maker_overtaken_rate', 'shop.commission', '创客被超越比例', NULL, 'float', '0.05', NULL, NULL, 93), ('shop.commission.partner_team_total', 'shop.commission', '团队拆分总额', NULL, 'float', '100', NULL, NULL, 94), ('shop.commission.partner_venue_split', 'shop.commission', '酒道馆拆分份额', NULL, 'float', '50', NULL, NULL, 95), ('shop.commission.partner_county_full', 'shop.commission', '无馆区县全额', NULL, 'float', '100', NULL, NULL, 96), ('shop.commission.partner_venue_share_per_order', 'shop.commission', '酒道馆每单奖池', NULL, 'float', '100', NULL, NULL, 97), ('shop.commission.partner_county_share_per_order', 'shop.commission', '区县每单奖池', NULL, 'float', '50', NULL, NULL, 98), ('shop.commission.partner_venue_peer_rate', 'shop.commission', '酒道馆平级比例', NULL, 'float', '0.10', NULL, NULL, 99), ('shop.commission.partner_county_peer_rate', 'shop.commission', '区县平级比例', NULL, 'float', '0.10', NULL, NULL, 100); -- 7. 初始化 7 条等级(已存在则忽略) INSERT IGNORE INTO `__PREFIX__shopro_commission_level` (`level`, `name`, `image`, `commission_rules`, `upgrade_type`, `upgrade_rules`) VALUES (1, '品酒师', '', '{\"commission_1\":0,\"commission_2\":0,\"commission_3\":0}', 0, '{}'), (2, '创客V1', '', '{\"commission_1\":0,\"commission_2\":0,\"commission_3\":0}', 0, '{}'), (3, '创客V2', '', '{\"commission_1\":0,\"commission_2\":0,\"commission_3\":0}', 0, '{}'), (4, '创客V3', '', '{\"commission_1\":0,\"commission_2\":0,\"commission_3\":0}', 0, '{}'), (5, '创客V4', '', '{\"commission_1\":0,\"commission_2\":0,\"commission_3\":0}', 0, '{}'), (6, '创客V5', '', '{\"commission_1\":0,\"commission_2\":0,\"commission_3\":0}', 0, '{}'), (7, '创客V6', '', '{\"commission_1\":0,\"commission_2\":0,\"commission_3\":0}', 0, '{}');