dj组dj_smartcarlife_dml.sql
5.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
### 陈希 -----------------start-------------------
### 陈希 -----------------end---------------------
### 立明 -----------------start-------------------
update dj_car_life_online_statement_account_trade_detail set shop_division_money=0,fws_division_money=0,gl_division_money=0 where division_flag='N';
update dj_car_life_online_statement_account_trade_detail a,dj_car_life_order_division od set a.division_flag=if(od.id is null,'N','Y'),a.shop_division_money=IFNULL(od.shop_division_money,0),fws_division_money=ifnull((
select sum(division_money) from dj_car_life_merchant_distribution md where md.deleted_flag='N' and rule_type=2 and division_order_code=od.division_order_code and target_merchant_type=2),0),
a.gl_division_money=ifnull(od.gl_division_money,0) + ifnull(od.djzhy_sub_merchant_division_money,0) - a.service_charge,a.division_date=od.division_date
where a.division_flag='N' and a.deleted_flag='N' and od.pay_order_id=a.pay_order_id and od.division_status=3 and od.deleted_flag='N';
update dj_car_life_online_statement_account_trade_detail a ,dj_car_life_order_division b
set a.reality_platform_merchant_id=b.reality_platform_merchant_id,a.reality_platform_merchant_name=b.reality_platform_merchant_name,
a.division_order_code=b.division_order_code
where a.pay_order_id=b.pay_order_id and a.deleted_flag='N' and b.deleted_flag='N' and b.division_type=2
and b.division_status=3 and a.division_order_code is null;
update dj_car_life_online_statement_account_trade_detail a ,dj_car_life_order_division b
set a.reality_platform_merchant_id=b.reality_platform_merchant_id,a.reality_platform_merchant_name=b.reality_platform_merchant_name,
a.division_order_code=b.division_order_code
where a.pay_order_id=b.pay_order_id and a.deleted_flag='N' and b.deleted_flag='N' and b.division_type=1
and b.division_status=3 and a.division_order_code is null;
update dj_car_life_online_statement_account_trade_detail a set a.estimated_arrival_time=(
select CONCAT(min(b.date),'') from dj_car_life_month_work_day_record b where b.deleted_flag='N' and b.date>DATE_FORMAT(a.division_date,'%Y-%m-%d') and is_not_work=0
) where deleted_flag='N' and a.estimated_arrival_time is null and a.division_date is not null;
insert into dj_car_life_online_statement_account_trade_distribution_detail(trade_detail_id,target_merchant_type,reality_merchant_id,reality_merchant_name,division_money,service_charge,created_by,created_date,updated_by,updated_date,deleted_flag)
select a.id,1,b.reality_platform_merchant_id,b.reality_platform_merchant_name, b.gl_division_money,
if(b.djzhy_sub_merchant_id is not null and b.djzhy_sub_merchant_id=b.fee_merchant_id,0,a.service_charge),
'system',NOW(),'system',now(),'N'
from dj_car_life_online_statement_account_trade_detail a
join dj_car_life_order_division b on b.division_order_code=a.division_order_code and b.deleted_flag='N'
where a.deleted_flag='N' AND b.gl_division_money>0 and a.division_order_code is not null;
insert into dj_car_life_online_statement_account_trade_distribution_detail(trade_detail_id,target_merchant_type,reality_merchant_id,reality_merchant_name,division_money,service_charge,created_by,created_date,updated_by,updated_date,deleted_flag)
select a.id,4,b.djzhy_sub_merchant_id,b.djzhy_sub_merchant_name, b.djzhy_sub_merchant_division_money,
if(b.djzhy_sub_merchant_id is not null and b.djzhy_sub_merchant_id=b.fee_merchant_id,a.service_charge,0),
'system',NOW(),'system',now(),'N'
from dj_car_life_online_statement_account_trade_detail a
join dj_car_life_order_division b on b.division_order_code=a.division_order_code and b.deleted_flag='N'
where a.deleted_flag='N' AND b.djzhy_sub_merchant_division_money>0 and a.division_order_code is not null;
insert into dj_car_life_online_statement_account_trade_distribution_detail(trade_detail_id,target_merchant_type,reality_merchant_id,reality_merchant_name,division_money,service_charge,created_by,created_date,updated_by,updated_date,deleted_flag)
select a.id,3,b.reality_shop_merchant_id,b.reality_shop_merchant_name, b.shop_division_money,0,'system',NOW(),'system',now(),'N'
from dj_car_life_online_statement_account_trade_detail a
join dj_car_life_order_division b on b.division_order_code=a.division_order_code and b.deleted_flag='N'
where a.deleted_flag='N' AND b.shop_division_money>0 and a.division_order_code is not null;
insert into dj_car_life_online_statement_account_trade_distribution_detail(trade_detail_id,target_merchant_type,reality_merchant_id,reality_merchant_name,division_money,service_charge,created_by,created_date,updated_by,updated_date,deleted_flag)
select a.id,2,b.reality_merchant_id,b.reality_merchant_name, b.division_money,0,'system',NOW(),'system',now(),'N'
from dj_car_life_merchant_distribution b
join dj_car_life_online_statement_account_trade_detail a on a.division_order_code=b.division_order_code and a.deleted_flag='N'
where b.deleted_flag='N' and b.target_merchant_type=2 and b.division_money>0 and a.division_order_code is not null and b.rule_type=2;
### 立明 -----------------end---------------------
### 彦峰 -----------------start-------------------
### 彦峰 -----------------end---------------------
### 富康 -----------------start-------------------
### 富康 -----------------end---------------------
### 璐琦 -----------------start-------------------
### 璐琦 -----------------end---------------------
### 林冲 -----------------start--------------------
### 林冲 -----------------end----------------------
### 潘诗林 -----------------start--------------------
UPDATE dj_car_life_merchant_deliver_target_config
SET period_start_date = CONCAT(target_month, '-01'),
period_end_date = DATE_FORMAT(LAST_DAY(CONCAT(target_month, '-01')), '%Y-%m-%d')
WHERE
target_month IS NOT NULL
AND period_start_date IS NULL;
### 潘诗林 -----------------end----------------------