合格订单的逻辑

Posted sakura3

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了合格订单的逻辑相关的知识,希望对你有一定的参考价值。

合格订单的逻辑, 关于合格单的算法。

 

--odps sql 
--********************************************************************--
--author:jz_admin
--create time:2019-06-10 14:45:16
--********************************************************************--
use jz_daojia;
select t.month
,t.category_text
,sum(t.order_num)
,sum(t.GMV)
,sum(t.yingshou)
,sum(t.audit_order_num)
,sum(t.audit_gmv)
,sum(t.audit_yingshou)
,sum(t.hege_order_num)
,sum(t.hege_gmv)
,sum(t.hege_yingshou)
from
(select to_char(to_date(a.order_date,yyyy-mm-dd hh:mi:ss), yyyy-mm) as month
,a.category_text as category_text
,count(distinct a.id) as order_num
,sum(b.sign_payable_amount) as GMV 
,sum(case when substr(cast(a.order_date as string),1,7)<=2019-06 and a.category_text=月嫂 then b.sign_payable_amount*0.3
      when a.category_text=育儿嫂 then b.sign_payable_amount*0.2 else b.origin_customer_info_fee end) as yingshou
,0 as audit_order_num
,0 as audit_gmv
,0 as audit_yingshou
,0 as hege_order_num
,0 as hege_gmv
,0 as hege_yingshou
from 
(select *
from jz_daojia.f_jz_order_main
where to_char(to_date(order_date,yyyy-mm-dd hh:mi:ss), yyyy-mm-dd)>=2019-01-01
and (category_id=270 or (category_id=205 and city_name!=北京))) a 
left join jz_daojia.f_ys_order_amount b 
on a.id=b.id
group by to_char(to_date(a.order_date,yyyy-mm-dd hh:mi:ss), yyyy-mm)
,a.category_text

union all 

select to_char(to_date(a.sign_pass_time,yyyy-mm-dd hh:mi:ss), yyyy-mm) as month
,a.category_text as category_text
,0 as order_num
,0 as GMV 
,0 as yingshou
,count(distinct a.id) as audit_order_num
,sum(b.audit_pass_amount) as audit_gmv
,sum(case when substr(cast(a.sign_pass_time as string),1,7)<=2019-06 and a.category_text=月嫂 then b.audit_pass_amount*0.3
      when a.category_text=育儿嫂 then b.audit_pass_amount*0.2 else b.audit_pass_revenue end) as audit_yingshou
,0 as hege_order_num
,0 as hege_gmv
,0 as hege_yingshou
from 
(select *
from jz_daojia.f_jz_order_main
where to_char(to_date(sign_pass_time,yyyy-mm-dd hh:mi:ss), yyyy-mm-dd)>=2019-01-01
and (category_id=270 or (category_id=205 and city_name!=北京))) a 
left join jz_daojia.f_ys_order_amount b 
on a.id=b.id
group by to_char(to_date(a.sign_pass_time,yyyy-mm-dd hh:mi:ss), yyyy-mm)
,a.category_text

union all 

select 
substr(cast(a.time as string),1,7) as month
,a.category_text as category_text
,0 as order_num
,0 as GMV 
,0 as yingshou
,0 as audit_order_num
,0 as audit_gmv
,0 as audit_yingshou
,count(distinct a.id) as hege_order_num
,sum(b.audit_pass_amount) as hege_gmv
,sum(case when substr(cast(a.time as string),1,7)<=2019-06 and a.category_text=月嫂 then b.audit_pass_amount*0.3
      when a.category_text=育儿嫂 then b.audit_pass_amount*0.2 else b.audit_pass_revenue end) as hege_yingshou
from
(select a.id,if(to_char(to_date(a.sign_pass_time,yyyy-mm-dd hh:mi:ss), yyyy-mm-dd)>=b.create_date,to_char(to_date(a.sign_pass_time,yyyy-mm-dd hh:mi:ss), yyyy-mm-dd),b.create_date) as time,a.category_text
from
(SELECT id,sign_pass_time,category_text
from jz_daojia.f_jz_order_main
where (category_id=270 or (category_id=205 and city_name!=北京))) a
inner join 
(select 
                a.id,
                b.create_date,
                row_number() over(partition by a.id order by b.create_date) as asc_number ,
                full_amount,
                sum_amount
            from (
                    select 
                       o.id,
                       (g.audit_pass_amount + coalesce(c.increased_amount,0) - coalesce(c.discount_amount,0)) as full_amount
                    from (
                        select 
                            a.id,
                            b.appointment_cycle
                        from (
                            select * from o_jz_order_t_order where dt = ${bdp.system.bizdate} and category_id in (205,270)
                        ) a left join (
                            select *,row_number() over(partition by order_id order by create_time) as asc_number from o_jz_order_t_order_item where dt = ${bdp.system.bizdate} and item_no = 1
                        ) b on a.id = b.order_id and b.asc_number = 1
                    ) o left join jz_daojia.f_ys_order_amount g on o.id = g.id
                    left join (
                        -- 加收优惠
                        SELECT
                            order_id,
                            sum(if(promote_amount > 0, promote_amount, 0)) as increased_amount, -- 加收金额
                            sum(if(promote_amount < 0, abs(promote_amount), 0)) as discount_amount, -- 优惠金额
                            sum(promote_amount) as promote_amount_sum -- 营销金额
                        from
                            o_jz_order_t_order_promote
                        where
                            dt = ${bdp.system.bizdate} and delete_flag = 0 
                        group by 
                            order_id
                    ) c on o.id = c.order_id 
                    ) a 
                    left join (
                    SELECT
                        a.create_date,
                        a.order_id,
                        sum(CASE WHEN b.create_date <= a.create_date THEN b.amount ELSE 0 END) AS sum_amount
                    FROM
                        (
                            SELECT DISTINCT
                                order_id,
                                date_format(create_time, yyyy-MM-dd) AS create_date
                            FROM
                                o_jz_order_t_payment_item
                            WHERE
                                dt = ${bdp.system.bizdate}
                                AND STATUS = 2
                                AND delete_flag = 0
                        ) a
                    LEFT JOIN (
                            SELECT
                                        order_id,
                                        date_format(create_time, yyyy-MM-dd) AS create_date,
                                        sum(amount) AS amount
                            FROM
                                        o_jz_order_t_payment_item
                            WHERE
                                dt = ${bdp.system.bizdate}
                                AND STATUS = 2
                                AND delete_flag = 0
                            GROUP BY
                                order_id,
                                date_format(create_time, yyyy-MM-dd)
                    ) b ON a.order_id = b.order_id
                    GROUP BY
                        a.create_date,
                        a.order_id
            ) b on a.id = b.order_id 
            where  round(a.full_amount, 0) <= round(b.sum_amount, 0)) b
            on a.id=b.id
            where to_char(to_date(a.sign_pass_time,yyyy-mm-dd hh:mi:ss), yyyy-mm-dd)>=2010-01-01
            and b.create_date>=2010-01-01
            and b.asc_number=1) a 
            left join jz_daojia.f_ys_order_amount b on a.id=b.id
            where substr(cast(a.time as string),1,7)>=2019-01
            group by substr(cast(a.time as string),1,7)
,a.category_text) t 
group by t.month
,t.category_text;

 

以上是关于合格订单的逻辑的主要内容,如果未能解决你的问题,请参考以下文章

巧用Vscode编辑器,快速编辑代码,教你一键写完一段代码,向合格的cv工程师前进

巧用Vscode编辑器,快速编辑代码,教你一键写完一段代码,向合格的cv工程师前进

巧用Vscode编辑器,快速编辑代码,教你一键写完一段代码,向合格的cv工程师前进

巧用Vscode编辑器,快速编辑代码,教你一键写完一段代码,向合格的cv工程师前进

此应用小部件片段中所有意图 (PendingIntents) 的逻辑流

图书预定系统