Commit 08e831b6 by guanchen

添加奖励类型, 更新sql

parent 4dab8293
...@@ -4,43 +4,21 @@ import org.slf4j.Logger; ...@@ -4,43 +4,21 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.scheduling.annotation.EnableScheduling;
/** /**
* @author houseme * @author houseme
*/ */
@SpringBootApplication @SpringBootApplication
@EnableCaching public class PartnerApplication {
@EnableScheduling
public class PartnerApplication extends SpringBootServletInitializer {
private static Logger logger = LoggerFactory.getLogger(PartnerApplication.class); private static Logger logger = LoggerFactory.getLogger(PartnerApplication.class);
public static void main(String[] args) { public static void main(String[] args) {
try { try {
SpringApplication.run(PartnerApplication.class, args);
logger.info("PartnerApplication >>>服务启动成功"); logger.info("PartnerApplication >>>服务启动成功");
Object lock = new Object(); SpringApplication.run(PartnerApplication.class, args);
synchronized (lock) {
try {
while (true) {
lock.wait();
}
} catch (InterruptedException e) {
logger.error(e.getMessage(), e);
}
}
} catch (Exception e) { } catch (Exception e) {
logger.error("PartnerApplication>>服务启动失败", e); // logger.error(e.getMessage(), e);
e.printStackTrace(); e.printStackTrace();
} }
} }
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(PartnerApplication.class);
}
} }
...@@ -791,7 +791,7 @@ ...@@ -791,7 +791,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,
...@@ -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
......
...@@ -874,8 +874,8 @@ ...@@ -874,8 +874,8 @@
0 bank_tax, 0 bank_tax,
SUM(if(reward_type=60 AND is_show_on_client=1, commission_acount, 0)) AS cash, SUM(if(reward_type=60 AND is_show_on_client=1, commission_acount, 0)) AS cash,
COUNT(reward_type=60 OR NULL) AS num, COUNT(reward_type=60 OR NULL) AS num,
SUM(if(reward_type IN (70,210,220, 100) AND is_show_on_client=1,commission_acount, 0)) AS upCash, SUM(if(reward_type IN (70,210,220,320,230, 100) AND is_show_on_client=1,commission_acount, 0)) AS upCash,
COUNT(reward_type IN (70,210,220, 100)OR NULL) AS upNum, COUNT(reward_type IN (70,210,220,320,230, 100)OR NULL) AS upNum,
SUM(if(reward_type=80 AND is_show_on_client=1, commission_acount, 0)) AS icash, SUM(if(reward_type=80 AND is_show_on_client=1, commission_acount, 0)) AS icash,
COUNT(reward_type=80 OR NULL) AS inum, COUNT(reward_type=80 OR NULL) AS inum,
SUM(if(reward_type=90 AND is_show_on_client=1, commission_acount, 0)) AS pcash, SUM(if(reward_type=90 AND is_show_on_client=1, commission_acount, 0)) AS pcash,
...@@ -916,8 +916,8 @@ ...@@ -916,8 +916,8 @@
0 bank_tax, 0 bank_tax,
SUM(if(reward_type=60 AND is_show_on_client=1, commission_acount, 0)) AS cash, SUM(if(reward_type=60 AND is_show_on_client=1, commission_acount, 0)) AS cash,
COUNT(reward_type=60 OR NULL) AS num, COUNT(reward_type=60 OR NULL) AS num,
SUM(if(reward_type IN (70,210,220, 100) AND is_show_on_client=1,commission_acount, 0)) AS upCash, SUM(if(reward_type IN (70,210,220,320,230, 100) AND is_show_on_client=1,commission_acount, 0)) AS upCash,
COUNT(reward_type IN (70,210,220, 100)OR NULL) AS upNum, COUNT(reward_type IN (70,210,220,320,230, 100)OR NULL) AS upNum,
SUM(if(reward_type=80 AND is_show_on_client=1, commission_acount, 0)) AS icash, SUM(if(reward_type=80 AND is_show_on_client=1, commission_acount, 0)) AS icash,
COUNT(reward_type=80 OR NULL) AS inum, COUNT(reward_type=80 OR NULL) AS inum,
SUM(if(reward_type=90 AND is_show_on_client=1, commission_acount, 0)) AS pcash, SUM(if(reward_type=90 AND is_show_on_client=1, commission_acount, 0)) AS pcash,
......
上线SQL:
ALTER TABLE `huhu`.`partner_account_log`
ADD COLUMN `snapshot` varchar(512) NULL COMMENT '变更前的快照' AFTER `modify_time`;
ALTER TABLE `huhu`.`agent_reward`
MODIFY COLUMN `reward_type` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '奖励类型 40 开卡奖励 50 充值奖励 30 购买VIP会员 20 购买超级VIP会员 60 分享赚 300 自购省 得的购买年-VIP; 720 城市代理商所得的购买半年-VIP; 730 城市代理商所得的购买超级VIP收益; 740 城市代理商的红包收益; 750 城市代理商的自购省收益; 760 城市代理商的分享赚收益 ' AFTER `user_id`;
ALTER TABLE `huhu`.`agent_account_log`
ADD COLUMN `snapshot` varchar(255) NOT NULL DEFAULT '' COMMENT '变更前的快照' AFTER `modify_time`;
ALTER TABLE `huhu`.`partner_account_log`
MODIFY COLUMN `change_num` decimal(20, 6) NOT NULL DEFAULT 0 COMMENT '变化的金额 进账为正数 出账为负数' AFTER `type`,
MODIFY COLUMN `changed_amount` decimal(20, 6) NOT NULL DEFAULT 0 COMMENT '变化的之后的金额' AFTER `change_num`;
ALTER TABLE `huhu`.`agent_account_log`
MODIFY COLUMN `change_num` decimal(20, 6) NOT NULL DEFAULT 0 COMMENT '变化的金额 进账为正数 出账为负数' AFTER `type`,
MODIFY COLUMN `changed_amount` decimal(20, 6) NOT NULL DEFAULT 0 COMMENT '变化的之后的金额' AFTER `change_num`;
ALTER TABLE `huhu`.`agent_account`
MODIFY COLUMN `balance` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '账户总额' AFTER `account_type`,
MODIFY COLUMN `frozen_balance` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '冻结余额' AFTER `balance`,
MODIFY COLUMN `income_freeze` decimal(20, 6) UNSIGNED NULL DEFAULT 0 COMMENT '收入冻结' AFTER `frozen_balance`,
MODIFY COLUMN `pay_freeze` decimal(20, 6) UNSIGNED NULL DEFAULT 0 COMMENT '出款冻结' AFTER `income_freeze`,
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
group by 1
) a
join agent_account_log b on a.m_id=b.id
where round(a.结算前余额+a.月结发钱+a.平台技术服务费+a.代扣个人所得税,2)
<>
round(b.changed_amount ,2);
2. agent_income_summary
select
income,
JSON_EXTRACT(content, '$.cashPlace')+
JSON_EXTRACT(content, '$.cashOpenCard')+
JSON_EXTRACT(content, '$.cashRecharge')+
JSON_EXTRACT(content, '$.cashUpgradePartner') 'income2',
content
from agent_income_summary
where yeartime=2019 and monthtime=7
and round(income,1)
<>
round(JSON_EXTRACT(content, '$.cashPlace')+JSON_EXTRACT(content, '$.cashOpenCard')+JSON_EXTRACT(content, '$.cashRecharge')+JSON_EXTRACT(content, '$.cashUpgradePartner'),1)
3. agent_salary
select
agent_id,
balance,
recharge_balance 'redpack_balance',
zigousheng_balance+share_balance 'order_balance',
opencard_balance+upgrade_balance+upgrade_super_balance+pingtui_balance 'others',
balance-zigousheng_balance-share_balance-tech_charge_redpack 'tax_base',
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
<>
tax_balance
4. agent_account
select
agent_id,
balance
from agent_account
合伙人:
select
a.user_id,
c.wx_free_balance 结算前余额,
a.月结发钱,
a.平台技术服务费,
a.代扣个人所得税,
c.wx_free_balance+a.月结发钱+a.平台技术服务费+a.代扣个人所得税 '预估结算后余额',
b.changed_amount '显示结算后余额'
from
(select
user_id,
max(REPLACE(substr(`snapshot`,INSTR(`snapshot`,'wxFreeBalance=')+14),')','')),
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 partner_account_log a
where yeartime=2019 and monthtime=8 and daytime=21
group by 1
) a
join partner_account_log b on a.m_id=b.id
join partner_account_copy1 c on a.user_id=c.user_id
where round(c.wx_free_balance+a.月结发钱+a.平台技术服务费+a.代扣个人所得税,2)
=
round(b.changed_amount ,2);
select
income,
JSON_EXTRACT(content, '$.cash')+
JSON_EXTRACT(content, '$.upCash')+
JSON_EXTRACT(content, '$.icash')+
JSON_EXTRACT(content, '$.pcash')+
JSON_EXTRACT(content, '$.scash')+
JSON_EXTRACT(content, '$.rcash')
'income2'
from partner_income_summary
where yeartime=2019 and monthtime=7
and round(income,1)
<>
round(JSON_EXTRACT(content, '$.cash')+JSON_EXTRACT(content, '$.upCash')+JSON_EXTRACT(content, '$.icash')+JSON_EXTRACT(content, '$.pcash')+JSON_EXTRACT(content, '$.scash')+JSON_EXTRACT(content, '$.rcash'),1)
select
user_id,
wx_free_balance
from partner_account
ALTER TABLE `huhu`.`partner_reward`
ADD COLUMN `settle_time` datetime(0) NULL COMMENT '结算奖励的时间: 淘宝客/京东联盟为确认收货时间, 其他类型奖励同于recharge_time' AFTER `tech_fee_rate`;
ALTER TABLE `huhu`.`agent_reward`
ADD COLUMN `settle_time` datetime(0) NULL COMMENT '结算奖励的时间: 淘宝客/京东联盟为确认收货时间, 其他类型奖励同于recharge_time' AFTER `ratio_all`;
10月25结算
update agent_reward
set ratio_all='[1,"0.03600000",0.03]'
where settle_time>='2019-09-01 00:00:00'
and ratio_all like '%0.03]'
and ratio_all not like ',0.03]'
and ratio_all='[1,"0.03600000"0.03]';
update agent_reward
set ratio_all='["1","0.27000000","0.01",0.03]'
where settle_time>='2019-09-01 00:00:00'
and ratio_all like '%0.03]'
and ratio_all not like ',0.03]'
and ratio_all='["1","0.27000000","0.01"0.03]';
update agent_reward
set ratio_all='[1,"0.00900000",0.03]'
where settle_time>='2019-09-01 00:00:00'
and ratio_all like '%0.03]'
and ratio_all not like ',0.03]'
and ratio_all='[1,"0.00900000"0.03]';
update agent_reward
set ratio_all='["1","0.04500000","0.01",0.03]'
where settle_time>='2019-09-01 00:00:00'
and ratio_all like '%0.03]'
and ratio_all not like ',0.03]'
and ratio_all='["1","0.04500000","0.01"0.03]';
结算前洗数据
ALTER TABLE `huhu_finance`.`agent_reward`
ADD COLUMN `tail_order_sn` varchar(64) NULL DEFAULT '' COMMENT '二次激活订单号' AFTER `invalid_time`;
ALTER TABLE `huhu_finance`.`agent_reward`
ADD COLUMN `deposite_tail_rate` decimal(11, 8) NULL DEFAULT 0 COMMENT '二次激活订单 定金和尾款订单 的 分成比例' AFTER `tail_order_sn`;
ALTER TABLE `huhu_finance`.`partner_reward`
ADD COLUMN `tail_order_sn` varchar(64) NULL DEFAULT '' COMMENT '二次激活订单号' AFTER `settle_in_advance`;
ALTER TABLE `huhu_finance`.`partner_reward`
ADD COLUMN `deposite_tail_rate` decimal(11, 8) NULL DEFAULT 0 COMMENT '二次激活订单 定金和尾款订单 的 分成比例' AFTER `tail_order_sn`;
ALTER TABLE `huhu_finance`.`agent_reward`
ADD INDEX `idx_ref`(`reference_id`) USING BTREE;
create table update_partner_agent_tail_order_reward(
type varchar(12),
order_type varchar(32),
order_sn varchar(64),
tail_order_sn varchar(64),
order_id varchar(32),
cnt_tail_order_sn int(11),
all_money decimal(20,6),
sum_all_money decimal(20,6),
deposite_tail_rate decimal(11,8)
);
ALTER TABLE `huhu_finance`.`update_partner_agent_tail_order_reward`
ADD PRIMARY KEY (`type`, `order_type`, `order_sn`, `tail_order_sn`, `order_id`);
INSERT INTO update_partner_agent_tail_order_reward(type,order_type,order_sn,tail_order_sn,order_id,all_money)
SELECT
DISTINCT
'partner',
a.order_type,
a.order_sn,
b.tail_order_sn_,
a.reference_id,
a.all_money_ori
FROM partner_reward a
JOIN
(SELECT
order_id,
max(REPLACE(order_sn,CONCAT(SUBSTRING_INDEX(order_sn,'_',1),'_'),'')) order_sn_,
max(type) order_type_,
max(order_sn) tail_order_sn_
FROM orders_active
WHERE order_sn like '%\_%' and settle_time between '2019-11-01 00:00:00' and '2019-11-30 23:59:59'
GROUP BY 1
) b on a.reference_id=b.order_id
WHERE a.reward_type=110 and a.settle_time between '2019-11-01 00:00:00' and '2019-11-30 23:59:59';
INSERT INTO update_partner_agent_tail_order_reward(type,order_type,order_sn,tail_order_sn,order_id,all_money)
SELECT
DISTINCT
'partner',
a.order_type,
a.order_sn,
'' tail_order_sn_,
a.reference_id,
a.all_money_ori
FROM partner_reward a
JOIN update_partner_agent_tail_order_reward b on a.reward_type=110 and a.order_type=b.order_type and a.order_sn=b.order_sn and b.type='partner'
WHERE a.reference_id<>b.order_id;
INSERT INTO update_partner_agent_tail_order_reward(type,order_type,order_sn,tail_order_sn,order_id,all_money)
SELECT
DISTINCT
'agent',
a.order_type,
a.order_sn,
b.tail_order_sn_,
a.reference_id,
a.all_money_ori
FROM agent_reward a
JOIN
(SELECT
order_id,
max(REPLACE(order_sn,CONCAT(SUBSTRING_INDEX(order_sn,'_',1),'_'),'')) order_sn_,
max(type) order_type_,
max(order_sn) tail_order_sn_
FROM orders_active
WHERE order_sn like '%\_%' and settle_time between '2019-11-01 00:00:00' and '2019-11-30 23:59:59'
GROUP BY 1
) b on a.reference_id=b.order_id
WHERE a.reward_type in (300,750) and a.settle_time between '2019-11-01 00:00:00' and '2019-11-30 23:59:59';
INSERT INTO update_partner_agent_tail_order_reward(type,order_type,order_sn,tail_order_sn,order_id,all_money)
SELECT
DISTINCT
'agent',
a.order_type,
a.order_sn,
'' tail_order_sn_,
a.reference_id,
a.all_money_ori
FROM agent_reward a
JOIN update_partner_agent_tail_order_reward b on a.reward_type in (300,750) and a.order_type=b.order_type and a.order_sn=b.order_sn and b.type='agent'
WHERE a.reference_id<>b.order_id;
UPDATE update_partner_agent_tail_order_reward a
JOIN
(SELECT
type,
order_type,
order_sn,
count(distinct tail_order_sn) cnt_tail_order_sn_,
sum(all_money) sum_all_money_
FROM update_partner_agent_tail_order_reward
GROUP BY 1,2,3
) b on a.type=b.type and a.order_type=b.order_type and a.order_sn=b.order_sn
SET a.cnt_tail_order_sn=b.cnt_tail_order_sn_,a.sum_all_money=b.sum_all_money_;
DELETE FROM update_partner_agent_tail_order_reward WHERE cnt_tail_order_sn=1;
UPDATE update_partner_agent_tail_order_reward SET deposite_tail_rate=all_money/sum_all_money;
UPDATE partner_reward a
JOIN update_partner_agent_tail_order_reward b on a.reward_type=110 and a.reference_id=b.order_id
SET a.tail_order_sn=b.tail_order_sn,a.deposite_tail_rate=b.deposite_tail_rate;
UPDATE agent_reward a
JOIN update_partner_agent_tail_order_reward b on a.reward_type in (300,750) and a.reference_id=b.order_id
SET a.tail_order_sn=b.tail_order_sn,a.deposite_tail_rate=b.deposite_tail_rate;
update agent_account a
join (
select agent_id,sum(change_num) change_num_
from agent_account_log a
where a.yeartime=2019 and a.monthtime=12 and a.daytime=24
group by 1
) b on a.agent_id=b.agent_id
join agent_account_2019122422 c on a.agent_id=c.agent_id
set a.balance=c.balance;
delete from agent_account_log where yeartime=2019 and monthtime=12 and daytime=24;
delete from agent_salary where yeartime=2019 and monthtime=11;
update agent_reward
set reward_status=100
where settle_time between '2019-11-01 00:00:00' and '2019-11-30 23:59:59' and reward_status=120
and settle_state>0;
update agent_reward
set settle_time=case when recharge_time<'2019-11-01 00:00:00' then '2019-11-01 00:00:00' else recharge_time end
where settle_time is null and recharge_time<'2019-11-30 23:59:59' and settle_state>0
and reward_type in (710,740);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment