【无标题】

use omni_stock_uat;
show create table pmc_push_ynap;

# logi_no
select count(1) from dw_tmp.dws_ord_sales_daily_statistics_fl_d03;
select count(1) from dw_ads.ads_ord_sales_data_fl_d;
select count(1) from dw_dwm.dwm_jv_item_sales_data_dtl_n_fl_d_new;
--重构替换



dw_dwm.dwm_jv_item_sales_data_dtl_n_fl_d 由替换
dw_ads.ads_ord_sales_data_fl_d

dw_dwm.dwm_jv_item_sales_data_dtl_n_fl_d_new 由替换
dw_ads.ads_ord_sales_data_fl_d

dw_dwm.dwm_jv_item_presell_fl_d    由替换 dw_ads.ads_ord_sales_presell_fl_d
dw_dwm.dwm_jv_item_daily_sales_fl_d  由替换 dw_dws.dws_ord_sales_daily_statistics_fl_d
dw_dwm.dwm_jv_item_presell_snapshot_iu_d   --单独的
dw_dwm.dwm_jv_item_sales_data_gift_only_fl_d --单独的
dw_dwm.dwm_tb_order_api_tmp --check逻辑用到



--ftid 分析
select count(1) from dw_dwd.dwd_jv_ecc_t_sd_tbsobill_fl_d
union all
select count(1) from dw_dwd.dwd_jv_api_t_sd_tbsobill_fl_d;


select t1.ftid,t1.fcreated,t1.fcreatetime,t1.fpaytime
from dw_dwd.dwd_jv_api_t_sd_tbsobill_fl_d t1
left join dw_dwd.dwd_jv_ecc_t_sd_tbsobill_fl_d t2
on t1.ftid=t2.ftid
where t2.ftid is null;


select dt from dw_ods.ods_app_tmall_trade_fullinfo_get_topic_iu_h where dt>='2023052200'
and content like '%3359086699266844428%';



--foid 分析

select count(1) from dw_dwd.dwd_jv_ecc_t_sd_tbsoentry_fl_d
union all
select count(1) from dw_dwd.dwd_jv_api_t_sd_tbsoentry_fl_d;



select t1.foid
from dw_dwd.dwd_jv_api_t_sd_tbsoentry_fl_d t1
left join dw_dwd.dwd_jv_ecc_t_sd_tbsoentry_fl_d t2
on t1.foid = t2.foid
where t2.foid is null;


--refund api



select count(1) from dw_dwd.dwd_jv_ecc_t_sd_tbrefund_fl_d
union all
select count(1) from dw_dwd.dwd_jv_api_t_sd_tbrefund_fl_d;

select t1.frefundid,t1.fcreatetime,t1.fcreated
from dw_dwd.dwd_jv_ecc_t_sd_tbrefund_fl_d t1
left join dw_dwd.dwd_jv_api_t_sd_tbrefund_fl_d t2
on t1.frefundid=t2.frefundid
where t2.frefundid is null
and t1.fcreatetime<='2023-06-07 00:20:00';


select t1.ftid,t1.fcreatetime,t1.fcreated
from dw_dwd.dwd_jv_ecc_t_sd_tbsobill_fl_d t1
left join dw_dwd.dwd_jv_api_t_sd_tbsobill_fl_d t2
on t1.ftid=t2.ftid
where t2.ftid is null;





select frefundid,fcreatetime,fcreated from dw_dwd.dwd_jv_api_t_sd_tbrefund_fl_d
where fcreated>='2023-05-22'
limit 10;



--promotion

select count(distinct ftid) from dw_dwd.dwd_jv_ecc_t_sd_tbpromotiondetail_fl_d
union all
select count(distinct ftid)  from dw_dwd.dwd_jv_api_t_sd_tbpromotiondetail_fl_d;

--tbgoods


select count(1) from dw_dwd.dwd_jv_ecc_t_ec_tbgoods_fl_d where dt='20230523'
union all
select count(1)  from dw_dwd.dwd_jv_api_t_ec_tbgoods_fl_d;

select t1.fnumiid,t1.fcreated,t1.fmodified
from (select * from dw_dwd.dwd_jv_ecc_t_ec_tbgoods_fl_d where dt ='20230523')t1
left join dw_dwd.dwd_jv_api_t_ec_tbgoods_fl_d t2
on t1.fnumiid=t2.fnumiid
where t2.fnumiid is null
order by fcreated desc limit 1000;


select dt from
dw_ods.ods_app_tmall_items_seller_list_get_topic_iu_h
where dt>='2023052200' and dt<='2023052500'
and content like '%719656428728%';


--tbsku

select t1.fskuid,t1.fcreated,t1.fmodified
from (select * from dw_dwd.dwd_jv_ecc_t_ec_tbsku_fl_d where dt ='20230524')t1
left join dw_dwd.dwd_jv_api_t_ec_tbsku_fl_d t2
on t1.fskuid=t2.fskuid
where t2.fskuid is null
order by fcreated desc limit 1000;
5019385625207

select dt from
dw_ods.ods_app_tmall_items_seller_list_get_topic_iu_h
where dt>='2023052200' and dt<='2023052500'
and content like '%5019385625207%';







--1dw_dwd.dwd_jv_api_t_sd_tbsobill_fl_d 映射代码逻辑
--初始化
insert overwrite table dw_dwd.dwd_jv_api_t_sd_tbsobill_fl_d
select ftid as fid,
       ftradeprocessstatus,
       fcreatetime,
       fsaleorderid,
       fsaleordernumber,
       flastupdatetime,
       fadjustfee,
       falipayid,
       falipayno,
       falipayurl,
       falipaywarnmsg,
       fareaid,
       favailableconfirmfee,
       fbuyeralipayno,
       fbuyerarea,
       fbuyercodfee,
       fbuyeremail,
       fbuyerflag,
       fbuyermemo,
       fbuyermessage,
       fbuyernick,
       fbuyerobtainpointfee,
       fbuyerrate,
       fcanrate,
       fcodfee,
       fcodstatus,
       fcommissionfee,
       fconsigntime,
       fcreated,
       fcreditcardfee,
       fdiscountfee,
       fendtime,
       feticketext,
       fexpressagencyfee,
       fhasbuyermessage,
       fhaspostfee,
       fhasyfx,
       fiid,
       finvoicename,
       fis3d,
       fisbrandsale,
       fisforcewlb,
       fislgtype,
       fispartconsign,
       flgaging,
       flgagingtype,
       fmarkdesc,
       fmodified,
       fnum,
       fnumiid,
       fnutfeature,
       fpaytime,
       fpayment,
       fpicpath,
       fpointfee,
       fpostfee,
       fprice,
       frealpointfee,
       freceivedpayment,
       freceiveraddress,
       freceivercity,
       freceiverdistrict,
       freceivermobile,
       freceivername,
       freceiverphone,
       freceiverstate,
       freceiverzip,
       fselleralipayno,
       fsellercanrate,
       fsellercodfee,
       fselleremail,
       fsellerflag,
       fsellermemo,
       ECBENC('P0Ak1PZuqEaM', fsellermobile) fsellermobile,
       fsellername,
       fsellernick,
       fsellerphone,
       fsellerrate,
       fsendtime,
       fshippingtype,
       fsnapshot,
       fsnapshoturl,
       fstatus,
       fsteppaidfee,
       fsteptradestatus,
       ftid,
       ftimeoutactiontime,
       ftitle,
       ftotalfee,
       ftradefrom,
       ftradememo,
       ftradesource,
       ftype,
       fyfxfee,
       fyfxid,
       fyfxtype,
       fplatformshopid,
       fconvertcount,
       fconvertmsg,
       fversion,
       fplatformid,
       fshoppick,
       fstorecode,
       ftenantid,
       ftradegenerrcount,
       ftradegenerrmsg,
       finvoicetype,
       finvoicekind,
       fbuyertaxno,
       ftimepromise,
       fpromiseservice,
       fesdate,
       fesrange,
       fosdate,
       fosrange,
       fcutoffminutes,
       festime,
       fdeliverytime,
       fcollecttime,
       fsigntime,
       fbuyeropenuid
from dw_ods.ods_jv_ecc_t_sd_tbsobill_fl_d
where dt='20230613';

select count(1) from dw_dwd.dwd_jv_api_t_sd_tbsobill_fl_d
union all
select count(1) from dw_dwd.dwd_jv_ecc_t_sd_tbsobill_fl_d;

select count(1) from
dw_dwd.dwd_jv_ecc_t_sd_tbsobill_fl_d t1
left join
dw_dwd.dwd_jv_api_t_sd_tbsobill_fl_d t2
on t1.ftid=t2.ftid
where t2.ftid is null;

--2 dw_dwd.dwd_jv_api_t_sd_tbsoentry_fl_d 映射代码逻辑
-- 初始化
insert overwrite table dw_dwd.dwd_jv_api_t_sd_tbsoentry_fl_d
select t1.foid as fid,
       t1.fadjustfee,
       t1.fbindoid,
       t1.fbuyernick,
       t1.fbuyerrate,
       t1.fcid,
       t1.fconsigntime,
       t1.fdiscountfee,
       t1.fendtime,
       t1.fiid,
       t1.finvoiceno,
       t1.fisoversold,
       t1.fisserviceorder,
       t1.fitemmealid,
       t1.fitemmealname,
       t1.flogisticscompany,
       t1.fmodified,
       t1.fnum,
       t1.fnumiid,
       t1.foid,
       t1.forderfrom,
       t1.fouteriid,
       t1.fouterskuid,
       t1.fpayment,
       t1.fpicpath,
       t1.fprice,
       t1.frefundid,
       t1.frefundstatus,
       t1.fsellernick,
       t1.fsellerrate,
       t1.fsellertype,
       t1.fshippingtype,
       t1.fskuid,
       t1.fskupropertiesname,
       t1.fsnapshot,
       t1.fsnapshoturl,
       t1.fstatus,
       t1.ftimeoutactiontime,
       t1.ftitle,
       t1.ftotalfee,
       t2.ftid as fparentid,
       t1.fversion,
       t1.ftenantid,
       t1.fstorecode,
       t1.festcontime
from dw_ods.ods_jv_ecc_t_sd_tbsoentry_fl_d t1
join dw_dwd.dwd_jv_ecc_t_sd_tbsobill_fl_d t2
on t1.fparentid=t2.fid
where dt='20230613';





select count(1) from dw_dwd.dwd_jv_api_t_sd_tbsoentry_fl_d
union all
select count(1) from dw_dwd.dwd_jv_ecc_t_sd_tbsoentry_fl_d;


--3 dw_dwd.dwd_jv_api_t_sd_tbrefund_fl_d 映射代码逻辑
--初始化
insert overwrite table dw_dwd.dwd_jv_api_t_sd_tbrefund_fl_d
select frefundid as fid,
       fadvancestatus,
       falipayno,
       fattribute,
       fbuyernick,
       fcreated,
       fcsstatus,
       fgoodstatus,
       fhasgoodreturn,
       fmodified,
       fnum,
       fnumiid,
       foid,
       foperationcontraint,
       forderstatus,
       fouterid,
       fpayment,
       fprice,
       freason,
       frefundfee,
       frefundid,
       frefundphase,
       frefundversion,
       fsellernick,
       fsku,
       fstatus,
       ftid,
       ftitle,
       fplatformid,
       fplatformshopid,
       fcreatetime,
       flastupdatetime,
       ftotalfee,
       fsalereturnsid,
       fsalereturnsnumber,
       frefundprocessstatus,
       fsyncflag,
       fsyncmessage,
       fversion,
       fsid,
       ftenantid,
       fisreject,
       fagrefundflag,
       fagrefundmessage,
       fagrefundfailcount,
       fcompanyname,
       fgoodreturntime,
       concat(`foid`,'') as oid
from dw_ods.ods_jv_ecc_t_sd_tbrefund_fl_d
where dt='20230613';

select count(1) from dw_dwd.dwd_jv_api_t_sd_tbrefund_fl_d
union all
select count(1) from dw_dwd.dwd_jv_ecc_t_sd_tbrefund_fl_d;

select fcsstatus,dt from dw_tmp.dwd_jv_api_t_sd_tbrefund_fl_d_02 where frefundid='209697770015393130';
select count(1) from dw_ods.ods_jv_ecc_t_sd_tbrefund_fl_d
where dt='20230315';


--4dwd_jv_ecc_t_sd_tbpromotiondetail_fl_d 映射逻辑 initial初始化
insert overwrite table dw_dwd.dwd_jv_api_t_sd_tbpromotiondetail_fl_d
select
 t1.ftid as fid
,t1.fdiscountfee
,t1.fgiftitemid
,t1.fgiftitemname
,t1.fgiftitemnum
,t1.fpromotiondesc
,t1.fpromotionid
,t1.fpromotionname
,t1.ftid
,t1.ftid as fparentid
,t1.fversion
,t1.ftenantid
from dw_ods.ods_jv_ecc_t_sd_tbpromotiondetail_fl_d t1
where t1.dt='20230522';




select * from dw_ods.ods_app_tmall_trade_fullinfo_get_topic_iu_h where dt>='2023031614' limit 10;





select
t1.numiid,t1.fnumiid,t2.fnumiid
from
(select * from dw_dwd.dwd_jv_ecc_t_ec_tbgoods_fl_d where dt='20230307') t1
left join
 dw_dwd.dwd_jv_api_t_ec_tbgoods_fl_d t2
on t1.fnumiid =t2.fnumiid
where t2.fnumiid is null;
select fnumiid from dw_dwd.dwd_jv_ecc_t_ec_tbgoods_fl_d where dt='20230307' and fnumiid='706252505776';
select fnumiid from dw_dwd.dwd_jv_api_t_ec_tbgoods_fl_d where fnumiid='706252505776';

select item
from (
    select
           get_json_object(get_json_object(get_json_object(content, '$.items_seller_list_get_response'), '$.items'),'$.item')item_array,
           dt
    from dw_ods.ods_app_tmall_items_seller_list_get_topic_iu_h
    where dt >= '2023030611'
--       and  dt <= '2023030714'
)t LATERAL VIEW EXPLODE_JSON_ARRAY(item_array) tmp as item
where get_json_object(item, '$.num_iid')='706252505776'
distribute by 50;
select fnumiid,numiid from dw_dwd.dwd_jv_ecc_t_ec_tbgoods_fl_d where dt='20230307' and fnumiid='706252505776';

select content
from dw_ods.ods_app_tmall_items_seller_list_get_topic_iu_h
where dt = '2023030711'
  and content like '%706252505776%'
distribute by 50;
--   and content like '%706252505776%';





--5 dwd_jv_ecc_t_ec_tbgoods_fl_d 初始化
insert overwrite table dw_dwd.dwd_jv_api_t_ec_tbgoods_fl_d
select fnumiid as `fid`
     , `faftersaleid`
     , `fapprovestatus`
     , `fauctionpoint`
     , `fautofill`
     , `fchangeprop`
     , `fcid`
     , `fcodpostageid`
     , `fcreated`
     , `fdelisttime`
     , `fdesc`
     , `fdetailurl`
     , `femsfee`
     , `fexpressfee`
     , `ffeatures`
     , `ffreightpayer`
     , `fglobalstocktype`
     , `fhasdiscount`
     , `fhasinvoice`
     , `fhasshowcase`
     , `fhaswarranty`
     , `fincrement`
     , `finnershopauctiontemplateid`
     , `finputpids`
     , `finputstr`
     , `fis3d`
     , `fisex`
     , `fisfenxiao`
     , `fislightningconsignment`
     , `fisprepay`
     , `fistaobao`
     , `fistiming`
     , `fisvirtual`
     , `fisxinpin`
     , `fitemsize`
     , `fitemweight`
     , `flisttime`
     , `fmodified`
     , `fnick`
     , `fnum`
     , `fnumiid`
     , `fonestation`
     , `fouterid`
     , `foutershopauctiontemplateid`
     , `fpicurl`
     , `fpostfee`
     , `fpostageid`
     , `fprice`
     , `fproductid`
     , `fpromotedservice`
     , `fpropertyalias`
     , `fprops`
     , `fpropsname`
     , `fscore`
     , `fsecondkill`
     , `fsellpoint`
     , `fsellpromise`
     , `fsellercids`
     , `fstuffstatus`
     , `fsubstock`
     , `ftemplateid`
     ,  ftitle
     , `ftype`
     , `fvalidthru`
     , `fviolation`
     , `fvolume`
     , `fwapdesc`
     , `fwapdetailurl`
     , `fwithholdquantity`
     , `fwwstatus`
     , `fecplatformshopid`
     , `fversion`
     , `fisdelete`
     , `fautoup`
     , `fautodelist`
     , `fautostuff`
     , `fdelistvalue`
     , `fstuffvalue`
     , `fupqty`
     , `fupsuccess`
     , `flastuptime`
     , `fupfailreason`
     , `flastupdatetime`
     , `flastupdateuser`
     , `ftenantid`
     , `fsyncrate`
     , `fsyncmode`
     , case
           when substr(fnumiid, 14, 1) = '9'
               then substr(ceil(fnumiid), 1, 12)
           else substr(fnumiid, 1, 12)
    end        as numiid
     ,fdelisttime
     ,flisttime
from dw_ods.ods_jv_ecc_t_ec_tbgoods_fl_d
where dt = '20230627' ;

select count(1) from dw_dwd.dwd_jv_api_t_ec_tbgoods_fl_d
union all
select count(1) from dw_dwd.dwd_jv_ecc_t_ec_tbgoods_fl_d where dt='20230504'
;





select count(1) from dw_dwd.dwd_jv_api_t_ec_tbsku_fl_d
union all
select count(1) from dw_tmp.dwd_jv_api_t_ec_tbsku_fl_d
;




select count(1) from dw_dwd.dwd_jv_api_t_ec_tbsku_fl_d
union all
select count(1) from dw_dwd.dwd_jv_ecc_t_ec_tbsku_fl_d where dt='20230504'
;




--6 dwd_jv_ecc_t_ec_tbsku_fl_d 初始化
insert overwrite table dw_dwd.dwd_jv_api_t_ec_tbsku_fl_d
select t1.fskuid,
       t1.fcreatetime,
       t1.fcreatorid,
       t1.flastupdatetime,
       t1.flastupdateuserid,
       t1.fchangeprop,
       t1.fcreated,
       t1.fiid,
       t1.fmodified,
       t2.fnumiid as fnumiid,
       t1.fouterid,
       t1.fprice,
       t1.fproperties,
       t1.fpropertiesname,
       t1.fquantity,
       t1.fskudeliverytime,
       t1.fskuid,
       t1.fskuspecid,
       t1.fstatus,
       t1.fwithholdquantity,
       t2.fnumiid as fparentid,
--        t1.fparentid,
       t1.fversion,
       t1.version,
       t1.fautoup,
       t1.fautodelist,
       t1.fautostuff,
       t1.fdelistvalue,
       t1.fstuffvalue,
       t1.fupqty,
       t1.fupsuccess,
       t1.flastuptime,
       t1.fupfailreason,
       t1.flastupdateuser,
       t1.ftenantid,
       t1.fsyncrate,
       t1.fsyncmode
from dw_ods.ods_jv_ecc_t_ec_tbsku_fl_d t1
left join dw_dwd.dwd_jv_ecc_t_ec_tbgoods_fl_d t2
on t1.fparentid=t2.fid
where t1.dt='20230427'
  and t2.dt='20230427';






-- 刷数 tbsku
insert overwrite table dw_tmp.dwd_jv_api_t_ec_tbsku_fl_d
select fskuid as fid,
       fcreatetime,
       fcreatorid,
       flastupdatetime,
       flastupdateuserid,
       fchangeprop,
       fcreated,
       fiid,
       fmodified,
       fnumiid,
       fouterid,
       fprice,
       fproperties,
       fpropertiesname,
       fquantity,
       fskudeliverytime,
       fskuid,
       fskuspecid,
       fstatus,
       fwithholdquantity,
       fparentid,
       fversion,
       version,
       fautoup,
       fautodelist,
       fautostuff,
       fdelistvalue,
       fstuffvalue,
       fupqty,
       fupsuccess,
       flastuptime,
       fupfailreason,
       flastupdateuser,
       ftenantid,
       fsyncrate,
       fsyncmode
from (select t1.fskuid,
       t1.fcreatetime,
       t1.fcreatorid,
       t1.flastupdatetime,
       t1.flastupdateuserid,
       t1.fchangeprop,
       t1.fcreated,
       t1.fiid,
       t1.fmodified,
       t2.fnumiid as fnumiid,
       t1.fouterid,
       t1.fprice,
       t1.fproperties,
       t1.fpropertiesname,
       t1.fquantity,
       t1.fskudeliverytime,
       t1.fskuid,
       t1.fskuspecid,
       t1.fstatus,
       t1.fwithholdquantity,
       t2.fnumiid as fparentid,
--        t1.fparentid,
       t1.fversion,
       t1.version,
       t1.fautoup,
       t1.fautodelist,
       t1.fautostuff,
       t1.fdelistvalue,
       t1.fstuffvalue,
       t1.fupqty,
       t1.fupsuccess,
       t1.flastuptime,
       t1.fupfailreason,
       t1.flastupdateuser,
       t1.ftenantid,
       t1.fsyncrate,
       t1.fsyncmode,
        row_number() over (partition by fskuid,t2.fnumiid order by t1.fmodified desc ) rank
from dw_ods.ods_jv_ecc_t_ec_tbsku_fl_d t1
left join dw_dwd.dwd_jv_ecc_t_ec_tbgoods_fl_d t2
on t1.fparentid=t2.fid
where t1.dt='20230419'
  and t2.dt='20230419')t1
where rank=1;


-- drop table if exists dw_dwd.dwd_jv_api_t_sd_tbpromotiondetail_fl_d;
create table dw_dwd.dwd_jv_api_t_sd_tbpromotiondetail_fl_d
like dw_dwd.dwd_jv_ecc_t_sd_tbpromotiondetail_fl_d;

--5 tbsku
CREATE TABLE dw_dwd.dwd_jv_api_t_ec_tbsku_fl_d(
  `fid` string COMMENT '',
  `fcreatetime` timestamp COMMENT '',
  `fcreatorid` string COMMENT '',
  `flastupdatetime` timestamp COMMENT '',
  `flastupdateuserid` string COMMENT '',
  `fchangeprop` string COMMENT '',
  `fcreated` string COMMENT '',
  `fiid` string COMMENT '',
  `fmodified` string COMMENT '',
  `fnumiid` bigint COMMENT '',
  `fouterid` string COMMENT '',
  `fprice` string COMMENT '',
  `fproperties` string COMMENT '',
  `fpropertiesname` string COMMENT '',
  `fquantity` bigint COMMENT '',
  `fskudeliverytime` string COMMENT '',
  `fskuid` bigint COMMENT '',
  `fskuspecid` bigint COMMENT '',
  `fstatus` string COMMENT '',
  `fwithholdquantity` bigint COMMENT '',
  `fparentid` string COMMENT '',
  `fversion` bigint COMMENT '',
  `version` int COMMENT '',
  `fautoup` int COMMENT '',
  `fautodelist` int COMMENT '',
  `fautostuff` int COMMENT '',
  `fdelistvalue` decimal(28,10) COMMENT '',
  `fstuffvalue` decimal(28,10) COMMENT '',
  `fupqty` decimal(28,10) COMMENT '',
  `fupsuccess` int COMMENT '',
  `flastuptime` timestamp COMMENT '',
  `fupfailreason` string COMMENT '',
  `flastupdateuser` string COMMENT '',
  `ftenantid` bigint COMMENT '租户ID',
  `fsyncrate` decimal(5,2) COMMENT '同步比例',
  `fsyncmode` tinyint COMMENT '')
COMMENT '淘宝sku表';

--6 tbgoods
CREATE TABLE dw_dwd.dwd_jv_api_t_ec_tbgoods_fl_d(
  `fid` string COMMENT '',
  `faftersaleid` bigint COMMENT '',
  `fapprovestatus` string COMMENT '',
  `fauctionpoint` bigint COMMENT '',
  `fautofill` string COMMENT '',
  `fchangeprop` string COMMENT '',
  `fcid` bigint COMMENT '',
  `fcodpostageid` bigint COMMENT '',
  `fcreated` timestamp COMMENT '',
  `fdelisttime` timestamp COMMENT '',
  `fdesc` string COMMENT '',
  `fdetailurl` string COMMENT '',
  `femsfee` string COMMENT '',
  `fexpressfee` string COMMENT '',
  `ffeatures` string COMMENT '',
  `ffreightpayer` string COMMENT '',
  `fglobalstocktype` string COMMENT '',
  `fhasdiscount` int COMMENT '',
  `fhasinvoice` int COMMENT '',
  `fhasshowcase` int COMMENT '',
  `fhaswarranty` int COMMENT '',
  `fincrement` string COMMENT '',
  `finnershopauctiontemplateid` bigint COMMENT '',
  `finputpids` string COMMENT '',
  `finputstr` string COMMENT '',
  `fis3d` int COMMENT '',
  `fisex` int COMMENT '',
  `fisfenxiao` bigint COMMENT '',
  `fislightningconsignment` int COMMENT '',
  `fisprepay` int COMMENT '',
  `fistaobao` int COMMENT '',
  `fistiming` int COMMENT '',
  `fisvirtual` int COMMENT '',
  `fisxinpin` int COMMENT '',
  `fitemsize` string COMMENT '',
  `fitemweight` string COMMENT '',
  `flisttime` timestamp COMMENT '',
  `fmodified` timestamp COMMENT '',
  `fnick` string COMMENT '',
  `fnum` bigint COMMENT '',
  `fnumiid` bigint COMMENT '',
  `fonestation` int COMMENT '',
  `fouterid` string COMMENT '',
  `foutershopauctiontemplateid` bigint COMMENT '',
  `fpicurl` string COMMENT '',
  `fpostfee` string COMMENT '',
  `fpostageid` bigint COMMENT '',
  `fprice` string COMMENT '',
  `fproductid` bigint COMMENT '',
  `fpromotedservice` string COMMENT '',
  `fpropertyalias` string COMMENT '',
  `fprops` string COMMENT '',
  `fpropsname` string COMMENT '',
  `fscore` bigint COMMENT '',
  `fsecondkill` string COMMENT '',
  `fsellpoint` string COMMENT '',
  `fsellpromise` int COMMENT '',
  `fsellercids` string COMMENT '',
  `fstuffstatus` string COMMENT '',
  `fsubstock` bigint COMMENT '',
  `ftemplateid` string COMMENT '',
  `ftitle` string COMMENT '',
  `ftype` string COMMENT '',
  `fvalidthru` bigint COMMENT '',
  `fviolation` int COMMENT '',
  `fvolume` bigint COMMENT '',
  `fwapdesc` string COMMENT '',
  `fwapdetailurl` string COMMENT '',
  `fwithholdquantity` bigint COMMENT '',
  `fwwstatus` int COMMENT '',
  `fecplatformshopid` string COMMENT '',
  `fversion` bigint COMMENT '',
  `fisdelete` int COMMENT '',
  `fautoup` int COMMENT '',
  `fautodelist` int COMMENT '',
  `fautostuff` int COMMENT '',
  `fdelistvalue` decimal(28,10) COMMENT '',
  `fstuffvalue` decimal(28,10) COMMENT '',
  `fupqty` decimal(28,10) COMMENT '',
  `fupsuccess` int COMMENT '',
  `flastuptime` timestamp COMMENT '',
  `fupfailreason` string COMMENT '',
  `flastupdatetime` timestamp COMMENT '',
  `flastupdateuser` string COMMENT '',
  `ftenantid` bigint COMMENT '租户id',
  `fsyncrate` decimal(5,2) COMMENT '同步比例',
  `fsyncmode` tinyint COMMENT '',
  `numiid` bigint COMMENT '宝贝ID格式化后字段')
COMMENT '淘宝商品表';

CREATE TABLE dw_ods.ods_app_tmall_trade_fullinfo_get_topic_iu_h(`content` STRING)
COMMENT ''
PARTITIONED BY (`dt` STRING COMMENT '分区日期')
;

CREATE TABLE `dw_ods`.`ods_app_tmall_refund_get_topic_iu_h`(`content` STRING)
COMMENT ''
PARTITIONED BY (`dt` STRING COMMENT '分区日期')
;

CREATE TABLE `dw_ods`.`ods_app_tmall_items_seller_list_get_topic_iu_h`(`content` STRING)
COMMENT ''
PARTITIONED BY (`dt` STRING COMMENT '分区日期')
;

CREATE TABLE dw_dwd.dwd_app_omni_stock_pmc_purchase_order_item_fl_d(
  `id` bigint COMMENT '主键',
  `voucher_no` string COMMENT '单据号',
  `voucher_num` bigint COMMENT '采购数量',
  `voucher_amount` decimal(18,2) COMMENT '采购价格',
  `voucher_sum_amount` decimal(18,2) COMMENT '采购总金额',
  `product_name` string COMMENT '商品名称',
  `product_code` string COMMENT 'gtin',
  `product_id` string COMMENT '货品id',
  `tax_rate` string COMMENT '税率',
  `zeng_flag` int COMMENT '是否赠品 0否 1是',
  `history_store_num` bigint COMMENT '历史退货数量',
  `item_quantity` bigint COMMENT '此次单据对应商品行退货数量',
  `inventory_type` bigint COMMENT '库存类型:1  正品 101 残次 102 机损 103 箱损 201 冻结库存',
  `supplier_name` string COMMENT '供应商名称',
  `supplier_code` string COMMENT '供应商编码',
  `create_user_id` string COMMENT '',
  `update_user_id` string COMMENT '',
  `create_user_name` string COMMENT '',
  `update_user_name` string COMMENT '',
  `create_time` timestamp COMMENT '',
  `update_time` timestamp COMMENT '',
  `version` bigint COMMENT '',
  `deleted` int COMMENT '',
  `sort_id` bigint COMMENT '',
  `beconfirmed_number` bigint COMMENT '待确认数量',
  `confirmed_number` bigint COMMENT '已确认数量',
  `refuse_number` bigint COMMENT '已拒绝数量',
  `pack_number` bigint COMMENT '已打包数量',
  `shipped_number` bigint COMMENT '已发货数量',
  `shipment_rejected_number` bigint COMMENT '发货已拒绝数量',
  `cancel_number` bigint COMMENT '已取消数量',
  `receiving_number` bigint COMMENT '已收货数量',
  `gtin_status` int COMMENT '补货状态 1:待确认2:已确认 3:已拒绝 4:已打包 5:已发货 6:发货拒绝 7:已取消 8:已收货 ',
  `cancel_flag` bigint COMMENT '1.未取消\n2.取消中\n3.已取消',
  `purchase_po` string COMMENT '单据po (对应入库单据no)',
  `order_item_id` string COMMENT 'orderitemid',
  `refund_no` string COMMENT '退货单号',
  `delivery_no` string COMMENT '出库单号',
  `create_po_time` timestamp COMMENT '创建po的时间',
  `cost` string COMMENT 'ynap回传的采购价',
  `po_number` bigint COMMENT '下发po时用的数量',
  `order_id` bigint COMMENT '订单主表的id号(scm用)',
  `asn_inbound` timestamp COMMENT 'asn入库时间',
  `total_confirm_number` bigint COMMENT '已确认过后用于记录已确认数量的字段')
;






create table dw_dwd.dwd_ord_channel_omni_order_detail_fl_d
(
    sub_order_no                  string comment '子订单号',
    order_no                      string comment '订单号',
    delivery_no                   string comment '出库单号',
    gtin                          string comment 'gtin',
    po_no                         string comment '采购单号(采购中心)',
    logi_no                       string comment '国内物流单号',
    return_logi_no                string comment '国内退货物流单号',
    ynap_po_no                    string comment 'YNAP PO单号',
    ynap_order_no                 string comment 'YNAP订单号',
    ynap_shipment_no              string comment '包裹单号',
    ynap_logi_no                  string comment '国际物流单号',
    order_create_time             string comment '下单时间',
    order_pay_time                string comment '付款时间',
    push_ynap_order_time          string comment '推送给ynap时间',
    ynap_confirm_delivery_time    string comment 'YNAP订单确认时间',
    ynap_delivery_time            string comment 'YNAP订单单发货时间',
    ynap_enter_warehouse_time     string comment 'YNAP订单入本地仓时间',
    ynap_cancel_time              string comment 'YNAP取消时间',
    quantity                      string comment '商品件数',
    ynap_confirmed_quantity       string comment 'YNAP确认数量',
    ynap_shipped_quantity         string comment 'YNAP发货数量',
    ynap_delivery_reject_quantity string comment 'YNAP拒绝发货数量',
    local_receipt_quantity        string comment '本地仓收货数量'
) stored as orc;















create table dw_dwd.dwd_ord_channel_omni_ynap_order_detail_fl_d(
delivery_no                   string comment '出库单号',
order_no                      string comment '订单号',
gtin                          string comment '',
po_no                         string comment '采购单号(采购中心)',
logi_no                       string comment '国内物流单号',
return_logi_no                string comment '国内退货物流单号',
ynap_po_no                    string comment 'YNAP PO单号',
ynap_order_no                 string comment 'YNAP订单号',
ynap_shipment_no              string comment '包裹单号',
ynap_logi_no                  string comment '国际物流单号',
order_create_time             string comment '下单时间',
order_pay_time                string comment '付款时间',
push_ynap_order_time          string comment '推送给ynap时间',
ynap_confirm_delivery_time    string comment 'YNAP订单确认时间',
ynap_delivery_time            string comment 'YNAP订单单发货时间',
ynap_enter_warehouse_time     string comment 'YNAP订单入本地仓时间',
ynap_cancel_time              string comment 'YNAP取消时间',
quantity                      string comment '商品件数',
ynap_confirmed_quantity       string comment 'YNAP确认数量',
ynap_shipped_quantity         string comment 'YNAP发货数量',
ynap_delivery_reject_quantity string comment 'YNAP拒绝发货数量',
local_receipt_quantity        string comment '本地仓收货数量'
)stored as orc;



show create table dw_ads.ads_ord_omni_delivery_time_fl_d;



CREATE TABLE dw_dwd.dwd_app_omni_stock_pmc_push_ynap_fl_d(
  `id` bigint COMMENT '主键',
  `create_user_id` string COMMENT '创建人id',
  `update_user_id` string COMMENT '修改人id',
  `create_user_name` string COMMENT '创建人姓名',
  `update_user_name` string COMMENT '修改人姓名',
  `create_time` timestamp COMMENT '创建时间',
  `update_time` timestamp COMMENT '修改时间',
  `sort_id` bigint COMMENT '排序',
  `version` bigint COMMENT '版本号',
  `partner_id` bigint COMMENT '',
  `deleted` int COMMENT '状态 0未删除  1已删除',
  `shop_order` string COMMENT '采购中心的单据编号',
  `gtin` string COMMENT 'gtins',
  `num` bigint COMMENT '数量',
  `push_status` int COMMENT '推送ynap的状态:1 成功 2失败',
  `order_status` int COMMENT '订单的状态 1:采购订单 2:OMS订单 3:补货订单',
  `operation_status` int COMMENT '对YNAP的操作 1:新增 2:取消 3:交付',
  `request_detail` string COMMENT '请求体');


CREATE TABLE `dw_dwd.dwd_app_omni_stock_pmc_push_ynap_fl_d`(
  `id` bigint COMMENT '主键',
  `create_user_id` string COMMENT '创建人id',
  `update_user_id` string COMMENT '修改人id',
  `create_user_name` string COMMENT '创建人姓名',
  `update_user_name` string COMMENT '修改人姓名',
  `create_time` timestamp COMMENT '创建时间',
  `update_time` timestamp COMMENT '修改时间',
  `sort_id` bigint COMMENT '排序',
  `version` bigint COMMENT '版本号',
  `partner_id` bigint COMMENT '',
  `deleted` int COMMENT '状态 0未删除  1已删除',
  `shop_order` string COMMENT '采购中心的单据编号',
  `gtin` string COMMENT 'gtins',
  `num` bigint COMMENT '数量',
  `push_status` int COMMENT '推送ynap的状态:1 成功 2失败',
  `order_status` int COMMENT '订单的状态 1:采购订单 2:OMS订单 3:补货订单',
  `operation_status` int COMMENT '对YNAP的操作 1:新增 2:取消 3:交付',
  `request_detail` string COMMENT '请求体')
;

CREATE TABLE dw_dwd.dwd_app_omni_stock_pmc_purchase_order_fl_d(
  `id` bigint COMMENT '主键',
  `oms_order_no` string COMMENT 'oms订单号(出库单号)',
  `voucher_no` string COMMENT '单据编号',
  `voucher_status` int COMMENT '单据状态 1, "待提交"), 2, "待审核"), 3, "审核通过"), 4, "审核驳回"), 5, "待推送"), 6, "已推送"), 7, "已创建(终态)"), 8, "已取消(终态)")\; 9:"待YNAP确认"',
  `purchase_type` int COMMENT '采购类型  110 商品采购 120 寄售采购 114 initialbuy 115 replenishment 116 JIT 190 寄售Consignment',
  `supplier_name` string COMMENT '供应商名称',
  `supplier_code` string COMMENT '供应商编码',
  `trade_attribute` string COMMENT '贸易属性 JIT , INITIAL BUY , LOCAL BUY , REPLENISHMENT',
  `product_item_num` bigint COMMENT '商品item数量',
  `product_sum` bigint COMMENT '商品总数',
  `voucher_channel` string COMMENT '订单来源',
  `warehouse_name` string COMMENT '仓库名称',
  `warehouse_code` string COMMENT '仓库编码',
  `cargo_owner_id` string COMMENT '货主ID',
  `cargo_owner_name` string COMMENT '货主名称',
  `currency` string COMMENT '币别',
  `discount_rate` string COMMENT '折扣率',
  `tax_rate` string COMMENT '税率',
  `once_payment` string COMMENT '首付款比例',
  `twice_payment` string COMMENT '二段付款比例',
  `three_payment` string COMMENT '三段付款比例',
  `accounting_period` string COMMENT '账期',
  `remake` string COMMENT '驳回理由',
  `order_type` bigint COMMENT '单据类型 采购入库 601 , 采购收货 701 , 采购退货 901',
  `estimated_delivery_time_str` timestamp COMMENT '预计送达开始时间',
  `estimated_delivery_time_end` timestamp COMMENT '预计送达结束时间',
  `pre_flag` int COMMENT '是否预售 0false, 1true',
  `return_goods_item_num` bigint COMMENT '退货item数',
  `return_goods_item_num_sum` bigint COMMENT '退货item总数',
  `store_start_time` timestamp COMMENT '要求出库时间',
  `transport_mode` bigint COMMENT '出库方式 1自提 2非自提',
  `create_user_id` string COMMENT '',
  `update_user_id` string COMMENT '',
  `create_user_name` string COMMENT '',
  `update_user_name` string COMMENT '',
  `create_time` timestamp COMMENT '',
  `update_time` timestamp COMMENT '',
  `version` bigint COMMENT '',
  `deleted` int COMMENT '',
  `sort_id` bigint COMMENT '',
  `purchase_id` string COMMENT '单据号id(对应入库单据id)',
  `purchase_po` string COMMENT '单据po (对应入库单据no)',
  `his_flag` int COMMENT '是否历史数据 0false(展示) 1true(隐藏)',
  `status` int COMMENT '补货单据状态 1:待推送 2:已推送 3:已取消 4:全部拒绝 5:部分发货 6:全部发货 7:部分送达 8:全部送达',
  `order_remark` string COMMENT '订单备注',
  `oms_hide_flag` int COMMENT 'oms单据隐藏标识 0false(展示) 1true(隐藏)',
  `insert_flag` int COMMENT '页面新增标识 0false(非页面新增) 1true(页面新增)',
  `create_po_time` timestamp COMMENT '创建po的时间');
CREATE TABLE dw_dwd.dwd_app_omni_stock_pmc_replenish_ynap_fl_d(
  `id` bigint COMMENT '补货单据gtin行主键',
  `create_user_id` string COMMENT '创建人id',
  `update_user_id` string COMMENT '修改人id',
  `create_user_name` string COMMENT '创建人姓名',
  `update_user_name` string COMMENT '修改人姓名',
  `create_time` timestamp COMMENT '创建时间',
  `update_time` timestamp COMMENT '修改时间',
  `sort_id` bigint COMMENT '排序',
  `version` bigint COMMENT '版本号',
  `partner_id` bigint COMMENT '',
  `deleted` int COMMENT '状态 0未删除  1已删除',
  `order_code` string COMMENT 'YNAP的单据号',
  `shop_order` string COMMENT '采购中心的单据编号',
  `ynap_update_time` timestamp COMMENT 'YNAP修改时间',
  `gtin` string COMMENT 'gtin',
  `num` string COMMENT '数量',
  `ynap_status` string COMMENT 'ynap返回的状态 :Item Rejected ,Item Confirmed,Item Shipping Rejected,Item Preparing,Item Cancelled',
  `logi_no` string COMMENT 'ynap传入的快递号',
  `request_json` string COMMENT '请求实体',
  `shipment_no` string COMMENT 'ynap幂等号')
;








CREATE TABLE dw_dwd.dwd_ord_model_order_refund_detail_fl_d(
  `sub_order_no` bigint COMMENT '出库单号',
  `order_no` string COMMENT '订单编号',
  `refund_no` string COMMENT '退款单号',
  `platform_refund_no` string,
  `platform_order_no` string,
  `platform_sub_order_no` bigint COMMENT '订单行表主键',
  `sku_code` string COMMENT '商品编号',
  `sku_name` string COMMENT '商品名称',
  `refund_fee` double COMMENT '退款金额',
  `refund_cash_fee` double,
  `refund_prepay_card_amount` decimal(20,2),
  `refund_origin_prepay_card_amount` decimal(20,2),
  `refund_extra_prepay_card_amount` decimal(20,2),
  `return_quantity` bigint,
  `return_stock_quantity` bigint,
  `is_goods_return` bigint,
  `return_status` bigint,
  `tms_no` string,
  `create_time` timestamp COMMENT '退款提交时间',
  `update_time` timestamp COMMENT '更新时间',
  `dc_system_time` timestamp)
;







create table dw_dwd.dwd_ord_model_order_detail_label_fl_d
(
    sub_order_no                       string comment '子订单号',
    order_no                           string comment '订单号',
    platform_order_no                  string comment '源平台订单号:tmall/douyin/app oms订单号',
    platform_sub_order_no              string comment '源平台订单号:tmall/douyin/app oms订单号',
    sku_code                           string comment 'sku_code',
    cancel_before_shipment_on_same_day string comment '当天未发货订单取消',
    cancel_before_shipment             string comment '非当天未发货订单取消',
    cancel_refund_before_shipment      string comment '发货前退款取消订单',
    is_gift                            string comment '是否是赠品商品',
    create_time                        string comment '创建时间',
    update_time                        string comment '更新时间',
    dc_system_time                     string comment '数据中台系统处理时间'
)
stored as orc;












CREATE TABLE dw_dwd.dwd_ord_model_order_detail_label_fl_d(
  sub_order_no string COMMENT '子订单号',
  order_no string COMMENT '订单号',
  order_channel string COMMENT '订单渠道:TMALL/DOUYIN/APP/WEB/H5/MINIPROGRAM/OFFLINE',
  day date COMMENT '数据日期',
  memberid string COMMENT '会员id',
  sku_code string COMMENT '商品标识',
  order_amount decimal(10,2) COMMENT '下单金额',
  pay_amount decimal(10,2) COMMENT '付款金额',
  ship_amount decimal(10,2) COMMENT '发货金额',
  refund_apply_amount decimal(10,2) COMMENT '申退金额',
  refund_apply_success_amount decimal(10,2) COMMENT '退款成功金额',
  refund_cancel_amount decimal(10,2) COMMENT '发货前退款金额',
  refund_cancel_success_amount decimal(10,2) COMMENT '发货前退款成功金额',
  order_num bigint COMMENT '下单件数',
  pay_num bigint COMMENT '付款件数',
  ship_num bigint COMMENT '发货件数',
  refund_apply_num bigint COMMENT '申退件数',
  refund_apply_success_num bigint COMMENT '退款成功件数',
  refund_cancel_num bigint COMMENT '发货前退款件数',
  refund_cancel_success_num bigint COMMENT '发货前退款成功件数',
  exchange_rate_cny_to_eur decimal(10,2) COMMENT '人名币兑换欧元汇率',
  exchange_rate_eur_to_cny decimal(10,2) COMMENT '欧元兑换人名币汇率',
  tax_rate decimal(10,2) COMMENT '税率',
  cash_pay_amunt decimal(10,2) COMMENT '实付现金金额',
  prepay_card_amount decimal(10,2) COMMENT '购买预付卡金额',
  origin_prepay_card_amount decimal(10,2) COMMENT '购买预付卡本金金额',
  extra_prepay_card_amount decimal(10,2) COMMENT '购买预付卡赠送金额',
  use_prepay_card_amount decimal(10,2) COMMENT '使用预付卡总金额',
  use_origin_prepay_card_amount decimal(10,2) COMMENT '使用预付卡本金金额',
  use_extra_prepay_card_amount decimal(10,2) COMMENT '使用预付卡赠送金额',
  order_prepay_deposit_amount decimal(10,2) COMMENT '预售支付定金',
  create_time timestamp COMMENT '创建时间',
  update_time timestamp COMMENT '更新时间',
  dc_system_time timestamp COMMENT '数据中台系统处理时间')
;

CREATE TABLE dw_dwd.dwd_ord_model_order_detail_basic_index_fl_d(
  `sub_order_no` string COMMENT '子订单号',
  `order_no` string COMMENT '订单号',
  `order_channel` string COMMENT '订单渠道:TMALL/DOUYIN/APP/WEB/H5/MINIPROGRAM/OFFLINE',
  `day` date COMMENT '数据日期',
  `memberid` string COMMENT '会员id',
  `sku_code` string COMMENT '商品标识',
  `order_amount` decimal(10,2) COMMENT '下单金额',
  `pay_amount` decimal(10,2) COMMENT '付款金额',
  `ship_amount` decimal(10,2) COMMENT '发货金额',
  `refund_apply_amount` decimal(10,2) COMMENT '申退金额',
  `refund_apply_success_amount` decimal(10,2) COMMENT '退款成功金额',
  `refund_cancel_amount` decimal(10,2) COMMENT '发货前退款金额',
  `refund_cancel_success_amount` decimal(10,2) COMMENT '发货前退款成功金额',
  `order_num` bigint COMMENT '下单件数',
  `pay_num` bigint COMMENT '付款件数',
  `ship_num` bigint COMMENT '发货件数',
  `refund_apply_num` bigint COMMENT '申退件数',
  `refund_apply_success_num` bigint COMMENT '退款成功件数',
  `refund_cancel_num` bigint COMMENT '发货前退款件数',
  `refund_cancel_success_num` bigint COMMENT '发货前退款成功件数',
  `exchange_rate_cny_to_eur` decimal(10,2) COMMENT '人名币兑换欧元汇率',
  `exchange_rate_eur_to_cny` decimal(10,2) COMMENT '欧元兑换人名币汇率',
  `tax_rate` decimal(10,2) COMMENT '税率',
  `cash_pay_amunt` decimal(10,2) COMMENT '实付现金金额',
  `prepay_card_amount` decimal(10,2) COMMENT '购买预付卡金额',
  `origin_prepay_card_amount` decimal(10,2) COMMENT '购买预付卡本金金额',
  `extra_prepay_card_amount` decimal(10,2) COMMENT '购买预付卡赠送金额',
  `use_prepay_card_amount` decimal(10,2) COMMENT '使用预付卡总金额',
  `use_origin_prepay_card_amount` decimal(10,2) COMMENT '使用预付卡本金金额',
  `use_extra_prepay_card_amount` decimal(10,2) COMMENT '使用预付卡赠送金额',
  `order_prepay_deposit_amount` decimal(10,2) COMMENT '预售支付定金',
  `create_time` timestamp COMMENT '创建时间',
  `update_time` timestamp COMMENT '更新时间',
  `dc_system_time` timestamp COMMENT '数据中台系统处理时间')
;
CREATE TABLE dw_tmp.dwd_ord_refund_detail_fl_d(
  `create_time` string,
  `update_time` string,
  `fid` string COMMENT '',
  `order_no` string,
  `sub_order_no` string,
  `refund_sub_order_no` string COMMENT '退款单ID',
  `refund_create_time` timestamp COMMENT '',
  `refund_update_time` timestamp COMMENT '',
  `last_update_time` timestamp COMMENT '',
  `seller_nickname` string COMMENT '',
  `buyer_customer_no` string COMMENT '',
  `refund_cs_status` string,
  `refund_status` string COMMENT '',
  `refund_phase` string COMMENT '',
  `refund_goods_id` string COMMENT '',
  `refund_spu_id` string,
  `refund_goods_name` string COMMENT '',
  `refund_goods_status` string COMMENT '',
  `is_goods_return` string COMMENT '',
  `refund_ship_time` timestamp COMMENT '退货时间',
  `refund_logistics_company` string COMMENT '退回快递公司名称',
  `refund_logistics_no` string COMMENT '退回运单号',
  `seller_address` string COMMENT '卖家收货地址',
  `sale_platform` string,
  `refund_goods_num` bigint COMMENT '',
  `goods_total_amount` double,
  `refund_amount` double,
  `refund_reason` string COMMENT '',
  `refund_desc` string COMMENT '退款说明',
  `has_gift_card` string,
  `storage_confirm_time` timestamp,
  `collect_parcel_start_time` timestamp)
;







CREATE TABLE dw_dwd.dwd_ord_model_order_detail_basic_index_fl_d(
  sub_order_no string COMMENT '子订单号',
  order_no string COMMENT '订单号',
  order_channel string COMMENT '订单渠道:TMALL/DOUYIN/APP/WEB/H5/MINIPROGRAM/OFFLINE',
  day date COMMENT '数据日期',
  memberid string COMMENT '会员id',
  sku_code string COMMENT '商品标识',
  order_amount decimal(10,2) COMMENT '下单金额',
  pay_amount decimal(10,2) COMMENT '付款金额',
  ship_amount decimal(10,2) COMMENT '发货金额',
  refund_apply_amount decimal(10,2) COMMENT '申退金额',
  refund_apply_success_amount decimal(10,2) COMMENT '退款成功金额',
  refund_cancel_amount decimal(10,2) COMMENT '发货前退款金额',
  refund_cancel_success_amount decimal(10,2) COMMENT '发货前退款成功金额',
  order_num bigint COMMENT '下单件数',
  pay_num bigint COMMENT '付款件数',
  ship_num bigint COMMENT '发货件数',
  refund_apply_num bigint COMMENT '申退件数',
  refund_apply_success_num bigint COMMENT '退款成功件数',
  refund_cancel_num bigint COMMENT '发货前退款件数',
  refund_cancel_success_num bigint COMMENT '发货前退款成功件数',
  exchange_rate_cny_to_eur decimal(10,2) COMMENT '人名币兑换欧元汇率',
  exchange_rate_eur_to_cny decimal(10,2) COMMENT '欧元兑换人名币汇率',
  tax_rate decimal(10,2) COMMENT '税率',
  cash_pay_amunt decimal(10,2) COMMENT '实付现金金额',
  prepay_card_amount decimal(10,2) COMMENT '购买预付卡金额',
  origin_prepay_card_amount decimal(10,2) COMMENT '购买预付卡本金金额',
  extra_prepay_card_amount decimal(10,2) COMMENT '购买预付卡赠送金额',
  use_prepay_card_amount decimal(10,2) COMMENT '使用预付卡总金额',
  use_origin_prepay_card_amount decimal(10,2) COMMENT '使用预付卡本金金额',
  use_extra_prepay_card_amount decimal(10,2) COMMENT '使用预付卡赠送金额',
  order_prepay_deposit_amount decimal(10,2) COMMENT '预售支付定金',
  create_time timestamp COMMENT '创建时间',
  update_time timestamp COMMENT '更新时间',
  dc_system_time timestamp COMMENT '数据中台系统处理时间')
;





CREATE TABLE dw_dwd.dwd_ord_model_order_label_fl_d(
  order_no string COMMENT '订单号', 
  platform_order_no string COMMENT '源平台订单号', 
  is_use_prepay_card string COMMENT '是否使用预付卡(APP礼品卡/TMALL兑换卡)', 
  is_buy_prepay_card string COMMENT '是否购买预付卡', 
  is_installment string COMMENT '是否分期', 
  is_interest_free string COMMENT '是否免息', 
  is_special_refund string COMMENT '是否特殊退款', 
  payment_modes string COMMENT '支付方式(拼接)', 
  is_88vip string COMMENT '88VIP标签', 
  terminal_type string COMMENT '终端来源类型:web/ios/android', 
  is_staff_order string COMMENT '员工订单标记', 
  is_mobile_order string COMMENT '是否移动端订单', 
  is_preorder string COMMENT '是否预售订单', 
  is_member_order string COMMENT '下单时是否会员订单', 
  is_first_order string COMMENT '是否购买首单', 
  is_second_retreat string COMMENT '是否非秒退首单', 
  th_buy string COMMENT '订单第几次购买', 
  is_gift_order string COMMENT '赠品订单标记', 
  is_free_order string COMMENT '0元购订单', 
  is_test string COMMENT '是否测试订单', 
  app_order_type string COMMENT '订单类型:销售订单sale,线下订单offline,Pre-OrderpreOrder', 
  app_channel_code string COMMENT '渠道:APP,WEBSITE,EIP', 
  is_affiliate_user string COMMENT '是否是Affiliate用户', 
  city_level string COMMENT '地域等级', 
  create_time timestamp COMMENT '创建时间', 
  update_time timestamp COMMENT '更新时间', 
  dc_system_time timestamp COMMENT '数据中台系统处理时间'
  )
stored as orc;





















-- 源头 dwd给足
show create table dw_dwd.dwd_ynap_oms_tmall_order_fl_d;
CREATE TABLE dw_dwd.dwd_ynap_oms_tmall_order_fl_d(
  `id` bigint COMMENT '订单表主键',
  `sharding_key_order_no` string COMMENT '主单编号,用于分库分表拆分键使用',
  `channel_code` bigint COMMENT '渠道:APP,WEBSITE, EIP',
  `order_no` string COMMENT '订单编号',
  `login_code` string COMMENT '登录用户编号',
  `login_type` bigint COMMENT '会员身份:0-普通会员,1-EIP',
  `login_name` string COMMENT '用户名',
  `phone` string COMMENT '手机号',
  `order_amount` decimal(10,2) COMMENT '订单金额 (商品总金额)',
  `discount_amount` decimal(10,2) COMMENT '订单折扣金额(营销优惠)',
  `coupon_amount` decimal(10,2) COMMENT '订单优惠金额(优惠券)',
  `payable_amount` decimal(10,2) COMMENT '应支付金额',
  `refunded_amount` decimal(10,2) COMMENT '已退款金额',
  `order_status` bigint COMMENT '订单状态\r\n待付款 1\r\n交易关闭 2\r\n已付款 3\r\n待审核 4\r\n待发货 5\r\n待收货 6\r\n已签收 7\r\n延长售后 8\r\n交易完成(已签收未关闭售后入口) 9\r\n交易完成(已签收且已关闭售后入口) 10\r\n拦截失败-11\r\n退款中-12\r\n退款成功-13\r\n商品入库失败-14',
  `previewing_status` bigint COMMENT '预检状态(0-未预检,1-预检不通过,2-预检通过)',
  `previewing_reason` string COMMENT '预检失败原因',
  `payment_status` bigint COMMENT '付款状态\r\n1.未支付\r\n2.已支付\r\n3.已退款',
  `shipment_status` bigint COMMENT '出货状态 1 待发货 2 已取消 3 已发货 4已拒绝',
  `imanual_cancel_flag` bigint COMMENT '是否手动取消\r\n1-是 0-否',
  `invoice_code` string COMMENT '开票信息id,用户中心存储的开发票信息编号',
  `invoice_flag` bigint COMMENT '是否开票\r\n1-是 0-否',
  `invoice_status` bigint COMMENT '发票状态\r\n1-未开票\r\n2-已开票',
  `currency_code` string COMMENT '货币编号,默认RMB',
  `delivery_type` string COMMENT '送货方式,默认方式-快递',
  `payment_time` timestamp COMMENT '支付时间',
  `payment_balance_time` timestamp COMMENT '支付尾款时间',
  `receiving_address_code` string COMMENT '收货地址id',
  `receiver_phone_number` string COMMENT '收货人手机号',
  `receiver_name` string COMMENT '收货人',
  `receiving_address` string COMMENT '收货地址',
  `receiving_address_decrypt` string,
  `card_content` string COMMENT '贺卡内容',
  `package_type` bigint COMMENT '包装类型',
  `package_name` string COMMENT '包装类型名称',
  `order_type` bigint COMMENT '订单类型:\r\n销售订单 sale\r\n线下订单 offline\r\nPre-Order preOrder',
  `pay_times` bigint COMMENT '发起支付次数\r\n调用支付中心发起支付接口单号 = 订单号+支付次数',
  `order_remark` string COMMENT '订单备注',
  `refund_remark` string COMMENT '破例退货备注',
  `cs_remark` string COMMENT '客服备注',
  `create_user_id` string COMMENT '创建人id',
  `update_user_id` string COMMENT '修改人id',
  `create_user_name` string COMMENT '创建人姓名',
  `update_user_name` string COMMENT '修改人姓名',
  `create_time` timestamp COMMENT '创建时间',
  `update_time` timestamp COMMENT '修改时间',
  `sort_id` bigint,
  `version` bigint COMMENT '版本号',
  `deleted` bigint COMMENT '状态 0未删除  1已删除',
  `order_time` timestamp COMMENT '下单时间',
  `freight` decimal(10,2) COMMENT '运费',
  `partner_id` bigint,
  `sync_status` bigint COMMENT '同步OMS状态:0-未同步,1-同步成功,2-同步失败',
  `ps_user_id` string COMMENT 'PS客服编号',
  `shops` string COMMENT '店铺',
  `serial_number` string COMMENT 'excel导入编号',
  `sub_channel` bigint COMMENT '订单来源',
  `operator` string COMMENT '操作人',
  `freight_refund_flag` bigint COMMENT '是否已退运费',
  `system_source` bigint COMMENT '系统来源  1 IOS 2 安卓 3PC 4E EIP',
  `ps_submit_flag` bigint COMMENT '是否是PS代客下单',
  `user_grade` bigint COMMENT '会员下单等级',
  `points` decimal(10,2) COMMENT '积分',
  `buyer_name` string COMMENT '礼品卡购买人姓名',
  `id_number` string COMMENT '礼品卡购买人身份证',
  `buyer_phone_number` string COMMENT '礼品卡购买人手机',
  `refunded_card_amount` decimal(10,2) COMMENT '已退款礼品卡金额',
  `affiliate_flag` bigint COMMENT '是否是Affiliate用户',
  `user_tag_ids` string COMMENT '下单是用户命中的标签id',
  `use_card_amount` decimal(10,2) COMMENT '礼品卡使用金额',
  `residue_amount` decimal(10,2) COMMENT '剩余应付金额 (扣除礼品卡后的支付现金)',
  `rel_order_no` string COMMENT '第三方数据订单编号',
  `dy_refund_flag` bigint COMMENT '抖音订单退款标志\r\n0:未退款\r\n1.未开票订单:请在发票后台开具蓝票\r\n2.已开票订单:请在发票后台红冲后重新开蓝票\r\n3.开票金额和OMS金额不一致,冲红后开票\r\n4:发生邮件成功\r\n5:发生邮件失败\r\n',
  `user_tags` string COMMENT '下单是用户命中的标签',
  `utm_source` string,
  `utm_content` string,
  `is_douyin_notstock` bigint COMMENT '抖音未预占库存就发生退款标识',
  `good_stock` bigint COMMENT '订单是否全部现货 1是 2否',
  `right_jit` bigint COMMENT '订单是否存在JIT商品 1是 2否',
  `oaid` string COMMENT 'oaid',
  `package_time` timestamp COMMENT '',
  `pay_type` string COMMENT '支付方式1.微信 2.支付宝 3.银联',
  `buyer_memo` string COMMENT '')
;

CREATE TABLE dw_dwd.dwd_ynap_oms_tmall_order_item_fl_d(
  `id` bigint COMMENT '订单行表主键',
  `order_item_no` string COMMENT '订单行编号',
  `sharding_key_order_no` string COMMENT '主单编号,用于分库分表拆分键使用',
  `product_code` string COMMENT '商品sku号',
  `spu_code` string COMMENT '商品spu号',
  `model_code` string COMMENT 'model_code',
  `product_quantity` bigint COMMENT '商品数量',
  `batch_code` string COMMENT '库存批次号 PO',
  `unit_price` decimal(10,2) COMMENT '商品单价',
  `product_name` string COMMENT '商品名称',
  `product_image` string COMMENT '商品图片',
  `order_line_type` bigint COMMENT '1:普通产品;\r\n2:购物车赠品\r\n3:商品赠品',
  `gift_flag` bigint COMMENT '是否是赠品 true 是 false 不是',
  `promotion_code` string COMMENT '促销编号',
  `promotion_name` string COMMENT '促销名称',
  `gift_source_sku_code` string COMMENT '赠品来源商品编号',
  `virtual_warehouse_code` string COMMENT '仓存编号',
  `returnable_flag` bigint COMMENT '是否可作退货,某些产品购买后不能作退货',
  `product_label` string COMMENT '商品标签',
  `order_item_status` bigint COMMENT '订单行状态 待付款 1\n交易关闭 2\n已付款 3\n待审核 4\n待发货 5\n待收货 6\n已签收 7\n延长售后 8\n交易完成(已签收未关闭售后入口) 9\n交易完成(已签收且已关闭售后入口) 10\n拦截失败-11\n退款中-12\n退款成功-13\n商品入库失败-14',
  `intercept_status` bigint COMMENT '拦截状态 -1 失败 1 成功',
  `aftersales_time` timestamp COMMENT '延长售后时间',
  `trading_closed_time` timestamp COMMENT '交易关闭时间',
  `create_user_id` string,
  `update_user_id` string,
  `version` bigint,
  `deleted` bigint COMMENT '0 删除 1 未删除',
  `create_user_name` string,
  `update_user_name` string,
  `create_time` timestamp,
  `update_time` timestamp,
  `sort_id` bigint,
  `partner_id` bigint,
  `product_markdown_price` decimal(10,2) COMMENT 'markdown价格',
  `product_eip_price` decimal(10,2) COMMENT 'EIP价格',
  `tms_service_code` string COMMENT '物流公司编号',
  `tms_service_name` string COMMENT '物流公司名称',
  `tms_number` string COMMENT '物流编号',
  `category_code` string COMMENT '商品销售一级类目',
  `brand_name` string COMMENT '品牌英文名',
  `product_size` string COMMENT '商品尺码',
  `product_colour` string COMMENT '商品颜色',
  `actually_amount` decimal(10,2) COMMENT '实付金额',
  `virtual_category` string COMMENT '虚拟类目',
  `delivery_item_no` bigint COMMENT '出库单号',
  `sku_product_label` string COMMENT 'sku标签',
  `spu_product_label` string COMMENT 'spu标签',
  `sku_tag_label` string COMMENT 'sku所有标签',
  `invoice_amount` decimal(10,2) COMMENT '开票金额',
  `refund_amount` decimal(10,2) COMMENT '退款金额',
  `reserve_stock_number` string COMMENT 'EIP预留商品预占单号',
  `freight` decimal(10,2) COMMENT '运费分摊(抖音用)',
  `sale_day` bigint COMMENT '下单时配置的售后期',
  `tms_number_flag` bigint COMMENT '下单时退货退款物流设置标识 0 不向宝尊申请物流单号 ,1 向宝尊申请物流单号',
  `check_jit` bigint COMMENT '是否是jit商品 1是 2否',
  `jit_stcok` bigint COMMENT '是否现货 1是 2否',
  `omni_stock_num` bigint COMMENT 'omni-库存分配记录数量使用',
  `asn_stock_num` bigint COMMENT 'omni-ASN记录数量使用',
  `oid` string COMMENT '天猫发货通知',
  `package_type` bigint COMMENT '包装类型');
CREATE TABLE dw_dwd.dwd_ynap_oms_tmall_order_delivery_fl_d(
  `id` bigint COMMENT '主键',
  `order_no` string COMMENT '订单编号',
  `sharding_key_order_no` string COMMENT '团单编号,用于分库分表拆分键使用',
  `delivery_no` string COMMENT '出库单编号',
  `virtual_warehouse_code` string COMMENT '虚拟仓库编号',
  `product_quantity` bigint COMMENT '商品数量',
  `delivery_status` bigint COMMENT '出库单状态\r\n待发货-1\r\n取消-2\r\n已发货-3\r\n已签收-4\r\n已拒收-5',
  `tms_service_code` string COMMENT '物流公司编号',
  `tms_service_name` string COMMENT '物流公司名称',
  `tms_number` string COMMENT '物流编号',
  `receiving_address_code` string COMMENT '收货地址id',
  `receiving_address` string COMMENT '收货地址',
  `receiver_name` string COMMENT '收货人',
  `receiver_phone_number` string COMMENT '收货人手机号',
  `shipping_address` string COMMENT '发货地址',
  `consignee_name` string COMMENT '收货人',
  `consignee_phone_number` string COMMENT '收货人电话',
  `deleted` bigint COMMENT '状态 0未删除 1已删除',
  `intercept_status` bigint COMMENT '拦截状态 -1拦截失败  1 拦截成功',
  `create_time` timestamp,
  `update_time` timestamp,
  `version` bigint COMMENT '数据版本',
  `sort_id` bigint COMMENT '显示顺序',
  `partner_id` bigint COMMENT '合作方id',
  `create_user_name` string COMMENT '创建用户名',
  `create_user_id` string COMMENT '创建uid',
  `update_user_name` string COMMENT '更新用户名',
  `update_user_id` string COMMENT '更新uid',
  `stock_number` string COMMENT '仓库编号',
  `order_remark` string COMMENT '订单备注',
  `phone` string COMMENT '会员手机号',
  `rel_order_no` string COMMENT '第三方数据订单编号',
  `channel` bigint COMMENT '渠道',
  `user_tags` string COMMENT '下单是用户命中的标签',
  `user_tag_ids` string,
  `delivery_type` bigint COMMENT '出库单类型 1.非JIT 2.JIT现货 3.JIT非现货',
  `send_ecc` bigint COMMENT '是否下发ecc 0未下发  1已下发  omni专用',
  `package_type` bigint);
CREATE TABLE dw_dwd.dwd_ynap_oms_tmall_order_delivery_items_fl_d(
  `id` bigint,
  `sharding_key_order_no` string COMMENT '团单编号,用于分库分表拆分键使用',
  `delivery_no` string COMMENT '出库单编号',
  `delevery_item_no` string COMMENT '出库单行编号',
  `sku_code` string COMMENT '商品编号',
  `product_quantity` bigint COMMENT '商品数量',
  `product_name` string COMMENT '商品名称',
  `product_img_url` string COMMENT '商品图片url',
  `item_type` bigint COMMENT '1:普通商品;\r\n2:购物车赠品\r\n3:商品赠品',
  `stock_number` string COMMENT '仓库编号',
  `virtual_warehouse_code` string COMMENT '虚拟仓库编号',
  `delivery_line_status` bigint COMMENT '商品行状态',
  `push_status` bigint COMMENT '推送状态\r\n已推送-1\r\n无需推送-2\r\n已取消-3',
  `deleted` bigint COMMENT '状态 0未删除 1已删除',
  `order_item_state` string COMMENT '订单行的状态',
  `create_time` timestamp,
  `update_time` timestamp,
  `version` bigint COMMENT '数据版本',
  `sort_id` bigint COMMENT '显示顺序',
  `partner_id` bigint COMMENT '合作方id',
  `create_user_name` string COMMENT '创建用户名',
  `create_user_id` string COMMENT '创建uid',
  `update_user_name` string COMMENT '更新用户名',
  `update_user_id` string COMMENT '更新uid',
  `jit_stock` bigint COMMENT '是否现货 1现货 2非现货',
  `package_type` bigint);
CREATE TABLE dw_dwd.dwd_ynap_oms_tmall_order_fl_d(
  `id` bigint COMMENT '订单表主键',
  `sharding_key_order_no` string COMMENT '主单编号,用于分库分表拆分键使用',
  `channel_code` bigint COMMENT '渠道:APP,WEBSITE, EIP',
  `order_no` string COMMENT '订单编号',
  `login_code` string COMMENT '登录用户编号',
  `login_type` bigint COMMENT '会员身份:0-普通会员,1-EIP',
  `login_name` string COMMENT '用户名',
  `phone` string COMMENT '手机号',
  `order_amount` decimal(10,2) COMMENT '订单金额 (商品总金额)',
  `discount_amount` decimal(10,2) COMMENT '订单折扣金额(营销优惠)',
  `coupon_amount` decimal(10,2) COMMENT '订单优惠金额(优惠券)',
  `payable_amount` decimal(10,2) COMMENT '应支付金额',
  `refunded_amount` decimal(10,2) COMMENT '已退款金额',
  `order_status` bigint COMMENT '订单状态\r\n待付款 1\r\n交易关闭 2\r\n已付款 3\r\n待审核 4\r\n待发货 5\r\n待收货 6\r\n已签收 7\r\n延长售后 8\r\n交易完成(已签收未关闭售后入口) 9\r\n交易完成(已签收且已关闭售后入口) 10\r\n拦截失败-11\r\n退款中-12\r\n退款成功-13\r\n商品入库失败-14',
  `previewing_status` bigint COMMENT '预检状态(0-未预检,1-预检不通过,2-预检通过)',
  `previewing_reason` string COMMENT '预检失败原因',
  `payment_status` bigint COMMENT '付款状态\r\n1.未支付\r\n2.已支付\r\n3.已退款',
  `shipment_status` bigint COMMENT '出货状态 1 待发货 2 已取消 3 已发货 4已拒绝',
  `imanual_cancel_flag` bigint COMMENT '是否手动取消\r\n1-是 0-否',
  `invoice_code` string COMMENT '开票信息id,用户中心存储的开发票信息编号',
  `invoice_flag` bigint COMMENT '是否开票\r\n1-是 0-否',
  `invoice_status` bigint COMMENT '发票状态\r\n1-未开票\r\n2-已开票',
  `currency_code` string COMMENT '货币编号,默认RMB',
  `delivery_type` string COMMENT '送货方式,默认方式-快递',
  `payment_time` timestamp COMMENT '支付时间',
  `payment_balance_time` timestamp COMMENT '支付尾款时间',
  `receiving_address_code` string COMMENT '收货地址id',
  `receiver_phone_number` string COMMENT '收货人手机号',
  `receiver_name` string COMMENT '收货人',
  `receiving_address` string COMMENT '收货地址',
  `receiving_address_decrypt` string,
  `card_content` string COMMENT '贺卡内容',
  `package_type` bigint COMMENT '包装类型',
  `package_name` string COMMENT '包装类型名称',
  `order_type` bigint COMMENT '订单类型:\r\n销售订单 sale\r\n线下订单 offline\r\nPre-Order preOrder',
  `pay_times` bigint COMMENT '发起支付次数\r\n调用支付中心发起支付接口单号 = 订单号+支付次数',
  `order_remark` string COMMENT '订单备注',
  `refund_remark` string COMMENT '破例退货备注',
  `cs_remark` string COMMENT '客服备注',
  `create_user_id` string COMMENT '创建人id',
  `update_user_id` string COMMENT '修改人id',
  `create_user_name` string COMMENT '创建人姓名',
  `update_user_name` string COMMENT '修改人姓名',
  `create_time` timestamp COMMENT '创建时间',
  `update_time` timestamp COMMENT '修改时间',
  `sort_id` bigint,
  `version` bigint COMMENT '版本号',
  `deleted` bigint COMMENT '状态 0未删除  1已删除',
  `order_time` timestamp COMMENT '下单时间',
  `freight` decimal(10,2) COMMENT '运费',
  `partner_id` bigint,
  `sync_status` bigint COMMENT '同步OMS状态:0-未同步,1-同步成功,2-同步失败',
  `ps_user_id` string COMMENT 'PS客服编号',
  `shops` string COMMENT '店铺',
  `serial_number` string COMMENT 'excel导入编号',
  `sub_channel` bigint COMMENT '订单来源',
  `operator` string COMMENT '操作人',
  `freight_refund_flag` bigint COMMENT '是否已退运费',
  `system_source` bigint COMMENT '系统来源  1 IOS 2 安卓 3PC 4E EIP',
  `ps_submit_flag` bigint COMMENT '是否是PS代客下单',
  `user_grade` bigint COMMENT '会员下单等级',
  `points` decimal(10,2) COMMENT '积分',
  `buyer_name` string COMMENT '礼品卡购买人姓名',
  `id_number` string COMMENT '礼品卡购买人身份证',
  `buyer_phone_number` string COMMENT '礼品卡购买人手机',
  `refunded_card_amount` decimal(10,2) COMMENT '已退款礼品卡金额',
  `affiliate_flag` bigint COMMENT '是否是Affiliate用户',
  `user_tag_ids` string COMMENT '下单是用户命中的标签id',
  `use_card_amount` decimal(10,2) COMMENT '礼品卡使用金额',
  `residue_amount` decimal(10,2) COMMENT '剩余应付金额 (扣除礼品卡后的支付现金)',
  `rel_order_no` string COMMENT '第三方数据订单编号',
  `dy_refund_flag` bigint COMMENT '抖音订单退款标志\r\n0:未退款\r\n1.未开票订单:请在发票后台开具蓝票\r\n2.已开票订单:请在发票后台红冲后重新开蓝票\r\n3.开票金额和OMS金额不一致,冲红后开票\r\n4:发生邮件成功\r\n5:发生邮件失败\r\n',
  `user_tags` string COMMENT '下单是用户命中的标签',
  `utm_source` string,
  `utm_content` string,
  `is_douyin_notstock` bigint COMMENT '抖音未预占库存就发生退款标识',
  `good_stock` bigint COMMENT '订单是否全部现货 1是 2否',
  `right_jit` bigint COMMENT '订单是否存在JIT商品 1是 2否',
  `oaid` string COMMENT 'oaid',
  `package_time` timestamp COMMENT '',
  `pay_type` string COMMENT '支付方式1.微信 2.支付宝 3.银联',
  `buyer_memo` string COMMENT '');
CREATE TABLE dw_dwd.dwd_ynap_oms_tmall_order_item_fl_d(
  `id` bigint COMMENT '订单行表主键',
  `order_item_no` string COMMENT '订单行编号',
  `sharding_key_order_no` string COMMENT '主单编号,用于分库分表拆分键使用',
  `product_code` string COMMENT '商品sku号',
  `spu_code` string COMMENT '商品spu号',
  `model_code` string COMMENT 'model_code',
  `product_quantity` bigint COMMENT '商品数量',
  `batch_code` string COMMENT '库存批次号 PO',
  `unit_price` decimal(10,2) COMMENT '商品单价',
  `product_name` string COMMENT '商品名称',
  `product_image` string COMMENT '商品图片',
  `order_line_type` bigint COMMENT '1:普通产品;\r\n2:购物车赠品\r\n3:商品赠品',
  `gift_flag` bigint COMMENT '是否是赠品 true 是 false 不是',
  `promotion_code` string COMMENT '促销编号',
  `promotion_name` string COMMENT '促销名称',
  `gift_source_sku_code` string COMMENT '赠品来源商品编号',
  `virtual_warehouse_code` string COMMENT '仓存编号',
  `returnable_flag` bigint COMMENT '是否可作退货,某些产品购买后不能作退货',
  `product_label` string COMMENT '商品标签',
  `order_item_status` bigint COMMENT '订单行状态 待付款 1\n交易关闭 2\n已付款 3\n待审核 4\n待发货 5\n待收货 6\n已签收 7\n延长售后 8\n交易完成(已签收未关闭售后入口) 9\n交易完成(已签收且已关闭售后入口) 10\n拦截失败-11\n退款中-12\n退款成功-13\n商品入库失败-14',
  `intercept_status` bigint COMMENT '拦截状态 -1 失败 1 成功',
  `aftersales_time` timestamp COMMENT '延长售后时间',
  `trading_closed_time` timestamp COMMENT '交易关闭时间',
  `create_user_id` string,
  `update_user_id` string,
  `version` bigint,
  `deleted` bigint COMMENT '0 删除 1 未删除',
  `create_user_name` string,
  `update_user_name` string,
  `create_time` timestamp,
  `update_time` timestamp,
  `sort_id` bigint,
  `partner_id` bigint,
  `product_markdown_price` decimal(10,2) COMMENT 'markdown价格',
  `product_eip_price` decimal(10,2) COMMENT 'EIP价格',
  `tms_service_code` string COMMENT '物流公司编号',
  `tms_service_name` string COMMENT '物流公司名称',
  `tms_number` string COMMENT '物流编号',
  `category_code` string COMMENT '商品销售一级类目',
  `brand_name` string COMMENT '品牌英文名',
  `product_size` string COMMENT '商品尺码',
  `product_colour` string COMMENT '商品颜色',
  `actually_amount` decimal(10,2) COMMENT '实付金额',
  `virtual_category` string COMMENT '虚拟类目',
  `delivery_item_no` bigint COMMENT '出库单号',
  `sku_product_label` string COMMENT 'sku标签',
  `spu_product_label` string COMMENT 'spu标签',
  `sku_tag_label` string COMMENT 'sku所有标签',
  `invoice_amount` decimal(10,2) COMMENT '开票金额',
  `refund_amount` decimal(10,2) COMMENT '退款金额',
  `reserve_stock_number` string COMMENT 'EIP预留商品预占单号',
  `freight` decimal(10,2) COMMENT '运费分摊(抖音用)',
  `sale_day` bigint COMMENT '下单时配置的售后期',
  `tms_number_flag` bigint COMMENT '下单时退货退款物流设置标识 0 不向宝尊申请物流单号 ,1 向宝尊申请物流单号',
  `check_jit` bigint COMMENT '是否是jit商品 1是 2否',
  `jit_stcok` bigint COMMENT '是否现货 1是 2否',
  `omni_stock_num` bigint COMMENT 'omni-库存分配记录数量使用',
  `asn_stock_num` bigint COMMENT 'omni-ASN记录数量使用',
  `oid` string COMMENT '天猫发货通知',
  `package_type` bigint COMMENT '包装类型');
CREATE TABLE dw_dwd.dwd_ynap_oms_tmall_order_refund_fl_d(
  `id` bigint COMMENT '主键id',
  `order_no` string COMMENT '订单编号',
  `sharding_key_order_no` string COMMENT '团单编号,用于分库分表拆分键使用',
  `operate_type` bigint COMMENT '操作类型:1、退款(发货前) 2、退款(发货后) 3 退货退款',
  `refund_no` string COMMENT '退款单号',
  `total_fee` decimal(10,2) COMMENT '原订单金额',
  `login_ada` string COMMENT '操作用户',
  `login_user_name` string COMMENT '用户名称',
  `order_status` bigint COMMENT '订单的状态',
  `refund_status` bigint COMMENT '退款状态',
  `goods_status` bigint COMMENT '货物状态',
  `has_good_return` bigint COMMENT '买家是否需要退货',
  `refund_fee` decimal(10,2) COMMENT '退款金额',
  `payment` decimal(10,2) COMMENT '订单剩余为退款金额(交易总金额-退还给买家的金额)',
  `reason` string COMMENT '退款原因',
  `refund_desc` string COMMENT '退款说明',
  `tms_service_code` string COMMENT '物流公司编号',
  `tms_service_name` string COMMENT '物流公司名称',
  `tms_number` string COMMENT '物流编号',
  `refund_version` bigint COMMENT '退款版本号(时间戳)',
  `deleted` bigint COMMENT '是否删除 0 未删除 1已删除',
  `create_time` timestamp COMMENT '退款提交时间',
  `update_time` timestamp COMMENT '更新时间',
  `collect_parcel_start_time` timestamp COMMENT '上门取件开始时间',
  `collect_parcel_end_time` timestamp COMMENT '上门取件结束时间',
  `images` string,
  `receiving_address` string COMMENT '收货地址',
  `receiver_name` string COMMENT '收货人',
  `receiver_phone_number` string COMMENT '收货人手机号',
  `shipping_address` string COMMENT '发货地址',
  `consignor_name` string COMMENT '发货人',
  `consignor_phone_number` string COMMENT '发货人手机号',
  `partner_id` string COMMENT '合作方id',
  `sort_id` bigint COMMENT '排序字段',
  `version` bigint COMMENT '版本号',
  `create_user_name` string COMMENT '创建人',
  `update_user_name` string COMMENT '修改人',
  `create_user_id` string,
  `update_user_id` string,
  `batch_code` string COMMENT '批次号 PO号',
  `store_code` string COMMENT '仓库编号',
  `delivery_no` string COMMENT '出库单编号',
  `channel_code` bigint COMMENT '渠道来源 1APP',
  `refuse_reason` string COMMENT '拒绝原因',
  `freight` decimal(10,2) COMMENT '运费',
  `refund_type` bigint COMMENT '1:app 2:oms',
  `storage_cofirm_time` timestamp COMMENT '确认入库时间',
  `refuse_storage_reason` string,
  `previewing_reason` string COMMENT '预检失败原因',
  `phone` string COMMENT '会员手机号',
  `user_grade` bigint COMMENT '会员下单等级',
  `refund_card_amount` decimal(10,2) COMMENT '礼品卡退款金额',
  `refund_cash_amount` decimal(10,2) COMMENT '现金退款金额',
  `gift_card_service_charge` decimal(20,2) COMMENT '礼品卡退卡手续费',
  `rel_order_no` string COMMENT '第三方数据订单编号',
  `rel_refund_no` string COMMENT '第三方数据销退单号',
  `refund_priority` bigint COMMENT '退款优先级 1-优先退礼品卡 2-优先退现金',
  `user_tag_ids` string COMMENT '下单时用户命中的标签',
  `cs_remark` string COMMENT '客服备注',
  `user_tags` string COMMENT '下单是用户命中的标签',
  `tms_number_flag` bigint COMMENT '下单时退货退款物流设置标识 0 不向宝尊申请物流单号 1 ,向宝尊申请物流单号',
  `is_automatic` bigint COMMENT '抖音是否自动退货退款 1:是 2:不是',
  `sync_stock` bigint COMMENT '抖音发货前退款同步全量库存 0 否,1 是',
  `wms_times` bigint COMMENT '下发wms后缀');
CREATE TABLE dw_dwd.dwd_ynap_oms_tmall_order_refund_items_fl_d(
  `id` bigint COMMENT '主键id',
  `order_no` string COMMENT '订单编号',
  `sharding_key_order_no` string COMMENT '团单编号,用于分库分表拆分键使用',
  `refund_no` string COMMENT '退款单号',
  `sku_code` string COMMENT '商品编号',
  `product_name` string COMMENT '商品名称',
  `product_img_url` string COMMENT '商品图片url',
  `quantity` bigint COMMENT '数量',
  `store_code` string COMMENT '仓储编号',
  `batch_code` string COMMENT '批次号,PO',
  `original_price` decimal(10,2) COMMENT '商品原价格',
  `deleted` bigint COMMENT '是否删除 0 未删除 1已删除',
  `refund_item_status` bigint COMMENT '销退单行状态',
  `create_time` timestamp COMMENT '退款提交时间',
  `update_time` timestamp COMMENT '更新时间',
  `actually_amount` decimal(10,2) COMMENT '商品实付金额',
  `gift_source_sku_code` string COMMENT '赠品来源商品编号',
  `gift_flag` bigint COMMENT '是否是赠品',
  `sku_type` bigint COMMENT '1 普通商品  2 订单级别 3 商品级别',
  `promotion_code` string COMMENT '促销编号',
  `promotion_name` string COMMENT '促销名称',
  `brand_name` string COMMENT '品牌英文名',
  `product_attr` string COMMENT '商品颜色尺码',
  `product_markdown_price` decimal(10,2) COMMENT 'markdown价格',
  `product_eip_price` decimal(10,2) COMMENT 'ELP价格',
  `partner_id` string COMMENT '合作方id',
  `sort_id` bigint COMMENT '排序号',
  `version` bigint COMMENT '版本号',
  `create_user_name` string COMMENT '创建人',
  `update_user_name` string COMMENT '修改人',
  `create_user_id` string COMMENT '',
  `update_user_id` string,
  `delivery_item_no` string COMMENT '出库单号',
  `order_item_status` bigint COMMENT '原订单行状态',
  `refund_fee` decimal(10,2) COMMENT '退款金额',
  `spu_code` string COMMENT 'spu_code');
CREATE TABLE dw_dwd.dwd_ynap_oms_tmall_payment_items_fl_d(
  `id` bigint COMMENT '交易流水表主键',
  `order_no` string COMMENT '订单号',
  `sharding_key_order_no` string COMMENT '订单编号,用于分库分表拆分键使用',
  `payment_code` string COMMENT '支付方式小类别(分期数),注意,此时记录的是发起支付时选择的分期数,由于PC端支付时用户可以改分期数,因此分期期数可能和实际用户选择的分期数可能不一样',
  `payment_mode` bigint COMMENT '支付方式 微信-wechat,支付宝-alipay,银联-uniepay,积分-points',
  `payment_amount` decimal(10,2) COMMENT '支付金额',
  `payment_total_amount` decimal(10,2) COMMENT '应支付总金额',
  `points` decimal(10,2) COMMENT '积分',
  `transaction_no` string COMMENT '交易流水号',
  `transaction_status` bigint COMMENT '交易状态',
  `transaction_type` bigint COMMENT '交易类型,1-支付 2-退款',
  `trade_order_no` string COMMENT '支付中心返回的订单编号',
  `bank_trade_no` string COMMENT '支付中心返回的银行流水号',
  `deleted` bigint COMMENT '是否删除 1删除 0 未删除',
  `create_user_id` string,
  `update_user_id` string,
  `create_user_name` string,
  `update_user_name` string,
  `sort_id` bigint COMMENT '排序值',
  `version` bigint COMMENT '版本号',
  `create_time` timestamp COMMENT '创建时间',
  `update_time` timestamp COMMENT '修改时间',
  `partner_id` string COMMENT '合作方id',
  `channel_code` bigint COMMENT '渠道来源 1 安卓 2 IOS',
  `merch_no` string COMMENT '商户号',
  `terminal_no` string COMMENT '终端号',
  `qr_code_id` string COMMENT '二维码ID',
  `refund_no` string COMMENT '销退单号',
  `txn_time` string COMMENT '银联直连商户发送交易时间',
  `direct_flag` bigint COMMENT '银联支付流水标识 1 直连 , 2 间连 ');
CREATE TABLE dw_dwd.dwd_order_oms_tmall_sync_time_fl_d(
  `id` bigint COMMENT '表主键',
  `order_no` string COMMENT '订单编号',
  `sku` string COMMENT '商品sku',
  `virtual_warehouse_code` string COMMENT '仓存编号',
  `child_order_delivery_time` timestamp COMMENT '子订单发货时间',
  `child_order_receive_time` timestamp COMMENT '子订单签收时间',
  `child_order_success_time` timestamp COMMENT '子订单交易成功时间',
  `child_order_cancel_time` timestamp COMMENT '子订单交易关闭时间',
  `child_order_refund_time` timestamp COMMENT '子订单退货发起时间',
  `child_order_refund_parcel_time` timestamp COMMENT '子订单退货上门揽件时间',
  `child_order_refund_backmoney_time` timestamp COMMENT '子订单退货确认退款时间',
  `refund_type` int COMMENT '退货类型(1、仅退款 2、退货退款)',
  `create_time` timestamp COMMENT '创建时间',
  `update_time` timestamp COMMENT '修改时间',
  `version` bigint COMMENT '版本号',
  `partner_id` string COMMENT '合作方id',
  `sort_id` bigint COMMENT '排序值',
  `deleted` int COMMENT '状态 0未删除  1已删除',
  `create_user_name` string COMMENT '创建人',
  `update_user_name` string COMMENT '修改人',
  `create_user_id` string COMMENT '创建人id',
  `update_user_id` string COMMENT '修改人id',
  `order_item_id` bigint COMMENT '子订单d');

--比较数据 模板
select
a.frefundid,a.fstatus,b.fstatus
from
dw_dwd.dwd_jv_ecc_t_sd_tbrefund_fl_d a
join
 dw_dwd.dwd_jv_api_t_sd_tbrefund_fl_d b
on a.frefundid=b.frefundid
where nvl(a.fstatus,'')!=nvl(b.fstatus,'');

select content,dt
from dw_ods.ods_app_tmall_refund_get_topic_iu_h
where  dt >= '2023030520'
--   and  dt <= '2023030705'
and get_json_object(get_json_object(get_json_object(content,'$.refund_get_response'),'$.refund'),'$.refund_id')
='207878187834035415'
order by dt;




--比较数据 模板
select
a.foid,b.foid,a.fadjustfee,b.fadjustfee
from
dw_dwd.dwd_jv_ecc_t_sd_tbsoentry_fl_d a
join
 dw_dwd.dwd_jv_api_t_sd_tbsoentry_fl_d b
on a.foid=b.foid
where nvl(cast(a.fdiscountfee as decimal(10,2)) ,'')!=nvl(cast(b.fdiscountfee as decimal(10,2)),'');



--对比订单明细 脚本全
select sum(if(nvl(cast(a.
fadjustfee          as string),'')=nvl(cast(b.fadjustfee           as string),''),0,1)) as check_1
,sum(if(nvl(cast(a.
fbuyerrate          as string),'')=nvl(cast(b.fbuyerrate           as string),''),0,1)) as check_2
,sum(if(nvl(cast(a.
fcid                as string),'')=nvl(cast(b.fcid                 as string),''),0,1)) as check_3
,sum(if(nvl(cast(a.
fconsigntime        as string),'')=nvl(cast(b.fconsigntime         as string),''),0,1)) as check_4
,sum(if(nvl(cast(a.
fdiscountfee        as string),'')=nvl(cast(b.fdiscountfee         as string),''),0,1)) as check_5
,sum(if(nvl(cast(a.
fendtime            as string),'')=nvl(cast(b.fendtime             as string),''),0,1)) as check_6
,sum(if(nvl(cast(a.
finvoiceno          as string),'')=nvl(cast(b.finvoiceno           as string),''),0,1)) as check_7
,sum(if(nvl(cast(a.
fisoversold         as string),'')=nvl(cast(b.fisoversold          as string),''),0,1)) as check_8
,sum(if(nvl(cast(a.
fitemmealid         as string),'')=nvl(cast(b.fitemmealid          as string),''),0,1)) as check_9
,sum(if(nvl(cast(a.
fitemmealname       as string),'')=nvl(cast(b.fitemmealname        as string),''),0,1)) as check_10
,sum(if(nvl(cast(a.
flogisticscompany   as string),'')=nvl(cast(b.flogisticscompany    as string),''),0,1)) as check_11
,sum(if(nvl(cast(a.
fmodified           as string),'')=nvl(cast(b.fmodified            as string),''),0,1)) as check_12
,sum(if(nvl(cast(a.
fnum                as string),'')=nvl(cast(b.fnum                 as string),''),0,1)) as check_13
,sum(if(nvl(cast(a.
fnumiid             as string),'')=nvl(cast(b.fnumiid              as string),''),0,1)) as check_14
,sum(if(nvl(cast(a.
foid                as string),'')=nvl(cast(b.foid                 as string),''),0,1)) as check_15
,sum(if(nvl(cast(a.
forderfrom          as string),'')=nvl(cast(b.forderfrom           as string),''),0,1)) as check_16
,sum(if(nvl(cast(a.
fouteriid           as string),'')=nvl(cast(b.fouteriid            as string),''),0,1)) as check_17
,sum(if(nvl(cast(a.
fouterskuid         as string),'')=nvl(cast(b.fouterskuid          as string),''),0,1)) as check_18
,sum(if(nvl(cast(a.
fpayment            as string),'')=nvl(cast(b.fpayment             as string),''),0,1)) as check_19
,sum(if(nvl(cast(a.
fpicpath            as string),'')=nvl(cast(b.fpicpath             as string),''),0,1)) as check_20
,sum(if(nvl(cast(a.
fprice              as string),'')=nvl(cast(b.fprice               as string),''),0,1)) as check_21
,sum(if(nvl(cast(a.
frefundid           as string),'')=nvl(cast(b.frefundid            as string),''),0,1)) as check_22
,sum(if(nvl(cast(a.
frefundstatus       as string),'')=nvl(cast(b.frefundstatus        as string),''),0,1)) as check_23
,sum(if(nvl(cast(a.
fsellernick         as string),'')=nvl(cast(b.fsellernick          as string),''),0,1)) as check_24
,sum(if(nvl(cast(a.
fsellerrate         as string),'')=nvl(cast(b.fsellerrate          as string),''),0,1)) as check_25
,sum(if(nvl(cast(a.
fsellertype         as string),'')=nvl(cast(b.fsellertype          as string),''),0,1)) as check_26
,sum(if(nvl(cast(a.
fshippingtype       as string),'')=nvl(cast(b.fshippingtype        as string),''),0,1)) as check_27
,sum(if(nvl(cast(a.
fskuid              as string),'')=nvl(cast(b.fskuid               as string),''),0,1)) as check_28
,sum(if(nvl(cast(a.
fstatus             as string),'')=nvl(cast(b.fstatus              as string),''),0,1)) as check_29
,sum(if(nvl(cast(a.
ftimeoutactiontime  as string),'')=nvl(cast(b.ftimeoutactiontime   as string),''),0,1)) as check_30
,sum(if(nvl(cast(a.
ftitle              as string),'')=nvl(cast(b.ftitle               as string),''),0,1)) as check_31
,sum(if(nvl(cast(a.
ftotalfee           as string),'')=nvl(cast(b.ftotalfee            as string),''),0,1)) as check_32
,sum(if(nvl(cast(a.
fstorecode          as string),'')=nvl(cast(b.fstorecode    as string),''),0,1)) as check_33
from (
select
foid,
fadjustfee         ,
fbuyerrate         ,
fcid               ,
fconsigntime       ,
fdiscountfee       ,
fendtime           ,
finvoiceno         ,
fisoversold        ,
fitemmealid        ,
fitemmealname      ,
flogisticscompany  ,
fmodified          ,
fnum               ,
fnumiid            ,
foid               ,
forderfrom         ,
fouteriid          ,
fouterskuid        ,
fpayment           ,
fpicpath           ,
fprice             ,
frefundid          ,
frefundstatus      ,
fsellernick        ,
fsellerrate        ,
fsellertype        ,
fshippingtype      ,
fskuid             ,
fstatus            ,
ftimeoutactiontime ,
ftitle             ,
ftotalfee          ,
fstorecode
from dw_dwd.dwd_jv_ecc_t_sd_tbsoentry_fl_d
) a
join (
    select foid
         , fadjustfee
         , fbuyerrate
         , fcid
         , fconsigntime
         , fdiscountfee
         , fendtime
         , finvoiceno
         , fisoversold
         , fitemmealid
         , fitemmealname
         , flogisticscompany
         , fmodified
         , fnum
         , fnumiid
         , foid
         , forderfrom
         , fouteriid
         , fouterskuid
         , fpayment
         , fpicpath
         , fprice
         , frefundid
         , frefundstatus
         , fsellernick
         , fsellerrate
         , fsellertype
         , fshippingtype
         , fskuid
         , fstatus
         , ftimeoutactiontime
         , ftitle
         , ftotalfee
         , fstorecode
    from dw_dwd.dwd_jv_api_t_sd_tbsoentry_fl_d
) b on a.
foid = b.foid
;





--对比订单主表 脚本全
select sum(if(nvl(cast(a.
fid                as string),'')=nvl(cast(b.fid                as string),''),0,1)) as check_1
,sum(if(nvl(cast(a.
fcreatetime        as string),'')=nvl(cast(b.fcreatetime        as string),''),0,1)) as check_2
,sum(if(nvl(cast(a.
flastupdatetime    as string),'')=nvl(cast(b.flastupdatetime    as string),''),0,1)) as check_3
,sum(if(nvl(cast(a.
fbuyermessage      as string),'')=nvl(cast(b.fbuyermessage      as string),''),0,1)) as check_4
,sum(if(nvl(cast(a.
fbuyernick         as string),'')=nvl(cast(b.fbuyernick         as string),''),0,1)) as check_5
,sum(if(nvl(cast(a.
fconsigntime       as string),'')=nvl(cast(b.fconsigntime       as string),''),0,1)) as check_6
,sum(if(nvl(cast(a.
fcreated           as string),'')=nvl(cast(b.fcreated           as string),''),0,1)) as check_7
,sum(if(nvl(cast(a.
fdiscountfee       as string),'')=nvl(cast(b.fdiscountfee       as string),''),0,1)) as check_8
,sum(if(nvl(cast(a.
fendtime           as string),'')=nvl(cast(b.fendtime           as string),''),0,1)) as check_9
,sum(if(nvl(cast(a.
fhasbuyermessage   as string),'')=nvl(cast(b.fhasbuyermessage   as string),''),0,1)) as check_10

,sum(if(nvl(cast(a.
fmodified          as string),'')=nvl(cast(b.fmodified          as string),''),0,1)) as check_11
,sum(if(nvl(cast(a.
fpaytime           as string),'')=nvl(cast(b.fpaytime           as string),''),0,1)) as check_12
,sum(if(nvl(cast(a.
fpayment           as string),'')=nvl(cast(b.fpayment           as string),''),0,1)) as check_13
,sum(if(nvl(cast(a.
fpostfee           as string),'')=nvl(cast(b.fpostfee           as string),''),0,1)) as check_14
,sum(if(nvl(cast(a.
freceiveraddress   as string),'')=nvl(cast(b.freceiveraddress   as string),''),0,1)) as check_15
,sum(if(nvl(cast(a.
freceivercity      as string),'')=nvl(cast(b.freceivercity      as string),''),0,1)) as check_16
,sum(if(nvl(cast(a.
freceiverdistrict  as string),'')=nvl(cast(b.freceiverdistrict  as string),''),0,1)) as check_17
,sum(if(nvl(cast(a.
freceivermobile    as string),'')=nvl(cast(b.freceivermobile    as string),''),0,1)) as check_18
,sum(if(nvl(cast(a.
freceivername      as string),'')=nvl(cast(b.freceivername      as string),''),0,1)) as check_19
,sum(if(nvl(cast(a.
freceiverphone     as string),'')=nvl(cast(b.freceiverphone     as string),''),0,1)) as check_20
,sum(if(nvl(cast(a.
freceiverstate     as string),'')=nvl(cast(b.freceiverstate     as string),''),0,1)) as check_21
,sum(if(nvl(cast(a.
freceiverzip       as string),'')=nvl(cast(b.freceiverzip       as string),''),0,1)) as check_22
,sum(if(nvl(cast(a.
fsellermobile      as string),'')=nvl(cast(b.fsellermobile      as string),''),0,1)) as check_23
,sum(if(nvl(cast(a.
fsellername        as string),'')=nvl(cast(b.fsellername        as string),''),0,1)) as check_24
,sum(if(nvl(cast(a.
fstatus            as string),'')=nvl(cast(b.fstatus            as string),''),0,1)) as check_25
,sum(if(nvl(cast(a.
fsteppaidfee       as string),'')=nvl(cast(b.fsteppaidfee       as string),''),0,1)) as check_26
,sum(if(nvl(cast(a.
fsteptradestatus   as string),'')=nvl(cast(b.fsteptradestatus   as string),''),0,1)) as check_27
,sum(if(nvl(cast(a.
ftid               as string),'')=nvl(cast(b.ftid               as string),''),0,1)) as check_28
,sum(if(nvl(cast(a.
ftitle             as string),'')=nvl(cast(b.ftitle             as string),''),0,1)) as check_29
,sum(if(nvl(cast(a.
ftradefrom         as string),'')=nvl(cast(b.ftradefrom         as string),''),0,1)) as check_30
,sum(if(nvl(cast(a.
ftype              as string),'')=nvl(cast(b.ftype
 as string),''),0,1)) as check_31
from (
select
ftid,
fid               ,
fcreatetime       ,
flastupdatetime   ,
fbuyermessage     ,
fbuyernick        ,
fconsigntime      ,
fcreated          ,
fdiscountfee      ,
fendtime          ,
fhasbuyermessage  ,
fmodified         ,
fpaytime          ,
fpayment          ,
fpostfee          ,
freceiveraddress  ,
freceivercity     ,
freceiverdistrict ,
freceivermobile   ,
freceivername     ,
freceiverphone    ,
freceiverstate    ,
freceiverzip      ,
fsellermobile     ,
fsellername       ,
fstatus           ,
fsteppaidfee      ,
fsteptradestatus  ,
ftid              ,
ftitle            ,
ftradefrom        ,
ftype
from dw_dwd.dwd_jv_ecc_t_sd_tbsobill_fl_d
) a
join (
    select ftid
         , fid
         , fcreatetime
         , flastupdatetime
         , fbuyermessage
         , fbuyernick
         , fconsigntime
         , fcreated
         , fdiscountfee
         , fendtime
         , fhasbuyermessage
         , fmodified
         , fpaytime
         , fpayment
         , fpostfee
         , freceiveraddress
         , freceivercity
         , freceiverdistrict
         , freceivermobile
         , freceivername
         , freceiverphone
         , freceiverstate
         , freceiverzip
         , fsellermobile
         , fsellername
         , fstatus
         , fsteppaidfee
         , fsteptradestatus
         , ftid
         , ftitle
         , ftradefrom
         , ftype
    from dw_dwd.dwd_jv_api_t_sd_tbsobill_fl_d
) b on a.
ftid = b.ftid
where a.fcreated<='2023-06-12';

ods_app_tmall_trade_fullinfo_get_topic_iu_h

ods_app_tmall_refund_get_topic_iu_h
insert overwrite table dw_ods.ods_app_tmall_trade_fullinfo_get_topic_iu_h
select content,dt from dw_ods.ods_ynap_dev_trade_fullinfo_get_topic where dt>='2023032317' and dt<='2023032419'
distribute by 50;
select count(1) from dw_ods.ods_app_tmall_refund_get_topic_iu_h where dt>='2023032422';


select count(1) from dw_dwd.dwd_jv_ecc_t_sd_tbsobill_fl_d
union all
select count(1) from dw_dwd.dwd_jv_api_t_sd_tbsobill_fl_d;

select t2.fid,t2.foid
from dw_dwd.dwd_jv_ecc_t_sd_tbsoentry_fl_d t2
left join dw_dwd.dwd_jv_manual_test_orders_fl_d t11
on t2.fid = t11.test_orders
where t11.test_orders is not null;



--tbgoods

python3 /home/hadoop/workspace/ynap-bigdata-etl/dw_base_check.py \
--table 'dw_dwd.dwd_jv_api_t_ec_tbgoods_fl_d,dw_dwd.dwd_jv_ecc_t_ec_tbgoods_fl_d' \
--is_dt 'false,false' --dt 'null,20230305' \
--id_column \
'
numiid:numiid
' \
--check_column \
'
fid            :fid            ,
fapprovestatus :fapprovestatus ,
fcreated       :fcreated       ,
fdelisttime    :fdelisttime    ,
fdetailurl     :fdetailurl     ,
fisxinpin      :fisxinpin      ,
flisttime      :flisttime      ,
fmodified      :fmodified      ,
fnumiid        :fnumiid        ,
fouterid       :fouterid       ,
fpicurl        :fpicurl        ,
fprice         :fprice         ,
fproductid     :fproductid     ,
fpropsname     :fpropsname     ,
fstuffstatus   :fstuffstatus   ,
ftitle         :ftitle         ,
numiid         :numiid

' \
--is_run='false'

select count(1),count(fskuid) from dw_dwd.dwd_jv_ecc_t_ec_tbsku_fl_d where dt='20230312';
select count(1),count(fskuid) from dw_dwd.dwd_jv_api_t_ec_tbsku_fl_d;

;
select sum(if(nvl(cast(a.
fid             as string),'')=nvl(cast(b.fid             as string),''),0,1)) as check_1
,sum(if(nvl(cast(a.
fapprovestatus  as string),'')=nvl(cast(b.fapprovestatus  as string),''),0,1)) as check_2
,sum(if(nvl(cast(a.
fcreated        as string),'')=nvl(cast(b.fcreated        as string),''),0,1)) as check_3
,sum(if(nvl(cast(a.
fdelisttime     as string),'')=nvl(cast(b.fdelisttime     as string),''),0,1)) as check_4
,sum(if(nvl(cast(a.
fdetailurl      as string),'')=nvl(cast(b.fdetailurl      as string),''),0,1)) as check_5
,sum(if(nvl(cast(a.
fisxinpin       as string),'')=nvl(cast(b.fisxinpin       as string),''),0,1)) as check_6
,sum(if(nvl(cast(a.
flisttime       as string),'')=nvl(cast(b.flisttime       as string),''),0,1)) as check_7
,sum(if(nvl(cast(a.
fmodified       as string),'')=nvl(cast(b.fmodified       as string),''),0,1)) as check_8
,sum(if(nvl(cast(a.
fnumiid         as string),'')=nvl(cast(b.fnumiid         as string),''),0,1)) as check_9
,sum(if(nvl(cast(a.
fouterid        as string),'')=nvl(cast(b.fouterid        as string),''),0,1)) as check_10
,sum(if(nvl(cast(a.
fpicurl         as string),'')=nvl(cast(b.fpicurl         as string),''),0,1)) as check_11
,sum(if(nvl(cast(a.
fprice          as string),'')=nvl(cast(b.fprice          as string),''),0,1)) as check_12
,sum(if(nvl(cast(a.
fproductid      as string),'')=nvl(cast(b.fproductid      as string),''),0,1)) as check_13
,sum(if(nvl(cast(a.
fpropsname      as string),'')=nvl(cast(b.fpropsname      as string),''),0,1)) as check_14
,sum(if(nvl(cast(a.
fstuffstatus    as string),'')=nvl(cast(b.fstuffstatus    as string),''),0,1)) as check_15
,sum(if(nvl(cast(a.
ftitle          as string),'')=nvl(cast(b.ftitle          as string),''),0,1)) as check_16
,sum(if(nvl(cast(a.
numiid          as string),'')=nvl(cast(b.numiid
 as string),''),0,1)) as check_17
from (
select
fid            ,
fapprovestatus ,
fcreated       ,
fdelisttime    ,
fdetailurl     ,
fisxinpin      ,
flisttime      ,
fmodified      ,
fnumiid        ,
fouterid       ,
fpicurl        ,
fprice         ,
fproductid     ,
fpropsname     ,
fstuffstatus   ,
ftitle         ,
numiid
from dw_dwd.dwd_jv_api_t_ec_tbgoods_fl_d
) a
join (
select numiid as fid
     , fapprovestatus
     , fcreated
     , fdelisttime
     , fdetailurl
     , fisxinpin
     , flisttime
     , fmodified
     , fnumiid
     , fouterid
     , fpicurl
     , fprice
     , fproductid
     , fpropsname
     , fstuffstatus
     , ftitle
     , numiid
from dw_dwd.dwd_jv_ecc_t_ec_tbgoods_fl_d where dt='20230323'
) b on a.
numiid = b.numiid;


check_1    check_2    check_3    check_4    check_5    check_6    check_7    check_8    check_9    check_10   check_11   check_12   check_13   check_14   check_15   check_16   check_17
0  1  0  2491   15667  0  2426   2570   0  0
0  0  0  0  0  2  0




python3 /home/hadoop/workspace/ynap-bigdata-etl/dw_base_check.py \
--table 'dw_dwd.dwd_jv_api_t_ec_tbsku_fl_d,dw_tmp.dwd_jv_api_t_ec_tbsku_fl_d' \
--is_dt 'false,false' --dt 'null,null' \
--id_column \
'
fnumiid:fnumiid
' \
--check_column \
'
fcreated        :fcreated       ,
fmodified       :fmodified      ,
fnumiid         :fnumiid        ,
fouterid        :fouterid       ,
fprice          :fprice         ,
fpropertiesname :fpropertiesname,
fquantity       :fquantity      ,
fskuid          :fskuid

' \
--is_run=''false''
;
--tbsku
--check 逻辑
;

select sum(if(nvl(cast(a.
fcreated         as string),'')=nvl(cast(b.fcreated        as string),''),0,1)) as check_1
,sum(if(nvl(cast(a.
fmodified        as string),'')=nvl(cast(b.fmodified       as string),''),0,1)) as check_2
,sum(if(nvl(cast(a.
fnumiid          as string),'')=nvl(cast(b.fnumiid         as string),''),0,1)) as check_3
,sum(if(nvl(cast(a.
fouterid         as string),'')=nvl(cast(b.fouterid        as string),''),0,1)) as check_4
,sum(if(nvl(cast(a.
fprice           as string),'')=nvl(cast(b.fprice          as string),''),0,1)) as check_5
,sum(if(nvl(cast(a.
fpropertiesname  as string),'')=nvl(cast(b.fpropertiesname as string),''),0,1)) as check_6
,sum(if(nvl(cast(a.
fquantity        as string),'')=nvl(cast(b.fquantity       as string),''),0,1)) as check_7
,sum(if(nvl(cast(a.
fskuid           as string),'')=nvl(cast(b.fskuid as string),''),0,1)) as check_8
from (
select
fnumiid,
fcreated        ,
fmodified       ,
fnumiid         ,
fouterid        ,
fprice          ,
fpropertiesname ,
fquantity       ,
fskuid
from dw_dwd.dwd_jv_api_t_ec_tbsku_fl_d
) a
join (
    select fnumiid
         , fcreated
         , fmodified
         , fnumiid
         , fouterid
         , fprice
         , fpropertiesname
         , fquantity
         , fskuid
from dw_tmp.dwd_jv_api_t_ec_tbsku_fl_d
) b on a.fnumiid = b.fnumiid and a.fskuid=b.fskuid;
check_1    check_2    check_3    check_4    check_5    check_6    check_7    check_8
0  16 0  0  0  0  129    0





select count(1),count(distinct fnumiid,fskuid) from dw_tmp.dwd_jv_api_t_ec_tbsku_fl_d;
select count(1),count(distinct fnumiid,fskuid) from dw_dwd.dwd_jv_api_t_ec_tbsku_fl_d;

select count(1)
from dw_dwd.dwd_jv_api_t_ec_tbsku_fl_d t1
left join dw_tmp.dwd_jv_api_t_ec_tbsku_fl_d t2
on t1.fnumiid=t2.fnumiid and t1.fskuid=t2.fskuid
where t2.fskuid is null;





-- sobill
python3 /home/hadoop/workspace/ynap-bigdata-etl/dw_base_check.py \
--table 'dw_dwd.dwd_jv_api_t_sd_tbsobill_fl_d,dw_dwd.dwd_jv_ecc_t_sd_tbsobill_fl_d' \
--is_dt 'false,false' --dt 'null,null' \
--id_column \
'
ftid:ftid
' \
--check_column \
'
fcreatetime       :fcreatetime      ,
flastupdatetime   :flastupdatetime  ,
fbuyermessage     :fbuyermessage    ,
fbuyernick        :fbuyernick       ,
fconsigntime      :fconsigntime     ,
fcreated          :fcreated         ,
fdiscountfee      :fdiscountfee     ,
fendtime          :fendtime         ,
fhasbuyermessage  :fhasbuyermessage ,
fmodified         :fmodified        ,
fpaytime          :fpaytime         ,
fpayment          :fpayment         ,
fpostfee          :fpostfee         ,
freceiveraddress  :freceiveraddress ,
freceivercity     :freceivercity    ,
freceiverdistrict :freceiverdistrict,
freceivermobile   :freceivermobile

' \
--is_run='false'

--比较

select sum(if(nvl(cast(a.
fcreatetime        as string),'')=nvl(cast(b.fcreatetime       as string),''),0,1)) as check_1
,sum(if(nvl(cast(a.
flastupdatetime    as string),'')=nvl(cast(b.flastupdatetime   as string),''),0,1)) as check_2
,sum(if(nvl(cast(a.
fbuyermessage      as string),'')=nvl(cast(b.fbuyermessage     as string),''),0,1)) as check_3
,sum(if(nvl(cast(a.
fbuyernick         as string),'')=nvl(cast(b.fbuyernick        as string),''),0,1)) as check_4
,sum(if(nvl(cast(a.
fconsigntime       as string),'')=nvl(cast(b.fconsigntime      as string),''),0,1)) as check_5
,sum(if(nvl(cast(a.
fcreated           as string),'')=nvl(cast(b.fcreated          as string),''),0,1)) as check_6
,sum(if(nvl(cast(a.
fdiscountfee       as string),'')=nvl(cast(b.fdiscountfee      as string),''),0,1)) as check_7
,sum(if(nvl(cast(a.
fendtime           as string),'')=nvl(cast(b.fendtime          as string),''),0,1)) as check_8
,sum(if(nvl(cast(a.
fhasbuyermessage   as string),'')=nvl(cast(b.fhasbuyermessage  as string),''),0,1)) as check_9
,sum(if(nvl(cast(a.
fmodified          as string),'')=nvl(cast(b.fmodified         as string),''),0,1)) as check_10
,sum(if(nvl(cast(a.
fpaytime           as string),'')=nvl(cast(b.fpaytime          as string),''),0,1)) as check_11
,sum(if(nvl(cast(a.
fpayment           as string),'')=nvl(cast(b.fpayment          as string),''),0,1)) as check_12
,sum(if(nvl(cast(a.
fpostfee           as string),'')=nvl(cast(b.fpostfee          as string),''),0,1)) as check_13
,sum(if(nvl(cast(a.
freceiveraddress   as string),'')=nvl(cast(b.freceiveraddress  as string),''),0,1)) as check_14
,sum(if(nvl(cast(a.
freceivercity      as string),'')=nvl(cast(b.freceivercity     as string),''),0,1)) as check_15
,sum(if(nvl(cast(a.
freceiverdistrict  as string),'')=nvl(cast(b.freceiverdistrict as string),''),0,1)) as check_16
,sum(if(nvl(cast(a.
freceivermobile    as string),'')=nvl(cast(b.freceivermobile

 as string),''),0,1)) as check_17
from (
select
ftid,
fcreatetime       ,
flastupdatetime   ,
fbuyermessage     ,
fbuyernick        ,
fconsigntime      ,
fcreated          ,
fdiscountfee      ,
fendtime          ,
fhasbuyermessage  ,
fmodified         ,
fpaytime          ,
fpayment          ,
fpostfee          ,
freceiveraddress  ,
freceivercity     ,
freceiverdistrict ,
freceivermobile
from dw_dwd.dwd_jv_api_t_sd_tbsobill_fl_d
) a
join (
    select ftid
         , fcreatetime
         , flastupdatetime
         , fbuyermessage
         , fbuyernick
         , fconsigntime
         , fcreated
         , fdiscountfee
         , fendtime
         , fhasbuyermessage
         , fmodified
         , fpaytime
         , fpayment
         , fpostfee
         , freceiveraddress
         , freceivercity
         , freceiverdistrict
         , freceivermobile
from dw_dwd.dwd_jv_ecc_t_sd_tbsobill_fl_d
) b on a.
ftid = b.ftid;

check_1    check_2    check_3    check_4    check_5    check_6    check_7    check_8    check_9    check_10   check_11   check_12   check_13   check_14   check_15   check_16   check_17
9809   9838   0  9809   0  0  7056   71 0  231
1  6976   9809   23 0  0  9788

select count(1) from dw_dwd.dwd_jv_ecc_t_sd_tbsobill_fl_d
union all
select count(1) from dw_dwd.dwd_jv_api_t_sd_tbsobill_fl_d;
select * from dw_dwd.dwd_jv_ecc_t_sd_tbsobill_fl_d where ftid='3358778223555991203';

select * from dw_ods.ods_app_tmall_trade_fullinfo_get_topic_iu_h where dt>='2023052200'
and content like '%3358778223555991203%';

--refund 比较
python3 /home/hadoop/workspace/ynap-bigdata-etl/dw_base_check.py \
--table 'dw_dwd.dwd_jv_api_t_sd_tbrefund_fl_d,dw_dwd.dwd_jv_ecc_t_sd_tbrefund_fl_d' \
--is_dt 'false,false' --dt 'null,null' \
--id_column \
'
frefundid:frefundid
' \
--check_column \
'
fbuyernick     :fbuyernick      ,
fcreated       :fcreated        ,
fcsstatus      :fcsstatus       ,
fgoodstatus    :fgoodstatus     ,
fhasgoodreturn :fhasgoodreturn  ,
fmodified      :fmodified       ,
fnum           :fnum            ,
fnumiid        :fnumiid         ,
foid           :foid            ,
freason        :freason         ,
frefundfee     :frefundfee      ,
frefundid      :frefundid       ,
frefundphase   :frefundphase    ,
fsellernick    :fsellernick     ,
fsku           :fsku            ,
fstatus        :fstatus         ,
ftid           :ftid            ,
ftitle         :ftitle          ,
flastupdatetime:flastupdatetime ,
ftotalfee      :ftotalfee       ,
fsid           :fsid            ,
fcompanyname   :fcompanyname    ,
fgoodreturntime:fgoodreturntime

' \
--is_run='false'



select sum(if(nvl(cast(a.
fbuyernick      as string),'')=nvl(cast(b.fbuyernick       as string),''),0,1)) as check_1
,sum(if(nvl(cast(a.
fcreated        as string),'')=nvl(cast(b.fcreated         as string),''),0,1)) as check_2
,sum(if(nvl(cast(a.
fcsstatus       as string),'')=nvl(cast(b.fcsstatus        as string),''),0,1)) as check_3
,sum(if(nvl(cast(a.
fgoodstatus     as string),'')=nvl(cast(b.fgoodstatus      as string),''),0,1)) as check_4
,sum(if(nvl(cast(a.
fhasgoodreturn  as string),'')=nvl(cast(b.fhasgoodreturn   as string),''),0,1)) as check_5
,sum(if(nvl(cast(a.
fmodified       as string),'')=nvl(cast(b.fmodified        as string),''),0,1)) as check_6
,sum(if(nvl(cast(a.
fnum            as string),'')=nvl(cast(b.fnum             as string),''),0,1)) as check_7
,sum(if(nvl(cast(a.
fnumiid         as string),'')=nvl(cast(b.fnumiid          as string),''),0,1)) as check_8
,sum(if(nvl(cast(a.
foid            as string),'')=nvl(cast(b.foid             as string),''),0,1)) as check_9
,sum(if(nvl(cast(a.
freason         as string),'')=nvl(cast(b.freason          as string),''),0,1)) as check_10
,sum(if(nvl(cast(a.
frefundfee      as string),'')=nvl(cast(b.frefundfee       as string),''),0,1)) as check_11
,sum(if(nvl(cast(a.
frefundid       as string),'')=nvl(cast(b.frefundid        as string),''),0,1)) as check_12
,sum(if(nvl(cast(a.
frefundphase    as string),'')=nvl(cast(b.frefundphase     as string),''),0,1)) as check_13
,sum(if(nvl(cast(a.
fsellernick     as string),'')=nvl(cast(b.fsellernick      as string),''),0,1)) as check_14
,sum(if(nvl(cast(a.
fsku            as string),'')=nvl(cast(b.fsku             as string),''),0,1)) as check_15
,sum(if(nvl(cast(a.
fstatus         as string),'')=nvl(cast(b.fstatus          as string),''),0,1)) as check_16
,sum(if(nvl(cast(a.
ftid            as string),'')=nvl(cast(b.ftid             as string),''),0,1)) as check_17
,sum(if(nvl(cast(a.
ftitle          as string),'')=nvl(cast(b.ftitle           as string),''),0,1)) as check_18
,sum(if(nvl(cast(a.
flastupdatetime as string),'')=nvl(cast(b.flastupdatetime  as string),''),0,1)) as check_19
,sum(if(nvl(cast(a.
ftotalfee       as string),'')=nvl(cast(b.ftotalfee        as string),''),0,1)) as check_20
,sum(if(nvl(cast(a.
fsid            as string),'')=nvl(cast(b.fsid             as string),''),0,1)) as check_21
,sum(if(nvl(cast(a.
fcompanyname    as string),'')=nvl(cast(b.fcompanyname     as string),''),0,1)) as check_22
,sum(if(nvl(cast(a.
fgoodreturntime as string),'')=nvl(cast(b.fgoodreturntime as string),''),0,1)) as check_23
from (
select
frefundid,
fbuyernick     ,
fcreated       ,
fcsstatus      ,
fgoodstatus    ,
fhasgoodreturn ,
fmodified      ,
fnum           ,
fnumiid        ,
foid           ,
freason        ,
frefundfee     ,
frefundid      ,
frefundphase   ,
fsellernick    ,
fsku           ,
fstatus        ,
ftid           ,
ftitle         ,
flastupdatetime,
ftotalfee      ,
fsid           ,
fcompanyname   ,
fgoodreturntime
from dw_dwd.dwd_jv_api_t_sd_tbrefund_fl_d
) a
join (
    select frefundid
         , fbuyernick
         , fcreated
         , fcsstatus
         , fgoodstatus
         , fhasgoodreturn
         , fmodified
         , fnum
         , fnumiid
         , foid
         , freason
         , frefundfee
         , frefundid
         , frefundphase
         , fsellernick
         , fsku
         , fstatus
         , ftid
         , ftitle
         , flastupdatetime
         , ftotalfee
         , fsid
         , fcompanyname
         , fgoodreturntime
from dw_dwd.dwd_jv_ecc_t_sd_tbrefund_fl_d
) b on a.
frefundid = b.frefundid;
check_1    check_2    check_3    check_4    check_5    check_6    check_7    check_8    check_9    check_10   check_11   check_12   check_13   check_14   check_15   check_16   check_17   check_18   check_19   check_20   check_21   check_22   check_23
7659   0  3  8  0  140    0  0  0  0
4672   0  0  0  0  49 0  0  7667   4676
8  8  8



select content
from dw_ods.ods_app_tmall_refund_get_topic_iu_h
where  dt >= '2023031122'
and  dt <= '2023031300'
and get_json_object(get_json_object(get_json_object(content,'$.refund_get_response'),'$.refund'),'$.refund_id')='';

select count(1),count(distinct frefundid) from dw_dwd.dwd_jv_api_t_sd_tbrefund_fl_d
union all
select count(1),count(distinct frefundid) from dw_dwd.dwd_jv_ecc_t_sd_tbrefund_fl_d;


--对比订单明细 脚本全 soentry
select sum(if(nvl(cast(a.
fadjustfee          as string),'')=nvl(cast(b.fadjustfee           as string),''),0,1)) as check_1
,sum(if(nvl(cast(a.
fbuyerrate          as string),'')=nvl(cast(b.fbuyerrate           as string),''),0,1)) as check_2
,sum(if(nvl(cast(a.
fcid                as string),'')=nvl(cast(b.fcid                 as string),''),0,1)) as check_3
,sum(if(nvl(cast(a.
fconsigntime        as string),'')=nvl(cast(b.fconsigntime         as string),''),0,1)) as check_4
,sum(if(nvl(cast(a.
fdiscountfee        as string),'')=nvl(cast(b.fdiscountfee         as string),''),0,1)) as check_5
,sum(if(nvl(cast(a.
fendtime            as string),'')=nvl(cast(b.fendtime             as string),''),0,1)) as check_6
,sum(if(nvl(cast(a.
finvoiceno          as string),'')=nvl(cast(b.finvoiceno           as string),''),0,1)) as check_7
,sum(if(nvl(cast(a.
fisoversold         as string),'')=nvl(cast(b.fisoversold          as string),''),0,1)) as check_8
,sum(if(nvl(cast(a.
fitemmealid         as string),'')=nvl(cast(b.fitemmealid          as string),''),0,1)) as check_9
,sum(if(nvl(cast(a.
fitemmealname       as string),'')=nvl(cast(b.fitemmealname        as string),''),0,1)) as check_10
,sum(if(nvl(cast(a.
flogisticscompany   as string),'')=nvl(cast(b.flogisticscompany    as string),''),0,1)) as check_11
,sum(if(nvl(cast(a.
fmodified           as string),'')=nvl(cast(b.fmodified            as string),''),0,1)) as check_12
,sum(if(nvl(cast(a.
fnum                as string),'')=nvl(cast(b.fnum                 as string),''),0,1)) as check_13
,sum(if(nvl(cast(a.
fnumiid             as string),'')=nvl(cast(b.fnumiid              as string),''),0,1)) as check_14
,sum(if(nvl(cast(a.
foid                as string),'')=nvl(cast(b.foid                 as string),''),0,1)) as check_15
,sum(if(nvl(cast(a.
forderfrom          as string),'')=nvl(cast(b.forderfrom           as string),''),0,1)) as check_16
,sum(if(nvl(cast(a.
fouteriid           as string),'')=nvl(cast(b.fouteriid            as string),''),0,1)) as check_17
,sum(if(nvl(cast(a.
fouterskuid         as string),'')=nvl(cast(b.fouterskuid          as string),''),0,1)) as check_18
,sum(if(nvl(cast(a.
fpayment            as string),'')=nvl(cast(b.fpayment             as string),''),0,1)) as check_19
,sum(if(nvl(cast(a.
fpicpath            as string),'')=nvl(cast(b.fpicpath             as string),''),0,1)) as check_20
,sum(if(nvl(cast(a.
fprice              as string),'')=nvl(cast(b.fprice               as string),''),0,1)) as check_21
,sum(if(nvl(cast(a.
frefundid           as string),'')=nvl(cast(b.frefundid            as string),''),0,1)) as check_22
,sum(if(nvl(cast(a.
frefundstatus       as string),'')=nvl(cast(b.frefundstatus        as string),''),0,1)) as check_23
,sum(if(nvl(cast(a.
fsellernick         as string),'')=nvl(cast(b.fsellernick          as string),''),0,1)) as check_24
,sum(if(nvl(cast(a.
fsellerrate         as string),'')=nvl(cast(b.fsellerrate          as string),''),0,1)) as check_25
,sum(if(nvl(cast(a.
fsellertype         as string),'')=nvl(cast(b.fsellertype          as string),''),0,1)) as check_26
,sum(if(nvl(cast(a.
fshippingtype       as string),'')=nvl(cast(b.fshippingtype        as string),''),0,1)) as check_27
,sum(if(nvl(cast(a.
fskuid              as string),'')=nvl(cast(b.fskuid               as string),''),0,1)) as check_28
,sum(if(nvl(cast(a.
fstatus             as string),'')=nvl(cast(b.fstatus              as string),''),0,1)) as check_29
,sum(if(nvl(cast(a.
ftimeoutactiontime  as string),'')=nvl(cast(b.ftimeoutactiontime   as string),''),0,1)) as check_30
,sum(if(nvl(cast(a.
ftitle              as string),'')=nvl(cast(b.ftitle               as string),''),0,1)) as check_31
,sum(if(nvl(cast(a.
ftotalfee           as string),'')=nvl(cast(b.ftotalfee            as string),''),0,1)) as check_32
,sum(if(nvl(cast(a.
fstorecode          as string),'')=nvl(cast(b.fstorecode    as string),''),0,1)) as check_33
from (
select
foid,
fadjustfee         ,
fbuyerrate         ,
fcid               ,
fconsigntime       ,
fdiscountfee       ,
fendtime           ,
finvoiceno         ,
fisoversold        ,
fitemmealid        ,
fitemmealname      ,
flogisticscompany  ,
fmodified          ,
fnum               ,
fnumiid            ,
foid               ,
forderfrom         ,
fouteriid          ,
fouterskuid        ,
fpayment           ,
fpicpath           ,
fprice             ,
frefundid          ,
frefundstatus      ,
fsellernick        ,
fsellerrate        ,
fsellertype        ,
fshippingtype      ,
fskuid             ,
fstatus            ,
ftimeoutactiontime ,
ftitle             ,
ftotalfee          ,
fstorecode
from dw_dwd.dwd_jv_ecc_t_sd_tbsoentry_fl_d
) a
join (
    select foid
         , fadjustfee
         , fbuyerrate
         , fcid
         , fconsigntime
         , fdiscountfee
         , fendtime
         , finvoiceno
         , fisoversold
         , fitemmealid
         , fitemmealname
         , flogisticscompany
         , fmodified
         , fnum
         , fnumiid
         , foid
         , forderfrom
         , fouteriid
         , fouterskuid
         , fpayment
         , fpicpath
         , fprice
         , frefundid
         , frefundstatus
         , fsellernick
         , fsellerrate
         , fsellertype
         , fshippingtype
         , fskuid
         , fstatus
         , ftimeoutactiontime
         , ftitle
         , ftotalfee
         , fstorecode
    from dw_dwd.dwd_jv_api_t_sd_tbsoentry_fl_d
) b on a.
foid = b.foid;


check_1    check_2    check_3    check_4    check_5    check_6    check_7    check_8    check_9    check_10   check_11   check_12   check_13   check_14   check_15   check_16   check_17   check_18   check_19   check_20   check_21   check_22   check_23   check_24   check_25   check_26   check_27   check_28   check_29   check_30   check_31   check_32   check_33
13439  1  0  0  0  8  0  0  0  0
0  13442  0  0  0  0  0  0  8236   0
13442  18 505    0  1  0  0  0  12 4022
0  13375  0


select timeout_action_time,dt from dw_tmp.dwd_jv_api_t_sd_tbsoentry_fl_d_01 where oid='3259848780860038058';
select ftimeoutactiontime,dt from dw_tmp.dwd_jv_api_t_sd_tbsoentry_fl_d_02 where foid='3266621028518825342';
select ftimeoutactiontime from dw_dwd.dwd_jv_ecc_t_sd_tbsoentry_fl_d where foid='1853804282057457690';

select count(1) from dw_ods.ods_app_tmall_trade_fullinfo_get_topic_iu_h where dt='2023032201';
select count(1) from dw_ods.dw_ods.ods_app_tmall_refund_get_topic_iu_h  where dt='2023032201';
select child_order_delivery_time from dw_dwd.dwd_app_oms_sync_time_fl_d;
select shipdate from dw_dwm.dwm_jv_item_sales_data_dtl_n_fl_d_new;
select * from dw_ods.ods_app_tmall_trade_fullinfo_get_topic_iu_h
where dt >= '2023032200'
and  dt <= '2023032312'
and content like '%3273507397256933912%' order by dt;

--promotion 比较

select count(1) from dw_dwd.dwd_jv_api_t_sd_tbpromotiondetail_fl_d
union all
select count(1) from dw_dwd.dwd_jv_ecc_t_sd_tbpromotiondetail_fl_d;



select * from dw_dwd.dwd_jv_ecc_t_sd_tbrefund_fl_d;














create table dw_dwd.dwd_ord_channel_tmall_order_detail_fl_d
as
select t2.order_no                                                                                 as order_no,
       t1.fparentid                                                                                as foid,
       t1.fpayment / sum(t1.fpayment) over (partition by t2.order_no) * t2.order_basic_price       as oid_basic_price,
       t1.fpayment / sum(t1.fpayment) over (partition by t2.order_no) * t2.order_expand_price      as oid_expand_price,
       t1.fpayment / sum(t1.fpayment) over (partition by t2.order_no) * t2.order_basic_price_used  as oid_basic_price_used,
       t1.fpayment / sum(t1.fpayment) over (partition by t2.order_no) * t2.order_expand_price_used as oid_expand_price_used
from dw_dwd.dwd_jv_api_t_sd_tbsoentry_fl_d t1
left join dw_dwd.dwd_ord_channel_tmall_order_fl_d t2
on t1.fparentid=t2.order_no;





drop table if exists dw_dwd.dwd_ord_channel_tmall_order_fl_d;
create table dw_dwd.dwd_ord_channel_tmall_order_fl_d
stored as orc
as
select tid as                                                                     order_no,
       cast(get_json_object(t1.expandcard_info, '$.basic_price') as double)       order_basic_price,
       cast(get_json_object(t1.expandcard_info, '$.expand_price') as double)      order_expand_price,
       cast(get_json_object(t1.expandcard_info, '$.basic_price_used') as double)  order_basic_price_used,
       cast(get_json_object(t1.expandcard_info, '$.expand_price_used') as double) order_expand_price_used
from dw_dwd.dwd_ynap_api_order_fl_d t1;


















drop table if exists dw_dwd.dwd_ord_channel_oms_order_refund_fl_d;
create table dw_dwd.dwd_ord_channel_oms_order_refund_fl_d
stored as orc
as
select
    t1.refund_no,                                                 --   退单号
    t1.sharding_key_order_no as order_no,                         --    订单号
    t5.order_channel         as order_channel,                    --   订单渠道
    case
        when t1.rel_refund_no is not null then t1.rel_refund_no
        else t1.refund_no
    end   as platform_refund_no,               --源平台退款单号
    t5.platform_order_no     as platform_order_no,                                    --源平台订单号
    t1.refund_type,                                               --仅退款,退货退款
    t1.refund_fee            as refund_total_fee,                 --退款总金额
    t1.freight               as refund_post_fee,                  --退运费
    t1.reason                as refund_reason,                    --   退款原因
    t1.desc                  as refund_desc,                      --退款说明
--     null         as refund_phase,                     --退款阶段,可选值:onsale(售中)/aftersale(售后) -- TODO 待确认
    t1.goods_status          as refund_goods_status,              --退款货品状态
--     ''                       as refund_cs_status,                 --退款客服介入状态 --  TODO 待确认
--     null     as seller_address,                   --卖家收货地址
--     null         as seller_name,                      --    卖家收货人
--     null as seller_phone_number,              --    卖家收货人手机号
    t1.refund_status    as orgin_refund_status,                    -- 原退单状态
    t4.target_status_code    as refund_status,                    -- 退单状态

    t1.has_goods_return                       as is_goods_return,                    --是否有退货
    t1.goods_status                      as return_status,                      --退货状态 TODO 待退货/待入库/已退货入库
    t1.tms_service_code       as return_tms_company_code,  --物流公司编码
    t1.tms_service_name       as return_tms_company_name,  --物流公司名称
    t1.tms_number as tms_no,    -- 退货
    t1.create_user_name as create_user_name,
    t1.update_user_name as update_user_name

    t1.create_time,
    t1.update_time,
    `current_timestamp`()    as dc_system_time
from (
    select * from dw_dwd.dwd_app_oms_order_refund_fl_d where deleted=0
)t1
left join(
    select source_status_code,
           target_status_code
    from dw_dim.dim_ord_status_fl_d
    where source_key='dwd_ord_order_detail_fl_d_reverse_app'
       or source_key='dwd_ord_order_detail_fl_d_reverse_ecc'
     and target_key = 'item_sales_data'
)t4
on t1.refund_status =t4.source_status_code
left join dw_dwd.dwd_ord_channel_oms_order_fl_d t5
on t1.order_no=t5.order_no
union all
select
    t1.refund_no,                                                  --  退单号
    t1.sharding_key_order_no  as order_no,                         --    订单号
    t5.order_channel                   as order_channel,                    -- 订单渠道
    case
       when t1.rel_refund_no is not null then t1.rel_refund_no
       else t1.refund_no
    end as platform_refund_no,               --源平台退款单号
    t5.platform_order_no as platform_order_no,                --源平台订单号
    t1.refund_type,                                                --仅退款,退货退款
    t1.refund_fee             as refund_total_fee,                 --退款总金额
    t1.freight                as refund_post_fee,                  --退运费
    t1.reason                as refund_reason,                    --   退款原因
    t1.desc                  as refund_desc,                      --退款说明
--     null          as refund_phase,                     --退款阶段,可选值:onsale(售中)/aftersale(售后) -- TODO 待确认
    t1.goods_status           as refund_goods_status,              --退款货品状态
--     null                      as refund_cs_status,                 --退款客服介入状态 --  TODO 待确认
--     null      as seller_address,                   --卖家收货地址
--     null          as seller_name,                      --   卖家收货人
--     null  as seller_phone_number,              --   卖家收货人手机号
    t1.refund_status as orgin_refund_status,                    --退单状态
    t4.target_status_code     as refund_status,                    --退单状态
    t1.has_goods_return                       as is_goods_return,                    --是否有退货
    t1.goods_status                      as return_status,                      --退货状态 TODO 待退货/待入库/已退货入库
    t1.tms_service_code       as return_tms_company_code,  --物流公司编码
    t1.tms_service_name       as return_tms_company_name,  --物流公司名称
    t1.tms_number as tms_no,    -- 退货物流单号
    t1.create_user_name as create_user_name,
    t1.update_user_name as update_user_name
    t1.create_time,
    t1.update_time,
    `current_timestamp`()     as dc_system_time
from (
    select * from dw_dwd.dwd_ynap_oms_tmall_order_refund_fl_d where deleted=0
)t1 left join(
    select source_status_code,
           target_status_code
    from dw_dim.dim_ord_status_fl_d
    where source_key='dwd_ord_order_detail_fl_d_reverse_app'
       or source_key='dwd_ord_order_detail_fl_d_reverse_ecc'
     and target_key = 'item_sales_data'
)t4
on t1.refund_status =t4.source_status_code
left join dw_dwd.dwd_ord_channel_oms_order_fl_d t5
on t1.order_no=t5.order_no
;

;





desc dw_dwd.dwd_ord_channel_offline_order_delivery_detail_fl_d;
desc dw_dwd.dwd_ord_channel_oms_order_delivery_detail_fl_d;


show create table dw_dwd.dwd_ord_channel_offline_order_delivery_fl_d;
CREATE TABLE dw_dwd.dwd_ord_channel_offline_order_delivery_fl_d(
  `delivery_no` string,
  `order_no` string COMMENT '',
  `platform_order_no` string COMMENT '',
  `delivery_status` string,
  `delivery_quantity` bigint,
  `create_time` timestamp COMMENT '',
  `update_time` timestamp COMMENT '',
  `dc_system_time` timestamp);

CREATE TABLE dw_dwd.dwd_ord_channel_offline_order_delivery_detail_fl_d(
  `sub_order_no` string COMMENT '',
  `delivery_no` string,
  `order_no` string COMMENT '',
  `platform_order_no` string COMMENT '',
  `platform_sub_order_no` string COMMENT '',
  `sku_code` string COMMENT '',
  `delivery_status` string,
  `delivery_sku_quantity` bigint COMMENT '',
  `create_time` timestamp COMMENT '',
  `update_time` timestamp COMMENT '',
  `dc_system_time` timestamp)
;






CREATE TABLE dw_dwd.dwd_ord_channel_omni_order_detail_fl_d(
  `sub_order_no` bigint COMMENT '订单行表主键',
  `order_no` string COMMENT '订单号',
  `delivery_no` string COMMENT '出库单号',
  `gtin` string COMMENT '',
  `po_no` string COMMENT '采购单号(采购中心)',
  `logi_no` string COMMENT '国内物流单号',
  `return_logi_no` string COMMENT '国内退货物流单号',
  `ynap_po_no` string COMMENT 'YNAP PO单号',
  `ynap_order_no` string COMMENT 'YNAP订单号',
  `ynap_shipment_no` string COMMENT '包裹单号',
  `ynap_logi_no` string COMMENT '国际物流单号',
  `order_create_time` string COMMENT '下单时间',
  `order_pay_time` string COMMENT '付款时间',
  `push_ynap_order_time` string COMMENT '推送给ynap时间',
  `ynap_confirm_delivery_time` string COMMENT 'YNAP订单确认时间',
  `ynap_delivery_time` string COMMENT 'YNAP订单单发货时间',
  `ynap_enter_warehouse_time` string COMMENT 'YNAP订单入本地仓时间',
  `ynap_cancel_time` string COMMENT 'YNAP取消时间',
  `quantity` string COMMENT '商品件数',
  `ynap_confirmed_quantity` string COMMENT 'YNAP确认数量',
  `ynap_shipped_quantity` string COMMENT 'YNAP发货数量',
  `ynap_delivery_reject_quantity` string COMMENT 'YNAP拒绝发货数量',
  `local_receipt_quantity` string COMMENT '本地仓收货数量')
;


create table dw_dwd.dwd_ord_channel_omni_ynap_order_detail_fl_d(
delivery_no                   string comment '出库单号',
order_no                      string comment '订单号',
gtin                          string comment '',
po_no                         string comment '采购单号(采购中心)',
logi_no                       string comment '国内物流单号',
return_logi_no                string comment '国内退货物流单号',
ynap_po_no                    string comment 'YNAP PO单号',
ynap_order_no                 string comment 'YNAP订单号',
ynap_shipment_no              string comment '包裹单号',
ynap_logi_no                  string comment '国际物流单号',
order_create_time             string comment '下单时间',
order_pay_time                string comment '付款时间',
push_ynap_order_time          string comment '推送给ynap时间',
ynap_confirm_delivery_time    string comment 'YNAP订单确认时间',
ynap_delivery_time            string comment 'YNAP订单单发货时间',
ynap_enter_warehouse_time     string comment 'YNAP订单入本地仓时间',
ynap_cancel_time              string comment 'YNAP取消时间',
quantity                      string comment '商品件数',
ynap_confirmed_quantity       string comment 'YNAP确认数量',
ynap_shipped_quantity         string comment 'YNAP发货数量',
ynap_delivery_reject_quantity string comment 'YNAP拒绝发货数量',
local_receipt_quantity        string comment '本地仓收货数量'
)stored as orc;
















create table dw_ods.ods_app_tmall_trade_fullinfo_get_topic_iu_h(
    content string
)
partitioned by (dt string)
stored as orc
;
































CREATE TABLE dw_tmp.tmp_dwd_ord_channel_oms_order_fl_d_grade(
  `orderid` string,
  `level` int,
  `is_member` int,
  `customerno` string COMMENT '数据类型 data.prctvmkt.netAPorter.MainOrder 字段 customerNo 的列',
  `memberid` string COMMENT '数据类型 data.prctvmkt.netAPorter.MainOrder 字段 memberId 的列'
);






drop table if exists dw_dwd.dwd_ord_channel_giftcard_order_fl_d;
create table dw_dwd.dwd_ord_channel_giftcard_order_fl_d
(
    order_no                     string comment '订单号',
    order_amount                 decimal(10, 2) comment '正向预付卡(礼品卡)使用金额=本金+赠送金额',
    order_origin_amount          decimal(10, 2) comment '正向预付卡(礼品卡)使用本金金额',
    order_send_amount            decimal(10, 2) comment '正向预付卡(礼品卡)使用赠送金额',
    refund_amount                decimal(10, 2) comment '逆向预付卡(礼品卡)使用金额',
    refund_origin_amount         decimal(10, 2) comment '逆向预付卡(礼品卡)使用本金金额',
    refund_send_amount           decimal(10, 2) comment '逆向预付卡(礼品卡)使用赠送金额',
    freight_order_amount         decimal(10, 2) comment '运费正向预付卡(礼品卡)使用金额=本金+赠送金额',
    freight_order_origin_amount  decimal(10, 2) comment '运费正向预付卡(礼品卡)使用本金金额',
    freight_order_send_amount    decimal(10, 2) comment '运费正向预付卡(礼品卡)使用赠送金额',
    freight_refund_amount        decimal(10, 2) comment '运费逆向预付卡(礼品卡)使用金额',
    freight_refund_origin_amount decimal(10, 2) comment '运费逆向预付卡(礼品卡)使用本金金额',
    freight_refund_send_amount   decimal(10, 2) comment '运费逆向预付卡(礼品卡)使用赠送金额'
) stored as orc;





drop table if exists dw_dwd.dwd_ord_channel_giftcard_order_detail_fl_d;
create table dw_dwd.dwd_ord_channel_giftcard_order_detail_fl_d
(
    sub_order_no         string         comment '子订单号',
    order_no             string         comment '订单号',
    gtin                 string         comment 'gtin',
    order_amount         decimal(10, 2) comment '正向预付卡(礼品卡)使用金额=本金+赠送金额',
    order_origin_amount  decimal(10, 2) comment '正向预付卡(礼品卡)使用本金金额',
    order_send_amount    decimal(10, 2) comment '正向预付卡(礼品卡)使用赠送金额',
    refund_amount        decimal(10, 2) comment '逆向预付卡(礼品卡)使用金额',
    refund_origin_amount decimal(10, 2) comment '逆向预付卡(礼品卡)使用本金金额',
    refund_send_amount   decimal(10, 2) comment '逆向预付卡(礼品卡)使用赠送金额',
    freight_order_amount         decimal(10, 2) comment '运费正向预付卡(礼品卡)使用金额=本金+赠送金额',
    freight_order_origin_amount  decimal(10, 2) comment '运费正向预付卡(礼品卡)使用本金金额',
    freight_order_send_amount    decimal(10, 2) comment '运费正向预付卡(礼品卡)使用赠送金额',
    freight_refund_amount        decimal(10, 2) comment '运费逆向预付卡(礼品卡)使用金额',
    freight_refund_origin_amount decimal(10, 2) comment '运费逆向预付卡(礼品卡)使用本金金额',
    freight_refund_send_amount   decimal(10, 2) comment '运费逆向预付卡(礼品卡)使用赠送金额'
) stored as orc;

drop table if exists dw_dwd.dwd_ord_channel_giftcard_product_detail_fl_d;
create table dw_dwd.dwd_ord_channel_giftcard_product_detail_fl_d
(
    order_no                     string comment '订单号',
    gtin                         string comment 'gtin',
    provide_type                 string comment '卡种类',
    order_amount                 decimal(10, 2) comment '正向预付卡(礼品卡)使用金额=本金+赠送金额',
    order_origin_amount          decimal(10, 2) comment '正向预付卡(礼品卡)使用本金金额',
    order_send_amount            decimal(10, 2) comment '正向预付卡(礼品卡)使用赠送金额',
    refund_amount                decimal(10, 2) comment '逆向预付卡(礼品卡)使用金额',
    refund_origin_amount         decimal(10, 2) comment '逆向预付卡(礼品卡)使用本金金额',
    refund_send_amount           decimal(10, 2) comment '逆向预付卡(礼品卡)使用赠送金额',
    freight_order_amount         decimal(10, 2) comment '运费正向预付卡(礼品卡)使用金额=本金+赠送金额',
    freight_order_origin_amount  decimal(10, 2) comment '运费正向预付卡(礼品卡)使用本金金额',
    freight_order_send_amount    decimal(10, 2) comment '运费正向预付卡(礼品卡)使用赠送金额',
    freight_refund_amount        decimal(10, 2) comment '运费逆向预付卡(礼品卡)使用金额',
    freight_refund_origin_amount decimal(10, 2) comment '运费逆向预付卡(礼品卡)使用本金金额',
    freight_refund_send_amount   decimal(10, 2) comment '运费逆向预付卡(礼品卡)使用赠送金额'
) stored as orc;








select
       t1.trade_no     as ftid,
       t1.gtin,
       t1.type,
       t1.share_total_amount,
       t1.share_origin_amount,
       t1.share_extra_amount
from (
      select trade_no,
             gtin,
             type,
             sum(share_total_amount)  share_total_amount,
             sum(share_origin_amount) share_origin_amount,
             sum(share_extra_amount)  share_extra_amount
      from dw_dwd.dwd_app_card_share_bill_fl_d t1
      join dw_dwd.dwd_app_giftcard_detail_fl_d t2 on t1.card_detail_id = t2.id
      join dw_dwd.dwd_app_giftcard_fl_d t3 on t2.card_id = t3.id
      where t1.card_no != 'CASH_PAY'
        and t1.gtin != 'freight'
      group by trade_no,gtin,type
) t1
left join (
     select concat(trade_no, gtin, 'BUY') concat
     from (
        select trade_no,gtin,count(1) cnt
        from (
            select trade_no,gtin
              from dw_dwd.dwd_app_card_share_bill_fl_d
              where card_no != 'CASH_PAY'
                and gtin != 'freight'
              group by trade_no, gtin, type
        ) t1
        group by trade_no,gtin
     ) t2 where cnt > 1
)t3
on concat(t1.trade_no, t1.gtin, t1.type)=t3.concat;













drop table if exists  dw_dwd.dwd_ord_channel_oms_order_fl_d;
CREATE TABLE dw_dwd.dwd_ord_channel_oms_order_fl_d(
  `order_no` string COMMENT '订单编号',
  `platform_order_no` string,
  `order_category` string,
  `order_channel` string,
  `order_status` string COMMENT '目标状态码',
  `original_order_status` bigint,
  `memberid` string COMMENT '数据类型 data.prctvmkt.netAPorter.MainOrder 字段 memberId 的列',
  `member_level_id` string COMMENT '数据类型 data.prctvmkt.netAPorter.MainOrder 字段 tierCurrent 的列',
  `customer_no` string COMMENT '登录用户编号',
  `order_original_amount` double,
  `order_markdown_amount` double COMMENT '订单金额 (商品总金额)',
  `order_total_amount` double COMMENT '应支付金额',
  `order_pay_amount` double COMMENT '应支付金额',
  `order_adjust_amount` double COMMENT '订单折扣金额(营销优惠)',
  `order_discount_amount` double,
  `order_coupon_amount` double COMMENT '订单优惠金额(优惠券)',
  `order_post_amount` double COMMENT '运费',
  `prepay_card_amount` double,
  `origin_prepay_card_amount` decimal(10,2),
  `extra_prepay_card_amount` decimal(10,2),
  `use_prepay_card_amount` decimal(20,2),
  `use_origin_prepay_card_amount` decimal(20,2),
  `use_extra_prepay_card_amount` decimal(20,2),
  `order_prepay_deposit_amount` int,
  `order_prepay_amount` int,
  `order_refund_amount` double COMMENT '已退款金额',
  `order_special_refund` decimal(10,2),
  `affiliate_giftcard_amount` decimal(10,2),
  `affiliate_giftcard_no` string,
  `sub_order_num` bigint,
  `order_sku_quantity` bigint,
  `buyer_nick` string COMMENT '用户名',
  `receiver_district` string,
  `receiver_city` string,
  `receiver_province` string,
  `receiver_address` string,
  `receiver_name` string COMMENT '收货人',
  `receiver_country` string COMMENT '收货地址',
  `receiver_postcode` string,
  `receiver_mobile` string COMMENT '收货人手机号',
  `receiver_phone` string,
  `system_source` bigint,
  `order_type` bigint,
  `channel_code` bigint,
  `residue_amount` decimal(10,2) COMMENT '剩余应付金额 (扣除礼品卡后的支付现金)',
  `is_affiliate_order` bigint,
  `utm_source` string COMMENT '',
  `utm_content` string COMMENT '',
  `is_douyin_notstock` bigint,
  `create_time` timestamp COMMENT '创建时间',
  `update_time` timestamp COMMENT '修改时间',
  `dc_system_time` timestamp,
  `order_create_time` timestamp
)stored as orc;





CREATE TABLE dw_tmp.tmp_crm_order_is_memrber_fl_d(
  `orderid` string,
  `level` int,
  `is_member` int,
  `customerno` string COMMENT '数据类型 data.prctvmkt.netAPorter.MainOrder 字段 customerNo 的列',
  `memberid` string COMMENT '数据类型 data.prctvmkt.netAPorter.MainOrder 字段 memberId 的列')
;
























CREATE TABLE dw_dws.dws_ord_doamin_order_detail_fl_d(
  `sub_order_no` bigint COMMENT '订单行表主键',
  `order_no` string COMMENT '团单编号,用于分库分表拆分键使用',
  `platform_sub_order_no` bigint COMMENT '订单行表主键',
  `platform_order_no` string COMMENT '',
  `refund_no` string COMMENT '退款单号',
  `platform_refund_no` string,
  `order_category` string,
  `order_channel` string COMMENT '',
  `sale_platform` int COMMENT '主平台',
  `sub_sale_platform` int COMMENT '子平台',
  `jv_user_id` string,
  `member_id` string COMMENT '会员id',
  `customer_no` string COMMENT '登录用户编号',
  `gtin` string COMMENT '商品sku号',
  `order_status` string COMMENT '目标状态码',
  `sub_order_status` string COMMENT '目标状态码',
  `order_original_amount` double,
  `order_markdown_amount` double COMMENT '订单金额 (商品总金额)',
  `order_total_amount` double COMMENT '应支付金额',
  `order_pay_amount` double COMMENT '应支付金额',
  `order_adjust_amount` double COMMENT '订单折扣金额(营销优惠)',
  `order_discount_amount` double,
  `order_coupon_amount` double COMMENT '订单优惠金额(优惠券)',
  `order_post_amount` double COMMENT '运费',
  `order_origin_prepay_card_amount` string,
  `order_extra_prepay_card_amount` string,
  `order_use_prepay_card_amount` string,
  `order_use_origin_prepay_card_amount` string,
  `order_use_extra_prepay_card_amount` string,
  `order_prepay_deposit_amount` int,
  `order_prepay_amount` int,
  `order_refund_amount` double COMMENT '已退款金额',
  `sub_order_num` bigint,
  `order_sku_quantity` bigint,
  `buyer_nick` string COMMENT '用户名',
  `receiver_district` string,
  `receiver_city` string,
  `receiver_province` string,
  `receiver_address` string,
  `receiver_name` string COMMENT '收货人',
  `receiver_country` string COMMENT '收货地址',
  `receiver_postcode` string,
  `receiver_mobile` string COMMENT '收货人手机号',
  `receiver_phone` string,
  `unit_price` double COMMENT '商品单价',
  `markdown_price` double COMMENT 'markdown价格',
  `is_preorder` int COMMENT '',
  `is_jit` int COMMENT '是否是jit商品 1是 2否',
  `is_jit_in_stock` int COMMENT '是否现货 1是 2否',
  `delivery_type` string,
  `delivery_status` bigint,
  `tms_company_code` string COMMENT '物流公司编号',
  `tms_company_name` string COMMENT '物流公司名称',
  `warehouse_code` string COMMENT '虚拟仓库编号',
  `logi_no` string COMMENT '物流编号',
  `delivery_quantity` bigint,
  `delivery_item_status` bigint,
  `delivery_sku_quantity` bigint,
  `wms_delivery_no` string,
  `sys_po_no` string,
  `rel_po_no` string,
  `international_logi_no` string,
  `international_logi_shipment_no` string,
  `refund_type` bigint,
  `refund_total_fee` double COMMENT '退款金额',
  `refund_cash_fee` double,
  `refund_prepay_card_amount` decimal(20,2),
  `refund_origin_prepay_card_amount` decimal(20,2),
  `refund_extra_prepay_card_amount` decimal(20,2),
  `refund_post_fee` double COMMENT '运费',
  `refund_desc` string COMMENT '退款说明',
  `refund_phase` bigint,
  `refund_goods_status` bigint,
  `refund_cs_status` string,
  `seller_address` string COMMENT '收货地址',
  `refund_status` string COMMENT '目标状态码',
  `refund_fee` double COMMENT '退款金额',
  `return_quantity` bigint,
  `return_stock_quantity` bigint,
  `is_goods_return` bigint,
  `return_status` bigint,
  `refund_reason` string COMMENT '退款原因',
  `tms_no` string,
  `order_create_time` timestamp COMMENT '创建时间',
  `order_prepay_time` timestamp,
  `order_pay_time` timestamp COMMENT '支付时间',
  `push_ynap_order_time` timestamp,
  `ynap_confirm_delivery_time` string,
  `ynap_delivery_time` string,
  `ynap_enter_warehouse_time` timestamp,
  `ynap_cancel_time` timestamp,
  `order_apply_delivery_time` timestamp,
  `order_delivery_time` timestamp COMMENT '发货时间 consigntime',
  `order_consign_time` timestamp COMMENT '子订单签收时间',
  `order_success_time` timestamp COMMENT '子订单交易成功时间',
  `order_end_time` timestamp COMMENT '子订单交易成功时间',
  `order_cancel_time` timestamp COMMENT '子订单交易关闭时间',
  `order_last_update_time` timestamp COMMENT '',
  `refund_apply_time` timestamp COMMENT '子订单退货发起时间',
  `return_apply_time` timestamp COMMENT '退款提交时间',
  `return_send_time` timestamp COMMENT '子订单退货上门揽件时间',
  `return_enter_warehouse_time` timestamp COMMENT '确认入库时间',
  `refund_backmoney_time` timestamp COMMENT '子订单退货确认退款时间',
  `refund_success_time` timestamp,
  `refund_close_time` timestamp,
  `refund_last_update_time` timestamp COMMENT '更新时间',
  `is_use_prepay_card` string,
  `is_buy_prepay_card` string,
  `is_installment` string,
  `is_special_refund` string,
  `payment_modes` string,
  `is_88vip` string,
  `terminal_type` string,
  `is_staff_order` string,
  `dm_utm_source` string,
  `lh_utm_source` string,
  `is_mobile_order` string,
  `is_member_order` string,
  `is_gift_order` string,
  `is_free_order` string,
  `app_order_type` string,
  `app_channel_code` string,
  `cancel_before_shipment_on_same_day` string,
  `cancel_before_shipment` string,
  `cancel_refund_before_shipment` string,
  `is_gift` int COMMENT '是否是赠品',
  `order_amount` decimal(10,2) COMMENT '下单金额',
  `pay_amount` decimal(10,2) COMMENT '付款金额',
  `ship_amount` decimal(10,2) COMMENT '发货金额',
  `refund_apply_amount` decimal(10,2) COMMENT '申退金额',
  `refund_apply_success_amount` decimal(10,2) COMMENT '退款成功金额',
  `refund_cancel_amount` decimal(10,2) COMMENT '发货前退款金额',
  `refund_cancel_success_amount` decimal(10,2) COMMENT '发货前退款成功金额',
  `order_num` bigint COMMENT '下单件数',
  `pay_num` bigint COMMENT '付款件数',
  `ship_num` bigint COMMENT '发货件数',
  `refund_apply_num` bigint COMMENT '申退件数',
  `refund_apply_success_num` bigint COMMENT '退款成功件数',
  `refund_cancel_num` bigint COMMENT '发货前退款件数',
  `refund_cancel_success_num` bigint COMMENT '发货前退款成功件数',
  `exchange_rate_cny_to_eur` decimal(10,2) COMMENT '人名币兑换欧元汇率',
  `exchange_rate_eur_to_cny` decimal(10,2) COMMENT '欧元兑换人名币汇率',
  `tax_rate` decimal(10,2) COMMENT '税率',
  `cash_pay_amunt` decimal(10,2) COMMENT '实付现金金额',
  `prepay_card_amount` double,
  `origin_prepay_card_amount` decimal(10,2),
  `extra_prepay_card_amount` decimal(10,2),
  `use_prepay_card_amount` decimal(20,2),
  `use_origin_prepay_card_amount` decimal(20,2),
  `use_extra_prepay_card_amount` decimal(20,2),
  `city_level` string)
;



drop table if exists dw_dwd.dwd_ord_channel_oms_order_fl_d;
create table dw_dwd.dwd_ord_channel_oms_order_fl_d
stored as orc as
select t1.order_no                                                   as order_no                      -- OMS订单号
     , case
           when t1.order_type = 11 and t1.channel_code = 4 --douyin
               then rel_order_no
           else t1.order_no end                                      as platform_order_no             -- 平台订单号
     , (case when t1.order_type = 10 then '礼品卡充值订单' else '销售订单' end) as order_category                -- 订单分类 TODO 销售订单/互动订单/购买预付卡订单
     , (case
            when t1.order_type = 1 and t1.channel_code = 7 then 'H5'
            when t1.order_type = 1 and t1.channel_code = 2 then 'WEB'
            when t1.order_type = 11 and t1.channel_code = 4 then 'DOUYIN'
            when t1.order_type = 1 and t1.channel_code = 9 then 'MINI PROGRAM'
            else 'APP' -- TODO 待确认
    end)                                                             as order_channel                 -- 订单渠道
     , t2.target_status_code                                         as order_status                  -- 订单状态
     , t1.order_status                                               as original_order_status         -- 原订单状态
     , t3.memberid                                                                                    -- 会员ID
     , t3.tiercurrent                                                as member_level_id               -- TODO 下单时会员等级 CRM
     , t1.login_code                                                 as customer_no                   -- app_user_id
     , t6.unit_price                                                 as order_original_amount         -- TODO 订单原价 商品单价(unit_price)*数量
     , t1.order_amount                                               as order_markdown_amount         -- TODO 订单划线价;不含运费; 商品折扣价*数量
     , t1.payable_amount                                             as order_total_amount            -- 订单总金额
     , t1.payable_amount                                             as order_pay_amount              -- 订单实付金额(含现金+预付卡本金)
     , t1.discount_amount                                            as order_adjust_amount           -- 订单调整金额
     , t1.order_amount - payable_amount - coupon_amount              as order_discount_amount         -- 订单折扣金额 -- TODO 确认不同情况场景
     , t1.coupon_amount                                              as order_coupon_amount           -- 订单优惠金额
     , t1.freight                                                    as order_post_amount             -- 订单运费 -- TODO 订单运费
     , case
           when t1.order_type = 10 then t1.payable_amount
           else 0 end                                                as prepay_card_amount            -- 购买预付卡金额 -- TODO 购买预付卡
     , cast(null as decimal(10,2))                                  as origin_prepay_card_amount     -- 购买预付卡本金金额
     , cast(null as decimal(10,2))                                  as extra_prepay_card_amount      -- 购买预付卡赠送金额
     , case when t5.type = 'BUY' then t5.share_total_amount end      as use_prepay_card_amount        -- 使用预付卡总金额
     , case when t5.type = 'BUY' then t5.share_total_amount end      as use_origin_prepay_card_amount -- 使用预付卡本金金额
     , case when t5.type = 'BUY' then t5.share_total_amount end      as use_extra_prepay_card_amount  -- 使用预付卡赠送金额
     , 0                                                             as order_prepay_deposit_amount   -- 预售支付定金
     , 0                                                             as order_prepay_amount           -- 预售支付金额(尾款)
     , t1.refunded_amount                                            as order_refund_amount           -- 退款金额。精确到2位小数;单位:元
     , cast(null as decimal(10,2))                                   as order_special_refund          -- TODO 是否含特殊退
     , cast(null as decimal(10,2))                                   as affiliate_giftcard_amount     -- TODO 反佣金额
     , cast(null as string)                                          as affiliate_giftcard_no         -- TODO 反佣卡号
     , t6.sub_order_num                                              as sub_order_num                 -- TODO 子订单数量
     , t6.order_sku_quantity                                         as order_sku_quantity            -- TODO 订单商品件数
     , t1.login_name                                                 as buyer_nick                    --买家昵称
     , split(t1.receiving_address, '\\|')[2]                         as receiver_district             -- 收货区 TODO 拆分省市区
     , split(t1.receiving_address, '\\|')[1]                         as receiver_city                 --收货城市
     , split(t1.receiving_address, '\\|')[0]                         as receiver_province             --收货省份
     , split(t1.receiving_address, '\\|')[4]                         as receiver_address              --   收货地址
     , t1.receiver_name                                              as receiver_name                 --收货人名称
     , t1.receiving_address                                          as receiver_country              --收货人国籍
     , cast(null as string)                                          as receiver_postcode             --   收货地址邮编
     , t1.receiver_phone_number                                      as receiver_mobile               --收货人手机号
     , cast(null as string)                                          as receiver_phone                --收货人固定电话
     , t1.system_source                                                                               -- 系统来源
     , t1.order_type
     , t1.channel_code
     , t1.residue_amount
     , t1.affiliate_flag                                             as is_affiliate_order
     , t1.utm_source
     , t1.utm_content
     , is_douyin_notstock                                                                             -- 抖音未预占库存就发生退款标识
     , t1.create_time
     , t1.update_time
     , `current_timestamp`()                                         as dc_system_time
from (
   select * from dw_dwd.dwd_app_oms_order_fl_d where deleted=0
) t1 left join(
    select source_status_code,target_status_code from dw_dim.dim_ord_status_fl_d
    where source_key='dwd_ord_order_detail_fl_d_app' and target_key = 'dwd_ord_order_detail_fl_d'
)t2 on t1.order_status =t2.source_status_code
left join dw_dwd.dwd_crm_d_p_n_mainorder_259_fl_d t3 on t1.order_no=t3.orderid
left join dw_dwd.dwd_app_giftcard_bill_fl_d t4 on t1.order_no=t4.id
left join (
    select trade_no,type,
           sum(share_total_amount) share_total_amount
    from dw_dwd.dwd_app_card_share_bill_fl_d
    group by trade_no,type
)t5 on t1.order_no=t5.trade_no
left join (
    select order_item_no,
           count(1) sub_order_num,
           sum(product_quantity) order_sku_quantity,
           sum(unit_price) unit_price
    from dw_dwd.dwd_app_oms_order_item_fl_d
    where deleted=0
    group by order_item_no
)t6
on t1.order_no=t6.order_item_no
union all
select t1.order_no                                                   as order_no                      -- OMS订单号
     , case
           when t1.order_type = 11 and t1.channel_code = 4 --douyin
               then rel_order_no
           else t1.order_no end                                      as platform_order_no             -- 平台订单号
     , (case when t1.order_type = 10 then '礼品卡充值订单' else '销售订单' end) as order_category                -- 订单分类 TODO 销售订单/互动订单/购买预付卡订单
     , 'TMALL'                                                             as order_channel                 -- 订单渠道
     , t2.target_status_code                                         as order_status                  -- 订单状态
     , t1.order_status                                               as original_order_status         -- 原订单状态
     , t3.memberid                                                                                    -- 会员ID
     , t3.tiercurrent                                                as member_level_id               -- TODO 下单时会员等级 CRM
     , t1.login_code                                                 as customer_no                   -- app_user_id
     , t6.unit_price                                                 as order_original_amount         -- TODO 订单原价 商品单价(unit_price)*数量
     , t1.order_amount                                               as order_markdown_amount         -- TODO 订单划线价;不含运费; 商品折扣价*数量
     , t1.payable_amount                                             as order_total_amount            -- 订单总金额
     , t1.payable_amount                                             as order_pay_amount              -- 订单实付金额(含现金+预付卡本金)
     , t1.discount_amount                                            as order_adjust_amount           -- 订单调整金额
     , t1.order_amount - payable_amount - coupon_amount              as order_discount_amount         -- 订单折扣金额 -- TODO 确认不同情况场景
     , t1.coupon_amount                                              as order_coupon_amount           -- 订单优惠金额
     , t1.freight                                                    as order_post_amount             -- 订单运费 -- TODO 订单运费
     , case
           when t1.order_type = 10 then t1.payable_amount
           else 0 end                                                as prepay_card_amount            -- 购买预付卡金额 -- TODO 购买预付卡
     , cast(null as decimal(10,2))                                   as origin_prepay_card_amount     -- 购买预付卡本金金额
     , cast(null as decimal(10,2))                                   as extra_prepay_card_amount      -- 购买预付卡赠送金额
     , case when t5.type = 'BUY' then t5.share_total_amount end      as use_prepay_card_amount        -- 使用预付卡总金额
     , case when t5.type = 'BUY' then t5.share_total_amount end      as use_origin_prepay_card_amount -- 使用预付卡本金金额
     , case when t5.type = 'BUY' then t5.share_total_amount end      as use_extra_prepay_card_amount  -- 使用预付卡赠送金额
     , 0                                                             as order_prepay_deposit_amount   -- 预售支付定金
     , 0                                                             as order_prepay_amount           -- 预售支付金额(尾款)
     , t1.refunded_amount                                            as order_refund_amount           -- 退款金额。精确到2位小数;单位:元
     , cast(null as decimal(10,2))                                   as order_special_refund          -- TODO 是否含特殊退
     , cast(null as decimal(10,2))                                   as affiliate_giftcard_amount     -- TODO 反佣金额
     , cast(null as string)                                          as affiliate_giftcard_no         -- TODO 反佣卡号
     , t6.sub_order_num                                              as sub_order_num                 -- TODO 子订单数量
     , t6.order_sku_quantity                                         as order_sku_quantity            -- TODO 订单商品件数
     , t1.login_name                                                 as buyer_nick                    --买家昵称
     , split(t1.receiving_address, '\\|')[2]                         as receiver_district             -- 收货区 TODO 拆分省市区
     , split(t1.receiving_address, '\\|')[1]                         as receiver_city                 --收货城市
     , split(t1.receiving_address, '\\|')[0]                         as receiver_province             --收货省份
     , split(t1.receiving_address, '\\|')[4]                         as receiver_address              --   收货地址
     , t1.receiver_name                                              as receiver_name                 --收货人名称
     , t1.receiving_address                                          as receiver_country              --收货人国籍
     , cast(null as string)                                          as receiver_postcode             --   收货地址邮编
     , t1.receiver_phone_number                                      as receiver_mobile               --收货人手机号
     , cast(null as string)                                          as receiver_phone                --收货人固定电话
     , t1.system_source                                                                               -- 系统来源
     , t1.order_type
     , t1.channel_code
     , t1.residue_amount
     , t1.affiliate_flag                                             as is_affiliate_order
     , t1.utm_source
     , t1.utm_content
     , is_douyin_notstock                                                                             -- 抖音未预占库存就发生退款标识
     , t1.create_time
     , t1.update_time
     , `current_timestamp`()                                         as dc_system_time
from (
   select * from dw_dwd.dwd_ynap_oms_tmall_order_fl_d where deleted=0
) t1 left join(
    select source_status_code,
           target_status_code
    from dw_dim.dim_ord_status_fl_d
    where source_key='dwd_ord_order_detail_fl_d_ecc'
    and target_key = 'item_sales_data'
)t2 on t1.order_status =t2.source_status_code
left join dw_dwd.dwd_crm_d_p_n_mainorder_259_fl_d t3 on t1.order_no=t3.orderid
left join dw_dwd.dwd_app_giftcard_bill_fl_d t4 on t1.order_no=t4.id
left join (
    select trade_no,type,
           sum(share_total_amount) share_total_amount
    from dw_dwd.dwd_app_card_share_bill_fl_d
    group by trade_no,type
)t5 on t1.rel_order_no=t5.trade_no
left join (
    select order_item_no,
           count(1) sub_order_num,
           sum(product_quantity) order_sku_quantity,
           sum(unit_price) unit_price
    from dw_dwd.dwd_ynap_oms_tmall_order_item_fl_d
    where deleted=0
    group by order_item_no
)t6
on t1.order_no=t6.order_item_no
union all
select max(t1.ftid)                 as order_no                      -- OMS订单号
     , max(t1.ftid)                 as platform_order_no             -- 平台订单号
     , '线下订单'                       as order_category                -- 订单分类 TODO 销售订单/互动订单/购买预付卡订单
     , 'OFFLINE'                    as order_channel                 -- 订单渠道
     , max(t1.fstatus)              as order_status                  -- 订单状态
     , max(t1.fstatus)              as original_order_status         -- 原订单状态
     , cast(null as string)                                          -- 会员ID
     , cast(null as string)         as member_level_id               -- TODO 下单时会员等级 CRM
     , cast(null as string)         as customer_no                   -- app_user_id
     , max(t1.price)                as order_original_amount         -- TODO 订单原价 商品单价(unit_price)*数量
     , max(t1.markdown_price)       as order_markdown_amount         -- TODO 订单划线价;不含运费; 商品折扣价*数量
     , max(t1.payment)              as order_total_amount            -- 订单总金额
     , max(t1.payment)              as order_pay_amount              -- 订单实付金额(含现金+预付卡本金)
     , max(t1.payment)              as order_adjust_amount           -- 订单调整金额
     , cast(null as string)         as order_discount_amount         -- 订单折扣金额 -- TODO 确认不同情况场景
     , cast(null as string)         as order_coupon_amount           -- 订单优惠金额
     , cast(null as string)         as order_post_amount             -- 订单运费 -- TODO 订单运费
     , cast(null as string)         as prepay_card_amount            -- 购买预付卡金额 -- TODO 购买预付卡
     , cast(null as decimal(10, 2)) as origin_prepay_card_amount     -- 购买预付卡本金金额
     , cast(null as decimal(10, 2)) as extra_prepay_card_amount      -- 购买预付卡赠送金额
     , cast(null as string)         as use_prepay_card_amount        -- 使用预付卡总金额
     , cast(null as string)         as use_origin_prepay_card_amount -- 使用预付卡本金金额
     , cast(null as string)         as use_extra_prepay_card_amount  -- 使用预付卡赠送金额
     , 0                            as order_prepay_deposit_amount   -- 预售支付定金
     , 0                            as order_prepay_amount           -- 预售支付金额(尾款)
     , max(t1.return_sales)         as order_refund_amount           -- 退款金额。精确到2位小数;单位:元
     , cast(null as decimal(10, 2)) as order_special_refund          -- TODO 是否含特殊退
     , cast(null as decimal(10, 2)) as affiliate_giftcard_amount     -- TODO 反佣金额
     , cast(null as string)         as affiliate_giftcard_no         -- TODO 反佣卡号
     , sum(1)                       as sub_order_num                 -- TODO 子订单数量
     , max(t1.fnum)                 as order_sku_quantity            -- TODO 订单商品件数
     , max(t1.buyer_nick)           as buyer_nick                    --买家昵称
     , max(t1.freceiverdistrict)    as receiver_district             -- 收货区 TODO 拆分省市区
     , max(t1.freceivercity)        as receiver_city                 --收货城市
     , max(t1.freceiverstate)       as receiver_province             --收货省份
     , cast(null as string)         as receiver_address              --    收货地址
     , cast(null as string)         as receiver_name                 --收货人名称
     , max(t1.freceiverdistrict)    as receiver_country              --收货人国籍
     , cast(null as string)         as receiver_postcode             --    收货地址邮编
     , max(t1.app_telephone)        as receiver_mobile               --收货人手机号
     , max(t1.app_telephone)        as receiver_phone                --收货人固定电话
     , cast(null as string)                                          -- 系统来源
     , cast(null as string)
     , cast(null as string)
     , cast(null as string)
     , cast(null as string)         as is_affiliate_order
     , cast(null as string)
     , cast(null as string)
     , cast(null as string)                                          -- 抖音未预占库存就发生退款标识
     , `current_timestamp`()
     , `current_timestamp`()
     , `current_timestamp`()        as dc_system_time
from dw_dwd.dwd_jv_manual_offline_sales_fl_d t1
group by ftid
;







drop table if exists dw_dwd.dwd_ord_channel_oms_order_delivery_fl_d;
create table dw_dwd.dwd_ord_channel_oms_order_delivery_fl_d
stored as orc as
select t1.delivery_no,                                 --出库单号
       t1.order_no,                                    --订单号
       case
           when t1.rel_order_no is not null then t1.rel_order_no
           else t1.order_no
           end                   as platform_order_no, --  源平台订单号
       t1.delivery_status        as delivery_status,   --出库单状态
       t1.tms_service_code       as tms_company_code,  --物流公司编码
       t1.tms_service_name       as tms_company_name,  --物流公司名称
       t1.virtual_warehouse_code as warehouse_code,    --发货仓库编码
       t1.tms_number             as logi_no,           --国内物流单号
       t2.delivery_quantity,                           --发货总数
       t1.create_time,                                 --创建时间
       t1.update_time,                                 --更新时间
       `current_timestamp`()     as dc_system_time     --系统更新时间
from (
    select *
    from
    dw_dwd.dwd_app_oms_order_delivery_fl_d
    where deleted=0
) t1
left join (
      select delivery_no,
             sum(product_quantity)delivery_quantity
      from dw_dwd.dwd_app_oms_order_delivery_items_fl_d
      where deleted=0 group by delivery_no
)t2
on t1.delivery_no=t2.delivery_no
union all
select t1.delivery_no,                                 --出库单号
       t1.order_no,                                    --订单号
       case
           when t1.rel_order_no is not null then t1.rel_order_no
           else t1.order_no
           end                   as platform_order_no, --  源平台订单号
       t1.delivery_status        as delivery_status,   --出库单状态
       t1.tms_service_code       as tms_company_code,  --物流公司编码
       t1.tms_service_name       as tms_company_name,  --物流公司名称
       t1.virtual_warehouse_code as warehouse_code,    --发货仓库编码
       t1.tms_number             as logi_no,           --国内物流单号
       t2.delivery_quantity,                           --发货总数
       t1.create_time,                                 --创建时间
       t1.update_time,                                 --更新时间
       `current_timestamp`()     as dc_system_time     --系统更新时间
from (
    select *
    from
    dw_dwd.dwd_ynap_oms_tmall_order_delivery_fl_d
    where deleted=0
) t1
left join (
      select delivery_no,
             sum(product_quantity)delivery_quantity
      from dw_dwd.dwd_ynap_oms_tmall_order_delivery_items_fl_d
      where deleted=0 group by delivery_no
)t2
on t1.delivery_no=t2.delivery_no
union all
select cast(null as string)     delivery_no,       --出库单号
       t1.ftid,                                    --订单号
       t1.ftid               as platform_order_no, --  源平台订单号
       cast(null as string)  as delivery_status,   --出库单状态
       cast(null as string)  as tms_company_code,  --物流公司编码
       cast(null as string)  as tms_company_name,  --物流公司名称
       cast(null as string)  as warehouse_code,    --发货仓库编码
       cast(null as string)  as logi_no,           --国内物流单号
       t1.fnum,                                    --发货总数
       `current_timestamp`(),                      --创建时间
       `current_timestamp`(),                      --更新时间
       `current_timestamp`() as dc_system_time     --系统更新时间
from dw_dwd.dwd_jv_manual_offline_sales_fl_d t1
;



drop table if exists dw_dwd.dwd_ord_model_order_detail_basic_index_fl_d;
create table dw_dwd.dwd_ord_model_order_detail_basic_index_fl_d
stored as orc as
select t1.id                                                                           as sub_order_no                 --子订单号
     , t1.sharding_key_order_no                                                        as order_no                     --订单号
     , (case
            when t2.order_type = 1 and t2.channel_code = 7 then 'H5'
            when t2.order_type = 1 and t2.channel_code = 2 then 'WEB'
            when t2.order_type = 11 and t2.channel_code = 4 then 'DOUYIN'
            when t2.order_type = 1 and t2.channel_code = 9 then 'MINI PROGRAM'
            else 'APP' -- TODO 口径待确认
    end)                                                                               as order_channel
     , `current_date`()                                                                as day                          --数据日期
     , t12.memberid                                                                    as memberid                     --会员id
     , t1.product_code                                                                 as sku_code                     --商品标识
     , t2.payable_amount                                                               as order_amount                 --下单金额
     , t2.payable_amount                                                               as pay_amount                   --付款金额
     , case when child_order_delivery_time is not null then t2.payable_amount end      as ship_amount                  --发货金额
     , t1.refund_amount                                                                as refund_apply_amount          --申退金额
     , t1.refund_amount                                                                as refund_apply_success_amount  --退款成功金额
     , case when t7.child_order_delivery_time is not null then t1.refund_amount end    as refund_cancel_amount         --发货前退款金额
     , case
           when t7.child_order_delivery_time is not null
               then t1.refund_amount end                                               as refund_cancel_success_amount --发货前退款成功金额
     , t1.product_quantity                                                             as order_num                    --下单件数
     , t1.product_quantity                                                             as pay_num                      --付款件数
     , case when t7.child_order_delivery_time is not null then t1.product_quantity end as ship_num                     --发货件数
     , t8.refund_goods_num                                                             as refund_apply_num             --申退件数
     , case when t8.refund_status = 'SUCCESS' then t8.refund_goods_num end             as refund_apply_success_num     --  退款成功件数
     , case when t7.child_order_delivery_time is null then t8.refund_goods_num end     as refund_cancel_num            --  发货前退款件数
     , case
           when t7.child_order_delivery_time is null
               then t8.refund_goods_num end                                            as refund_cancel_success_num    --发货前退款成功件数
     , cast(null as string)                                                            as exchange_rate_cny_to_eur     --人名币兑换欧元汇率
     , cast(null as string)                                                            as exchange_rate_eur_to_cny--欧元兑换人名币汇率
     , cast(null as string)                                                            as tax_rate--   税率
     , t2.payable_amount                                                               as cash_pay_amunt--实付现金金额
     , cast(null as string)                                                            as prepay_card_amount--购买预付卡金额
     , cast(null as string)                                                            as origin_prepay_card_amount--      购买预付卡本金金额
     , cast(null as string)                                                            as extra_prepay_card_amount--       购买预付卡赠送金额
     , cast(null as string)                                                            as use_prepay_card_amount--使用预付卡总金额
     , cast(null as string)                                                            as use_origin_prepay_card_amount--      使用预付卡本金金额
     , cast(null as string)                                                            as use_extra_prepay_card_amount--       使用预付卡赠送金额
     , cast(null as string)                                                            as order_prepay_deposit_amount--    预售支付定金
     , t1.create_time                                                                  as create_time
     , t1.update_time                                                                  as update_time                               -- 更新时间
     , `current_timestamp`()                                                           as dc_system_time
from(
    select *
    from dw_dwd.dwd_app_oms_order_item_fl_d                    --dwd_app_trade_order_item_fl_d
    where deleted = 0
) t1
left join(
     select *
     from dw_dwd.dwd_app_oms_order_fl_d
     where deleted = 0
) t2                                 --dwd_app_trade_order_fl_d
on t1.order_item_no=t2.order_no
left join(
      select *
      from (
          select *,
                 row_number() over (partition by delivery_item_no order by id desc ) rk
          from dw_dwd.dwd_app_oms_order_refund_items_fl_d
          where deleted = 0
      )t where rk=1
) t3
on t1.id=t3.delivery_Item_no
----需要改discount逻辑
left join(
       SELECT order_no
              ,sku_code
              ,discount_price/item_id_num      as discount_price
              ,allocation_amount/item_id_num    as allocation_amount
       FROM (
           select order_no
                  ,sku_code
                  ,sum(discount_price)       as discount_price
                  ,sum(allocation_amount)    as allocation_amount
           from dw_dwd.dwd_app_oms_discount_allocation_fl_d
           where deleted = 0
           group by order_no
                    ,sku_code
       )a left join (
             SELECT `sharding_key_order_no`
                    ,product_code
                    ,count(distinct id) item_id_num
             FROM dw_dwd.dwd_app_oms_order_item_fl_d
             group by
             `sharding_key_order_no`
             ,product_code
       ) b on a.order_no=b.sharding_key_order_no
           and a.sku_code=b.product_code
) t4
on t1.order_item_no=t4.order_no and t1.product_code=t4.sku_code
left join(
        select s1.sharding_key_order_no
              ,s1.sku_code
              ,s1.delevery_item_no
              ,s2.tms_service_name                     --物流公司
              ,s2.virtual_warehouse_code               --虚拟仓库编码
              ,s2.delivery_status
        from (
            select sharding_key_order_no
                   ,sku_code
                   ,delivery_no
                   ,delevery_item_no
            from dw_dwd.dwd_app_oms_order_delivery_items_fl_d
            where deleted = 0
        ) s1
        left join(
            select delivery_no
                   ,virtual_warehouse_code
                   ,tms_service_name
                   ,delivery_status
            from dw_dwd.dwd_app_oms_order_delivery_fl_d
            where deleted = 0
        ) s2
        on s1.delivery_no=s2.delivery_no
) t5
on t1.id=t5.delevery_item_no
left join(
     select order_no
            ,sku
            ,child_order_receive_time
            ,child_order_delivery_time
            ,order_item_id
     from dw_dwd.dwd_app_oms_sync_time_fl_d
     where deleted = 0
) t7
on t1.id=t7.order_item_id
left join(
      select refund_sub_order_no
             , order_no
             , is_goods_return
             , refund_status
             , refund_update_time
             , refund_create_time
             , refund_cs_status
             , refund_goods_status
             , refund_goods_num
             , refund_amount
             , last_update_time
             , sub_order_no
             , refund_reason
             ,storage_confirm_time
             ,collect_parcel_start_time
      from dw_tmp.dwd_ord_refund_detail_fl_d
) t8
on t3.id=t8.refund_sub_order_no and t3.delivery_Item_no =t8.sub_order_no  -- refund_sub_order_no id 都是对应的frefundid
left join(
    select source_status_code,
           target_status_code
    from dw_dim.dim_ord_status_fl_d
    where source_key='dwd_ord_order_detail_fl_d_app'
    and target_key = 'item_sales_data'
)t9
on t1.order_item_status =t9.source_status_code
left join(
    select source_status_code,
           target_status_code
    from dw_dim.dim_ord_status_fl_d
    where source_key='dwd_ord_order_detail_fl_d_app' and target_key = 'dwd_ord_order_detail_fl_d'
)t10
on t1.order_item_status =t10.source_status_code
left join(
    select order_no
            ,concat_ws(',',collect_set(cast(payment_mode as string)))  as  payment_mode
    from dw_dwd.dwd_app_oms_payment_items_fl_d
    where deleted = 0 and transaction_status = 2
    group by order_no
) t11
on t1.order_item_no=t11.order_no
left join
dw_tmp.tmp_crm_order_is_memrber_fl_d t12
--会员订单表
on t1.order_item_no = t12.orderid
union all
select t1.id                                                                           as sub_order_no                 --子订单号
     , t1.sharding_key_order_no                                                        as order_no                     --订单号
     , (case
            when t2.order_type = 1 and t2.channel_code = 7 then 'H5'
            when t2.order_type = 1 and t2.channel_code = 2 then 'WEB'
            when t2.order_type = 11 and t2.channel_code = 4 then 'DOUYIN'
            when t2.order_type = 1 and t2.channel_code = 9 then 'MINI PROGRAM'
            else 'APP' -- TODO 口径待确认
    end)                                                                               as order_channel
     , `current_date`()                                                                as day                          --数据日期
     , t12.memberid                                                                    as memberid                     --会员id
     , t1.product_code                                                                 as sku_code                     --商品标识
     , t2.payable_amount                                                               as order_amount                 --下单金额
     , t2.payable_amount                                                               as pay_amount                   --付款金额
     , case when child_order_delivery_time is not null then t2.payable_amount end      as ship_amount                  --发货金额
     , t1.refund_amount                                                                as refund_apply_amount          --申退金额
     , t1.refund_amount                                                                as refund_apply_success_amount  --退款成功金额
     , case when t7.child_order_delivery_time is not null then t1.refund_amount end    as refund_cancel_amount         --发货前退款金额
     , case
           when t7.child_order_delivery_time is not null
               then t1.refund_amount end                                               as refund_cancel_success_amount --发货前退款成功金额
     , t1.product_quantity                                                             as order_num                    --下单件数
     , t1.product_quantity                                                             as pay_num                      --付款件数
     , case when t7.child_order_delivery_time is not null then t1.product_quantity end as ship_num                     --发货件数
     , t8.refund_goods_num                                                             as refund_apply_num             --申退件数
     , case when t8.refund_status = 'SUCCESS' then t8.refund_goods_num end             as refund_apply_success_num     --  退款成功件数
     , case when t7.child_order_delivery_time is null then t8.refund_goods_num end     as refund_cancel_num            --  发货前退款件数
     , case
           when t7.child_order_delivery_time is null
               then t8.refund_goods_num end                                            as refund_cancel_success_num    --发货前退款成功件数
     , cast(null as string)                                                            as exchange_rate_cny_to_eur     --人名币兑换欧元汇率
     , cast(null as string)                                                            as exchange_rate_eur_to_cny--欧元兑换人名币汇率
     , cast(null as string)                                                            as tax_rate--   税率
     , t2.payable_amount                                                               as cash_pay_amunt--实付现金金额
     , cast(null as string)                                                            as prepay_card_amount--购买预付卡金额
     , cast(null as string)                                                            as origin_prepay_card_amount--      购买预付卡本金金额
     , cast(null as string)                                                            as extra_prepay_card_amount--       购买预付卡赠送金额
     , cast(null as string)                                                            as use_prepay_card_amount--使用预付卡总金额
     , cast(null as string)                                                            as use_origin_prepay_card_amount--      使用预付卡本金金额
     , cast(null as string)                                                            as use_extra_prepay_card_amount--       使用预付卡赠送金额
     , cast(null as string)                                                            as order_prepay_deposit_amount--    预售支付定金
     , t1.create_time                                                                  as create_time
     , t1.update_time                                                                  as update_time                               -- 更新时间
     , `current_timestamp`()                                                           as dc_system_time
from(
    select *
    from dw_dwd.dwd_ynap_oms_tmall_order_item_fl_d                    --dwd_app_trade_order_item_fl_d
    where deleted = 0
) t1
left join(
     select *
     from dw_dwd.dwd_ynap_oms_tmall_order_fl_d
     where deleted = 0
) t2                                 --dwd_app_trade_order_fl_d
on t1.order_item_no=t2.order_no
left join(
      select *
      from (
          select *,
                 row_number() over (partition by delivery_item_no order by id desc ) rk
          from dw_dwd.dwd_ynap_oms_tmall_order_refund_items_fl_d
          where deleted = 0
      )t where rk=1
) t3
on t1.id=t3.delivery_Item_no
----需要改discount逻辑
left join(
       SELECT order_no
              ,sku_code
              ,discount_price/item_id_num      as discount_price
              ,allocation_amount/item_id_num    as allocation_amount
       FROM (
           select order_no
                  ,sku_code
                  ,sum(discount_price)       as discount_price
                  ,sum(allocation_amount)    as allocation_amount
           from dw_dwd.dwd_app_oms_discount_allocation_fl_d
           where deleted = 0
           group by order_no
                    ,sku_code
       )a left join (
             SELECT `sharding_key_order_no`
                    ,product_code
                    ,count(distinct id) item_id_num
             FROM dw_dwd.dwd_ynap_oms_tmall_order_item_fl_d
             group by
             `sharding_key_order_no`
             ,product_code
       ) b on a.order_no=b.sharding_key_order_no
           and a.sku_code=b.product_code
) t4
on t1.order_item_no=t4.order_no and t1.product_code=t4.sku_code
left join(
        select s1.sharding_key_order_no
              ,s1.sku_code
              ,s1.delevery_item_no
              ,s2.tms_service_name                     --物流公司
              ,s2.virtual_warehouse_code               --虚拟仓库编码
              ,s2.delivery_status
        from (
            select sharding_key_order_no
                   ,sku_code
                   ,delivery_no
                   ,delevery_item_no
            from dw_dwd.dwd_ynap_oms_tmall_order_delivery_items_fl_d
            where deleted = 0
        ) s1
        left join(
            select delivery_no
                   ,virtual_warehouse_code
                   ,tms_service_name
                   ,delivery_status
            from dw_dwd.dwd_ynap_oms_tmall_order_delivery_fl_d
            where deleted = 0
        ) s2
        on s1.delivery_no=s2.delivery_no
) t5
on t1.id=t5.delevery_item_no
left join(
     select order_no
            ,sku
            ,child_order_receive_time
            ,child_order_delivery_time
            ,order_item_id
     from dw_dwd.dwd_order_oms_tmall_sync_time_fl_d
     where deleted = 0
) t7
on t1.id=t7.order_item_id
left join(
      select refund_sub_order_no
             , order_no
             , is_goods_return
             , refund_status
             , refund_update_time
             , refund_create_time
             , refund_cs_status
             , refund_goods_status
             , refund_goods_num
             , refund_amount
             , last_update_time
             , sub_order_no
             , refund_reason
             ,storage_confirm_time
             ,collect_parcel_start_time
      from dw_tmp.dwd_ord_refund_detail_fl_d
) t8
on t3.id=t8.refund_sub_order_no and t3.delivery_Item_no =t8.sub_order_no  -- refund_sub_order_no id 都是对应的frefundid
left join(
    select source_status_code,
           target_status_code
    from dw_dim.dim_ord_status_fl_d
    where source_key='dwd_ord_order_detail_fl_d_app'
    and target_key = 'item_sales_data'
)t9
on t1.order_item_status =t9.source_status_code
left join(
    select source_status_code,
           target_status_code
    from dw_dim.dim_ord_status_fl_d
    where source_key='dwd_ord_order_detail_fl_d_app' and target_key = 'dwd_ord_order_detail_fl_d'
)t10
on t1.order_item_status =t10.source_status_code
left join(
    select order_no
            ,concat_ws(',',collect_set(cast(payment_mode as string)))  as  payment_mode
    from dw_dwd.dwd_ynap_oms_tmall_payment_items_fl_d
    where deleted = 0 and transaction_status = 2
    group by order_no
) t11
on t1.order_item_no=t11.order_no
left join
dw_tmp.tmp_crm_order_is_memrber_fl_d t12
--会员订单表
on t1.order_item_no = t12.orderid
;




drop table if exists dw_dwd.dwd_ord_channel_oms_order_delivery_detail_fl_d;
create table dw_dwd.dwd_ord_channel_oms_order_delivery_detail_fl_d
stored as orc as
select t1.delevery_Item_no                                                       as sub_order_no,                   --子订单号
       t1.delivery_no                                                            as delivery_no,                    --出库单号
       t1.sharding_key_order_no                                                  as order_no,--订单号
       case
           when t2.rel_order_no is not null then t2.rel_order_no
           else order_no end                                                     as platform_order_no,              --源平台订单号
       ''                                                                        as platform_sub_order_no,-- 源平台订单号
       t1.sku_code                                                               as sku_code,
       t1.delivery_line_status                                                   as delivery_status,                -- 出库单状态
       t1.product_quantity                                                       as delivery_sku_quantity,          --数量
--        '' as po_no, -- TODO PO 放dws层
--        TODO rel_po_no 先进先出PO,放dws层
       t3.logi_no                                                                as international_logi_no,          --OMNI 国际物流单编号
       case when t4.ynap_status_shipped = 'Item Shipped' then t4.shipment_no end as international_logi_shipment_no, --shipment_no 国际到国内批次号
       t1.create_time,                                                                                              --创建时间
       t1.update_time,                                                                                              --更新时间
       `current_timestamp`()                                                     as dc_system_time
from (
    select *
    from
    dw_dwd.dwd_app_oms_order_delivery_items_fl_d
    where deleted=0
)t1
left join (
        select *
        from dw_dwd.dwd_app_oms_order_fl_d
        where deleted=0
)t2 on t1.sharding_key_order_no=t2.order_no
left join (
    select shop_order,
           gtin,
           concat_ws(',',collect_set(logi_no)) logi_no
    from dw_dwd.dwd_app_omni_stock_pmc_replenish_ynap_fl_d
    where deleted=0 and ynap_status = 'Item Shipped'
    group by shop_order,gtin
)t3
on t1.sharding_key_order_no=t3.shop_order and t1.sku_code=t3.gtin
left join (
       select max(order_code) as order_code,
              shop_order,
              gtin,
              max(case when ynap_status='Item Shipped' then num end) as shipped_num,
              max(case when ynap_status in ('Item Shipped') then ynap_status end) as ynap_status_shipped,
              max(case when ynap_status in ('Item Confirmed') then ynap_status end) as ynap_status_confirmed,
              max(case when ynap_status in ('Item Shipped') then ynap_update_time end) as ynap_shipped_time,
              max(case when ynap_status in ('Item Confirmed') then ynap_update_time end) as ynap_confirmed_time,
              max(case when ynap_status='Item Shipped' then shipment_no end) as shipment_no,
              max(case when ynap_status='Item Confirmed' then num end) as confirmed_num
       from (
            select order_code,
                   shop_order,
                   gtin,
                   ynap_status,
                   ynap_update_time,
                   num,
                   shipment_no,
                   row_number() over (partition by shop_order,gtin,ynap_status order by ynap_update_time)rank
            from dw_dwd.dwd_app_omni_stock_pmc_replenish_ynap_fl_d
            where deleted=0 and ynap_status in ('Item Shipped','Item Confirmed')
       )where rank=1
       group by shop_order,gtin
) t4
on t1.sharding_key_order_no=t4.shop_order and
   t1.sku_code=t4.gtin
union all
select t1.delevery_Item_no                                                       as sub_order_no,                   --子订单号
       t1.delivery_no                                                            as delivery_no,                    --出库单号
       t1.sharding_key_order_no                                                  as order_no,                       --订单号
       case
           when t2.rel_order_no is not null then t2.rel_order_no
           else order_no end                                                     as platform_order_no,              --源平台订单号
       t1.delevery_item_no                                                       as platform_sub_order_no,          -- 源平台订单号
       t1.sku_code                                                               as sku_code,
       t1.delivery_line_status                                                   as delivery_status,                -- 出库单状态
       t1.product_quantity                                                       as delivery_sku_quantity,          --数量
--        '' as po_no, -- TODO PO 放dws层
--        TODO rel_po_no 先进先出PO,放dws层
       null                                                                      as international_logi_no,          --OMNI 国际物流单编号
       null                                                                      as international_logi_shipment_no, --shipment_no 国际到国内批次号
       t1.create_time,                                                                                              --创建时间
       t1.update_time,                                                                                              --更新时间
       `current_timestamp`()                                                     as dc_system_time
from (
    select *
    from
    dw_dwd.dwd_ynap_oms_tmall_order_delivery_items_fl_d
    where deleted=0
)t1
left join (
        select *
        from dw_dwd.dwd_ynap_oms_tmall_order_fl_d
        where deleted=0
)t2 on t1.sharding_key_order_no=t2.order_no
union all
select t1.foid               as sub_order_no,                   --子订单号
       cast(null as string)  as delivery_no,                    --出库单号
       t1.ftid               as order_no,                       --订单号
       t1.ftid               as platform_order_no,              --源平台订单号
       t1.foid               as platform_sub_order_no,          -- 源平台订单号
       cast(null as string)  as sku_code,
       cast(null as string)  as delivery_status,                -- 出库单状态
       t1.fnum               as delivery_sku_quantity,          --数量
       cast(null as string)  as international_logi_no,          --OMNI 国际物流单编号
       cast(null as string)  as international_logi_shipment_no, --shipment_no 国际到国内批次号
       `current_timestamp`() as create_time,                    --创建时间
       `current_timestamp`() as update_time,                    --更新时间
       `current_timestamp`() as dc_system_time
from dw_dwd.dwd_jv_manual_offline_sales_fl_d t1;




















drop table if exists dw_dwd.dwd_ord_model_order_refund_fl_d;
create table dw_dwd.dwd_ord_model_order_refund_fl_d
stored as orc as
select t1.refund_no,                                                 --    退单号
       t1.sharding_key_order_no as order_no,                         --    订单号
       case
           when t2.order_type = 1 and t2.channel_code = 7 then 'H5'
           when t2.order_type = 1 and t2.channel_code = 2 then 'WEB'
           when t2.order_type = 11 and t2.channel_code = 4 then 'DOUYIN'
           when t2.order_type = 1 and t2.channel_code = 9 then 'MINI PROGRAM'
           else 'APP'
           end                  as order_channel,                    --    订单渠道
       case
           when t2.order_type = 11 and t2.channel_code = 4 then t1.rel_refund_no
           else refund_no end   as platform_refund_no,               --源平台退款单号
       case
           when t2.order_type = 11 and t2.channel_code = 4 then t1.rel_order_no
           else t1.order_no end as platform_order_no,                --源平台订单号
       t1.refund_type,                                               --仅退款,退货退款
       t1.refund_fee            as refund_total_fee,                 --退款总金额
       t1.refund_cash_amount    as refund_cash_fee,                  --退现金金额
       t3.share_total_amount    as refund_prepay_card_amount,        --退预付卡总金额
       t3.share_total_amount    as refund_origin_prepay_card_amount, --退预付卡本金金额
       t3.share_total_amount    as refund_extra_prepay_card_amount,  --退预付卡赠送金额
       t1.freight               as refund_post_fee,                  --退运费
       t1.reason                as refund_reason,                    --    退款原因
       t1.desc                  as refund_desc,                      --退款说明
       t1.refund_status         as refund_phase,                     --退款阶段,可选值:onsale(售中)/aftersale(售后)
       t1.goods_status          as refund_goods_status,              --退款货品状态
       ''                       as refund_cs_status,                 --退款客服介入状态
       t1.receiving_address     as seller_address,                   --卖家收货地址
       t1.receiver_name         as seller_name,                      --    卖家收货人
       t1.receiver_phone_number as seller_phone_number,              --    卖家收货人手机号
       t4.target_status_code    as refund_status,                    --退单状态
       t1.create_time,
       t1.update_time,
       `current_timestamp`()    as dc_system_time
from (
    select *
    from dw_dwd.dwd_app_oms_order_refund_fl_d
    where deleted=0
)t1
left join (
    select *
    from dw_dwd.dwd_app_oms_order_fl_d
    where deleted=0
)t2
on t1.order_no=t2.order_no
left join (
    select trade_no,
           sum(share_total_amount)share_total_amount
    from dw_dwd.dwd_app_card_share_bill_fl_d
    where type='REFUND'
    group by trade_no
)t3
on t1.order_no=t3.trade_no
left join(
    select source_status_code,
           target_status_code
    from dw_dim.dim_ord_status_fl_d
    where source_key='dwd_ord_order_detail_fl_d_reverse_app'
       or source_key='dwd_ord_order_detail_fl_d_reverse_ecc'
     and target_key = 'item_sales_data'
)t4
on t1.refund_status =t4.source_status_code
union all
select t1.refund_no,                                                  --   退单号
       t1.sharding_key_order_no  as order_no,                         --    订单号
       'TMALL'                   as order_channel,                    --   订单渠道
       case
           when t1.rel_refund_no is not null then t1.rel_refund_no
           else t1.refund_no end as platform_refund_no,               --源平台退款单号
       case
           when t1.rel_order_no is not null then t1.rel_order_no
           else t1.order_no end  as platform_order_no,                --源平台订单号
       t1.refund_type,                                                --仅退款,退货退款
       t1.refund_fee             as refund_total_fee,                 --退款总金额
       t1.refund_cash_amount     as refund_cash_fee,                  --退现金金额
       null                      as refund_prepay_card_amount,        --退预付卡总金额
       null                      as refund_origin_prepay_card_amount, --退预付卡本金金额
       null                      as refund_extra_prepay_card_amount,  --退预付卡赠送金额
       t1.freight                as refund_post_fee,                  --退运费
       t1.reason                 as refund_reason,                    --   退款原因
       cast(null as string)      as refund_desc,                      --退款说明
       t1.refund_status          as refund_phase,                     --退款阶段,可选值:onsale(售中)/aftersale(售后)
       t1.goods_status           as refund_goods_status,              --退款货品状态
       null                      as refund_cs_status,                 --退款客服介入状态
       t1.receiving_address      as seller_address,                   --卖家收货地址
       t1.receiver_name          as seller_name,                      --   卖家收货人
       t1.receiver_phone_number  as seller_phone_number,              --   卖家收货人手机号
       t4.target_status_code     as refund_status,                    --退单状态
       t1.create_time,
       t1.update_time,
       `current_timestamp`()     as dc_system_time
from (
    select *
    from dw_dwd.dwd_order_oms_tmall_order_refund_fl_d
    where deleted=0
)t1
left join (
    select *
    from dw_dwd.dwd_order_oms_tmall_order_fl_d
    where deleted=0
)t2
on t1.order_no=t2.order_no
left join(
    select source_status_code,
           target_status_code
    from dw_dim.dim_ord_status_fl_d
    where source_key='dwd_ord_order_detail_fl_d_reverse_app'
       or source_key='dwd_ord_order_detail_fl_d_reverse_ecc'
     and target_key = 'item_sales_data'
)t4
on t1.refund_status =t4.source_status_code
union all
select cast(null as string),                                                 --    退单号
       t1.ftid               as order_no,                                    --    订单号
       'OFFLINE'             as order_channel,                               --    订单渠道
       cast(null as string)  as platform_refund_no,                          --源平台退款单号
       t1.ftid               as platform_order_no,                           --源平台订单号
       case
           when t1.return_units != 0 and t1.return_sales != 0 then '退货退款'
           when t1.return_units = 0 and t1.return_sales != 0 then '仅退款' end, --仅退款,退货退款
       t1.return_sales       as refund_total_fee,                            --退款总金额
       cast(null as string)  as refund_cash_fee,                             --退现金金额
       cast(null as string)  as refund_prepay_card_amount,                   --退预付卡总金额
       cast(null as string)  as refund_origin_prepay_card_amount,            --退预付卡本金金额
       cast(null as string)  as refund_extra_prepay_card_amount,             --退预付卡赠送金额
       cast(null as string)  as refund_post_fee,                             --退运费
       cast(null as string)  as refund_reason,                               --    退款原因
       cast(null as string)  as refund_desc,                                 --退款说明
       t1.refund_status      as refund_phase,                                --退款阶段,可选值:onsale(售中)/aftersale(售后)
       t1.fstatus            as refund_goods_status,                         --退款货品状态
       cast(null as string)  as refund_cs_status,                            --退款客服介入状态
       t1.freceiverdistrict  as seller_address,                              --卖家收货地址
       t1.buyer_nick         as seller_name,                                 --    卖家收货人
       t1.app_telephone      as seller_phone_number,                         --    卖家收货人手机号
       t1.refund_status      as refund_status,                               --退单状态
       `current_timestamp`(),
       `current_timestamp`(),
       `current_timestamp`() as dc_system_time
from dw_dwd.dwd_jv_manual_offline_sales_fl_d t1
;


drop table if exists dw_dwd.dwd_ord_channel_oms_order_timeline_fl_d;
create table dw_dwd.dwd_ord_channel_oms_order_timeline_fl_d
stored as orc as
select t1.id                                as sub_order_no,
       t1.sharding_key_order_no             as order_no,
       case
           when t2.order_type = 11 and t2.channel_code = 4 then t2.rel_order_no
           else t1.order_item_no end        as platform_order_no,
       cast(null as string)                 as platform_sub_order_no,
       t1.product_code                      as sku_code,
       case
           when t2.order_type = 1 and t2.channel_code = 7 then 'H5'
           when t2.order_type = 1 and t2.channel_code = 2 then 'WEB'
           when t2.order_type = 11 and t2.channel_code = 4 then 'DOUYIN'
           when t2.order_type = 1 and t2.channel_code = 9 then 'MINI PROGRAM'
           else 'APP' end                      order_channel,
       t2.create_time                       as order_create_time,
       t3.create_time                       as order_prepay_time,           -- 预售订金支付时间 TODO 只有预售订单才有预售支付时间,预售时间口径
       t2.payment_time                      as order_pay_time,
--        TODO YNAP相关口径逻辑
       t4.create_time                       as push_ynap_order_time,
       case
           when t5.ynap_status_confirmed = 'Item Confirmed'
               then from_unixtime(unix_timestamp(t5.ynap_confirmed_time) + 28800, 'yyyy-MM-dd HH:mm:ss')
           end                              as ynap_confirm_delivery_time,
       case
           when t5.ynap_status_shipped = 'Item Shipped'
               then from_unixtime(unix_timestamp(t5.ynap_shipped_time) + 28800, 'yyyy-MM-dd HH:mm:ss')
           end                              as ynap_delivery_time,          --omni YNAP发货时间
       cast(null as timestamp)              as ynap_enter_warehouse_time,   --omni 入本地仓时间
       cast(null as timestamp)              as ynap_cancel_time,            --omni YNAP取消时间
       cast(null as timestamp)              as order_apply_delivery_time,   -- 申请国内发货时间
       t6.child_order_delivery_time         as order_delivery_time,         --国内仓库发货时间
       t6.child_order_receive_time          as order_consign_time,          -- 客户签收时间
       t6.child_order_success_time          as order_success_time,          --订单交易成功时间
       t6.child_order_success_time          as order_end_time,              --订单完成时间(售后期结束)
       t6.child_order_cancel_time           as order_cancel_time,           --订单取消时间
       t1.update_time                       as order_last_update_time,      --订单最后更新时间
       t6.child_order_refund_time           as refund_apply_time,           --退款申请时间
       t9.create_time                       as return_apply_time,           -- TODO 退货申请时间
       t6.child_order_refund_parcel_time    as return_send_time,            --退货商品寄出时间(APP上门揽件时间)
       t8.storage_cofirm_time               as return_enter_warehouse_time, --退货入库时间
       t6.child_order_refund_backmoney_time as refund_backmoney_time,       --退款确认时间
       cast(null as timestamp)              as refund_success_time,         -- TODO 退款成功时间
       cast(null as timestamp)              as refund_close_time,           -- TODO 退款关闭时间
       t7.update_time                       as refund_last_update_time,     --退款最后更新时间
       `current_timestamp`()                as dc_system_time
from (
    select *
    from dw_dwd.dwd_app_oms_order_item_fl_d
    where deleted=0
)t1
left join (
    select *
    from dw_dwd.dwd_app_oms_order_fl_d
    where deleted=0
)t2
on t1.order_item_no=t2.order_no
left join (
    select order_no,
           min(create_time)create_time
    from
    dw_dwd.dwd_app_oms_payment_items_fl_d
    where deleted=0
    group by order_no
)t3
on t1.order_item_no=t3.order_no
left join (
    select max(create_time) create_time,
           shop_order
    from dw_dwd.dwd_app_omni_stock_pmc_push_ynap_fl_d
    where operation_status=1
      and push_status=1
      and deleted=0
    group by shop_order
) t4
on t1.order_item_no=t4.shop_order
left join (
       select max(order_code) as order_code,
              shop_order,
              gtin,
              max(case when ynap_status='Item Shipped' then num end) as shipped_num,
              max(case when ynap_status in ('Item Shipped') then ynap_status end) as ynap_status_shipped,
              max(case when ynap_status in ('Item Confirmed') then ynap_status end) as ynap_status_confirmed,
              max(case when ynap_status in ('Item Shipped') then ynap_update_time end) as ynap_shipped_time,
              max(case when ynap_status in ('Item Confirmed') then ynap_update_time end) as ynap_confirmed_time,
              max(case when ynap_status='Item Shipped' then shipment_no end) as shipment_no,
              max(case when ynap_status='Item Confirmed' then num end) as confirmed_num
       from (
            select order_code,
                   shop_order,
                   gtin,
                   ynap_status,
                   ynap_update_time,
                   num,
                   shipment_no,
                   row_number() over (partition by shop_order,gtin,ynap_status order by ynap_update_time)rank
            from dw_dwd.dwd_app_omni_stock_pmc_replenish_ynap_fl_d
            where deleted=0 and ynap_status in ('Item Shipped','Item Confirmed')
       )where rank=1
       group by shop_order,gtin
) t5
on t1.order_item_no=t5.shop_order and
   t1.product_code=t5.gtin
left join (
    select order_no,
           sku,
           child_order_delivery_time,
           child_order_receive_time,
           child_order_success_time,
           child_order_cancel_time,
           child_order_refund_time,
           child_order_refund_parcel_time,
           child_order_refund_backmoney_time
    from (
       select order_no,
              sku,
              child_order_delivery_time,
              child_order_receive_time,
              child_order_success_time,
              child_order_cancel_time,
              child_order_refund_time,
              child_order_refund_parcel_time,
              child_order_refund_backmoney_time,
              row_number() over (partition by order_no,sku order by update_time desc ) rank
       from
       dw_dwd.dwd_app_oms_sync_time_fl_d where deleted=0
    )where rank=1
) t6
on t1.order_item_no=t6.order_no and t1.product_code=t6.sku
left join (
    select * from (
        select sharding_key_order_no,
               sku_code,
               update_time,
               refund_no,
               row_number() over (partition by refund_no order by update_time desc )rk
        from dw_dwd.dwd_app_oms_order_refund_items_fl_d
        where deleted=0
    )t where rk=1
)t7
on t1.order_item_no=t7.sharding_key_order_no and t1.product_code=t7.sku_code
left join (
    select *
    from dw_dwd.dwd_app_oms_order_refund_fl_d
    where deleted=0
)t8
on t7.refund_no=t8.refund_no
left join (
    select * from dw_dwd.dwd_app_oms_order_refund_items_fl_d where deleted=0
)t9
on t1.id=t9.delivery_item_no
union all
select t1.id                         as sub_order_no,
       t1.sharding_key_order_no      as order_no,
       case
           when t2.order_type = 11 and t2.channel_code = 4 then t2.rel_order_no
           else t1.order_item_no end as platform_order_no,
       cast(null as string)          as platform_sub_order_no,
       t1.product_code               as sku_code,
       case
           when t2.order_type = 1 and t2.channel_code = 7 then 'H5'
           when t2.order_type = 1 and t2.channel_code = 2 then 'WEB'
           when t2.order_type = 11 and t2.channel_code = 4 then 'DOUYIN'
           when t2.order_type = 1 and t2.channel_code = 9 then 'MINI PROGRAM'
           else 'APP' end               order_channel,
       t2.create_time                as order_create_time,
       t3.create_time                as order_prepay_time,           -- 预售订金支付时间 TODO 只有预售订单才有预售支付时间,预售时间口径
       t2.payment_time               as order_pay_time,
--        TODO YNAP相关口径逻辑
       cast(null as timestamp)       as push_ynap_order_time,
       cast(null as timestamp)       as ynap_confirm_delivery_time,
       cast(null as timestamp)       as ynap_delivery_time,          --omni YNAP发货时间
       cast(null as timestamp)       as ynap_enter_warehouse_time,   --omni 入本地仓时间
       cast(null as timestamp)       as ynap_cancel_time,            --omni YNAP取消时间
       cast(null as timestamp)       as order_apply_delivery_time,   --    申请国内发货时间
       cast(null as timestamp)       as order_delivery_time,         --国内仓库发货时间
       cast(null as timestamp)       as order_consign_time,          --    客户签收时间
       cast(null as timestamp)       as order_success_time,          --订单交易成功时间
       cast(null as timestamp)       as order_end_time,              --订单完成时间(售后期结束)
       cast(null as timestamp)       as order_cancel_time,           --订单取消时间
       t1.update_time                as order_last_update_time,      --订单最后更新时间
       cast(null as timestamp)       as refund_apply_time,           --退款申请时间
       t9.create_time                as return_apply_time,           -- TODO 退货申请时间
       cast(null as timestamp)       as return_send_time,            --退货商品寄出时间(APP上门揽件时间)
       t8.storage_cofirm_time        as return_enter_warehouse_time, --退货入库时间
       cast(null as timestamp)       as refund_backmoney_time,       --退款确认时间
       cast(null as timestamp)       as refund_success_time,         -- TODO 退款成功时间
       cast(null as timestamp)       as refund_close_time,           -- TODO 退款关闭时间
       t7.update_time                as refund_last_update_time,     --退款最后更新时间
       `current_timestamp`()         as dc_system_time
from (
    select *
    from dw_dwd.dwd_order_oms_tmall_order_item_fl_d
    where deleted=0
)t1
left join (
    select *
    from dw_dwd.dwd_order_oms_tmall_order_fl_d
    where deleted=0
)t2
on t1.order_item_no=t2.order_no
left join (
    select order_no,
           min(create_time)create_time
    from
    dw_dwd.dwd_order_oms_tmall_payment_items_fl_d
    where deleted=0
    group by order_no
)t3
on t1.order_item_no=t3.order_no
left join (
    select * from (
        select sharding_key_order_no,
               sku_code,
               update_time,
               refund_no,
               row_number() over (partition by refund_no order by update_time desc )rk
        from dw_dwd.dwd_order_oms_tmall_order_refund_items_fl_d
        where deleted=0
    )t where rk=1
)t7
on t1.order_item_no=t7.sharding_key_order_no and t1.product_code=t7.sku_code
left join (
    select *
    from dw_dwd.dwd_order_oms_tmall_order_refund_fl_d
    where deleted=0
)t8
on t7.refund_no=t8.refund_no
left join (
    select * from dw_dwd.dwd_order_oms_tmall_order_refund_items_fl_d where deleted=0
)t9
on t1.id=t9.delivery_item_no
union all
select t1.foid                 as sub_order_no,
       t1.ftid                 as order_no,
       t1.foid                 as platform_order_no,
       cast(null as string)    as platform_sub_order_no,
       cast(null as string)    as sku_code,
       'OFFLINE'               as order_channel,
       `current_timestamp`()   as order_create_time,
       `current_timestamp`()   as order_prepay_time,           -- 预售订金支付时间 TODO 只有预售订单才有预售支付时间,预售时间口径
       t1.fpaytime             as order_pay_time,
--        TODO YNAP相关口径逻辑
       cast(null as timestamp) as push_ynap_order_time,
       cast(null as timestamp) as ynap_confirm_delivery_time,
       cast(null as timestamp) as ynap_delivery_time,          --omni YNAP发货时间
       cast(null as timestamp) as ynap_enter_warehouse_time,   --omni 入本地仓时间
       cast(null as timestamp) as ynap_cancel_time,            --omni YNAP取消时间
       cast(null as timestamp) as order_apply_delivery_time,   --  申请国内发货时间
       cast(null as timestamp) as order_delivery_time,         --国内仓库发货时间
       cast(null as timestamp) as order_consign_time,          --  客户签收时间
       cast(null as timestamp) as order_success_time,          --订单交易成功时间
       cast(null as timestamp) as order_end_time,              --订单完成时间(售后期结束)
       cast(null as timestamp) as order_cancel_time,           --订单取消时间
       `current_timestamp`()   as order_last_update_time,      --订单最后更新时间
       cast(null as timestamp) as refund_apply_time,           --退款申请时间
       cast(null as timestamp) as return_apply_time,           -- TODO 退货申请时间
       cast(null as timestamp) as return_send_time,            --退货商品寄出时间(APP上门揽件时间)
       cast(null as timestamp) as return_enter_warehouse_time, --退货入库时间
       cast(null as timestamp) as refund_backmoney_time,       --退款确认时间
       cast(null as timestamp) as refund_success_time,         -- TODO 退款成功时间
       cast(null as timestamp) as refund_close_time,           -- TODO 退款关闭时间
       cast(null as timestamp) as refund_last_update_time,     --退款最后更新时间
       `current_timestamp`()   as dc_system_time
from dw_dwd.dwd_jv_manual_offline_sales_fl_d t1
;

drop table if exists dw_dwd.dwd_ord_model_order_refund_detail_fl_d;
create table dw_dwd.dwd_ord_model_order_refund_detail_fl_d
stored as orc as
select t1.delivery_item_no                      sub_order_no,                         --子订单号
       t1.order_no,
       t1.refund_no,                                                                  --退单号
       case
           when t2.rel_refund_no is not null then t2.rel_refund_no
           else t1.refund_no end             as platform_refund_no,                  --源平台退单号
       case
           when t2.rel_order_no is not null then t2.order_no
           else t1.order_no end              as platform_order_no,                   --源平台订单号
       t4.id                                 as platform_sub_order_no,               --源平台子订单号
       t1.sku_code,
       t1.product_name                       as sku_name,                            --商品名称
       t1.refund_fee, --退单金额=现金+预付卡
       t2.refund_fee - t2.refund_card_amount as refund_cash_fee,                     --退现金金额
       t3.share_total_amount                 as refund_prepay_card_amount,           --退预付卡总金额
       t3.share_total_amount                 as refund_origin_prepay_card_amount,    --退预付卡本金金额
       t3.share_total_amount                 as refund_extra_prepay_card_amount,     --退预付卡赠送金额
       t1.quantity                           as return_quantity,                     -- 退货数量
       t1.quantity                           as return_stock_quantity, -- TODO 已入库数量
       t2.operate_type                       as is_goods_return,                    --是否有退货
       t2.refund_status                      as return_status,                      --退货状态
--        TODO refund_reason -- 退款原因
       cast(null as string)                  as tms_no,                     --        TODO tms_no -- 退货物流单号
--        TODO tms_company_name -- 退货物流公司
-- TODO 创建用户
       t1.create_time,
       t1.update_time,
       `current_timestamp`()                 as dc_system_time,
       t1.delivery_item_no as  delivery_item_no
from (
    select * from
    dw_dwd.dwd_app_oms_order_refund_items_fl_d
    where deleted=0
)t1
left join (
    select *
    from dw_dwd.dwd_app_oms_order_refund_fl_d
    where deleted=0
)t2
on t1.refund_no=t2.refund_no
left join (
    select trade_no,
           sum(share_total_amount)share_total_amount
    from dw_dwd.dwd_app_card_share_bill_fl_d
    where type='REFUND'
    group by trade_no
)t3
on t1.order_no=t3.trade_no
left join (
    select * from dw_dwd.dwd_app_oms_order_item_fl_d where deleted=0
)t4
on t1.delivery_item_no=t4.id
union all
select t1.delivery_item_no                      sub_order_no,                         --子订单号
       t1.order_no,
       t1.refund_no,                                                                  --退单号
       case
           when t2.rel_refund_no is not null then t2.rel_refund_no
           else t1.refund_no end             as platform_refund_no,                  --源平台退单号
       case
           when t2.rel_order_no is not null then t2.order_no
           else t1.order_no end              as platform_order_no,                   --源平台订单号
       t4.id                                 as platform_sub_order_no,               --源平台子订单号
       t1.sku_code,
       t1.product_name                       as sku_name,                            --商品名称
       t1.refund_fee, --退单金额=现金+预付卡
       t2.refund_fee - t2.refund_card_amount as refund_cash_fee,                     --退现金金额
       cast(null as decimal(10,2))           as refund_prepay_card_amount,           --退预付卡总金额
       cast(null as decimal(10,2))           as refund_origin_prepay_card_amount,    --退预付卡本金金额
       cast(null as decimal(10,2))           as refund_extra_prepay_card_amount,     --退预付卡赠送金额
       t1.quantity                           as return_quantity,                     -- 退货数量
       t1.quantity                           as return_stock_quantity, -- TODO 已入库数量
       t2.operate_type                       as is_goods_return,                    --是否有退货
       t2.refund_status                      as return_status,                      --退货状态
       t2.tms_number                         as tms_no,                              --退货物流单号
--        TODO refund_reason -- 退款原因
--        TODO tms_company_name -- 退货物流公司
-- TODO 创建用户
       t1.create_time,
       t1.update_time,
       `current_timestamp`()                 as dc_system_time,
       t1.delivery_item_no as delivery_item_no
from (
    select * from
    dw_dwd.dwd_ynap_oms_tmall_order_refund_items_fl_d
    where deleted=0
)t1
left join (
    select *
    from dw_dwd.dwd_ynap_oms_tmall_order_refund_fl_d
    where deleted=0
)t2
on t1.refund_no=t2.refund_no
left join (
    select * from dw_dwd.dwd_ynap_oms_tmall_order_fl_d where deleted=0
)t4
on t1.delivery_item_no=t4.id
union all
select t1.foid                                             as sub_order_no,                     --子订单号
       t1.ftid,
       cast(null as string),                                                                    --退单号
       cast(null as string)                                as platform_refund_no,               --源平台退单号
       t1.ftid                                             as platform_order_no,                --源平台订单号
       t1.foid                                             as platform_sub_order_no,            --源平台子订单号
       cast(null as string),
       cast(null as string)                                as sku_name,                         --商品名称
       t1.return_sales,                                                                         --退单金额=现金+预付卡
       cast(null as string)                                as refund_cash_fee,                  --退现金金额
       cast(null as decimal(10, 2))                        as refund_prepay_card_amount,        --退预付卡总金额
       cast(null as decimal(10, 2))                        as refund_origin_prepay_card_amount, --退预付卡本金金额
       cast(null as decimal(10, 2))                        as refund_extra_prepay_card_amount,  --退预付卡赠送金额
       t1.return_units                                     as return_quantity,                  -- 退货数量
       t1.fnum                                             as return_stock_quantity,            -- TODO 已入库数量
       case when t1.return_units != 0 then 1 else null end as is_goods_return,                  --是否有退货
       t1.refund_status                                    as return_status,                    --退货状态
       cast(null as string)                                as tms_no,                           --退货物流单号
--        TODO refund_reason -- 退款原因
--        TODO tms_company_name -- 退货物流公司
-- TODO 创建用户
       `current_timestamp`(),
       `current_timestamp`(),
       `current_timestamp`()                               as dc_system_time,
       foid as delivery_item_no
from dw_dwd.dwd_jv_manual_offline_sales_fl_d t1
;



















CREATE TABLE dw_dwd.dwd_ord_model_order_refund_detail_fl_d(
  `sub_order_no` bigint COMMENT '出库单号',
  `order_no` string COMMENT '订单编号',
  `refund_no` string COMMENT '退款单号',
  `platform_refund_no` string,
  `platform_order_no` string,
  `platform_sub_order_no` bigint COMMENT '订单行表主键',
  `sku_code` string COMMENT '商品编号',
  `sku_name` string COMMENT '商品名称',
  `refund_fee` double COMMENT '退款金额',
  `refund_cash_fee` double,
  `refund_prepay_card_amount` decimal(20,2),
  `refund_origin_prepay_card_amount` decimal(20,2),
  `refund_extra_prepay_card_amount` decimal(20,2),
  `return_quantity` bigint,
  `return_stock_quantity` bigint,
  `is_goods_return` bigint,
  `return_status` bigint,
  `tms_no` string,
  `create_time` timestamp COMMENT '退款提交时间',
  `update_time` timestamp COMMENT '更新时间',
  `dc_system_time` timestamp)
;









show create table dw_dwd.dwd_ord_channel_oms_order_fl_d;


--11
drop table if exists dw_dwd.dwd_ord_channel_oms_order_detail_fl_d;
CREATE TABLE dw_dwd.dwd_ord_channel_oms_order_detail_fl_d
(
    `sub_order_no`                   bigint COMMENT '订单行表主键',
    `order_no`                       string COMMENT '团单编号,用于分库分表拆分键使用',
    `platform_order_no`              string COMMENT '',
    `platform_sub_order_no`          bigint COMMENT '订单行表主键',
    `order_channel`                  string COMMENT '',
    `sub_order_status`               string COMMENT '目标状态码',
    `sku_code`                       string COMMENT '商品sku号',
    `sku_name`                       string COMMENT '商品名称',
    `unit_price`                     double COMMENT '商品单价',
    `markdown_price`                 double COMMENT 'markdown价格',
    `payment`                        double COMMENT '实付金额',
    `sku_quantity`                   int COMMENT '商品数量',
    `is_preorder`                    int COMMENT '',
    `is_jit`                         int COMMENT '是否是jit商品 1是 2否',
    `is_jit_in_stock`                int COMMENT '是否现货 1是 2否',
    `item_affiliate_giftcard_amount` string COMMENT '',
    `item_affiliate_rate`            string COMMENT '',
    `create_time`                    timestamp COMMENT '创建时间',
    `update_time`                    timestamp COMMENT '更新时间',
    `dc_system_time`                 timestamp comment '系统时间',
    gift_flag                        int comment '是否是赠品'
) stored as orc;










--22
CREATE TABLE `dw_dwd.dwd_ord_channel_oms_order_fl_d`(
  `order_no` string COMMENT '订单编号',
  `platform_order_no` string comment '',
  `order_category` string comment '',
  `order_channel` string comment '',
  `order_status` string COMMENT '目标状态码' ,
  `original_order_status` bigint comment '',
  `memberid` string COMMENT '数据类型 data.prctvmkt.netAPorter.MainOrder 字段 memberId 的列',
  `member_level_id` string COMMENT '数据类型 data.prctvmkt.netAPorter.MainOrder 字段 tierCurrent 的列',
  `customer_no` string COMMENT '登录用户编号',
  `order_original_amount` double comment '',
  `order_markdown_amount` double COMMENT '订单金额 (商品总金额)',
  `order_total_amount` double COMMENT '应支付金额',
  `order_pay_amount` double COMMENT '应支付金额',
  `order_adjust_amount` double COMMENT '订单折扣金额(营销优惠)',
  `order_discount_amount` double comment '',
  `order_coupon_amount` double COMMENT '订单优惠金额(优惠券)',
  `order_post_amount` double COMMENT '运费',
  `prepay_card_amount` double comment '',
  `origin_prepay_card_amount` decimal(10,2) comment '',
  `extra_prepay_card_amount` decimal(10,2) comment '',
  `use_prepay_card_amount` decimal(20,2) comment '',
  `use_origin_prepay_card_amount` decimal(20,2) comment '',
  `use_extra_prepay_card_amount` decimal(20,2) comment '',
  `order_prepay_deposit_amount` int comment '',
  `order_prepay_amount` int comment '',
  `order_refund_amount` double COMMENT '已退款金额',
  `order_special_refund` decimal(10,2) comment '',
  `affiliate_giftcard_amount` decimal(10,2) comment '',
  `affiliate_giftcard_no` string comment '',
  `sub_order_num` bigint comment '',
  `order_sku_quantity` bigint comment '',
  `buyer_nick` string COMMENT '用户名',
  `receiver_district` string comment '',
  `receiver_city` string comment '',
  `receiver_province` string comment '',
  `receiver_address` string comment '',
  `receiver_name` string COMMENT '收货人',
  `receiver_country` string COMMENT '收货地址',
  `receiver_postcode` string comment '',
  `receiver_mobile` string COMMENT '收货人手机号',
  `receiver_phone` string comment '',
  `system_source` bigint comment '',
    order_type      bigint comment '订单类型:销售订单 sale线下订单 offlinePre-Order preOrder',
    channel_code    bigint comment '渠道:APP,WEBSITE, EIP',
  `residue_amount` decimal(10,2) COMMENT '剩余应付金额 (扣除礼品卡后的支付现金)',
  `is_affiliate_order` bigint comment '',
  `utm_source` string COMMENT '',
  `utm_content` string COMMENT '',
  `is_douyin_notstock` bigint comment '',
  `create_time` timestamp COMMENT '创建时间',
  `update_time` timestamp COMMENT '修改时间',
  `dc_system_time` timestamp comment '',
  `order_create_time` timestamp comment '订单创建时间'

)
;

































-- 源头 dwd给足
show create table dw_dwd.dwd_ynap_oms_tmall_order_fl_d;
CREATE TABLE dw_dwd.dwd_ynap_oms_tmall_order_fl_d(
  `id` bigint COMMENT '订单表主键',
  `sharding_key_order_no` string COMMENT '主单编号,用于分库分表拆分键使用',
  `channel_code` bigint COMMENT '渠道:APP,WEBSITE, EIP',
  `order_no` string COMMENT '订单编号',
  `login_code` string COMMENT '登录用户编号',
  `login_type` bigint COMMENT '会员身份:0-普通会员,1-EIP',
  `login_name` string COMMENT '用户名',
  `phone` string COMMENT '手机号',
  `order_amount` decimal(10,2) COMMENT '订单金额 (商品总金额)',
  `discount_amount` decimal(10,2) COMMENT '订单折扣金额(营销优惠)',
  `coupon_amount` decimal(10,2) COMMENT '订单优惠金额(优惠券)',
  `payable_amount` decimal(10,2) COMMENT '应支付金额',
  `refunded_amount` decimal(10,2) COMMENT '已退款金额',
  `order_status` bigint COMMENT '订单状态\r\n待付款 1\r\n交易关闭 2\r\n已付款 3\r\n待审核 4\r\n待发货 5\r\n待收货 6\r\n已签收 7\r\n延长售后 8\r\n交易完成(已签收未关闭售后入口) 9\r\n交易完成(已签收且已关闭售后入口) 10\r\n拦截失败-11\r\n退款中-12\r\n退款成功-13\r\n商品入库失败-14',
  `previewing_status` bigint COMMENT '预检状态(0-未预检,1-预检不通过,2-预检通过)',
  `previewing_reason` string COMMENT '预检失败原因',
  `payment_status` bigint COMMENT '付款状态\r\n1.未支付\r\n2.已支付\r\n3.已退款',
  `shipment_status` bigint COMMENT '出货状态 1 待发货 2 已取消 3 已发货 4已拒绝',
  `imanual_cancel_flag` bigint COMMENT '是否手动取消\r\n1-是 0-否',
  `invoice_code` string COMMENT '开票信息id,用户中心存储的开发票信息编号',
  `invoice_flag` bigint COMMENT '是否开票\r\n1-是 0-否',
  `invoice_status` bigint COMMENT '发票状态\r\n1-未开票\r\n2-已开票',
  `currency_code` string COMMENT '货币编号,默认RMB',
  `delivery_type` string COMMENT '送货方式,默认方式-快递',
  `payment_time` timestamp COMMENT '支付时间',
  `payment_balance_time` timestamp COMMENT '支付尾款时间',
  `receiving_address_code` string COMMENT '收货地址id',
  `receiver_phone_number` string COMMENT '收货人手机号',
  `receiver_name` string COMMENT '收货人',
  `receiving_address` string COMMENT '收货地址',
  `receiving_address_decrypt` string,
  `card_content` string COMMENT '贺卡内容',
  `package_type` bigint COMMENT '包装类型',
  `package_name` string COMMENT '包装类型名称',
  `order_type` bigint COMMENT '订单类型:\r\n销售订单 sale\r\n线下订单 offline\r\nPre-Order preOrder',
  `pay_times` bigint COMMENT '发起支付次数\r\n调用支付中心发起支付接口单号 = 订单号+支付次数',
  `order_remark` string COMMENT '订单备注',
  `refund_remark` string COMMENT '破例退货备注',
  `cs_remark` string COMMENT '客服备注',
  `create_user_id` string COMMENT '创建人id',
  `update_user_id` string COMMENT '修改人id',
  `create_user_name` string COMMENT '创建人姓名',
  `update_user_name` string COMMENT '修改人姓名',
  `create_time` timestamp COMMENT '创建时间',
  `update_time` timestamp COMMENT '修改时间',
  `sort_id` bigint,
  `version` bigint COMMENT '版本号',
  `deleted` bigint COMMENT '状态 0未删除  1已删除',
  `order_time` timestamp COMMENT '下单时间',
  `freight` decimal(10,2) COMMENT '运费',
  `partner_id` bigint,
  `sync_status` bigint COMMENT '同步OMS状态:0-未同步,1-同步成功,2-同步失败',
  `ps_user_id` string COMMENT 'PS客服编号',
  `shops` string COMMENT '店铺',
  `serial_number` string COMMENT 'excel导入编号',
  `sub_channel` bigint COMMENT '订单来源',
  `operator` string COMMENT '操作人',
  `freight_refund_flag` bigint COMMENT '是否已退运费',
  `system_source` bigint COMMENT '系统来源  1 IOS 2 安卓 3PC 4E EIP',
  `ps_submit_flag` bigint COMMENT '是否是PS代客下单',
  `user_grade` bigint COMMENT '会员下单等级',
  `points` decimal(10,2) COMMENT '积分',
  `buyer_name` string COMMENT '礼品卡购买人姓名',
  `id_number` string COMMENT '礼品卡购买人身份证',
  `buyer_phone_number` string COMMENT '礼品卡购买人手机',
  `refunded_card_amount` decimal(10,2) COMMENT '已退款礼品卡金额',
  `affiliate_flag` bigint COMMENT '是否是Affiliate用户',
  `user_tag_ids` string COMMENT '下单是用户命中的标签id',
  `use_card_amount` decimal(10,2) COMMENT '礼品卡使用金额',
  `residue_amount` decimal(10,2) COMMENT '剩余应付金额 (扣除礼品卡后的支付现金)',
  `rel_order_no` string COMMENT '第三方数据订单编号',
  `dy_refund_flag` bigint COMMENT '抖音订单退款标志\r\n0:未退款\r\n1.未开票订单:请在发票后台开具蓝票\r\n2.已开票订单:请在发票后台红冲后重新开蓝票\r\n3.开票金额和OMS金额不一致,冲红后开票\r\n4:发生邮件成功\r\n5:发生邮件失败\r\n',
  `user_tags` string COMMENT '下单是用户命中的标签',
  `utm_source` string,
  `utm_content` string,
  `is_douyin_notstock` bigint COMMENT '抖音未预占库存就发生退款标识',
  `good_stock` bigint COMMENT '订单是否全部现货 1是 2否',
  `right_jit` bigint COMMENT '订单是否存在JIT商品 1是 2否',
  `oaid` string COMMENT 'oaid',
  `package_time` timestamp COMMENT '',
  `pay_type` string COMMENT '支付方式1.微信 2.支付宝 3.银联',
  `buyer_memo` string COMMENT '')
;

CREATE TABLE dw_dwd.dwd_ynap_oms_tmall_order_item_fl_d(
  `id` bigint COMMENT '订单行表主键',
  `order_item_no` string COMMENT '订单行编号',
  `sharding_key_order_no` string COMMENT '主单编号,用于分库分表拆分键使用',
  `product_code` string COMMENT '商品sku号',
  `spu_code` string COMMENT '商品spu号',
  `model_code` string COMMENT 'model_code',
  `product_quantity` bigint COMMENT '商品数量',
  `batch_code` string COMMENT '库存批次号 PO',
  `unit_price` decimal(10,2) COMMENT '商品单价',
  `product_name` string COMMENT '商品名称',
  `product_image` string COMMENT '商品图片',
  `order_line_type` bigint COMMENT '1:普通产品;\r\n2:购物车赠品\r\n3:商品赠品',
  `gift_flag` bigint COMMENT '是否是赠品 true 是 false 不是',
  `promotion_code` string COMMENT '促销编号',
  `promotion_name` string COMMENT '促销名称',
  `gift_source_sku_code` string COMMENT '赠品来源商品编号',
  `virtual_warehouse_code` string COMMENT '仓存编号',
  `returnable_flag` bigint COMMENT '是否可作退货,某些产品购买后不能作退货',
  `product_label` string COMMENT '商品标签',
  `order_item_status` bigint COMMENT '订单行状态 待付款 1\n交易关闭 2\n已付款 3\n待审核 4\n待发货 5\n待收货 6\n已签收 7\n延长售后 8\n交易完成(已签收未关闭售后入口) 9\n交易完成(已签收且已关闭售后入口) 10\n拦截失败-11\n退款中-12\n退款成功-13\n商品入库失败-14',
  `intercept_status` bigint COMMENT '拦截状态 -1 失败 1 成功',
  `aftersales_time` timestamp COMMENT '延长售后时间',
  `trading_closed_time` timestamp COMMENT '交易关闭时间',
  `create_user_id` string,
  `update_user_id` string,
  `version` bigint,
  `deleted` bigint COMMENT '0 删除 1 未删除',
  `create_user_name` string,
  `update_user_name` string,
  `create_time` timestamp,
  `update_time` timestamp,
  `sort_id` bigint,
  `partner_id` bigint,
  `product_markdown_price` decimal(10,2) COMMENT 'markdown价格',
  `product_eip_price` decimal(10,2) COMMENT 'EIP价格',
  `tms_service_code` string COMMENT '物流公司编号',
  `tms_service_name` string COMMENT '物流公司名称',
  `tms_number` string COMMENT '物流编号',
  `category_code` string COMMENT '商品销售一级类目',
  `brand_name` string COMMENT '品牌英文名',
  `product_size` string COMMENT '商品尺码',
  `product_colour` string COMMENT '商品颜色',
  `actually_amount` decimal(10,2) COMMENT '实付金额',
  `virtual_category` string COMMENT '虚拟类目',
  `delivery_item_no` bigint COMMENT '出库单号',
  `sku_product_label` string COMMENT 'sku标签',
  `spu_product_label` string COMMENT 'spu标签',
  `sku_tag_label` string COMMENT 'sku所有标签',
  `invoice_amount` decimal(10,2) COMMENT '开票金额',
  `refund_amount` decimal(10,2) COMMENT '退款金额',
  `reserve_stock_number` string COMMENT 'EIP预留商品预占单号',
  `freight` decimal(10,2) COMMENT '运费分摊(抖音用)',
  `sale_day` bigint COMMENT '下单时配置的售后期',
  `tms_number_flag` bigint COMMENT '下单时退货退款物流设置标识 0 不向宝尊申请物流单号 ,1 向宝尊申请物流单号',
  `check_jit` bigint COMMENT '是否是jit商品 1是 2否',
  `jit_stcok` bigint COMMENT '是否现货 1是 2否',
  `omni_stock_num` bigint COMMENT 'omni-库存分配记录数量使用',
  `asn_stock_num` bigint COMMENT 'omni-ASN记录数量使用',
  `oid` string COMMENT '天猫发货通知',
  `package_type` bigint COMMENT '包装类型');
CREATE TABLE dw_dwd.dwd_ynap_oms_tmall_order_delivery_fl_d(
  `id` bigint COMMENT '主键',
  `order_no` string COMMENT '订单编号',
  `sharding_key_order_no` string COMMENT '团单编号,用于分库分表拆分键使用',
  `delivery_no` string COMMENT '出库单编号',
  `virtual_warehouse_code` string COMMENT '虚拟仓库编号',
  `product_quantity` bigint COMMENT '商品数量',
  `delivery_status` bigint COMMENT '出库单状态\r\n待发货-1\r\n取消-2\r\n已发货-3\r\n已签收-4\r\n已拒收-5',
  `tms_service_code` string COMMENT '物流公司编号',
  `tms_service_name` string COMMENT '物流公司名称',
  `tms_number` string COMMENT '物流编号',
  `receiving_address_code` string COMMENT '收货地址id',
  `receiving_address` string COMMENT '收货地址',
  `receiver_name` string COMMENT '收货人',
  `receiver_phone_number` string COMMENT '收货人手机号',
  `shipping_address` string COMMENT '发货地址',
  `consignee_name` string COMMENT '收货人',
  `consignee_phone_number` string COMMENT '收货人电话',
  `deleted` bigint COMMENT '状态 0未删除 1已删除',
  `intercept_status` bigint COMMENT '拦截状态 -1拦截失败  1 拦截成功',
  `create_time` timestamp,
  `update_time` timestamp,
  `version` bigint COMMENT '数据版本',
  `sort_id` bigint COMMENT '显示顺序',
  `partner_id` bigint COMMENT '合作方id',
  `create_user_name` string COMMENT '创建用户名',
  `create_user_id` string COMMENT '创建uid',
  `update_user_name` string COMMENT '更新用户名',
  `update_user_id` string COMMENT '更新uid',
  `stock_number` string COMMENT '仓库编号',
  `order_remark` string COMMENT '订单备注',
  `phone` string COMMENT '会员手机号',
  `rel_order_no` string COMMENT '第三方数据订单编号',
  `channel` bigint COMMENT '渠道',
  `user_tags` string COMMENT '下单是用户命中的标签',
  `user_tag_ids` string,
  `delivery_type` bigint COMMENT '出库单类型 1.非JIT 2.JIT现货 3.JIT非现货',
  `send_ecc` bigint COMMENT '是否下发ecc 0未下发  1已下发  omni专用',
  `package_type` bigint);
CREATE TABLE dw_dwd.dwd_ynap_oms_tmall_order_delivery_items_fl_d(
  `id` bigint,
  `sharding_key_order_no` string COMMENT '团单编号,用于分库分表拆分键使用',
  `delivery_no` string COMMENT '出库单编号',
  `delevery_item_no` string COMMENT '出库单行编号',
  `sku_code` string COMMENT '商品编号',
  `product_quantity` bigint COMMENT '商品数量',
  `product_name` string COMMENT '商品名称',
  `product_img_url` string COMMENT '商品图片url',
  `item_type` bigint COMMENT '1:普通商品;\r\n2:购物车赠品\r\n3:商品赠品',
  `stock_number` string COMMENT '仓库编号',
  `virtual_warehouse_code` string COMMENT '虚拟仓库编号',
  `delivery_line_status` bigint COMMENT '商品行状态',
  `push_status` bigint COMMENT '推送状态\r\n已推送-1\r\n无需推送-2\r\n已取消-3',
  `deleted` bigint COMMENT '状态 0未删除 1已删除',
  `order_item_state` string COMMENT '订单行的状态',
  `create_time` timestamp,
  `update_time` timestamp,
  `version` bigint COMMENT '数据版本',
  `sort_id` bigint COMMENT '显示顺序',
  `partner_id` bigint COMMENT '合作方id',
  `create_user_name` string COMMENT '创建用户名',
  `create_user_id` string COMMENT '创建uid',
  `update_user_name` string COMMENT '更新用户名',
  `update_user_id` string COMMENT '更新uid',
  `jit_stock` bigint COMMENT '是否现货 1现货 2非现货',
  `package_type` bigint);
CREATE TABLE dw_dwd.dwd_ynap_oms_tmall_order_fl_d(
  `id` bigint COMMENT '订单表主键',
  `sharding_key_order_no` string COMMENT '主单编号,用于分库分表拆分键使用',
  `channel_code` bigint COMMENT '渠道:APP,WEBSITE, EIP',
  `order_no` string COMMENT '订单编号',
  `login_code` string COMMENT '登录用户编号',
  `login_type` bigint COMMENT '会员身份:0-普通会员,1-EIP',
  `login_name` string COMMENT '用户名',
  `phone` string COMMENT '手机号',
  `order_amount` decimal(10,2) COMMENT '订单金额 (商品总金额)',
  `discount_amount` decimal(10,2) COMMENT '订单折扣金额(营销优惠)',
  `coupon_amount` decimal(10,2) COMMENT '订单优惠金额(优惠券)',
  `payable_amount` decimal(10,2) COMMENT '应支付金额',
  `refunded_amount` decimal(10,2) COMMENT '已退款金额',
  `order_status` bigint COMMENT '订单状态\r\n待付款 1\r\n交易关闭 2\r\n已付款 3\r\n待审核 4\r\n待发货 5\r\n待收货 6\r\n已签收 7\r\n延长售后 8\r\n交易完成(已签收未关闭售后入口) 9\r\n交易完成(已签收且已关闭售后入口) 10\r\n拦截失败-11\r\n退款中-12\r\n退款成功-13\r\n商品入库失败-14',
  `previewing_status` bigint COMMENT '预检状态(0-未预检,1-预检不通过,2-预检通过)',
  `previewing_reason` string COMMENT '预检失败原因',
  `payment_status` bigint COMMENT '付款状态\r\n1.未支付\r\n2.已支付\r\n3.已退款',
  `shipment_status` bigint COMMENT '出货状态 1 待发货 2 已取消 3 已发货 4已拒绝',
  `imanual_cancel_flag` bigint COMMENT '是否手动取消\r\n1-是 0-否',
  `invoice_code` string COMMENT '开票信息id,用户中心存储的开发票信息编号',
  `invoice_flag` bigint COMMENT '是否开票\r\n1-是 0-否',
  `invoice_status` bigint COMMENT '发票状态\r\n1-未开票\r\n2-已开票',
  `currency_code` string COMMENT '货币编号,默认RMB',
  `delivery_type` string COMMENT '送货方式,默认方式-快递',
  `payment_time` timestamp COMMENT '支付时间',
  `payment_balance_time` timestamp COMMENT '支付尾款时间',
  `receiving_address_code` string COMMENT '收货地址id',
  `receiver_phone_number` string COMMENT '收货人手机号',
  `receiver_name` string COMMENT '收货人',
  `receiving_address` string COMMENT '收货地址',
  `receiving_address_decrypt` string,
  `card_content` string COMMENT '贺卡内容',
  `package_type` bigint COMMENT '包装类型',
  `package_name` string COMMENT '包装类型名称',
  `order_type` bigint COMMENT '订单类型:\r\n销售订单 sale\r\n线下订单 offline\r\nPre-Order preOrder',
  `pay_times` bigint COMMENT '发起支付次数\r\n调用支付中心发起支付接口单号 = 订单号+支付次数',
  `order_remark` string COMMENT '订单备注',
  `refund_remark` string COMMENT '破例退货备注',
  `cs_remark` string COMMENT '客服备注',
  `create_user_id` string COMMENT '创建人id',
  `update_user_id` string COMMENT '修改人id',
  `create_user_name` string COMMENT '创建人姓名',
  `update_user_name` string COMMENT '修改人姓名',
  `create_time` timestamp COMMENT '创建时间',
  `update_time` timestamp COMMENT '修改时间',
  `sort_id` bigint,
  `version` bigint COMMENT '版本号',
  `deleted` bigint COMMENT '状态 0未删除  1已删除',
  `order_time` timestamp COMMENT '下单时间',
  `freight` decimal(10,2) COMMENT '运费',
  `partner_id` bigint,
  `sync_status` bigint COMMENT '同步OMS状态:0-未同步,1-同步成功,2-同步失败',
  `ps_user_id` string COMMENT 'PS客服编号',
  `shops` string COMMENT '店铺',
  `serial_number` string COMMENT 'excel导入编号',
  `sub_channel` bigint COMMENT '订单来源',
  `operator` string COMMENT '操作人',
  `freight_refund_flag` bigint COMMENT '是否已退运费',
  `system_source` bigint COMMENT '系统来源  1 IOS 2 安卓 3PC 4E EIP',
  `ps_submit_flag` bigint COMMENT '是否是PS代客下单',
  `user_grade` bigint COMMENT '会员下单等级',
  `points` decimal(10,2) COMMENT '积分',
  `buyer_name` string COMMENT '礼品卡购买人姓名',
  `id_number` string COMMENT '礼品卡购买人身份证',
  `buyer_phone_number` string COMMENT '礼品卡购买人手机',
  `refunded_card_amount` decimal(10,2) COMMENT '已退款礼品卡金额',
  `affiliate_flag` bigint COMMENT '是否是Affiliate用户',
  `user_tag_ids` string COMMENT '下单是用户命中的标签id',
  `use_card_amount` decimal(10,2) COMMENT '礼品卡使用金额',
  `residue_amount` decimal(10,2) COMMENT '剩余应付金额 (扣除礼品卡后的支付现金)',
  `rel_order_no` string COMMENT '第三方数据订单编号',
  `dy_refund_flag` bigint COMMENT '抖音订单退款标志\r\n0:未退款\r\n1.未开票订单:请在发票后台开具蓝票\r\n2.已开票订单:请在发票后台红冲后重新开蓝票\r\n3.开票金额和OMS金额不一致,冲红后开票\r\n4:发生邮件成功\r\n5:发生邮件失败\r\n',
  `user_tags` string COMMENT '下单是用户命中的标签',
  `utm_source` string,
  `utm_content` string,
  `is_douyin_notstock` bigint COMMENT '抖音未预占库存就发生退款标识',
  `good_stock` bigint COMMENT '订单是否全部现货 1是 2否',
  `right_jit` bigint COMMENT '订单是否存在JIT商品 1是 2否',
  `oaid` string COMMENT 'oaid',
  `package_time` timestamp COMMENT '',
  `pay_type` string COMMENT '支付方式1.微信 2.支付宝 3.银联',
  `buyer_memo` string COMMENT '');
CREATE TABLE dw_dwd.dwd_ynap_oms_tmall_order_item_fl_d(
  `id` bigint COMMENT '订单行表主键',
  `order_item_no` string COMMENT '订单行编号',
  `sharding_key_order_no` string COMMENT '主单编号,用于分库分表拆分键使用',
  `product_code` string COMMENT '商品sku号',
  `spu_code` string COMMENT '商品spu号',
  `model_code` string COMMENT 'model_code',
  `product_quantity` bigint COMMENT '商品数量',
  `batch_code` string COMMENT '库存批次号 PO',
  `unit_price` decimal(10,2) COMMENT '商品单价',
  `product_name` string COMMENT '商品名称',
  `product_image` string COMMENT '商品图片',
  `order_line_type` bigint COMMENT '1:普通产品;\r\n2:购物车赠品\r\n3:商品赠品',
  `gift_flag` bigint COMMENT '是否是赠品 true 是 false 不是',
  `promotion_code` string COMMENT '促销编号',
  `promotion_name` string COMMENT '促销名称',
  `gift_source_sku_code` string COMMENT '赠品来源商品编号',
  `virtual_warehouse_code` string COMMENT '仓存编号',
  `returnable_flag` bigint COMMENT '是否可作退货,某些产品购买后不能作退货',
  `product_label` string COMMENT '商品标签',
  `order_item_status` bigint COMMENT '订单行状态 待付款 1\n交易关闭 2\n已付款 3\n待审核 4\n待发货 5\n待收货 6\n已签收 7\n延长售后 8\n交易完成(已签收未关闭售后入口) 9\n交易完成(已签收且已关闭售后入口) 10\n拦截失败-11\n退款中-12\n退款成功-13\n商品入库失败-14',
  `intercept_status` bigint COMMENT '拦截状态 -1 失败 1 成功',
  `aftersales_time` timestamp COMMENT '延长售后时间',
  `trading_closed_time` timestamp COMMENT '交易关闭时间',
  `create_user_id` string,
  `update_user_id` string,
  `version` bigint,
  `deleted` bigint COMMENT '0 删除 1 未删除',
  `create_user_name` string,
  `update_user_name` string,
  `create_time` timestamp,
  `update_time` timestamp,
  `sort_id` bigint,
  `partner_id` bigint,
  `product_markdown_price` decimal(10,2) COMMENT 'markdown价格',
  `product_eip_price` decimal(10,2) COMMENT 'EIP价格',
  `tms_service_code` string COMMENT '物流公司编号',
  `tms_service_name` string COMMENT '物流公司名称',
  `tms_number` string COMMENT '物流编号',
  `category_code` string COMMENT '商品销售一级类目',
  `brand_name` string COMMENT '品牌英文名',
  `product_size` string COMMENT '商品尺码',
  `product_colour` string COMMENT '商品颜色',
  `actually_amount` decimal(10,2) COMMENT '实付金额',
  `virtual_category` string COMMENT '虚拟类目',
  `delivery_item_no` bigint COMMENT '出库单号',
  `sku_product_label` string COMMENT 'sku标签',
  `spu_product_label` string COMMENT 'spu标签',
  `sku_tag_label` string COMMENT 'sku所有标签',
  `invoice_amount` decimal(10,2) COMMENT '开票金额',
  `refund_amount` decimal(10,2) COMMENT '退款金额',
  `reserve_stock_number` string COMMENT 'EIP预留商品预占单号',
  `freight` decimal(10,2) COMMENT '运费分摊(抖音用)',
  `sale_day` bigint COMMENT '下单时配置的售后期',
  `tms_number_flag` bigint COMMENT '下单时退货退款物流设置标识 0 不向宝尊申请物流单号 ,1 向宝尊申请物流单号',
  `check_jit` bigint COMMENT '是否是jit商品 1是 2否',
  `jit_stcok` bigint COMMENT '是否现货 1是 2否',
  `omni_stock_num` bigint COMMENT 'omni-库存分配记录数量使用',
  `asn_stock_num` bigint COMMENT 'omni-ASN记录数量使用',
  `oid` string COMMENT '天猫发货通知',
  `package_type` bigint COMMENT '包装类型');
CREATE TABLE dw_dwd.dwd_ynap_oms_tmall_order_refund_fl_d(
  `id` bigint COMMENT '主键id',
  `order_no` string COMMENT '订单编号',
  `sharding_key_order_no` string COMMENT '团单编号,用于分库分表拆分键使用',
  `operate_type` bigint COMMENT '操作类型:1、退款(发货前) 2、退款(发货后) 3 退货退款',
  `refund_no` string COMMENT '退款单号',
  `total_fee` decimal(10,2) COMMENT '原订单金额',
  `login_ada` string COMMENT '操作用户',
  `login_user_name` string COMMENT '用户名称',
  `order_status` bigint COMMENT '订单的状态',
  `refund_status` bigint COMMENT '退款状态',
  `goods_status` bigint COMMENT '货物状态',
  `has_good_return` bigint COMMENT '买家是否需要退货',
  `refund_fee` decimal(10,2) COMMENT '退款金额',
  `payment` decimal(10,2) COMMENT '订单剩余为退款金额(交易总金额-退还给买家的金额)',
  `reason` string COMMENT '退款原因',
  `refund_desc` string COMMENT '退款说明',
  `tms_service_code` string COMMENT '物流公司编号',
  `tms_service_name` string COMMENT '物流公司名称',
  `tms_number` string COMMENT '物流编号',
  `refund_version` bigint COMMENT '退款版本号(时间戳)',
  `deleted` bigint COMMENT '是否删除 0 未删除 1已删除',
  `create_time` timestamp COMMENT '退款提交时间',
  `update_time` timestamp COMMENT '更新时间',
  `collect_parcel_start_time` timestamp COMMENT '上门取件开始时间',
  `collect_parcel_end_time` timestamp COMMENT '上门取件结束时间',
  `images` string,
  `receiving_address` string COMMENT '收货地址',
  `receiver_name` string COMMENT '收货人',
  `receiver_phone_number` string COMMENT '收货人手机号',
  `shipping_address` string COMMENT '发货地址',
  `consignor_name` string COMMENT '发货人',
  `consignor_phone_number` string COMMENT '发货人手机号',
  `partner_id` string COMMENT '合作方id',
  `sort_id` bigint COMMENT '排序字段',
  `version` bigint COMMENT '版本号',
  `create_user_name` string COMMENT '创建人',
  `update_user_name` string COMMENT '修改人',
  `create_user_id` string,
  `update_user_id` string,
  `batch_code` string COMMENT '批次号 PO号',
  `store_code` string COMMENT '仓库编号',
  `delivery_no` string COMMENT '出库单编号',
  `channel_code` bigint COMMENT '渠道来源 1APP',
  `refuse_reason` string COMMENT '拒绝原因',
  `freight` decimal(10,2) COMMENT '运费',
  `refund_type` bigint COMMENT '1:app 2:oms',
  `storage_cofirm_time` timestamp COMMENT '确认入库时间',
  `refuse_storage_reason` string,
  `previewing_reason` string COMMENT '预检失败原因',
  `phone` string COMMENT '会员手机号',
  `user_grade` bigint COMMENT '会员下单等级',
  `refund_card_amount` decimal(10,2) COMMENT '礼品卡退款金额',
  `refund_cash_amount` decimal(10,2) COMMENT '现金退款金额',
  `gift_card_service_charge` decimal(20,2) COMMENT '礼品卡退卡手续费',
  `rel_order_no` string COMMENT '第三方数据订单编号',
  `rel_refund_no` string COMMENT '第三方数据销退单号',
  `refund_priority` bigint COMMENT '退款优先级 1-优先退礼品卡 2-优先退现金',
  `user_tag_ids` string COMMENT '下单时用户命中的标签',
  `cs_remark` string COMMENT '客服备注',
  `user_tags` string COMMENT '下单是用户命中的标签',
  `tms_number_flag` bigint COMMENT '下单时退货退款物流设置标识 0 不向宝尊申请物流单号 1 ,向宝尊申请物流单号',
  `is_automatic` bigint COMMENT '抖音是否自动退货退款 1:是 2:不是',
  `sync_stock` bigint COMMENT '抖音发货前退款同步全量库存 0 否,1 是',
  `wms_times` bigint COMMENT '下发wms后缀');
CREATE TABLE dw_dwd.dwd_ynap_oms_tmall_order_refund_items_fl_d(
  `id` bigint COMMENT '主键id',
  `order_no` string COMMENT '订单编号',
  `sharding_key_order_no` string COMMENT '团单编号,用于分库分表拆分键使用',
  `refund_no` string COMMENT '退款单号',
  `sku_code` string COMMENT '商品编号',
  `product_name` string COMMENT '商品名称',
  `product_img_url` string COMMENT '商品图片url',
  `quantity` bigint COMMENT '数量',
  `store_code` string COMMENT '仓储编号',
  `batch_code` string COMMENT '批次号,PO',
  `original_price` decimal(10,2) COMMENT '商品原价格',
  `deleted` bigint COMMENT '是否删除 0 未删除 1已删除',
  `refund_item_status` bigint COMMENT '销退单行状态',
  `create_time` timestamp COMMENT '退款提交时间',
  `update_time` timestamp COMMENT '更新时间',
  `actually_amount` decimal(10,2) COMMENT '商品实付金额',
  `gift_source_sku_code` string COMMENT '赠品来源商品编号',
  `gift_flag` bigint COMMENT '是否是赠品',
  `sku_type` bigint COMMENT '1 普通商品  2 订单级别 3 商品级别',
  `promotion_code` string COMMENT '促销编号',
  `promotion_name` string COMMENT '促销名称',
  `brand_name` string COMMENT '品牌英文名',
  `product_attr` string COMMENT '商品颜色尺码',
  `product_markdown_price` decimal(10,2) COMMENT 'markdown价格',
  `product_eip_price` decimal(10,2) COMMENT 'ELP价格',
  `partner_id` string COMMENT '合作方id',
  `sort_id` bigint COMMENT '排序号',
  `version` bigint COMMENT '版本号',
  `create_user_name` string COMMENT '创建人',
  `update_user_name` string COMMENT '修改人',
  `create_user_id` string COMMENT '',
  `update_user_id` string,
  `delivery_item_no` string COMMENT '出库单号',
  `order_item_status` bigint COMMENT '原订单行状态',
  `refund_fee` decimal(10,2) COMMENT '退款金额',
  `spu_code` string COMMENT 'spu_code');
CREATE TABLE dw_dwd.dwd_ynap_oms_tmall_payment_items_fl_d(
  `id` bigint COMMENT '交易流水表主键',
  `order_no` string COMMENT '订单号',
  `sharding_key_order_no` string COMMENT '订单编号,用于分库分表拆分键使用',
  `payment_code` string COMMENT '支付方式小类别(分期数),注意,此时记录的是发起支付时选择的分期数,由于PC端支付时用户可以改分期数,因此分期期数可能和实际用户选择的分期数可能不一样',
  `payment_mode` bigint COMMENT '支付方式 微信-wechat,支付宝-alipay,银联-uniepay,积分-points',
  `payment_amount` decimal(10,2) COMMENT '支付金额',
  `payment_total_amount` decimal(10,2) COMMENT '应支付总金额',
  `points` decimal(10,2) COMMENT '积分',
  `transaction_no` string COMMENT '交易流水号',
  `transaction_status` bigint COMMENT '交易状态',
  `transaction_type` bigint COMMENT '交易类型,1-支付 2-退款',
  `trade_order_no` string COMMENT '支付中心返回的订单编号',
  `bank_trade_no` string COMMENT '支付中心返回的银行流水号',
  `deleted` bigint COMMENT '是否删除 1删除 0 未删除',
  `create_user_id` string,
  `update_user_id` string,
  `create_user_name` string,
  `update_user_name` string,
  `sort_id` bigint COMMENT '排序值',
  `version` bigint COMMENT '版本号',
  `create_time` timestamp COMMENT '创建时间',
  `update_time` timestamp COMMENT '修改时间',
  `partner_id` string COMMENT '合作方id',
  `channel_code` bigint COMMENT '渠道来源 1 安卓 2 IOS',
  `merch_no` string COMMENT '商户号',
  `terminal_no` string COMMENT '终端号',
  `qr_code_id` string COMMENT '二维码ID',
  `refund_no` string COMMENT '销退单号',
  `txn_time` string COMMENT '银联直连商户发送交易时间',
  `direct_flag` bigint COMMENT '银联支付流水标识 1 直连 , 2 间连 ');
CREATE TABLE dw_dwd.dwd_order_oms_tmall_sync_time_fl_d(
  `id` bigint COMMENT '表主键',
  `order_no` string COMMENT '订单编号',
  `sku` string COMMENT '商品sku',
  `virtual_warehouse_code` string COMMENT '仓存编号',
  `child_order_delivery_time` timestamp COMMENT '子订单发货时间',
  `child_order_receive_time` timestamp COMMENT '子订单签收时间',
  `child_order_success_time` timestamp COMMENT '子订单交易成功时间',
  `child_order_cancel_time` timestamp COMMENT '子订单交易关闭时间',
  `child_order_refund_time` timestamp COMMENT '子订单退货发起时间',
  `child_order_refund_parcel_time` timestamp COMMENT '子订单退货上门揽件时间',
  `child_order_refund_backmoney_time` timestamp COMMENT '子订单退货确认退款时间',
  `refund_type` int COMMENT '退货类型(1、仅退款 2、退货退款)',
  `create_time` timestamp COMMENT '创建时间',
  `update_time` timestamp COMMENT '修改时间',
  `version` bigint COMMENT '版本号',
  `partner_id` string COMMENT '合作方id',
  `sort_id` bigint COMMENT '排序值',
  `deleted` int COMMENT '状态 0未删除  1已删除',
  `create_user_name` string COMMENT '创建人

',
  `update_user_name` string COMMEN
select * from dw_ads.adsordsa;




-- dwd model 8
drop table if exists dw_dwd.dwd_ord_model_order_detail_timeline_fl_d;
create table dw_dwd.dwd_ord_model_order_detail_timeline_fl_d
(
    sub_order_no                string comment '子订单号',
    order_no                    string comment '订单号',
    platform_order_no           string comment '源平台订单号:tmall/douyin/appoms订单号',
    platform_sub_order_no       string comment '源平台订单号:tmall/douyin/appoms订单号',
    sku_code                    string comment '',
    order_channel               string comment '订单渠道TMALL/DOUYIN/APP/WEB/H5/MINIPROGRAM/OFFLINE',
    order_create_time           timestamp comment '下单时间',
    order_prepay_time           timestamp comment '预售订金支付时间',
    order_pay_time              timestamp comment '支付时间',
    push_ynap_order_time        timestamp comment 'omni推送给ynap的时间',
    ynap_confirm_delivery_time  timestamp comment 'omniYNAP订单确认时间',
    ynap_delivery_time          timestamp comment 'omniYNAP发货时间',
    ynap_enter_warehouse_time   timestamp comment 'omni入本地仓时间',
    ynap_cancel_time            timestamp comment 'omniYNAP取消时间',
    order_apply_delivery_time   timestamp comment '申请国内发货时间',
    order_delivery_time         timestamp comment '国内仓库发货时间',
    order_consign_time          timestamp comment '客户签收时间',
    order_success_time          timestamp comment '订单交易成功时间',
    order_end_time              timestamp comment '订单完成时间(售后期结束)',
    order_cancel_time           timestamp comment '订单取消时间',
    order_last_update_time      timestamp comment '订单最后更新时间',
    refund_apply_time           timestamp comment '退款申请时间',
    return_apply_time           timestamp comment '退货申请时间',
    return_send_time            timestamp comment '退货商品寄出时间(APP上门揽件时间)',
    return_enter_warehouse_time timestamp comment '退货入库时间',
    refund_backmoney_time       timestamp comment '退款确认时间',
    refund_success_time         timestamp comment '退款成功时间',
    refund_close_time           timestamp comment '退款关闭时间',
    refund_last_update_time     timestamp comment '退款最后更新时间',
    dc_system_time              timestamp comment '系统更新时间',
    create_time                 timestamp comment '创建时间',
    update_time                 timestamp comment '更新时间'
)
comment '订单时间表'
stored as orc;




--10
drop table if exists dw_dwd.dwd_ord_model_order_label_fl_d;
create table dw_dwd.dwd_ord_model_order_label_fl_d
(
    order_no           string comment '订单号',
    platform_order_no  string comment '源平台订单号',
    is_use_prepay_card string comment '是否使用预付卡(APP礼品卡/TMALL兑换卡)',
    is_buy_prepay_card string comment '是否购买预付卡',
    is_installment     string comment '是否分期',
    is_interest_free   string comment '是否免息',
    is_special_refund  string comment '是否特殊退款',
    payment_modes      string comment '支付方式(拼接)',
    is_88vip           string comment '88VIP标签',
    terminal_type      string comment '终端来源类型:web/ios/android',
    is_staff_order     string comment '员工订单标记',
    is_mobile_order    string comment '是否移动端订单',
    is_preorder        string comment '是否预售订单',
    is_member_order    string comment '下单时是否会员订单',
    is_first_order     string comment '是否购买首单',
    is_second_retreat  string comment '是否非秒退首单',
    th_buy             string comment '订单第几次购买',
    is_gift_order      string comment '赠品订单标记',
    is_free_order      string comment '0元购订单',
    is_test            string comment '是否测试订单',
    app_order_type     string comment '订单类型:销售订单sale,线下订单offline,Pre-OrderpreOrder',
    app_channel_code   string comment '渠道:APP,WEBSITE,EIP',
    is_affiliate_user  string comment '是否是Affiliate用户',
    city_level         string comment '地域等级',
    create_time        timestamp comment '创建时间',
    update_time        timestamp comment '更新时间',
    dc_system_time     timestamp comment '数据中台系统处理时间'
)
comment '.订单标签表'
stored as orc;


--11
drop table if exists dw_dwd.dwd_ord_model_order_detail_label_fl_d;
create table dw_dwd.dwd_ord_model_order_detail_label_fl_d
(
    sub_order_no                  string comment '子订单号',
    order_no                      string comment '订单号',
    order_channel                 string comment '订单渠道:TMALL/DOUYIN/APP/WEB/H5/MINIPROGRAM/OFFLINE',
    day                           date comment '数据日期',
    memberid                      string comment '会员id',
    sku_code                      string comment '商品标识',
    order_amount                  decimal(10,2) comment '下单金额',
    pay_amount                    decimal(10,2) comment '付款金额',
    ship_amount                   decimal(10,2) comment '发货金额',
    refund_apply_amount           decimal(10,2) comment '申退金额',
    refund_apply_success_amount   decimal(10,2) comment '退款成功金额',
    refund_cancel_amount          decimal(10,2) comment '发货前退款金额',
    refund_cancel_success_amount  decimal(10,2) comment '发货前退款成功金额',
    order_num                     bigint comment '下单件数',
    pay_num                       bigint comment '付款件数',
    ship_num                      bigint comment '发货件数',
    refund_apply_num              bigint comment '申退件数',
    refund_apply_success_num      bigint comment '退款成功件数',
    refund_cancel_num             bigint comment '发货前退款件数',
    refund_cancel_success_num     bigint comment '发货前退款成功件数',
    exchange_rate_cny_to_eur      decimal(10,2) comment '人名币兑换欧元汇率',
    exchange_rate_eur_to_cny      decimal(10,2) comment '欧元兑换人名币汇率',
    tax_rate                      decimal(10,2) comment '税率',
    cash_pay_amunt                decimal(10,2) comment '实付现金金额',
    prepay_card_amount            decimal(10,2) comment '购买预付卡金额',
    origin_prepay_card_amount     decimal(10,2) comment '购买预付卡本金金额',
    extra_prepay_card_amount      decimal(10,2) comment '购买预付卡赠送金额',
    use_prepay_card_amount        decimal(10,2) comment '使用预付卡总金额',
    use_origin_prepay_card_amount decimal(10,2) comment '使用预付卡本金金额',
    use_extra_prepay_card_amount  decimal(10,2) comment '使用预付卡赠送金额',
    order_prepay_deposit_amount   decimal(10,2) comment '预售支付定金',
    create_time                   timestamp comment '创建时间',
    update_time                   timestamp comment '更新时间',
    dc_system_time                timestamp comment '数据中台系统处理时间'
)
comment '订单详情标签表'
stored as orc;


--12
drop table if exists dw_dwd.dwd_ord_model_order_detail_basic_index_fl_d;
create table dw_dwd.dwd_ord_model_order_detail_basic_index_fl_d
(
sub_order_no                   string comment '子订单号',
order_no                       string comment '订单号',
order_channel                  string comment '订单渠道:TMALL/DOUYIN/APP/WEB/H5/MINIPROGRAM/OFFLINE',
day                            date comment '数据日期',
memberid                       string comment '会员id',
sku_code                       string comment '商品标识',
order_amount                   decimal(10,2) comment '下单金额',
pay_amount                     decimal(10,2) comment '付款金额',
ship_amount                    decimal(10,2) comment '发货金额',
refund_apply_amount            decimal(10,2) comment '申退金额',
refund_apply_success_amount    decimal(10,2) comment '退款成功金额',
refund_cancel_amount           decimal(10,2) comment '发货前退款金额',
refund_cancel_success_amount   decimal(10,2) comment '发货前退款成功金额',
order_num                      bigint comment '下单件数',
pay_num                        bigint comment '付款件数',
ship_num                       bigint comment '发货件数',
refund_apply_num               bigint comment '申退件数',
refund_apply_success_num       bigint comment '退款成功件数',
refund_cancel_num              bigint comment '发货前退款件数',
refund_cancel_success_num      bigint comment '发货前退款成功件数',
exchange_rate_cny_to_eur       decimal(10,2) comment '人名币兑换欧元汇率',
exchange_rate_eur_to_cny       decimal(10,2) comment '欧元兑换人名币汇率',
tax_rate                       decimal(10,2) comment '税率',
cash_pay_amunt                 decimal(10,2) comment '实付现金金额',
prepay_card_amount             decimal(10,2) comment '购买预付卡金额',
origin_prepay_card_amount      decimal(10,2) comment '购买预付卡本金金额',
extra_prepay_card_amount       decimal(10,2) comment '购买预付卡赠送金额',
use_prepay_card_amount         decimal(10,2) comment '使用预付卡总金额',
use_origin_prepay_card_amount  decimal(10,2) comment '使用预付卡本金金额',
use_extra_prepay_card_amount   decimal(10,2) comment '使用预付卡赠送金额',
order_prepay_deposit_amount    decimal(10,2) comment '预售支付定金',
create_time                    timestamp comment '创建时间',
update_time                    timestamp comment '更新时间',
dc_system_time                 timestamp comment '数据中台系统处理时间'
)
comment '子订单级原子指标'
stored as orc;

--ads 宽表

drop table if exists dw_ads.ads_ord_model_order_detail_fl_d;
create table dw_ads.ads_ord_model_order_detail_fl_d
(
--
    sub_order_no                     string comment '子订单号,oms:order_item_no,tmall:oid',
    order_no                         string comment '订单号,全渠道唯一',
    platform_sub_order_no            string comment '源平台子订单号:tmall/douyin/appoms订单号',
    platform_order_no                string comment '平台订单号:tmall/douyin/appoms订单号',
    refund_no                        string comment '退单号',
    platform_refund_no               string comment '源平台退款单号:tmall/douyin/appoms编号',
    order_category                   string comment '订单种类:销售订单/互动订单/礼品卡充值订单',
    order_channel                    string comment '订单渠道:TMALL/DOUYIN/APP/WEB/H5/MINIPROGRAM/OFFLINE',
    sale_platform                    string comment '销售渠道',
    sub_sale_platform                string comment '子销售渠道',
    jv_user_id                       string comment '中台用户id',
    member_id                        string comment '会员id',
    customer_no                      string comment '平台用户id:tmall:buyer_open_uid/douyin:openid/app:app_user_id',
--用户属性、标签,
    earlist_paydate                  date comment '用户最早的支付日期(剔除秒退)(天猫)',
    store_paydate                    date comment '用户最早的支付日期(剔除秒退)',
    staff_flag                       string comment '员工订单标签',
--商品维度,字段
    ynapchannel                      string comment '渠道。NAP,MRP,TPP',
    gift_order_flag                  string comment '赠品标签',
    brand_code                       string comment '品牌编号',
    brand_name                       string comment '品牌名称',
    size_schema                      string comment '尺寸',
    category_name                    string comment 'YNAP一级品类',
    subcategory_name                 string comment 'YNAP二级品类',
    sub_subcategory_name             string comment 'YNAP三级品类',
    model_id                         string comment 'Modelid',
    variant_id                       string comment 'Variantid',
    gtin                             string comment '商品条码',
    brand_size                       string comment '品牌尺码',
    sub_channel                      string comment '二级渠道',
    channel                          string comment '一级渠道',
    ftitle                           string comment '天猫商品名称',
    sale_season                      string comment 'YNAPSeason',
    fouteriid                        string comment 'Model级别Glscode',
    fpicpath                         string comment '商品图片',
    price                            decimal(10, 2) comment '商品天猫价格',
    fouterskuid                      string comment 'GTIN级别的glscode',
    hard_or_soft_luxury              string comment '软硬奢分类。HardLuxury:硬奢,SoftLuxury:软奢',
    numiid                           string comment '宝贝ID',
    gender                           string comment '性别',
    collocationinfo                  string comment '巴黎世家商品系列名称',
    merchant_gender                  string comment '采购部门定义的性别',
    product_url                      string comment '宝尊的商品照片',
    brand_colour                     string comment '品牌颜色',
    hard_luxury                      string comment '是否是硬奢',
    category_id_new                  string comment '处理后的一级品类编号',
    ynaprichemonttppchannel          string comment '渠道。YNAP,历峰和TPP',
    retail_price                     decimal(10, 2) comment '零售价',
    brand_simple_name                string comment '品牌简称',
    category_name_manual             string comment '采购部门定义的一级品类',
    subcategory_name_manual          string comment '采购部门定义的二级品类',
    sub_subcategory_name_manual      string comment '采购部门定义的三级品类',
    ynap_full_price                  decimal(10, 2) comment 'YNAP原价',
    merchant_season                  string comment '采购部门定义的商品季节',
    pid_style_clr                    string comment 'ProductID',
    model_fabric_colour              string comment 'Model级别的商品颜色',
    model_fabric                     string comment '面料',
    subchannel_hl_sl_alia_buccellati string comment '三级渠道',
    napmrprichemontchannel           string comment '渠道。NAP,MRP,Richemont,TTP'
)
comment '订单宽表'
stored as orc;



T '修改人',
  `create_user_id` string COMMENT '创建人id',
  `update_user_id` string COMMENT '修改人id',
  `order_item_id` bigint COMMENT '子订单d');

你可能感兴趣的:(sql,数据库)