Commit 92b91955 by guanzhenshan

优化获取sku利润的接口

parent 3ee5d0cb
......@@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Text;
using Bailun.DC.Models;
using System.Linq;
using MySql.Data.MySqlClient;
using Dapper;
namespace Bailun.DC.HappenAmount
{
......@@ -40,14 +42,20 @@ namespace Bailun.DC.HappenAmount
var sqlhappen = "";
var sqlsales = "";
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
#region 管理成本
var url = "http://api.fee.bailuntec.com/purchase/other/cost/api/manageCostList?o=0";
var cwurl = "http://cw.bailuntec.com/api/api/GetRepayPlanDetails?";
url += "&startDate=" + start.ToString("yyyy-MM-dd") + "&endDate=" + end.ToString("yyyy-MM-dd");
cwurl += "BeginRepayTime=" + start.ToString("yyyy-MM-dd") + "&EndRepayTime=" + end.ToString("yyyy-MM-dd");
url += "&startDate=" + start.ToString("yyyy-MM-dd HH:mm:ss") + "&endDate=" + end.ToString("yyyy-MM-dd HH:mm:ss");
cwurl += "BeginRepayTime=" + start.ToString("yyyy-MM-dd HH:mm:ss") + "&EndRepayTime=" + end.ToString("yyyy-MM-dd HH:mm:ss");
//利息支出
var listInterest = new Bailun.DC.Services.FinanceReportServices().ListInterestExpense(cwurl);
......@@ -59,21 +67,21 @@ namespace Bailun.DC.HappenAmount
if (list.Count > 0)
{
m.hl_amount_pay += list.Sum(a => a.amountRmb);
m.hl_amount_happen += list.Sum(a => a.amountRmb);
m.ac_amount_pay += list.Sum(a => a.amountRmb);
m.ac_amount_happen += list.Sum(a => a.amountRmb);
var objtemp = list.Where(a => a.companyValue == 5 || a.companyValue == 2).Where(b => listFeeType.Contains(b.feeSuperType));
if (objtemp.Count() > 0)
{
m.hl_amount_sales = objtemp.Sum(a => a.amountRmb);
m.ac_amount_sales = objtemp.Sum(a => a.amountRmb);
}
}
if (listInterest.Count > 0)
{
m.hl_amount_pay += listInterest.Sum(a => a.RepayInterestRMB);
m.hl_amount_happen += listInterest.Sum(a => a.RepayInterestRMB);
m.ac_amount_pay += listInterest.Sum(a => a.RepayInterestRMB);
m.ac_amount_happen += listInterest.Sum(a => a.RepayInterestRMB);
}
#endregion
......@@ -81,16 +89,61 @@ namespace Bailun.DC.HappenAmount
#region 头程物流
//已付款
sqlpay = $"select sum(cashier_paymoneyrmb) cashier_paymoneyrmb from dc_base_finance_cashier where cashier_type=1 and cashier_status=1 and sourcecode in ('newCost','oldbuy') and type_name='销售费用/物流费' and cashier_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and cashier_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}'";
m.hl_amount_pay += cn.QueryFirstOrDefault<decimal>(sqlpay, null, null, 2 * 60);
//发生额
//销售额
sqlsales = $"select sum(cost_first*bailun_sku_quantity_ordered) as cost_first from dc_base_oms_sku where paid_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and paid_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and bailun_order_status!='Canceled' and cost_first>0 and has_scalp=0 and has_delete=0 and has_innersale=0 and company_id=1";
m.hl_amount_sales += cn.QueryFirstOrDefault<decimal>(sqlsales, null, null, 2 * 60);
#endregion
#region 尾程物流
//已付款
m.tl_amount_pay = m.hl_amount_pay;
//发生额
sqlhappen = $@"select sum(t2.cost_tail*t1.quantity_shipped) from dc_base_oms_pick t1
join dc_base_oms_sku t2 on t1.bailun_sku = t2.bailun_sku and t1.origin_order_id = t2.origin_order_id and t2.bailun_order_status != 'Canceled' and t2.has_scalp = 0 and t2.has_delete = 0 and t2.has_innersale = 0 and t2.company_id = 1 and t2.cost_tail > 0
where t1.shipping_time >= '{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.shipping_time < '{end.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.has_delete = 0 and t1.company_id = 1 and t1.shipping_status = 'TotalShipping'";
m.tl_amount_happen += cn.QueryFirstOrDefault<decimal>(sqlhappen,null,null,2*60);
//销售额
sqlsales = $"select sum(cost_logistics*bailun_sku_quantity_ordered) from dc_base_oms_sku t1 where paid_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and paid_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and bailun_order_status!='Canceled' and has_scalp=0 and has_delete=0 and has_innersale=0 and company_id=1 and cost_logistics>0";
m.tl_amount_sales += cn.QueryFirstOrDefault<decimal>(sqlsales, null, null, 2 * 60);
#endregion
//尾程物流
#region 一级供应商
//付款额
sqlpay = $"select sum(cashier_paymoneyrmb) cashier_paymoneyrmb from dc_base_finance_cashier where cashier_type=1 and cashier_status=1 and sourcecode ='Buy' and cashier_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and cashier_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}'";
m.tos_amount_pay += cn.QueryFirstOrDefault<decimal>(sqlpay, null, null, 2 * 60);
//一级供应商
//发生额
//二级供应商
//销售额
#endregion
#region 二级供应商
//付款额
//发生额
//销售额
#endregion
}
}
}
......
......@@ -3666,17 +3666,18 @@ namespace Bailun.DC.Services
{
var sqlparam = new DynamicParameters();
var sql = $@"select t1.id,t2.warehouse_code,((((t1.amount_product-t1.cost_platform_fee)*t1.seller_order_exchange_rate)-t1.cost_logistics-t1.cost_handle_bailun)*t2.quantity_shipped) as productvalue, t1.platform_type,t1.seller_account,t1.bailun_account_id,t1.website,t1.bailun_order_id,t1.origin_order_id,t1.transaction_id,t1.paid_time,t1.gmt_modified,t1.bailun_sku,(t1.amount_sales*t1.seller_order_exchange_rate*t2.quantity_shipped) amount_sales,(t1.profit_total*t2.quantity_shipped) profit_total,t2.quantity_shipped as platform_sku_quantity_shipped,t1.company_id,t2.pick_order_id,t2.shipping_time,t2.has_delete
from dc_base_oms_sku t1
join dc_base_oms_pick t2 on t1.bailun_order_id = t2.bailun_order_id and t1.bailun_sku = t2.bailun_sku and t2.gmt_modified >= '{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t2.gmt_modified < '{end.ToString("yyyy-MM-dd HH:mm:ss")}' and t2.shipping_status = 'TotalShipping' and t2.company_id = 1
where t1.bailun_order_status != 'Canceled' and t1.has_scalp = 0 and t1.bailun_order_status != 'CantHandle' and t1.has_scalp = 0 and t1.has_innersale = 0 and t1.company_id = 1 and t1.has_delete = 0 ";
var str = "";
if (!string.IsNullOrEmpty(orderno))
{
sql += " and t1.bailun_order_id=@orderno";
sqlparam.Add("orderno", orderno);
str += $" and t2.bailun_order_id='{orderno}'";
}
var sql = $@"select t1.id,t2.warehouse_code,((((t1.amount_product-t1.cost_platform_fee)*t1.seller_order_exchange_rate)-t1.cost_logistics-t1.cost_handle_bailun)*t2.quantity_shipped) as productvalue, t1.platform_type,t1.seller_account,t1.bailun_account_id,t1.website,t1.bailun_order_id,t1.origin_order_id,t1.transaction_id,t1.paid_time,t1.gmt_modified,t1.bailun_sku,(t1.amount_sales*t1.seller_order_exchange_rate*t2.quantity_shipped) amount_sales,(t1.profit_total*t2.quantity_shipped) profit_total,t2.quantity_shipped as platform_sku_quantity_shipped,t1.company_id,t2.pick_order_id,t2.shipping_time,t2.has_delete from
(select t2.origin_order_id,t2.bailun_sku,t2.quantity_shipped,t2.warehouse_code,t2.shipping_time,t2.has_delete,t2.pick_order_id from dc_base_oms_pick t2 where t2.gmt_modified>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t2.gmt_modified<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and t2.shipping_status='TotalShipping' and t2.company_id=1 {str} {" limit " + (page - 1) * pagesize + "," + pagesize}) t2
left join dc_base_oms_sku t1 on t1.origin_order_id=t2.origin_order_id and t1.bailun_sku=t2.bailun_sku and t1.has_delete = 0";
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
......@@ -3684,7 +3685,7 @@ namespace Bailun.DC.Services
cn.Open();
}
var obj = cn.Query<dc_base_oms_sku>(sql + " limit " + (page - 1) * pagesize + "," + pagesize,sqlparam,null,true,2 * 60);
var obj = cn.Query<dc_base_oms_sku>(sql,sqlparam,null,true,2 * 60);
return obj.ToList();
}
......
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