Commit 89dd4bd4 by guanzhenshan

完善内部编码利润报表,增加导出功能

parent 6130af1e
...@@ -124,5 +124,10 @@ namespace Bailun.DC.Models.Orders ...@@ -124,5 +124,10 @@ namespace Bailun.DC.Models.Orders
/// </summary> /// </summary>
public string transaction_id { get; set; } public string transaction_id { get; set; }
/// <summary>
/// 付款时间
/// </summary>
public DateTime paid_time { get; set; }
} }
} }
...@@ -3408,20 +3408,25 @@ namespace Bailun.DC.Services ...@@ -3408,20 +3408,25 @@ namespace Bailun.DC.Services
where t1.company_id=1 and t1.bailun_order_status!='Canceled' and t1.paid_time>='{start.ToString("yyyy-MM-dd")}' and t1.paid_time<'{end.AddDays(1).ToString("yyyy-MM-dd")}' and t1.has_scalp=0 and t1.has_cancle=0 and t1.has_delete=0 and t1.has_innersale=0 and t1.platform_type='Ebay' where t1.company_id=1 and t1.bailun_order_status!='Canceled' and t1.paid_time>='{start.ToString("yyyy-MM-dd")}' and t1.paid_time<'{end.AddDays(1).ToString("yyyy-MM-dd")}' and t1.has_scalp=0 and t1.has_cancle=0 and t1.has_delete=0 and t1.has_innersale=0 and t1.platform_type='Ebay'
"; ";
var sql = $@"select t2.product_inner_code,t1.origin_order_id,t1.platform_type,t1.website,t1.seller_account,t1.bailun_order_status,t1.pay_status,t1.shipping_status,sum(t1.amount_sales*seller_order_exchange_rate) amount_sales,sum(t1.cost_platform_fee*t1.seller_other_exchange_rate) cost_platform_fee,sum(t1.cost_product) cost_product,sum(t1.cost_first) cost_first,sum(t1.cost_logistics) cost_logistics,sum(t1.cost_handle_bailun) cost_handle_bailun,sum(t1.cost_handle_platform) cost_handle_platform,sum(t1.cost_paypal_fee*t1.seller_order_exchange_rate) cost_paypal_fee,sum(t1.cost_total) cost_total,sum(t1.bailun_sku_quantity_ordered) bailun_sku_quantity_ordered,sum(t1.profit_total) profit_total,(sum(t1.profit_rate)/count(t1.id)) profit_rate,t1.create_time,t1.order_update_time,t1.transaction_id var sql = $@"select t2.product_inner_code,t1.origin_order_id,t1.platform_type,t1.website,t1.seller_account,t1.bailun_order_status,t1.pay_status,t1.shipping_status,sum(t1.amount_sales*seller_order_exchange_rate) amount_sales,sum(t1.cost_platform_fee*t1.seller_other_exchange_rate) cost_platform_fee,sum(t1.cost_product) cost_product,sum(t1.cost_first) cost_first,sum(t1.cost_logistics) cost_logistics,sum(t1.cost_handle_bailun) cost_handle_bailun,sum(t1.cost_handle_platform) cost_handle_platform,sum(t1.cost_paypal_fee*t1.seller_order_exchange_rate) cost_paypal_fee,sum(t1.cost_total) cost_total,sum(t1.bailun_sku_quantity_ordered) bailun_sku_quantity_ordered,sum(t1.profit_total) profit_total,(sum(t1.profit_rate)/count(t1.id)) profit_rate,t1.create_time,t1.order_update_time,t1.transaction_id,t1.paid_time
"; ";
if (!string.IsNullOrEmpty(skucode)) if (!string.IsNullOrEmpty(skucode))
{ {
sqlwhere += " and t2.product_inner_code=@skucode"; sqlwhere += " and t2.product_inner_code='"+skucode+"'";
sqlparam.Add("skucode", skucode); //sqlparam.Add("skucode", skucode);
} }
if (!string.IsNullOrEmpty(orderno)) if (!string.IsNullOrEmpty(orderno))
{ {
sqlwhere += " and t1.origin_order_id=@origin_order_id"; sqlwhere += " and t1.origin_order_id='"+orderno+"'";
sqlparam.Add("origin_order_id", orderno);
}
var strOrder = "";
if (!string.IsNullOrEmpty(parameter.sort))
{
strOrder += " order by "+parameter.sort+" "+parameter.order;
} }
sqlwhere += "group by t1.origin_order_id,t2.product_inner_code "; sqlwhere += "group by t1.origin_order_id,t2.product_inner_code ";
...@@ -3432,7 +3437,7 @@ namespace Bailun.DC.Services ...@@ -3432,7 +3437,7 @@ namespace Bailun.DC.Services
cn.Open(); cn.Open();
} }
var obj = cn.Query<mInnerCodeProfit>(sql + sqlwhere + ((parameter.pageIndex-1)*parameter.limit+","+parameter.limit), sqlparam, null, true, 2 * 60); var obj = cn.Query<mInnerCodeProfit>(sql + sqlwhere+ strOrder + (" limit "+ (parameter.pageIndex-1)*parameter.limit+","+parameter.limit), sqlparam, null, true, 2 * 60);
total = cn.QueryFirstOrDefault<int>("select count(*) from (select t2.product_inner_code,t1.origin_order_id,t1.platform_type,t1.website " + sqlwhere + ") tb",sqlparam); total = cn.QueryFirstOrDefault<int>("select count(*) from (select t2.product_inner_code,t1.origin_order_id,t1.platform_type,t1.website " + sqlwhere + ") tb",sqlparam);
...@@ -3462,15 +3467,13 @@ namespace Bailun.DC.Services ...@@ -3462,15 +3467,13 @@ namespace Bailun.DC.Services
if (!string.IsNullOrEmpty(skucode)) if (!string.IsNullOrEmpty(skucode))
{ {
sqlwhere += " and t2.product_inner_code=@skucode"; sqlwhere += " and t2.product_inner_code='" + skucode + "'";
sqlparam.Add("skucode", skucode);
} }
if (!string.IsNullOrEmpty(orderno)) if (!string.IsNullOrEmpty(orderno))
{ {
sqlwhere += " and t1.origin_order_id=@origin_order_id"; sqlwhere += " and t1.origin_order_id='" + orderno + "'";
sqlparam.Add("origin_order_id", orderno);
} }
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString)) using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{ {
...@@ -3485,7 +3488,50 @@ namespace Bailun.DC.Services ...@@ -3485,7 +3488,50 @@ namespace Bailun.DC.Services
} }
} }
/// <summary>
/// 导出内部编码sku利润
/// </summary>
/// <param name="start">付款开始时间</param>
/// <param name="end">付款结束时间</param>
/// <param name="skucode">内部商品编码</param>
/// <param name="orderno">平台订单号</param>
/// <returns></returns>
public List<mInnerCodeProfit> ExportEbayInnerCodeProfit(DateTime start, DateTime end, string skucode, string orderno)
{
var sqlparam = new DynamicParameters();
var sqlwhere = $@"from dc_base_oms_sku t1
join dc_base_sku t2 on t1.bailun_sku=t2.bailun_sku
where t1.company_id=1 and t1.bailun_order_status!='Canceled' and t1.paid_time>='{start.ToString("yyyy-MM-dd")}' and t1.paid_time<'{end.AddDays(1).ToString("yyyy-MM-dd")}' and t1.has_scalp=0 and t1.has_cancle=0 and t1.has_delete=0 and t1.has_innersale=0 and t1.platform_type='Ebay'
";
var sql = $@"select t2.product_inner_code,t1.origin_order_id,t1.platform_type,t1.website,t1.seller_account,t1.bailun_order_status,t1.pay_status,t1.shipping_status,sum(t1.amount_sales*seller_order_exchange_rate) amount_sales,sum(t1.cost_platform_fee*t1.seller_other_exchange_rate) cost_platform_fee,sum(t1.cost_product) cost_product,sum(t1.cost_first) cost_first,sum(t1.cost_logistics) cost_logistics,sum(t1.cost_handle_bailun) cost_handle_bailun,sum(t1.cost_handle_platform) cost_handle_platform,sum(t1.cost_paypal_fee*t1.seller_order_exchange_rate) cost_paypal_fee,sum(t1.cost_total) cost_total,sum(t1.bailun_sku_quantity_ordered) bailun_sku_quantity_ordered,sum(t1.profit_total) profit_total,(sum(t1.profit_rate)/count(t1.id)) profit_rate,t1.create_time,t1.order_update_time,t1.transaction_id
";
if (!string.IsNullOrEmpty(skucode))
{
sqlwhere += " and t2.product_inner_code='" + skucode + "'";
}
if (!string.IsNullOrEmpty(orderno))
{
sqlwhere += " and t1.origin_order_id='" + orderno + "'";
}
sqlwhere += "group by t1.origin_order_id,t2.product_inner_code ";
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
var obj = cn.Query<mInnerCodeProfit>(sql + sqlwhere, sqlparam, null, true, 2 * 60);
return obj.ToList();
}
}
#endregion #endregion
......
...@@ -1410,7 +1410,8 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers ...@@ -1410,7 +1410,8 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
profit_total = a.profit_total.ToString("N2"), profit_total = a.profit_total.ToString("N2"),
a.seller_account, a.seller_account,
a.shipping_status, a.shipping_status,
a.website a.website,
paid_time = a.paid_time.ToString("yyyy-MM-dd HH:mm:ss")
}); });
...@@ -1441,6 +1442,81 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers ...@@ -1441,6 +1442,81 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
} }
/// <summary>
/// 导出内部商品编码利润
/// </summary>
/// <param name="start"></param>
/// <param name="end"></param>
/// <param name="code"></param>
/// <param name="orderno"></param>
/// <returns></returns>
public ActionResult ExportEbayInnerCodeProfit(DateTime start, DateTime end, string code, string orderno)
{
var _service = new Services.OrdersServices();
var obj = _service.ExportEbayInnerCodeProfit(start, end,code,orderno);
var list = obj.Select(a => new {
amount_sales = a.amount_sales.ToString("N2"),
a.bailun_order_status,
bailun_sku_quantity_ordered = a.bailun_sku_quantity_ordered.ToString("N0"),
cost_first = a.cost_first.ToString("N2"),
cost_handle_bailun = a.cost_handle_bailun.ToString("N2"),
cost_handle_platform = a.cost_handle_platform.ToString("N2"),
cost_logistics = a.cost_logistics.ToString("N2"),
cost_paypal_fee = a.cost_paypal_fee.ToString("N2"),
cost_platform_fee = a.cost_platform_fee.ToString("N2"),
cost_product = a.cost_product.ToString("N2"),
cost_total = a.cost_total.ToString("N2"),
create_time = a.create_time.ToString("yyyy-MM-dd HH:mm:ss"),
order_update_time = a.order_update_time.ToString("yyyy-MM-dd HH:mm:ss"),
a.origin_order_id,
a.pay_status,
a.platform_type,
a.product_inner_code,
profit_rate = (a.profit_rate * 100).ToString("N2"),
profit_total = a.profit_total.ToString("N2"),
a.seller_account,
a.shipping_status,
a.website,
paid_time = a.paid_time.ToString("yyyy-MM-dd HH:mm:ss")
});
var colNames = new List<string> {"内部编码","平台单号","平台类型", "站点", "销售帐号",
"订单状态", "付款状态","发货状态","销售额","平台费",
"产品成本","头程费","尾程费","百伦处理费","平台操作费",
"paypal费","总支出","销售数量","利润","利润率",
"创建时间","付款时间","更新时间"
};
var listVal = new List<string>();
foreach (var item in list)
{
listVal.Add(
item.product_inner_code + "|" + item.origin_order_id + "|" + item.platform_type + "|" + item.website + "|" + item.seller_account + "|" +
item.bailun_order_status + "|" + item.pay_status+"|"+item.shipping_status+"|"+item.amount_sales+"|"+item.cost_platform_fee+"|"+
item.cost_product+"|"+item.cost_first+"|"+item.cost_logistics+"|"+item.cost_handle_bailun+"|"+item.cost_handle_platform+"|"+
item.cost_paypal_fee+"|"+item.cost_total+"|"+item.bailun_sku_quantity_ordered+"|"+item.profit_total+"|"+item.profit_rate+"|"+
item.create_time+"|"+item.paid_time+"|"+item.order_update_time
);
}
var guid = Guid.NewGuid().ToString();
var filename = "内部编码利润导出" + DateTime.Now.ToString("yyyyMMddHHmmss");
var filepath = _hostingEnvironment.WebRootPath + "\\Files\\Report\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
ToCSV(listVal, colNames, guid, filepath);
var ms = new System.IO.MemoryStream();
using (var f = new System.IO.FileStream(filepath + guid + ".csv", System.IO.FileMode.Open))
{
f.CopyTo(ms);
}
ms.Position = 0;
return File(ms, "text/csv", filename + ".csv");
}
#endregion #endregion
#region 平台利润 #region 平台利润
...@@ -2238,7 +2314,7 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers ...@@ -2238,7 +2314,7 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
public ActionResult ExportListReturn(DateTime? start, DateTime? end, DateTime? paystart, DateTime? payend, string platform, string website, string orderno,int companyid) public ActionResult ExportListReturn(DateTime? start, DateTime? end, DateTime? paystart, DateTime? payend, string platform, string website, string orderno,int companyid)
{ {
var _service = new Services.OrdersServices(); var _service = new Services.OrdersServices();
//var companyid = HttpContextHelper.Current?.User?.GetCompanyId().ToInt32();
var obj = _service.ListOrderReturn(start, end, paystart, payend, companyid, platform, website, orderno); var obj = _service.ListOrderReturn(start, end, paystart, payend, companyid, platform, website, orderno);
var list = obj.Select(a => new { var list = obj.Select(a => new {
a.platform_type, a.platform_type,
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<div class="form-inline" style="line-height:40px;"> <div class="form-inline" style="line-height:40px;">
<div class="form-group"> <div class="form-group">
<label>付款时间</label> <label>付款时间</label>
<input id="start" name="start" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd"))" /> <input id="start" name="start" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"))" />
<span>至</span> <span>至</span>
<input id="end" name="end" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.ToString("yyyy-MM-dd"))" /> <input id="end" name="end" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.ToString("yyyy-MM-dd"))" />
</div> </div>
...@@ -22,18 +22,19 @@ ...@@ -22,18 +22,19 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label>&nbsp;</label> <label>&nbsp;</label>
<input id="sku" name="sku" class="form-control" style="width:130px;" placeholder="sku内部编码" /> <input id="code" name="code" class="form-control" style="width:130px;" placeholder="sku内部编码" />
</div> </div>
<div class="form-group"> <div class="form-group">
<label>&nbsp;</label> <label>&nbsp;</label>
<button type="button" class="btn btn-primary" onclick="list();"><i class="fa fa-search"></i>&nbsp;查询</button> <button type="button" class="btn btn-primary" onclick="list();"><i class="fa fa-search"></i>&nbsp;查询</button>
<a class="btn btn-success" onclick="exportxls();">导出</a>
</div> </div>
</div> </div>
</form> </form>
</div> </div>
<div class="ibox-contentc"> <div class="ibox-content m-b-sm border-bottom">
<table id="roletable"></table> <table id="roletable" style="table-layout:fixed;"></table>
</div> </div>
</div> </div>
</div> </div>
...@@ -90,7 +91,7 @@ ...@@ -90,7 +91,7 @@
{ field: 'cost_total', title: '总支出', width: '110', sortable: true, iscount: true }, { field: 'cost_total', title: '总支出', width: '110', sortable: true, iscount: true },
{ field: 'bailun_sku_quantity_ordered', title: '销售数量', width: '110', sortable: true, iscount: true }, { field: 'bailun_sku_quantity_ordered', title: '销售数量', width: '110', sortable: true, iscount: true },
{ field: 'profit_total', title: '利润', width: '110', sortable: true, iscount: true }, { field: 'profit_total', title: '利润', width: '110', sortable: true, iscount: true },
{ field: 'profit_rate', title: '利润率', width: '110' }, { field: 'profit_rate', title: '利润率', width: '110', sortable: true, iscount: true },
{ field: 'create_time', title: '创建时间', width: '130' }, { field: 'create_time', title: '创建时间', width: '130' },
{ field: 'paid_time', title: '付款时间', width: '130' }, { field: 'paid_time', title: '付款时间', width: '130' },
{ field: 'order_update_time', title: '更新时间', width: '130' } { field: 'order_update_time', title: '更新时间', width: '130' }
...@@ -115,10 +116,7 @@ ...@@ -115,10 +116,7 @@
} }
} }
} }
}, { });
fixedcol: true,
fixedcolnum:1
});
} }
else { else {
tb.bootstrapTable('refresh', { url: url }); tb.bootstrapTable('refresh', { url: url });
...@@ -156,6 +154,10 @@ ...@@ -156,6 +154,10 @@
} }
}) })
} }
function exportxls() {
window.open('@Url.Content("~/Reports/Orders/ExportEbayInnerCodeProfit?")' + $("#toolbar").serialize(), '_blank');
}
</script> </script>
......
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