Commit d8944ea6 by guanzhenshan

1、修复数据中心预收订单的算法

2、平台利润统计报表增加wish的广告费
parent 70f47a2b
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.Models
{
/// <summary>
/// wish 广告费
/// </summary>
public class dc_base_finance_wish
{
/// <summary>
///
/// </summary>
public int id { get; set; }
/// <summary>
/// 广告系列id
/// </summary>
public string campaign_id { get; set; }
/// <summary>
/// 广告系列的名称
/// </summary>
public string campaign_name { get; set; }
/// <summary>
/// 其他转人民币汇率
/// </summary>
public decimal other_to_cny_exchange_rate { get; set; }
/// <summary>
/// 其他转美元汇率
/// </summary>
public decimal other_to_usd_exchange_rate { get; set; }
/// <summary>
/// 广告系列预算
/// </summary>
public decimal campaign_max_budget { get; set; }
/// <summary>
/// 为true表示是一个自动广告系列
/// </summary>
public int is_automated_campaign { get; set; }
/// <summary>
/// 为true则广告系列结束后自动续订
/// </summary>
public int auto_renew { get; set; }
/// <summary>
/// 预算金额
/// </summary>
public decimal scheduled_add_budget_amount { get; set; }
/// <summary>
/// 总展示次数
/// </summary>
public int total_impressions { get; set; }
/// <summary>
/// 开始时间
/// </summary>
public DateTime start_time { get; set; }
/// <summary>
/// 总销售量
/// </summary>
public int sales { get; set; }
/// <summary>
/// 付费展示的总费用
/// </summary>
public decimal total_impression_fees_charged { get; set; }
/// <summary>
/// 为true表示预算会定期自动添加到此广告系列
/// </summary>
public int scheduled_add_budget_enabled { get; set; }
/// <summary>
///
/// </summary>
public string merchant_id { get; set; }
/// <summary>
/// 印象费用细分
/// </summary>
public string impression_fees_breakdown { get; set; }
/// <summary>
/// 广告状态
/// </summary>
public string campaign_state { get; set; }
/// <summary>
/// 是否可编辑
/// </summary>
public int can_edit { get; set; }
/// <summary>
/// 0-1之间的比率代表折扣
/// </summary>
public decimal discount_ratio { get; set; }
/// <summary>
/// 为true表示此广告系列是Simple Boost广告系列
/// </summary>
public int is_simple_boost { get; set; }
/// <summary>
/// 此广告系列的总费用 美元
/// </summary>
public decimal total_campaign_spend { get; set; }
/// <summary>
/// 0-6,表示星期几的预算会自动添加到此广告系列中
/// </summary>
public string scheduled_add_budget_days { get; set; }
/// <summary>
/// 广告系列的最后更新时间
/// </summary>
public DateTime last_updated_time { get; set; }
/// <summary>
/// 结束时间
/// </summary>
public DateTime end_time { get; set; }
/// <summary>
/// 注册费用
/// </summary>
public decimal total_enrollment_fees_charged { get; set; }
/// <summary>
/// 总gmv
/// </summary>
public decimal gmv { get; set; }
/// <summary>
///
/// </summary>
public int account_id { get; set; }
/// <summary>
///
/// </summary>
public int company_id { get; set; }
/// <summary>
///
/// </summary>
public DateTime gmt_create_time { get; set; }
/// <summary>
///
/// </summary>
public DateTime gmt_modify_time { get; set; }
/// <summary>
/// 数据中心统计时间
/// </summary>
public DateTime record_time { get; set; }
/// <summary>
///
/// </summary>
public decimal daily_campaign_max_budget { get; set; }
/// <summary>
/// 每日广告产生的费用
/// </summary>
public decimal daily_total_campaign_spend { get; set; }
/// <summary>
///
/// </summary>
public decimal daily_gmv { get; set; }
}
}
...@@ -1517,7 +1517,7 @@ namespace Bailun.DC.Services ...@@ -1517,7 +1517,7 @@ namespace Bailun.DC.Services
public List<Models.Orders.dc_base_oms_sku> ListPlatformProfit(string platform, string website, DateTime? start, DateTime? end, DateTime? shipstart, DateTime? shipend, bool isUSD, int? companyid, string skucategoryids) public List<Models.Orders.dc_base_oms_sku> ListPlatformProfit(string platform, string website, DateTime? start, DateTime? end, DateTime? shipstart, DateTime? shipend, bool isUSD, int? companyid, string skucategoryids)
{ {
var sqlparam = new DynamicParameters(); var sqlparam = new DynamicParameters();
var sql = "select tb.platform_type,count(tb.bailun_order_id) order_count,sum(tb.amount_sales*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + ") as amount_sales,sum(tb.cost_platform_fee*(if(tb.platform_type='Ebay'," + (isUSD ? "tb.other_to_usd_exchange_rate" : "tb.seller_other_exchange_rate") + "," + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + "))) as cost_platform_fee,sum(tb.cost_first*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + ") as cost_first,sum(tb.cost_tail*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + ") cost_tail,sum(tb.cost_handle_bailun*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + ") cost_handle_bailun,sum(tb.cost_handle_platform*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + ") cost_handle_platform,sum(tb.amount_refund*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + ") amount_refund,sum(tb.cost_fba_fee*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + ") cost_fba_fee,sum(tb.cost_paypal_fee*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + ") cost_paypal_fee,sum(tb.amount_shipping*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + ") amount_shipping,sum(tb.cost_promotion*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + ") cost_promotion,sum(tb.cost_product*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + ") cost_product,sum(tb.profit_total*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + ") profit_total,(sum(tb.profit_total*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + ")/sum(tb.amount_sales*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + ")) profit_rate,count(tb.amount_prepaid>0 or null) as noshippingcount,sum(tb.amount_prepaid*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + ") amount_prepaid from dc_base_oms_order tb "; var sql = "select tb.platform_type,count(tb.bailun_order_id) order_count,sum(tb.amount_sales*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + ") as amount_sales,sum(tb.cost_platform_fee*(if(tb.platform_type='Ebay'," + (isUSD ? "tb.other_to_usd_exchange_rate" : "tb.seller_other_exchange_rate") + "," + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + "))) as cost_platform_fee,sum(tb.cost_first*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + ") as cost_first,sum(tb.cost_tail*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + ") cost_tail,sum(tb.cost_handle_bailun*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + ") cost_handle_bailun,sum(tb.cost_handle_platform*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + ") cost_handle_platform,sum(tb.amount_refund*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + ") amount_refund,sum(tb.cost_fba_fee*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + ") cost_fba_fee,sum(tb.cost_paypal_fee*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + ") cost_paypal_fee,sum(tb.amount_shipping*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + ") amount_shipping,sum(tb.cost_promotion*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + ") cost_promotion,sum(tb.cost_product*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + ") cost_product,sum(tb.profit_total*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + ") profit_total,(sum(tb.profit_total*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + ")/sum(tb.amount_sales*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + ")) profit_rate,count((tb.amount_prepaid>0 and tb.bailun_order_status!='Finished') or null) as noshippingcount,sum(tb.amount_prepaid*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + ") amount_prepaid from dc_base_oms_order tb ";
if (shipstart.HasValue || shipend.HasValue) if (shipstart.HasValue || shipend.HasValue)
{ {
...@@ -4530,11 +4530,115 @@ namespace Bailun.DC.Services ...@@ -4530,11 +4530,115 @@ namespace Bailun.DC.Services
#endregion #endregion
#region Wish
/// <summary>
/// Wish广告费列表
/// </summary>
/// <param name="parameter">分页信息</param>
/// <param name="companyid">公司id</param>
/// <param name="account_id">帐号id</param>
/// <param name="start">开始时间</param>
/// <param name="end">结束时间</param>
/// <param name="total">符合条件的总记录数</param>
/// <param name="isUSD">是否美元</param>
/// <returns></returns>
public List<dc_base_finance_wish> ListWishAD(BtTableParameter parameter,int? companyid, int? account_id, DateTime? start, DateTime? end, ref int total,bool isUSD)
{
var sqlparam = new DynamicParameters();
var sql = $"select t1.campaign_name,t2.account_name,t1.daily_total_campaign_spend,(t1.daily_total_campaign_spend*{(isUSD? "t1.other_to_usd_exchange_rate":"t1.other_to_cny_exchange_rate")}) daily_total_campaign_spend from dc_base_finance_wish t1 left join dc_base_company_account t2 on t1.account_id=t2.account_id where 1=1 ";
if (companyid.HasValue && companyid.Value > 0)
{
sql += " and t1.company_id="+companyid.Value;
}
if (account_id.HasValue && account_id.Value > 0)
{
sql += " and t1.account_id=@account_id";
sqlparam.Add("account_id", account_id);
}
if (start.HasValue)
{
sql += " and t1.record_time>=@start";
sqlparam.Add("start", start.Value);
}
if (end.HasValue)
{
sql += " and t1.record_time<@end";
sqlparam.Add("end", end.Value.AddDays(1));
}
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
var obj = cn.Page<dc_base_finance_wish>(parameter.pageIndex, parameter.limit, sql, ref total, sqlparam, "", 2 * 60);
return obj.AsList();
}
}
/// <summary>
/// Wish广告费汇总
/// </summary>
/// <param name="companyid">公司id</param>
/// <param name="account_id">帐号id</param>
/// <param name="start">开始时间</param>
/// <param name="end">结束时间</param>
/// <param name="isUSD">是否美元</param>
/// <returns></returns>
public dc_base_finance_wish ListWishADCount(int? companyid, int? account_id, DateTime? start, DateTime? end, bool isUSD)
{
var sqlparam = new DynamicParameters();
var sql = $"select sum(t1.daily_total_campaign_spend) daily_total_campaign_spend,sum(t1.daily_total_campaign_spend*{(isUSD ? "t1.other_to_usd_exchange_rate" : "t1.other_to_cny_exchange_rate")}) daily_total_campaign_spend from dc_base_finance_wish t1 where 1=1 ";
if (companyid.HasValue && companyid.Value > 0)
{
sql += " and t1.company_id=" + companyid.Value;
}
if (account_id.HasValue && account_id.Value > 0)
{
sql += " and t1.account_id=@account_id";
sqlparam.Add("account_id", account_id);
}
if (start.HasValue)
{
sql += " and t1.record_time>=@start";
sqlparam.Add("start", start.Value);
}
if (end.HasValue)
{
sql += " and t1.record_time<@end";
sqlparam.Add("end", end.Value.AddDays(1));
}
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
var obj = cn.QueryFirstOrDefault<dc_base_finance_wish>(sql, sqlparam,null,2*60);
return obj;
}
}
#endregion
#endregion #endregion
#region Paypal #region Paypal
/// <summary> /// <summary>
/// paypal费流水 /// paypal费流水
/// </summary> /// </summary>
......
...@@ -1398,7 +1398,8 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers ...@@ -1398,7 +1398,8 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
ebayADFee = _service.EbayFeeCount(companyid, dtstart, dtend, ADfeeType, "", "", currency.ToUpper() == "USD"); ebayADFee = _service.EbayFeeCount(companyid, dtstart, dtend, ADfeeType, "", "", currency.ToUpper() == "USD");
ebayPutAway = _service.EbayFeeCount(companyid, dtstart, dtend, PutAwayFeeType, "", "", currency.ToUpper() == "USD"); ebayPutAway = _service.EbayFeeCount(companyid, dtstart, dtend, PutAwayFeeType, "", "", currency.ToUpper() == "USD");
var amazonAD = _service.ListAmazonADSkuCount("", dtstart, dtend, companyid, currency.ToUpper() == "USD"); var amazonAD = _service.ListAmazonADSkuCount("", dtstart, dtend, companyid, currency.ToUpper() == "USD");
var wishAD = _service.ListWishADCount(companyid, null, dtstart, dtend, currency.ToUpper() == "USD");
foreach (var item in result) foreach (var item in result)
{ {
...@@ -1415,7 +1416,7 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers ...@@ -1415,7 +1416,7 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
item.profit_rate = Math.Round((item.profit_total / item.amount_sales), 2); item.profit_rate = Math.Round((item.profit_total / item.amount_sales), 2);
} }
if (item.platform_type.ToLower() == "fba") else if (item.platform_type.ToLower() == "fba")
{ {
item.adfee = amazonAD != null ? amazonAD.cost_rmb : 0; item.adfee = amazonAD != null ? amazonAD.cost_rmb : 0;
...@@ -1423,6 +1424,13 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers ...@@ -1423,6 +1424,13 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
item.profit_rate = Math.Round((item.profit_total / item.amount_sales), 2); item.profit_rate = Math.Round((item.profit_total / item.amount_sales), 2);
} }
else if (item.platform_type.ToLower() == "wish")
{
item.adfee = wishAD != null ? wishAD.daily_total_campaign_spend : 0;
item.profit_total = (item.profit_total - item.adfee ?? 0);
item.profit_rate = Math.Round((item.profit_total / item.amount_sales), 2);
}
item.amount_refund = 0; item.amount_refund = 0;
item.amount_refund_rate = 0; item.amount_refund_rate = 0;
var objRefund = listRefund.Where(a => a.platform_type.ToLower() == item.platform_type.ToLower()).FirstOrDefault(); var objRefund = listRefund.Where(a => a.platform_type.ToLower() == item.platform_type.ToLower()).FirstOrDefault();
......
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