Commit d9b2ecd0 by lizefeng

新增复制供应商统计

parent c56b983d
......@@ -1448,5 +1448,90 @@ truncate table dc_base_purchase_7_temp;", new { time = DateTime.Now.AddDays(-8).
return datas;
}
public static List<supplier_sales_dto> SupplierSalesList(supplier_sales_search_dto m, int offset, int limit, ref int total, string order = "", string sort = "")
{
var list = new List<supplier_sales_dto>();
try
{
DynamicParameters parameters = new DynamicParameters();
string sql = "";
sql = @"
select
t2.suppliers_id,
t2.suppliers_name,
sum(case when t1.create_time>=@time1 and t1.create_time<=@time2 then t1.bailun_sku_quantity_ordered else 0 end) as 'yesterday_sales_count', -- 昨日销量
sum(case when t1.create_time>=@time1 and t1.create_time<=@time2 then ROUND(t1.bailun_sku_quantity_ordered * t1.amount_sales * t1.seller_order_exchange_rate,2) else 0 end) as 'yesterday_sales_amount',
sum(case when t1.create_time>=@time3 and t1.create_time<=@time2 then t1.bailun_sku_quantity_ordered else 0 end) as 'sales_count_7', -- 7日销量
sum(case when t1.create_time>=@time3 and t1.create_time<=@time2 then ROUND(t1.bailun_sku_quantity_ordered * t1.amount_sales * t1.seller_order_exchange_rate,2) else 0 end) as 'sales_amount_7', -- 7日销量
t3.yesterday_purchase_count,
t3.yesterday_purchase_amount,
t3.purchase_count_7,
t3.purchase_amount_7
from dc_base_oms_sku_7 as t1
left join dc_base_sku as t2 on t1.bailun_sku = t2.bailun_sku
left join (
select tp_1.supplier_id,
sum(case when tp_1.create_time>=@time1 and tp_1.create_time<=@time2 then tp_1.count else 0 end) as 'yesterday_purchase_count', -- 昨日销量
sum(case when tp_1.create_time>=@time1 and tp_1.create_time<=@time2 then ROUND(tp_1.count * tp_1.price,2) else 0 end) as 'yesterday_purchase_amount',
sum(case when tp_1.create_time>=@time4 then tp_1.count else 0 end) as 'purchase_count_7', -- 7日采购
sum(case when tp_1.create_time>=@time4 then ROUND(tp_1.count * tp_1.price,2) else 0 end) as 'purchase_amount_7' -- 日采购
from dc_base_purchase_7 as tp_1
GROUP BY tp_1.supplier_id
) as t3 on t2.suppliers_id = t3.supplier_id
where t2.buyer_name = '赵美聪'
";
string count_sql = @"
select
1
from dc_base_oms_sku_7 as t1
left join dc_base_sku as t2 on t1.bailun_sku = t2.bailun_sku
where t2.buyer_name = '赵美聪'
";
parameters.Add("time1",DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 00:00:00"));
parameters.Add("time2", DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 23:59:59"));
parameters.Add("time3", DateTime.Now.AddDays(-8).ToString("yyyy-MM-dd 00:00:00"));
parameters.Add("time4", DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd 00:00:00"));
if (!string.IsNullOrWhiteSpace(m.supplier_name))
{
sql += " and t2.suppliers_name=@suppliers_name ";
count_sql += " and t2.suppliers_name=@suppliers_name ";
parameters.Add("supplier_name", m.supplier_name);
}
sql += " GROUP BY t2.suppliers_id ";
count_sql += " GROUP BY t2.suppliers_id ";
total = _connection.ExecuteScalar<int>(count_sql, parameters);
//设置默认排序字段
if (string.IsNullOrWhiteSpace(sort)) sort = "yesterday_sales_count";
if (!string.IsNullOrEmpty(sort))
{
sql += " order by " + sort;
if (!string.IsNullOrEmpty(order))
{
sql += " " + order;
}
else
{
sql += " desc";
}
}
sql += " limit " + offset + "," + limit;
var obj = _connection.Query<supplier_sales_dto>(sql, parameters, buffered: false, commandTimeout: 0);
return obj.AsList();
}
catch (Exception ex)
{
return list;
}
}
}
}
......
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models.Report
{
/// <summary>
/// 供应商采购,销量统计
/// </summary>
public class supplier_sales_dto
{
public int suppliers_id { get; set; }
public string suppliers_name { get; set; }
public int? yesterday_sales_count { get; set; }
public decimal? yesterday_sales_amount { get; set; }
public int? sales_count_7 { get; set; }
public decimal? sales_amount_7 { get; set; }
public int? yesterday_purchase_count { get; set; }
public decimal? yesterday_purchase_amount { get; set; }
public int? purchase_count_7 { get; set; }
public decimal? purchase_amount_7 { get; set; }
}
public class supplier_sales_search_dto
{
public string supplier_name { get; set; }
}
}
......@@ -492,6 +492,12 @@ namespace AutoTurnOver.Services
}
public List<supplier_sales_dto> SupplierSalesList(supplier_sales_search_dto m, int offset, int limit, ref int total, string order = "", string sort = "")
{
return report.SupplierSalesList(m, offset, limit, ref total, order, sort);
}
}
}
......@@ -639,5 +639,22 @@ namespace AutoTurnOver.Controllers
total = 0,
});
}
public JsonResult SupplierSalesList(string supplier_name, int offset, int limit, string order, string sort)
{
var m = new supplier_sales_search_dto
{
supplier_name = supplier_name,
};
var services = new ReportServices();
var total = 0;
var list = services.SupplierSalesList(m, offset, limit, ref total, order: order, sort: sort);
return new JsonResult(new
{
rows = list,
total = total,
});
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment