Commit 57100411 by zhouminghui

SQL

parent 0923450d
......@@ -685,9 +685,9 @@ and s1.management_cost_name = @managementcostname";
month = month.Replace("月份", "");
var start =Convert.ToDateTime(month).Date;
var end = start.AddMonths(1).Date;
var sql = BuildMonthProfitFeeManagementCostDetailSql(start, end, feeName);
var sql = BuildMonthProfitFeeManagementCostDetailSql(start, end, feeName, out DynamicParameters parameters);
var data = SimpleCRUD.Query<FinanceDetailsDto>(sql,null,GlobalConfig.ConnectionString).ToList();
var data = SimpleCRUD.Query<FinanceDetailsDto>(sql, parameters, GlobalConfig.ConnectionString).ToList();
foreach (var item in data)
{
if (item.cost_form == 2)
......@@ -720,19 +720,22 @@ and s1.management_cost_name = @managementcostname";
});
return new CommonApiResponseDto<List<FinanceDetailsDto>> { Data = data };
}
public string BuildMonthProfitFeeManagementCostDetailSql(DateTime start,DateTime end,string feeName)
public string BuildMonthProfitFeeManagementCostDetailSql(DateTime start,DateTime end,string feeName,out DynamicParameters parameters)
{
parameters = new DynamicParameters();
StringBuilder sql = new StringBuilder();
sql.Append($@"select amount as Amount,amount_rmb as AmountRmb,company_name as CompanyName,
sql.Append(@"select amount as Amount,amount_rmb as AmountRmb,company_name as CompanyName,
dic as Currency,department_name as DepartmentName,type_name as TypeName,
cost_no as FeeId,accounting_subject_name as Accounting,bank_company as ReceiveUnit,
cost_reason as CostReason,cost_remark as CostRemark,pay_time
from dc_base_finance_fee where cost_status=4 and (is_lend is null or is_lend=1 or (is_lend=2 and lend_balance>0)
or (is_lend=2 and cost_form=1)) and pay_time>='{start}' and pay_time<'{end}' ");
or (is_lend=2 and cost_form=1)) and pay_time>= @start and pay_time< @end ");
parameters.Add("start", start);
parameters.Add("end", end);
if (feeName == "广州歌戈儿生活科技有限公司")
{
sql.Append($" and (company_name like '%{feeName}%' and (type_name!='销售收入' and type_name!='出口退税款')) ");
sql.Append(" and (company_name like '%歌戈儿%' and (type_name!='销售收入' and type_name!='出口退税款')) ");
}
else if (feeName.Contains("广州电子服装仓&阳山"))
{
......@@ -740,14 +743,15 @@ or (is_lend=2 and cost_form=1)) and pay_time>='{start}' and pay_time<'{end}' ");
}
else
{
sql.Append($" and (company_name ='{feeName}' and type_name!='出口退税款') ");
sql.Append(" and (company_name =@feeName and type_name!='出口退税款') ");
parameters.Add("feeName", feeName);
}
return sql.ToString();
}
public CommonApiResponseDto<PageResult<List<MonthPlatformProfitDto>>> GetMonthProfitFeePlatformFeeDetail(GetMonthProfitPlatformDetailInput input)
{
var sql = BuildMonthProfitFeePlatformFeeDetailSql(input);
var sql = BuildMonthProfitFeePlatformFeeDetailSql(input, out DynamicParameters param);
var result = new PageResult<List<MonthPlatformProfitDto>>();
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString_DW))
{
......@@ -756,12 +760,12 @@ or (is_lend=2 and cost_form=1)) and pay_time>='{start}' and pay_time<'{end}' ");
cn.Open();
}
int total = 0;
var obj = cn.Page<MonthPlatformProfitDto>(input.PageIndex, input.PageNumber, sql, ref total);
var obj = cn.Page<MonthPlatformProfitDto>(input.PageIndex, input.PageNumber, sql, ref total, param);
var data = obj.ToList();
if (data.Count > 0)
{
var sumSql = BuildMonthProfitFeePlatformFeeDetailSql(input, false, true);
var count = cn.Query<(decimal, decimal)>(sumSql).FirstOrDefault();
var sumSql = BuildMonthProfitFeePlatformFeeDetailSql(input, out DynamicParameters paramSum, false, true);
var count = cn.Query<(decimal, decimal)>(sumSql, paramSum).FirstOrDefault();
data.Add(new MonthPlatformProfitDto
{
Currency = "合计",
......@@ -776,8 +780,9 @@ or (is_lend=2 and cost_form=1)) and pay_time>='{start}' and pay_time<'{end}' ");
return new CommonApiResponseDto<PageResult<List<MonthPlatformProfitDto>>> { Data = result };
}
public string BuildMonthProfitFeePlatformFeeDetailSql(GetMonthProfitPlatformDetailInput input,bool isPage = false,bool isSum = false)
public string BuildMonthProfitFeePlatformFeeDetailSql(GetMonthProfitPlatformDetailInput input, out DynamicParameters parameters, bool isPage = false,bool isSum = false)
{
parameters = new DynamicParameters();
input.Month = input.Month.Replace("月份", "");
StringBuilder sql = new StringBuilder();
if (isSum)
......@@ -785,19 +790,20 @@ or (is_lend=2 and cost_form=1)) and pay_time>='{start}' and pay_time<'{end}' ");
sql.Append($@"SELECT sum(s1.amountval) as amountval, sum(s1.amountval_rmb) amountval_rmb
from order_fee_value_amazon s1
JOIN order_fee_config s2
ON s2.id = s1.order_fee_config_id WHERE s1.amountval != 0 AND s1.month = '{input.Month}'");
ON s2.id = s1.order_fee_config_id WHERE s1.amountval != 0 AND s1.month = @month ");
}
else
{
sql.Append($@"SELECT s1.platform AS PlatForm,s1.website AS WebSite,s1.orderno AS Orderno,
sql.Append(@"SELECT s1.platform AS PlatForm,s1.website AS WebSite,s1.orderno AS Orderno,
s1.datatime AS DataTime,s1.amountval AS AmountVal,
s2.feetype AS FeeType,s2.subjectcode AS Subjectcode,s2.projectcode AS ProjectCode,
s2.financecategory AS FinanceCategory,s2.datacenter_col AS DatacenterCol,s2.currency AS Currency,
s1.exchange_rate AS ExchangeRate,s1.amountval_rmb AS AmountValRmb,s1.month AS Month
from order_fee_value_amazon s1
JOIN order_fee_config s2
ON s2.id = s1.order_fee_config_id WHERE s1.amountval != 0 AND s1.month = '{input.Month}'");
ON s2.id = s1.order_fee_config_id WHERE s1.amountval != 0 AND s1.month = @month ");
}
parameters.Add("month", input.Month);
if (input.FeeName == "FBA费")
{
sql.Append("AND s2.datacenter_col LIKE '%佣金及平台费-亚马逊FBA%'");
......@@ -808,14 +814,17 @@ ON s2.id = s1.order_fee_config_id WHERE s1.amountval != 0 AND s1.month = '{input
}
if (isPage)
{
sql.Append($" LIMIT {input.PageNumber} OFFSET {(input.PageIndex - 1) * input.PageNumber}");
//sql.Append($" LIMIT {input.PageNumber} OFFSET {(input.PageIndex - 1) * input.PageNumber}");
sql.Append($" LIMIT @linits OFFSET @offsets");
parameters.Add("linits", input.PageNumber);
parameters.Add("offsets", (input.PageIndex - 1) * input.PageNumber);
}
return sql.ToString();
}
public List<MonthPlatformProfitDto> ExportMonthProfitFeePlatformFeeDetail(GetMonthProfitPlatformDetailInput input)
{
var sql = BuildMonthProfitFeePlatformFeeDetailSql(input, false, false);
var data = SimpleCRUD.Query<MonthPlatformProfitDto>(sql, null, GlobalConfig.ConnectionString_DW).ToList();
var sql = BuildMonthProfitFeePlatformFeeDetailSql(input, out DynamicParameters parameters, false, false);
var data = SimpleCRUD.Query<MonthPlatformProfitDto>(sql, parameters, GlobalConfig.ConnectionString_DW).ToList();
return data;
}
/// <summary>
......@@ -931,16 +940,17 @@ where t1.refund_time >= @start and t1.refund_time < @end ");
var sql = $@"SELECT t1.*, t2.origin_order_id, t2.bailun_order_id
FROM dc_month_sales_profit_orderdetail t1
JOIN dc_base_oms_sku t2 ON t1.orderskuid = t2.id
WHERE t1. MONTH = '{input.Month}'
WHERE t1. MONTH = @month
ORDER BY t1.createtime DESC ";
var parameters = new DynamicParameters();
parameters.Add("month", input.Month);
//LIMIT {input.PageNumber}
//OFFSET { (input.PageIndex - 1) * input.PageNumber} ";
if (isPage)
{
using (var cn = new MySqlConnection(GlobalConfig.ConnectionString))
{
data = cn.Page<dc_month_sales_profit_orderdetail>(input.PageIndex, input.PageNumber, sql, ref total, null).ToList();
data = cn.Page<dc_month_sales_profit_orderdetail>(input.PageIndex, input.PageNumber, sql, ref total, parameters).ToList();
}
}
else
......
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