SUM(case when recharge_time < '2019-08-16 12:03:50' and agent_level=4 and reward_type in (60,760,300,750) then amount * 0.06 else 0 end) techChargeOrder,
SUM(case when recharge_time < '2019-08-16 12:03:50' and agent_level=4 and reward_type in (60,760,300,750) then amount * 0.06 else 0 end) techChargeOrder,
SUM(case when reward_type in (40) then amount else 0 end) opencardBalance,
SUM(case when reward_type in (40) then amount else 0 end) opencardBalance,
SUM(case when reward_type in (50,740) then amount else 0 end) rechargeBalance,
SUM(case when reward_type in (50,740) then amount else 0 end) rechargeBalance,
SUM(case when reward_type in (30,710,720,210) then amount else 0 end) upgradeBalance,
SUM(case when reward_type in (30,710,720,210,80,230 ,780) then amount else 0 end) upgradeBalance,
SUM(case when reward_type in (20,730) then amount else 0 end) upgradeSuperBalance,
SUM(case when reward_type in (20,730) then amount else 0 end) upgradeSuperBalance,
SUM(case when reward_type in (60,760) then amount else 0 end) shareBalance,
SUM(case when reward_type in (60,760) then amount else 0 end) shareBalance,
SUM(case when reward_type in (300,750) then amount else 0 end) zigoushengBalance,
SUM(case when reward_type in (300,750) then amount else 0 end) zigoushengBalance,
...
@@ -802,8 +802,8 @@
...
@@ -802,8 +802,8 @@
COUNT(reward_type IN (50, 740) OR NULL) AS onlinerechargeNum,
COUNT(reward_type IN (50, 740) OR NULL) AS onlinerechargeNum,
SUM(if(reward_type=40, amount, 0)) AS open_card_cash,
SUM(if(reward_type=40, amount, 0)) AS open_card_cash,
COUNT(reward_type=40 OR NULL) AS open_card_num,
COUNT(reward_type=40 OR NULL) AS open_card_num,
SUM(if(reward_type IN (30, 20, 710, 720, 730, 210),amount, 0)) AS upgrade_partner_cash,
SUM(if(reward_type IN (30, 20, 710, 720, 730, 210, 80, 230 ,780),amount, 0)) AS upgrade_partner_cash,
COUNT(reward_type IN (30, 20, 710, 720, 730, 210) OR NULL) AS upgrade_partner_num,
COUNT(reward_type IN (30, 20, 710, 720, 730, 210, 80, 230 ,780) OR NULL) AS upgrade_partner_num,
SUM(if(reward_type IN (50, 30, 20),cash_code, 0)) AS marketPerformance,
SUM(if(reward_type IN (50, 30, 20),cash_code, 0)) AS marketPerformance,
SUM(if(reward_type IN (30, 20),cash_code, 0)) AS upgrade_market_cash,
SUM(if(reward_type IN (30, 20),cash_code, 0)) AS upgrade_market_cash,
SUM(if(reward_type=50, cash_code, 0)) AS recharge_market_cash
SUM(if(reward_type=50, cash_code, 0)) AS recharge_market_cash
...
@@ -854,7 +854,7 @@
...
@@ -854,7 +854,7 @@
SUM(case when recharge_time < '2019-08-16 12:03:50' and agent_level=4 and reward_type in (60,760,300,750) then amount * 0.06 else 0 end) techChargeOrder,
SUM(case when recharge_time < '2019-08-16 12:03:50' and agent_level=4 and reward_type in (60,760,300,750) then amount * 0.06 else 0 end) techChargeOrder,
SUM(case when reward_type in (40) then amount else 0 end) opencardBalance,
SUM(case when reward_type in (40) then amount else 0 end) opencardBalance,
SUM(case when reward_type in (50,740) then amount else 0 end) rechargeBalance,
SUM(case when reward_type in (50,740) then amount else 0 end) rechargeBalance,
SUM(case when reward_type in (30,710,720,210) then amount else 0 end) upgradeBalance,
SUM(case when reward_type in (30,710,720,210, 80, 230 ,780) then amount else 0 end) upgradeBalance,
SUM(case when reward_type in (20,730) then amount else 0 end) upgradeSuperBalance,
SUM(case when reward_type in (20,730) then amount else 0 end) upgradeSuperBalance,
SUM(case when reward_type in (60,760) then amount else 0 end) shareBalance,
SUM(case when reward_type in (60,760) then amount else 0 end) shareBalance,
SUM(case when reward_type in (300,750) then amount else 0 end) zigoushengBalance,
SUM(case when reward_type in (300,750) then amount else 0 end) zigoushengBalance,
...
@@ -865,8 +865,8 @@
...
@@ -865,8 +865,8 @@
COUNT(reward_type IN (50, 740) OR NULL) AS onlinerechargeNum,
COUNT(reward_type IN (50, 740) OR NULL) AS onlinerechargeNum,
SUM(if(reward_type=40, amount, 0)) AS open_card_cash,
SUM(if(reward_type=40, amount, 0)) AS open_card_cash,
COUNT(reward_type=40 OR NULL) AS open_card_num,
COUNT(reward_type=40 OR NULL) AS open_card_num,
SUM(if(reward_type IN (30, 20, 710, 720, 730,210),amount, 0)) AS upgrade_partner_cash,
SUM(if(reward_type IN (30, 20, 710, 720, 730, 210, 80, 230 ,780),amount, 0)) AS upgrade_partner_cash,
COUNT(reward_type IN (30, 20, 710, 720, 730,210) OR NULL) AS upgrade_partner_num,
COUNT(reward_type IN (30, 20, 710, 720, 730, 210, 80, 230 ,780) OR NULL) AS upgrade_partner_num,
SUM(if(reward_type IN (50, 30, 20),cash_code, 0)) AS marketPerformance,
SUM(if(reward_type IN (50, 30, 20),cash_code, 0)) AS marketPerformance,
SUM(if(reward_type IN (30, 20),cash_code, 0)) AS upgrade_market_cash,
SUM(if(reward_type IN (30, 20),cash_code, 0)) AS upgrade_market_cash,
SUM(if(reward_type=50, cash_code, 0)) AS recharge_market_cash
SUM(if(reward_type=50, cash_code, 0)) AS recharge_market_cash
MODIFY COLUMN `free_balance` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '可用余额' AFTER `pay_freeze`,
MODIFY COLUMN `income_balance` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '账户收入总额' AFTER `free_balance`,
MODIFY COLUMN `recharge_income` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '在线充值收入' AFTER `income_balance`,
MODIFY COLUMN `opencard_income` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '账户开卡收入' AFTER `recharge_income`,
MODIFY COLUMN `withdraw_balance` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '提现总额' AFTER `deleted_at`,
MODIFY COLUMN `consume_balance` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '消费总额' AFTER `withdraw_balance`;
UPDATE agent_reward a
JOIN user_agent b ON a.agent_id=b.agent_id
SET a.agent_level=b.agent_level
WHERE a.recharge_time BETWEEN '2019-06-01 00:00:00' and '2019-06-30 23:59:59'
AND a.agent_level=0;
测试
select * from agent_salary where agent_id=1648 and yeartime=2019 and monthtime=6;
select * from agent_account_log where agent_id=1648;
select * from agent_reward where agent_id=1648 and recharge_time BETWEEN '2019-06-01 00:00:00' and '2019-06-30 23:59:59';
select * from agent_income_summary where agent_id=1648 and yeartime=2019 and monthtime=6;
delete from agent_salary where agent_id=1648 and yeartime=2019 and monthtime=6;
delete from agent_account_log where agent_id=1648;
update agent_reward set reward_status=100,settle_state=case when settle_state=300 then 200 else settle_state end where agent_id=1648 and recharge_time BETWEEN '2019-06-01 00:00:00' and '2019-06-30 23:59:59' ;
delete from agent_income_summary where agent_id=1648 and yeartime=2019 and monthtime=6;
select * from partner_account_log where user_id=1648 order by id desc;
select * from partner_reward where user_id=1648 and recharge_time BETWEEN '2019-06-01 00:00:00' and '2019-06-30 23:59:59';
select * from partner_income_summary where user_id=1648 and yeartime=2019 and monthtime=6;
delete from partner_account_log where user_id=1648 and yeartime=2019 and monthtime=6;
update partner_reward set reward_status=100,settle_state=case when settle_state=300 then 200 else settle_state end where user_id=1648 and recharge_time BETWEEN '2019-06-01 00:00:00' and '2019-06-30 23:59:59' ;
delete from partner_income_summary where user_id=1648 and yeartime=2019 and monthtime=6;
更新自购省分享赚比例
update income_rate_config
set self_rate=0.522
where type in (20,40) and self_role=10;
update income_rate_config
set self_rate=0.783
where type in (20,40) and self_role=20;
update income_rate_config
set self_rate=0.8352
where type in (20,40) and self_role=30;
update income_rate_config
set self_rate=0.54
where type in (10,30) and self_role=10;
update income_rate_config
set self_rate=0.81
where type in (10,30) and self_role=20;
update income_rate_config
set self_rate=0.864
where type in (10,30) and self_role=30;
ALTER TABLE `huhu`.`partner_reward`
ADD COLUMN `tech_fee_rate` decimal(11, 6) NOT NULL DEFAULT 0 COMMENT '技术服务费扣除比例' AFTER `ratio_all`;
ALTER TABLE `huhu`.`agent_salary`
MODIFY COLUMN `pingtui_balance` decimal(20, 6) NOT NULL DEFAULT 0 COMMENT '来自城市代理商的平推奖励' AFTER `zigousheng_balance`,
MODIFY COLUMN `tech_charge` decimal(20, 6) NOT NULL DEFAULT 0 COMMENT '技术服务费' AFTER `pingtui_balance`,
ADD COLUMN `tech_charge_redpack` decimal(20, 6) NOT NULL DEFAULT 0 COMMENT '红包技术服务费' AFTER `tech_charge`,
ADD COLUMN `tech_charge_order` decimal(20, 6) NOT NULL DEFAULT 0 COMMENT '佣金技术服务费' AFTER `tech_charge_redpack`;
ALTER TABLE `huhu`.`agent_income_summary`
MODIFY COLUMN `income` decimal(20, 6) NOT NULL DEFAULT 0.0000 COMMENT '结算金额' AFTER `monthtime`;
结算后核对SQL:
代理商:
1. agent_account_log
select
a.agent_id,
a.结算前余额,
a.月结发钱,
a.平台技术服务费,
a.代扣个人所得税,
a.结算前余额+a.月结发钱+a.平台技术服务费+a.代扣个人所得税 '预估结算后余额',
b.changed_amount '显示结算后余额'
from
(select
agent_id,
max(case when pay_remark='2019-07月结发钱' then REPLACE(substr(`snapshot`,INSTR(`snapshot`,'balance=')+8),')','') else '0' end) '结算前余额',
sum(case when pay_remark='2019-07月结发钱' then change_num else 0 end) '月结发钱',
sum(case when pay_remark='2019-07平台技术服务费' then change_num else 0 end) '平台技术服务费',
sum(case when pay_remark='2019-07代扣个人所得税' then change_num else 0 end) '代扣个人所得税',
max(id) m_id
from agent_account_log a
where yeartime=2019 and monthtime=8 and daytime=21
case when (balance-zigousheng_balance-share_balance-tech_charge_redpack-800)*0.1 > 0 then (balance-zigousheng_balance-share_balance-tech_charge_redpack-800)*0.1 else 0 end 'tax',
tax_balance
from agent_salary
where yeartime=2019 and monthtime=7
and case when (balance-zigousheng_balance-share_balance-tech_charge_redpack-800)*0.1 > 0 then (balance-zigousheng_balance-share_balance-tech_charge_redpack-800)*0.1 else 0 end