Commit d10c9c33 by 泽锋 李

fix

parent ff435be4
...@@ -1069,6 +1069,70 @@ where t1.create_time>=@btime and t1.create_time<=@etime "; ...@@ -1069,6 +1069,70 @@ where t1.create_time>=@btime and t1.create_time<=@etime ";
} }
} }
/// <summary>
/// 取安全库存规则
/// </summary>
/// <returns></returns>
public static dc_auto_config_safe_inventory GetInventoryRule(List<dc_auto_config_safe_inventory> configs, string warehouse_code)
{
return (configs.Where(s => s.warehouse_code == warehouse_code).FirstOrDefault() ?? new dc_auto_config_safe_inventory { weighting_coefficient_seven = 0.5M, weighting_coefficient_fourteen = 0.25M, weighting_coefficient_thirty = 0.25M });
}
/// <summary>
/// 获取平台分摊比例
/// </summary>
/// <returns></returns>
public static List<dc_report_cash_flow_platform_share_dto> GetPlatformShare(DateTime occurDate, MySqlConnection conn, List<dc_auto_config_safe_inventory> configs, string warehouse_code, string bailun_sku)
{
var rule = GetInventoryRule(configs, warehouse_code);
var sql = @"SELECT platform_type,website as 'web_stie',
sum( case when paid_time >= @btime7 then bailun_sku_quantity_ordered else 0 end) as 'sales_7',
sum( case when paid_time >= @btime14 then bailun_sku_quantity_ordered else 0 end) as 'sales_14',
sum(bailun_sku_quantity_ordered) as 'sales_30'
FROM `dc_base_oms_sku` where bailun_sku =@bailun_sku and warehouse_code = @warehouse_code and paid_time>= @btime30 and paid_time<=@ctime
GROUP BY platform_type,website";
var datas = conn.Query<dc_report_cash_flow_platform_share_dto>(sql, new
{
btime7 = occurDate.AddDays(-7).ToDayHome(),
btime14 = occurDate.AddDays(-14).ToDayHome(),
btime30 = occurDate.AddDays(-30).ToDayHome(),
ctime = occurDate.ToDayEnd(),
bailun_sku = bailun_sku,
warehouse_code = warehouse_code
}).ToList();
if (datas == null || datas.Count <= 0)
{
var now = occurDate.AddMonths(1);
datas = conn.Query<dc_report_cash_flow_platform_share_dto>(sql, new
{
btime7 = now.AddDays(-7).ToDayHome(),
btime14 = now.AddDays(-14).ToDayHome(),
btime30 = now.AddDays(-30).ToDayHome(),
bailun_sku = bailun_sku,
warehouse_code = warehouse_code
}).ToList();
}
if (datas != null && datas.Count >= 1)
{
foreach (var item in datas)
{
item.sales_weight = Math.Round(((item.sales_7 * rule.weighting_coefficient_seven) + (item.sales_14 * rule.weighting_coefficient_fourteen) + (item.sales_30 * rule.weighting_coefficient_thirty)), 2);
}
// 总加权销量
var sales_weight_sum = datas.Sum(s => s.sales_weight);
foreach (var item in datas)
{
item.ratio = item.sales_weight / sales_weight_sum;
}
// 把精度导致的误差全部算给最高的平台
var sumRatio = datas.Sum(s => s.ratio);
datas.OrderByDescending(s => s.ratio).FirstOrDefault().ratio += (1 - sumRatio);
}
return datas;
}
public static List<report_cash_flow_view_dto> GetView(report_cash_flow_view_search_dto search) public static List<report_cash_flow_view_dto> GetView(report_cash_flow_view_search_dto search)
{ {
List<report_cash_flow_view_dto> datas = new List<report_cash_flow_view_dto>(); List<report_cash_flow_view_dto> datas = new List<report_cash_flow_view_dto>();
...@@ -1183,24 +1247,24 @@ where t1.create_time>=@btime and t1.create_time<=@etime "; ...@@ -1183,24 +1247,24 @@ where t1.create_time>=@btime and t1.create_time<=@etime ";
return _connection.Query<dc_report_cash_flow_log_dto>(sql, parameters).AsList(); return _connection.Query<dc_report_cash_flow_log_dto>(sql, parameters).AsList();
} }
public static Page<dc_report_cash_flow_sku_group_dto> SkuView(dc_report_cash_flow_sku_group_search_dto search) public static Page<dc_report_cash_flow_sku_group_dto> SkuView(dc_report_cash_flow_sku_group_search_dto search)
{ {
if (search.data_type == null || search.data_type <= 0) if (search.data_type == null || search.data_type <= 0)
{ {
search.data_type = 1; search.data_type = 1;
} }
var sql = @" select t1.*,t2.sku_title_cn as 'sku_name',t2.`status` as 'sku_status',t2.buyer_name, var sql = @" select t1.*,t2.sku_title_cn as 'sku_name',t2.`status` as 'sku_status',t2.buyer_name,ifnull(t3.warehouse_name,t3.warehouse_extend_name) as 'warehouse_name',ifnull(t4.usable_stock,0) as 'usable_stock',(ifnull(t5.quantity_transfer,0)+ifnull(t5.quantity_purchase,0)) as 'on_the_way',
ifnull(t4.usable_stock,0) as 'usable_stock', (ifnull(t4.usable_stock,0) * t2.unit_price) as 'stock_amount',(ifnull(t5.quantity_transfer,0)+ifnull(t5.quantity_purchase,0)) as 'on_the_way_amount',ifnull(t8.history_sevenday_sales,0) as 'history_sevenday_sales',ifnull(t8.history_fourteenday_sales,0) as 'history_fourteenday_sales',ifnull(t8.history_thirtyday_sales,0) as 'history_thirtyday_sales'
(ifnull(t4.on_the_way,0)) as 'on_the_way',
(ifnull(t4.stock_amount,0)) as 'stock_amount',
(ifnull(t4.on_the_way_amount,0)) as 'on_the_way_amount',
ifnull(t4.history_sevenday_sales,0) as 'history_sevenday_sales',
ifnull(t4.history_fourteenday_sales,0) as 'history_fourteenday_sales',
ifnull(t4.history_thirtyday_sales,0) as 'history_thirtyday_sales'
from dc_report_cash_flow_sku_group as t1 from dc_report_cash_flow_sku_group as t1
left join dc_base_sku as t2 on t1.bailun_sku=t2.bailun_sku left join dc_base_sku as t2 on t1.bailun_sku=t2.bailun_sku
left join dc_base_sku_sum as t4 on t1.bailun_sku = t4.bailun_sku left join dc_base_warehouse as t3 on t1.warehouse_code = t3.warehouse_code
left join dc_base_stock as t4 on t1.bailun_sku = t4.bailun_sku and t1.warehouse_code = t4.warehouse_code
left join dc_mid_transit as t5 on t1.bailun_sku = t5.bailun_sku and t1.warehouse_code = t5.warehouse_code
left join dc_auto_config_sku_label as t6 on t1.bailun_sku = t6.bailun_sku left join dc_auto_config_sku_label as t6 on t1.bailun_sku = t6.bailun_sku
left join dc_auto_config_sku_warehouse as t7 on t1.bailun_sku = t7.bailun_sku and t1.warehouse_code = t7.warehouse_code
left join dc_auto_turnover as t8 on t1.bailun_sku = t8.bailun_sku and t1.warehouse_code = t8.warehouse_code
where t1.type=@type "; where t1.type=@type ";
DynamicParameters parameters = new DynamicParameters(); DynamicParameters parameters = new DynamicParameters();
parameters.Add("type", search.data_type); parameters.Add("type", search.data_type);
...@@ -1225,77 +1289,40 @@ where t1.type=@type "; ...@@ -1225,77 +1289,40 @@ where t1.type=@type ";
sql += " and t2.buyer_name = @buyer_name"; sql += " and t2.buyer_name = @buyer_name";
parameters.Add("buyer_name", search.buyer_name); parameters.Add("buyer_name", search.buyer_name);
} }
if (!string.IsNullOrWhiteSpace(search.supplier_name)) if (search.monitor_status == 1)
{ {
sql += " and t2.suppliers_name =@suppliers_name "; sql += " and t7.`status`=1 ";
parameters.Add("suppliers_name", search.supplier_name);
}
return _connection.Page<dc_report_cash_flow_sku_group_dto>(sql, search, parameters);
} }
if (search.monitor_status == 0)
/// <summary>
/// 取安全库存规则
/// </summary>
/// <returns></returns>
public static dc_auto_config_safe_inventory GetInventoryRule(List<dc_auto_config_safe_inventory> configs,string warehouse_code)
{ {
return (configs.Where(s => s.warehouse_code == warehouse_code).FirstOrDefault() ?? new dc_auto_config_safe_inventory {weighting_coefficient_seven = 0.5M,weighting_coefficient_fourteen = 0.25M,weighting_coefficient_thirty = 0.25M }); sql += " and ( t7.`status`=0 or t7.`status` is null ) ";
} }
if (!string.IsNullOrWhiteSpace(search.supplier_name))
/// <summary>
/// 获取平台分摊比例
/// </summary>
/// <returns></returns>
public static List<dc_report_cash_flow_platform_share_dto> GetPlatformShare(DateTime occurDate, MySqlConnection conn, List<dc_auto_config_safe_inventory> configs, string warehouse_code,string bailun_sku)
{
var rule = GetInventoryRule(configs, warehouse_code);
var sql = @"SELECT platform_type,website,
sum( case when paid_time >= @btime7 then bailun_sku_quantity_ordered else 0 end) as 'sales_7',
sum( case when paid_time >= @btime14 then bailun_sku_quantity_ordered else 0 end) as 'sales_14',
sum(bailun_sku_quantity_ordered) as 'sales_30'
FROM `dc_base_oms_sku` where bailun_sku =@bailun_sku and warehouse_code = @warehouse_code and paid_time>= @btime30 and paid_time<=@ctime
GROUP BY platform_type,website";
var datas = conn.Query<dc_report_cash_flow_platform_share_dto>(sql, new
{
btime7 = occurDate.AddDays(-7).ToDayHome(),
btime14 = occurDate.AddDays(-14).ToDayHome(),
btime30 = occurDate.AddDays(-30).ToDayHome(),
ctime = occurDate.ToDayEnd(),
bailun_sku = bailun_sku,
warehouse_code = warehouse_code
}).ToList();
if(datas==null|| datas.Count <= 0)
{ {
var now = occurDate.AddMonths(1); sql += " and t2.suppliers_name =@suppliers_name ";
datas = conn.Query<dc_report_cash_flow_platform_share_dto>(sql, new parameters.Add("suppliers_name", search.supplier_name);
}
if (search.warehouse_code != null)
{ {
btime7 = now.AddDays(-7).ToDayHome(), sql += $" and t1.warehouse_code=@warehouse_code ";
btime14 = now.AddDays(-14).ToDayHome(), parameters.Add("warehouse_code", search.warehouse_code);
btime30 = now.AddDays(-30).ToDayHome(),
bailun_sku = bailun_sku,
warehouse_code = warehouse_code
}).ToList();
} }
if (datas != null &&datas.Count>=1) else
{ {
foreach (var item in datas) if (!string.IsNullOrWhiteSpace(search.warehousetype))
{ {
item.sales_weight = Math.Round( ((item.sales_7 * rule.weighting_coefficient_seven)+ (item.sales_14 * rule.weighting_coefficient_fourteen)+ (item.sales_30 * rule.weighting_coefficient_thirty)),2); sql += " and t3.hq_type=" + $"'{search.warehousetype}'";
} }
// 总加权销量 if (search.warehousearea > 0)
var sales_weight_sum = datas.Sum(s=> s.sales_weight);
foreach (var item in datas)
{ {
item.ratio = item.sales_weight / sales_weight_sum; sql += " and t3.area_id=" + search.warehousearea;
} }
// 把精度导致的误差全部算给最高的平台
var sumRatio = datas.Sum(s => s.ratio);
datas.OrderByDescending(s => s.ratio).FirstOrDefault().ratio += (1- sumRatio) ;
} }
return datas;
return _connection.Page<dc_report_cash_flow_sku_group_dto>(sql, search, parameters);
} }
} }
} }
...@@ -88,7 +88,7 @@ namespace AutoTurnOver.Controllers ...@@ -88,7 +88,7 @@ namespace AutoTurnOver.Controllers
return File(memory, "text/csv", "现金流明细.csv"); return File(memory, "text/csv", "现金流明细.csv");
} }
public JsonResult GetSkuView(int? data_type , string sku_label, string bailun_sku, int offset, int limit, string order, string sort, string buyer_name, string supplier_name,string product_type) public JsonResult GetSkuView(int? data_type, string sku_label, string bailun_sku, int offset, int limit, string order, string sort, string buyer_name, string warehousecode, string supplier_name, string warehousetype, int? warehousearea, int? monitor_status = null, string product_type = null)
{ {
try try
{ {
...@@ -103,7 +103,11 @@ namespace AutoTurnOver.Controllers ...@@ -103,7 +103,11 @@ namespace AutoTurnOver.Controllers
sku_label = string.IsNullOrWhiteSpace( sku_label)?null : WebUtility.UrlDecode(sku_label), sku_label = string.IsNullOrWhiteSpace( sku_label)?null : WebUtility.UrlDecode(sku_label),
data_type = data_type, data_type = data_type,
supplier_name = supplier_name, supplier_name = supplier_name,
product_type = product_type product_type = product_type,
warehouse_code = warehousecode,
monitor_status =monitor_status,
warehousearea = warehousearea,
warehousetype = warehousetype
}; };
var services = new CashFlowServices(); var services = new CashFlowServices();
var page_data = services.SkuView(m); var page_data = services.SkuView(m);
......
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