Commit 7f28e323 by guanzhenshan

etsy平台改为预收

parent 4edb12f7
...@@ -7,29 +7,29 @@ namespace Bailun.DC.DailyPlatformReceivable ...@@ -7,29 +7,29 @@ namespace Bailun.DC.DailyPlatformReceivable
{ {
class Program class Program
{ {
//static async Task Main(string[] args) static async Task Main(string[] args)
//{ {
// Console.WriteLine("启动服务 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Console.WriteLine("启动服务 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
// var builder = new HostBuilder().ConfigureServices((hostContext, services) => var builder = new HostBuilder().ConfigureServices((hostContext, services) =>
// { {
// services.AddHostedService<Services>(); services.AddHostedService<Services>();
// }); });
// await builder.RunConsoleAsync(); await builder.RunConsoleAsync();
//} }
static void Main(string[] args) //static void Main(string[] args)
{ //{
var _services = new Services(); // var _services = new Services();
var start = DateTime.Parse("2020-11-30"); // var start = DateTime.Parse("2021-03-01");
while (start.AddDays(1) < DateTime.Now) // while (start.AddDays(1) < DateTime.Now)
{ // {
Console.WriteLine(start); // Console.WriteLine(start);
_services.Init(start); // _services.Init(start);
start = start.AddDays(1); // start = start.AddDays(1);
} // }
} //}
} }
} }
...@@ -182,13 +182,71 @@ namespace Bailun.DC.DailyPlatformReceivable ...@@ -182,13 +182,71 @@ namespace Bailun.DC.DailyPlatformReceivable
m_shopify.lastupdateusername = "system"; m_shopify.lastupdateusername = "system";
} }
//Etsy 预收账款=期初预收余额+本期收款(订单付款金额)-发货金额-退款(未发货的)+其他
//期初预收余额
sql = $"select * from dc_daily_receivable where day='{day.AddDays(-1).ToString("yyyy-MM-dd")}' and platform='Etsy'";
objBefore = cn.QueryFirstOrDefault<dc_daily_receivable>(sql);
//本期收款
sql = $"select sum(amount_sales*seller_order_exchange_rate) amount from dc_base_oms_order where platform_type='Etsy' and paid_time>='{day.ToString("yyyy-MM-dd")}' and paid_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' and company_id=1 and bailun_order_status!='Canceled' and has_scalp=0 and has_innersale=0 and bailun_interception_status in ('None','Failed')";
var EtsySales = cn.QueryFirstOrDefault<decimal?>(sql) ?? 0;
//发货金额
sql = $@"select sum(t1.amount_sales*t2.quantity_shipped*t1.seller_order_exchange_rate) amount
from dc_base_oms_pick t2
join dc_base_oms_sku t1 on t1.bailun_order_id=t2.bailun_order_id and t1.bailun_sku=t2.bailun_sku and t1.has_scalp=0 and t1.has_delete=0 and t1.has_innersale=0 and t1.bailun_order_status!='Canceled' and t1.has_innersale=0 and t1.company_id=1 and t1.platform_type='Etsy'
where t2.has_delete=0 and t2.shipping_status='TotalShipping' and t2.company_id=1 and t2.shipping_time>='{day.ToString("yyyy-MM-dd")}' and t2.shipping_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' ";
var EtsyShipping = cn.QueryFirstOrDefault<decimal?>(sql) ?? 0;
//退款(未发货的)
sql = $"select sum(amount_refund_rmb) amount from dc_base_crm_refund where platform_type = 'Etsy' and company_id = 1 and is_deleted = 0 and is_freeze = 0 and shipping_status = 'UnShipping' and refund_time>= '{day.ToString("yyyy-MM-dd")}' and refund_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}'";
var EtsyRefund = cn.QueryFirstOrDefault<decimal?>(sql) ?? 0;
sql = $"select * from dc_daily_receivable where day='{day.ToString("yyyy-MM-dd")}' and platform='Etsy'";
var m_Etsy = cn.QueryFirstOrDefault<dc_daily_receivable>(sql);
if (m_Etsy == null)
{
m_Etsy = new dc_daily_receivable
{
day = day,
amount_end = (objBefore != null ? objBefore.amount_end : 0) + EtsySales - EtsyShipping - EtsyRefund,
amount_start = (objBefore != null ? objBefore.amount_end : 0),
amount_sale_pay = EtsySales,
amount_shipping = EtsyShipping,
amount_refund = EtsyRefund,
amount_incoming = 0,
amount_other = 0,
amount_platformfee = 0,
amount_sale_shipping = 0,
createtime = DateTime.Now,
lastupdatetime = DateTime.Now,
lastupdateuserid = 0,
lastupdateusername = "system",
platform = "Etsy",
};
}
else
{
m_Etsy.amount_start = (objBefore != null ? objBefore.amount_end : 0);
m_Etsy.amount_sale_pay = EtsySales;
m_Etsy.amount_shipping = EtsyShipping;
m_Etsy.amount_refund = EtsyRefund;
m_Etsy.amount_end = m_Etsy.amount_start + EtsySales - EtsyShipping - EtsyRefund + m_Etsy.amount_other;
m_Etsy.lastupdatetime = DateTime.Now;
m_Etsy.lastupdateuserid = 0;
m_Etsy.lastupdateusername = "system";
}
//非Ebay\shopify 应收账款=期初应收余额+本期销售收入-平台扣费-放款金额-退款金额+其他 //非Ebay\shopify\Etsy 应收账款=期初应收余额+本期销售收入-平台扣费-放款金额-退款金额+其他
sql = $@"select * from ( sql = $@"select * from (
select t1.platform_type,sum(t1.amount_sales*t1.seller_order_exchange_rate*t2.quantity_shipped) amount,sum(t1.cost_platform_fee*t1.seller_order_exchange_rate*t2.quantity_shipped) cost_platform_fee,0 as cost_fba_fee select t1.platform_type,sum(t1.amount_sales*t1.seller_order_exchange_rate*t2.quantity_shipped) amount,sum(t1.cost_platform_fee*t1.seller_order_exchange_rate*t2.quantity_shipped) cost_platform_fee,0 as cost_fba_fee
from dc_base_oms_pick t2 from dc_base_oms_pick t2
join dc_base_oms_sku t1 on t1.bailun_order_id=t2.bailun_order_id and t1.bailun_sku=t2.bailun_sku and t1.has_scalp=0 and t1.has_delete=0 and t1.has_innersale=0 and t1.bailun_order_status!='Canceled' and t1.has_innersale=0 and t1.company_id=1 and t1.platform_type!='Ebay' and t1.platform_type!='shopify' and t1.platform_type!='FBA' join dc_base_oms_sku t1 on t1.bailun_order_id=t2.bailun_order_id and t1.bailun_sku=t2.bailun_sku and t1.has_scalp=0 and t1.has_delete=0 and t1.has_innersale=0 and t1.bailun_order_status!='Canceled' and t1.has_innersale=0 and t1.company_id=1 and t1.platform_type!='Ebay' and t1.platform_type!='shopify' and t1.platform_type!='Etsy' and t1.platform_type!='FBA'
where t2.has_delete=0 and t2.shipping_status='TotalShipping' and t2.company_id=1 and t2.shipping_time>='{day.ToString("yyyy-MM-dd")}' and t2.shipping_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' group by platform_type where t2.has_delete=0 and t2.shipping_status='TotalShipping' and t2.company_id=1 and t2.shipping_time>='{day.ToString("yyyy-MM-dd")}' and t2.shipping_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' group by platform_type
union all union all
select platform_type,sum(amount_sales*seller_order_exchange_rate) amount,sum((cost_platform_fee+cost_fba_fee)*seller_order_exchange_rate) cost_platform_fee,sum(cost_fba_fee*seller_order_exchange_rate) cost_fba_fee from dc_base_oms_order where platform_type='FBA' and create_time>='{day.ToString("yyyy-MM-dd")}' and create_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' and company_id=1 and bailun_order_status!='Canceled' and has_scalp=0 and has_innersale=0 select platform_type,sum(amount_sales*seller_order_exchange_rate) amount,sum((cost_platform_fee+cost_fba_fee)*seller_order_exchange_rate) cost_platform_fee,sum(cost_fba_fee*seller_order_exchange_rate) cost_fba_fee from dc_base_oms_order where platform_type='FBA' and create_time>='{day.ToString("yyyy-MM-dd")}' and create_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' and company_id=1 and bailun_order_status!='Canceled' and has_scalp=0 and has_innersale=0
...@@ -198,17 +256,17 @@ namespace Bailun.DC.DailyPlatformReceivable ...@@ -198,17 +256,17 @@ namespace Bailun.DC.DailyPlatformReceivable
//非Ebay 平台费,按付款时间 //非Ebay 平台费,按付款时间
sql = $@"select * from ( sql = $@"select * from (
select t1.platform_type,sum(t1.cost_platform_fee*t1.seller_order_exchange_rate*t1.bailun_sku_quantity_ordered) cost_platform_fee,0 as cost_fba_fee select t1.platform_type,sum(t1.cost_platform_fee*t1.seller_order_exchange_rate*t1.bailun_sku_quantity_ordered) cost_platform_fee,0 as cost_fba_fee
from dc_base_oms_sku t1 where t1.has_scalp=0 and t1.has_delete=0 and t1.has_innersale=0 and t1.bailun_order_status!='Canceled' and t1.has_innersale=0 and t1.company_id=1 and t1.platform_type!='Ebay' and t1.platform_type!='shopify' and t1.platform_type!='FBA' and t1.paid_time>='{day.ToString("yyyy-MM-dd")}' and t1.paid_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' and t1.bailun_interception_status in ('None','Failed') and (t1.platform_type!='FBA' and t1.bailun_order_status!='CantHandle') from dc_base_oms_sku t1 where t1.has_scalp=0 and t1.has_delete=0 and t1.has_innersale=0 and t1.bailun_order_status!='Canceled' and t1.has_innersale=0 and t1.company_id=1 and t1.platform_type!='Ebay' and t1.platform_type!='shopify' and t1.platform_type!='Etsy' and t1.platform_type!='FBA' and t1.paid_time>='{day.ToString("yyyy-MM-dd")}' and t1.paid_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' and t1.bailun_interception_status in ('None','Failed') and (t1.platform_type!='FBA' and t1.bailun_order_status!='CantHandle')
group by platform_type group by platform_type
union all union all
select platform_type,sum((cost_platform_fee+cost_fba_fee)*seller_order_exchange_rate) cost_platform_fee,sum(cost_fba_fee*seller_order_exchange_rate) cost_fba_fee from dc_base_oms_order where platform_type='FBA' and create_time>='{day.ToString("yyyy-MM-dd")}' and create_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' and company_id=1 and bailun_order_status!='Canceled' and has_scalp=0 and has_innersale=0 and bailun_interception_status in ('None','Failed') select platform_type,sum((cost_platform_fee+cost_fba_fee)*seller_order_exchange_rate) cost_platform_fee,sum(cost_fba_fee*seller_order_exchange_rate) cost_fba_fee from dc_base_oms_order where platform_type='FBA' and create_time>='{day.ToString("yyyy-MM-dd")}' and create_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' and company_id=1 and bailun_order_status!='Canceled' and has_scalp=0 and has_innersale=0 and bailun_interception_status in ('None','Failed')
) tb"; ) tb";
var listPlatformFee = cn.Query<platformamount>(sql); var listPlatformFee = cn.Query<platformamount>(sql);
var listPlatform = cn.Query<string>("select platform_type from dc_base_oms_order group by platform_type").Where(a=>a.ToLower()!= "amazon2b" && a.ToLower()!= "fba" && a.ToLower()!= "ebay" && a.ToLower() != "shopify").ToList(); var listPlatform = cn.Query<string>("select platform_type from dc_base_oms_order group by platform_type").Where(a=>a.ToLower()!= "amazon2b" && a.ToLower()!= "fba" && a.ToLower()!= "ebay" && a.ToLower() != "shopify" && a.ToLower() != "etsy").ToList();
//退款 //退款
sql = $"select sum(amount_refund_rmb) as amount,platform_type from dc_base_crm_refund where platform_type!='Ebay' and platform_type!='shopify' and company_id=1 and is_deleted=0 and is_freeze=0 and shipping_status='TotalShipping' and refund_time>='{day.ToString("yyyy-MM-dd")}' and refund_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' GROUP BY platform_type;"; sql = $"select sum(amount_refund_rmb) as amount,platform_type from dc_base_crm_refund where platform_type!='Ebay' and platform_type!='shopify' and platform_type!='Etsy' and company_id=1 and is_deleted=0 and is_freeze=0 and shipping_status='TotalShipping' and refund_time>='{day.ToString("yyyy-MM-dd")}' and refund_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' GROUP BY platform_type;";
var listRefund = cn.Query<platformamount>(sql); var listRefund = cn.Query<platformamount>(sql);
//提现金额 //提现金额
...@@ -217,7 +275,7 @@ namespace Bailun.DC.DailyPlatformReceivable ...@@ -217,7 +275,7 @@ namespace Bailun.DC.DailyPlatformReceivable
where createTime>='{day.ToString("yyyy-MM-dd")}' and createTime<'{day.AddDays(1).ToString("yyyy-MM-dd")}' group by salesl_platform"; where createTime>='{day.ToString("yyyy-MM-dd")}' and createTime<'{day.AddDays(1).ToString("yyyy-MM-dd")}' group by salesl_platform";
var listIncome = cn.Query<platformamount>(sql); var listIncome = cn.Query<platformamount>(sql);
var listM = new List<dc_daily_receivable>() { m_ebay, m_shopify }; var listM = new List<dc_daily_receivable>() { m_ebay, m_shopify,m_Etsy };
foreach (var item in listPlatform) foreach (var item in listPlatform)
{ {
//期初 //期初
...@@ -350,9 +408,9 @@ namespace Bailun.DC.DailyPlatformReceivable ...@@ -350,9 +408,9 @@ namespace Bailun.DC.DailyPlatformReceivable
//更新资产负债表的应收账款 //更新资产负债表的应收账款
//Ebay+shopify //Ebay+shopify
var listEbayAmount = listM.Where(a => a.platform.ToLower() == "ebay" || a.platform.ToLower() == "shopify"); var listEbayAmount = listM.Where(a => a.platform.ToLower() == "ebay" || a.platform.ToLower() == "shopify" || a.platform.ToLower() == "etsy");
//其他平台 //其他平台
var listOtherAmount = listM.Where(a => a.platform.ToLower() != "ebay" && a.platform.ToLower() != "shopify"); var listOtherAmount = listM.Where(a => a.platform.ToLower() != "ebay" && a.platform.ToLower() != "shopify" && a.platform.ToLower() != "etsy");
new Bailun.DC.Services.FinanceReportServices().UpdateLogisticsEndAmount(day, (listOtherAmount.Count() > 0 ? listOtherAmount.Sum(a => a.amount_end) : 0) - (listEbayAmount.Count() > 0 ? listEbayAmount.Sum(a => a.amount_end) : 0), "accountsReceivableUpdate"); new Bailun.DC.Services.FinanceReportServices().UpdateLogisticsEndAmount(day, (listOtherAmount.Count() > 0 ? listOtherAmount.Sum(a => a.amount_end) : 0) - (listEbayAmount.Count() > 0 ? listEbayAmount.Sum(a => a.amount_end) : 0), "accountsReceivableUpdate");
......
...@@ -7030,15 +7030,15 @@ group by currency"; ...@@ -7030,15 +7030,15 @@ group by currency";
if (type == 1) //Ebay if (type == 1) //Ebay
{ {
sql += " and platform in ('Ebay','shopify') "; sql += " and platform in ('Ebay','shopify','Etsy') ";
sql_start += " and platform in ('Ebay','shopify') "; sql_start += " and platform in ('Ebay','shopify','Etsy') ";
sql_end += " and platform in ('Ebay','shopify') "; sql_end += " and platform in ('Ebay','shopify','Etsy') ";
} }
else if (type == 2) //非Ebay else if (type == 2) //非Ebay
{ {
sql += " and platform!='Ebay' and platform!='shopify' "; sql += " and platform!='Ebay' and platform!='shopify' and platform!='Etsy' ";
sql_start += " and platform!='Ebay' and platform!='shopify' "; sql_start += " and platform!='Ebay' and platform!='shopify' and platform!='Etsy' ";
sql_end += " and platform!='Ebay' and platform!='shopify' "; sql_end += " and platform!='Ebay' and platform!='shopify' and platform!='Etsy' ";
} }
sql += " group by platform"; sql += " group by platform";
...@@ -7102,11 +7102,11 @@ group by currency"; ...@@ -7102,11 +7102,11 @@ group by currency";
if (type == 1) //Ebay if (type == 1) //Ebay
{ {
sql += " and platform in('Ebay','shopify') "; sql += " and platform in('Ebay','shopify','Etsy') ";
} }
else if (type == 2) //非Ebay else if (type == 2) //非Ebay
{ {
sql += " and platform!='Ebay' and platform!='shopify' "; ; sql += " and platform!='Ebay' and platform!='shopify' and platform!='Etsy' "; ;
} }
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString)) using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
...@@ -7143,11 +7143,11 @@ group by currency"; ...@@ -7143,11 +7143,11 @@ group by currency";
if (type == 1) //Ebay if (type == 1) //Ebay
{ {
sql += " and platform in ('Ebay','shopify') "; sql += " and platform in ('Ebay','shopify','Etsy') ";
} }
else if (type == 2) //非Ebay else if (type == 2) //非Ebay
{ {
sql += " and platform!='Ebay' and platform!='shopify' "; sql += " and platform!='Ebay' and platform!='shopify' and platform!='Etsy' ";
} }
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString)) using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
...@@ -7203,7 +7203,7 @@ group by currency"; ...@@ -7203,7 +7203,7 @@ group by currency";
} }
if (obj.platform.ToLower() == "ebay" || obj.platform.ToLower() == "shopify") if (obj.platform.ToLower() == "ebay" || obj.platform.ToLower() == "shopify" || obj.platform.ToLower() == "etsy")
{ {
//期初预收余额+本期收款(订单付款金额)-发货金额-退款(未发货的)+其他 //期初预收余额+本期收款(订单付款金额)-发货金额-退款(未发货的)+其他
obj.amount_end = obj.amount_start + obj.amount_sale_pay - obj.amount_shipping - obj.amount_refund + obj.amount_other; obj.amount_end = obj.amount_start + obj.amount_sale_pay - obj.amount_shipping - obj.amount_refund + obj.amount_other;
...@@ -7288,7 +7288,7 @@ group by currency"; ...@@ -7288,7 +7288,7 @@ group by currency";
if (obj != null) if (obj != null)
{ {
//Ebay预收账款=期初预收余额+本期收款(订单付款金额)-发货金额-退款(未发货的) //Ebay预收账款=期初预收余额+本期收款(订单付款金额)-发货金额-退款(未发货的)
if (obj.platform.ToLower() == "ebay" || obj.platform.ToLower() == "shopify") if (obj.platform.ToLower() == "ebay" || obj.platform.ToLower() == "shopify" || obj.platform.ToLower()=="etsy")
{ {
obj.amount_start = m.amount_end; obj.amount_start = m.amount_end;
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
<div class="ibox-content m-b-sm border-bottom"> <div class="ibox-content m-b-sm border-bottom">
<div class="alert alert-warning"> <div class="alert alert-warning">
说明:<br /> 说明:<br />
Ebay预收账款 = 期初预收余额+本期收款(订单付款金额)-发货金额-退款(未发货的)+其他<br /> 预收账款(ebay、shopify、etsy) = 期初预收余额+本期收款(订单付款金额)-发货金额-退款(未发货的)+其他<br />
非Ebay应收账款 = 期初应收余额+本期销售收入-平台扣费-放款金额-退款金额+其他 应收账款 = 期初应收余额+本期销售收入-平台扣费-放款金额-退款金额+其他
</div> </div>
</div> </div>
<div class="ibox-content m-b-sm border-bottom"> <div class="ibox-content m-b-sm border-bottom">
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
<div class="form-group"> <div class="form-group">
<label>类型</label> <label>类型</label>
<select id="type" name="type" class="form-control" style="width:160px;"> <select id="type" name="type" class="form-control" style="width:160px;">
<option value="1">Ebay和shopify</option> <option value="1">预收</option>
<option value="2">非Ebay</option> <option value="2">应收</option>
</select> </select>
</div> </div>
<div class="form-group"> <div class="form-group">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment