Commit 8eee12ed by lizefeng

新增投资回报分析的计算模块

parent 9653a6b7
......@@ -950,6 +950,57 @@ where t1.`code`=@code limit 1
}
}
/// <summary>
/// 获取pps刊登的shopify sku销量
/// </summary>
/// <param name="skus"></param>
/// <returns></returns>
public static List<PpsSkuResponseDto.result_dto.data_dto> GetPPSSkus()
{
var url = ConfigHelper.GetValue("pps-sys:GetSkus");
var response_json = HttpHelper.Request(url+ "?pageIndex=1&pageNumber=100000", RequestType.POST, "", entype: "application/json", timeout: 1000 * 60 * 30);
var r = response_json.ToObj<PpsSkuResponseDto>();
if (r.statusCode != 200)
{
throw new Exception("pps sku数据拉取异常:"+r.message);
}
return r.result.data;
}
/// <summary>
/// 获取btm的全站点广告费
/// </summary>
/// <param name="skus"></param>
/// <returns></returns>
public static List<BtmAdFeeResponseDto.data_dto> GetBtmAdFees(DateTime btime,DateTime etime)
{
var url = ConfigHelper.GetValue("btm-sys:ad-fee");
var response_json = HttpHelper.Request(url+ $"?btime={btime.ToString("yyyy-MM-dd HH:mm:ss")}&etime={etime.ToString("yyyy-MM-dd HH:mm:ss")}", RequestType.GET, "", timeout: 1000 * 60 * 30);
var r = response_json.ToObj<BtmAdFeeResponseDto>();
if (!r.success)
{
throw new Exception("btm ad fee 数据拉取异常:"+r.message);
}
return r.data;
}
/// <summary>
/// 获取btm的退款订单
/// </summary>
/// <param name="skus"></param>
/// <returns></returns>
public static List<BtmOrderRefundResponseDto.data_dto> GetBtmOrderRefunds(DateTime btime,DateTime etime)
{
var url = ConfigHelper.GetValue("btm-sys:order-refund");
var response_json = HttpHelper.Request(url+ $"?btime={btime.ToString("yyyy-MM-dd HH:mm:ss")}&etime={etime.ToString("yyyy-MM-dd HH:mm:ss")}", RequestType.GET, "", timeout: 1000 * 60 * 30);
var r = response_json.ToObj<BtmOrderRefundResponseDto>();
if (!r.success)
{
throw new Exception("btm ad fee 数据拉取异常:"+r.message);
}
return r.data;
}
/// <summary>
/// 推送调拨计划
/// </summary>
......
......@@ -1221,8 +1221,8 @@ where 1=1 ";
WHERE
bailun_order_status not in ('Canceled')
and bailun_interception_status in('None','Failed')
and warehouse_code = @warehouse_code and bailun_sku=@bailun_sku
and platform_type != 'FBA'
and warehouse_code = @warehouse_code and bailun_sku=@bailun_sku
AND paid_time >= '2019-03-01 12:00:00'
and bailun_sku_quantity_ordered > bailun_sku_quantity_picked
";
......
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models.ApiDto
{
public class BtmAdFeeResponseDto
{
public bool success { get; set; }
public string message { get; set; }
public List<data_dto> data { get; set; }
public class data_dto {
public decimal fee { get; set; }
public decimal fee_cny { get; set; }
public string date_str { get; set; }
public string data_id { get; set; }
public int account_id { get; set; }
}
}
public class BtmOrderRefundResponseDto
{
public bool success { get; set; }
public string message { get; set; }
public List<data_dto> data { get; set; }
public class data_dto {
public string bailun_order_id { get; set; }
public string origin_order_id { get; set; }
public string bailun_sku { get; set; }
public decimal refund_amount { get; set; }
public DateTime order_pay_time { get; set; }
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models.ApiDto
{
public class PpsSkuResponseDto
{
public string message { get; set; }
public int statusCode { get; set; }
public result_dto result { get; set; }
public class result_dto
{
public int rows { get; set; }
public List<data_dto> data { get; set; }
public class data_dto
{
public string skuCode { get; set; }
}
}
}
}
......@@ -94,7 +94,7 @@ namespace AutoTurnOver.Models.Report
/// <summary>
/// 账号id
/// </summary>
public int bailun_account_id { get; set; }
public string bailun_account_id { get; set; }
/// <summary>
/// 环球账号
......
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models
{
/// <summary>
/// 投资回报分析表
/// </summary>
public class dc_report_invest_return_analysis
{
public int id { get; set; }
public string sku { get; set; }
public string project { get; set; }
public string sku_name { get; set; }
public decimal price { get; set; }
public DateTime gmt_create_time { get; set; }
public DateTime gmt_update_time { get; set; }
public string create_user { get; set; }
/// <summary>
/// 仓库编码
/// </summary>
public string warehouse_code { get; set; }
public string warehouse_name { get; set; }
/// <summary>
/// 总库存(在库+在途)
/// </summary>
public decimal stock { get; set; }
/// <summary>
/// 总金额 (在库+在途)
/// </summary>
public decimal stock_amount { get; set; }
/// <summary>
/// /日均销量 30天日均销量占比50%,7天日均销量占比50%。 来算日均销量。
/// </summary>
public decimal sales_day_average { get; set; }
/// <summary>
/// 销售订单转人民币汇率
/// </summary>
public decimal? seller_order_exchange_rate { get; set; }
/// <summary>
/// 过去30天销量
/// </summary>
public decimal sales_day_30 { get; set; }
/// <summary>
/// 过去7天销量
/// </summary>
public decimal sales_day_7 { get; set; }
/// <summary>
/// 出单天数 (总)
/// </summary>
public decimal order_days { get; set; }
/// <summary>
/// 出单天数 (过去30天)
/// </summary>
public decimal consume_days_30 { get; set; }
/// <summary>
/// 首次出单日期
/// </summary>
public DateTime? first_order_date { get; set; }
/// <summary>
/// 最后出单日期
/// </summary>
public DateTime? last_order_date { get; set; }
/// <summary>
/// 30天利润
///预计30天内销量,可售天数大于30天的,则为加权日均销量*30,可售天数小于30天的,则为加权日均销量* 可售天数
///预计30天内销售额=预计30天内销量* 单位售价
///预计30天营业利润=预计30天内销量* 单位售价*(1-最近1个月的款率-最近1个月的平台费率最近1个月的广告费率)-预计30天内销量* 单位采购成本
/// </summary>
public decimal profit_30_forecast { get; set; }
/// <summary>
/// 可售天数:
///总库存除于加权日均销量得出可售天数
/// </summary>
public decimal vendibility_days { get; set; }
/// <summary>
/// 预测30天销量
/// </summary>
public decimal sales_day_30_forecast { get; set; }
/// <summary>
/// 最近30天的平均销售单价
/// </summary>
public decimal gmv_day30_avg_unit_price_cny { get; set; }
/// <summary>
/// 预计30天销售额
/// </summary>
public decimal gmv_day_30_forecast_cny { get; set; }
/// <summary>
/// 最近30天的广告费(usd)
/// </summary>
public decimal adfee_day_30 { get; set; }
/// <summary>
/// 最近30天的平台费
/// </summary>
public decimal platform_fee_day_30 { get; set; }
/// <summary>
/// 最近30天的销售额(usd)
/// </summary>
public decimal amount_total_day_30 { get; set; }
/// <summary>
/// 广告费率 (最近30天的广告费/最近30天的销售额)
/// </summary>
public decimal adfee_rate { get; set; }
/// <summary>
/// 平台费率 (最近30天的广告费/最近30天的销售额)
/// </summary>
public decimal platform_fee_rate { get; set; }
/// <summary>
/// 采购在途数量
/// </summary>
public decimal quantity_purchase { get; set; }
/// <summary>
/// 采购在途金额
/// </summary>
public decimal quantity_purchase_amount { get; set; }
/// <summary>
/// 头程在途
/// </summary>
public decimal quantity_transfer { get; set; }
/// <summary>
/// 头程在途金额
/// </summary>
public decimal quantity_transfer_amount { get; set; }
/// <summary>
/// 在库库存
/// </summary>
public decimal library_stock { get; set; }
/// <summary>
/// 在库金额
/// </summary>
public decimal library_stock_amount { get; set; }
/// <summary>
/// 预估运费: 现在的总库存数(在途和在库)占用的库存运费
/// </summary>
public decimal estimated_freight { get; set; }
/// <summary>
/// 库存分数
/// </summary>
public decimal stock_score { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models
{
/// <summary>
/// 投资回报分析,sku基础表
/// </summary>
public class dc_report_invest_return_sku
{
public int id { get; set; }
public string sku { get; set; }
/// <summary>
/// 项目
/// </summary>
public string project { get; set; }
/// <summary>
/// sku名称
/// </summary>
public string sku_name { get; set; }
public DateTime gmt_create_time { get; set; }
public DateTime gmt_update_time { get; set; }
public string create_user { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models
{
public class t_base_shopify_adfee
{
public int id { get; set; }
/// <summary>
/// 销售账号id
/// </summary>
public int account_id { get; set; }
public DateTime? share_time { get; set; }
/// <summary>
/// 美元 费用
/// </summary>
public decimal fee { get; set; }
public decimal fee_cny { get; set; }
/// <summary>
/// 美东时间
/// </summary>
public string date_str { get; set; }
public string data_id { get; set; }
/// <summary>
/// 北京时间
/// </summary>
public DateTime bdate { get; set; }
/// <summary>
/// 北京时间
/// </summary>
public DateTime edate { get; set; }
public DateTime gmt_create_time { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models
{
/// <summary>
/// 广告费分摊到订单上
/// </summary>
public class t_base_shopify_adfee_order
{
public long id { get; set; }
/// <summary>
/// t_base_shopify_adfee.data_id
/// </summary>
public string fee_data_id { get; set; }
/// <summary>
/// 订单的唯一约束 `origin_order_id`,`bailun_account_id`,`bailun_sku`
/// </summary>
public string order_unique { get; set; }
public string origin_order_id { get; set; }
public string bailun_account_id { get; set; }
public string bailun_sku { get; set; }
public string warehouse_code { get; set; }
/// <summary>
/// 费用周期(这里是美东时间 yyyy-MM-dd)
/// </summary>
public string date_str { get; set; }
public string unique_id { get; set; }
/// <summary>
/// 原始费用美金
/// </summary>
public decimal origin_fee { get; set; }
/// <summary>
/// 原始费用 人民币
/// </summary>
public decimal origin_fee_cny { get; set; }
public int is_delete { get; set; }
/// <summary>
/// 计算的时间范围 (北京时间)
/// </summary>
public DateTime calculation_btime { get; set; }
/// <summary>
/// 订单付款时间,北京时间
/// </summary>
public DateTime order_pay_time { get; set; }
/// <summary>
/// 计算的时间范围 (北京时间)
/// </summary>
public DateTime calculation_etime { get; set; }
/// <summary>
/// 范围内销售总额(USD)
/// </summary>
public decimal amount_total_usd { get; set; }
/// <summary>
/// 本订单的总销售额(USD)
/// </summary>
public decimal order_amount_total_usd { get; set; }
/// <summary>
/// 订单时间分摊到的广告费
/// </summary>
public decimal order_fee { get; set; }
/// <summary>
/// 订单实际分摊到的广告费 人民币
/// </summary>
public decimal order_fee_cny { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Models
{
/// <summary>
/// shopify订单退款记录
/// </summary>
public class t_base_shopify_refund
{
public int id { get; set; }
public string bailun_order_id { get; set; }
public string origin_order_id { get; set; }
public string bailun_sku { get; set; }
public decimal refund_amount { get; set; }
public DateTime order_pay_time { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoTurnOver.Utility
{
/// <summary>
/// AMESTime 的摘要说明:
/// 美东时间的转换
///
/// 美东时间在UTC-5时区,美国有夏时制,即在夏令时启用之后美东时间比起所在时区早一个小时,即UTC-4
/// 在未使用夏令时时美东时间比北京时间(UTC+8时区)晚13个小时,在启用夏令时时美东时间比北京时间晚12个小时
///
///
/// 美国国会2005年通过的能源法案,夏令时时段:从2007年开始每年3月的第二个星期日开始夏令时,结束日期为11月的第一个星期日。
/// </summary>
public class AMESTime
{
private static DateTime _thisYearDaylightSavingTimeStart,
_thisYearDaylightSavingTimeEnd;
private const int TIMEZONE_OFFSET_DAY_SAVING_LIGHT = -12;
private const int TIMEZONE_OFFSET = -13;
public static DateTime BeijingTimeToAMESTime(DateTime beijingTime)
{
int offsetHours = (IsNowAMESDayLightSavingTime(beijingTime) ? TIMEZONE_OFFSET_DAY_SAVING_LIGHT : TIMEZONE_OFFSET);
return beijingTime.AddHours(offsetHours);
}
public static DateTime AMESTimeToBeijingTime(DateTime meiDongTime)
{
int offsetHours = (IsNowAMESDayLightSavingTime(meiDongTime) ? TIMEZONE_OFFSET_DAY_SAVING_LIGHT : TIMEZONE_OFFSET);
return meiDongTime.AddHours(0 - offsetHours);
}
public static DateTime AMESNow
{
get
{
return BeijingTimeToAMESTime(DateTime.Now);
}
}
/// <summary>
/// 判断当前日期是否是美国夏令时
/// 从2007年开始每年3月的第二个星期日开始夏令时,结束日期为11月的第一个星期日。
/// </summary>
/// <returns>是,返回true,否则为false</returns>
public static bool IsNowAMESDayLightSavingTime(DateTime beijinTime)
{
var utcTime = beijinTime.AddHours(-8);
return utcTime > DayLightSavingStartTimeUtc
&& utcTime < DayLightSavingEndTimeUtc;
}
/// <summary>
/// 夏令时开始时间
/// </summary>
static DateTime DayLightSavingStartTimeUtc
{
get
{
if (_thisYearDaylightSavingTimeStart.Year != DateTime.Now.Year)
{
DateTime temp = new DateTime(DateTime.Now.Year, 3, 8, 0, 0, 0);
while (temp.DayOfWeek != DayOfWeek.Sunday)
{
temp = temp.AddDays(1);
}
_thisYearDaylightSavingTimeStart = temp.AddHours(TIMEZONE_OFFSET);
}
return _thisYearDaylightSavingTimeStart;
}
}
/// <summary>
/// 夏令时结束时间
/// </summary>
static DateTime DayLightSavingEndTimeUtc
{
get
{
if (_thisYearDaylightSavingTimeEnd.Year != DateTime.Now.Year)
{
DateTime temp = new DateTime(DateTime.Now.Year, 11, 1, 0, 0, 0);
while (temp.DayOfWeek != DayOfWeek.Sunday)
{
temp = temp.AddDays(1);
}
_thisYearDaylightSavingTimeEnd = temp.AddHours(TIMEZONE_OFFSET_DAY_SAVING_LIGHT);
}
return _thisYearDaylightSavingTimeEnd;
}
}
}
}
......@@ -304,6 +304,20 @@ namespace AutoTurnOver.Utility
return Math.Round(val, 1);
}
/// <summary>
/// 美国夏令时间转北京时间
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static DateTime AMESTimeToBeijinTime(this DateTime s)
{
return AMESTime.AMESTimeToBeijingTime(s);
}
public static DateTime BeijingTimeToAMESTime(this DateTime s)
{
return AMESTime.BeijingTimeToAMESTime(s);
}
}
}
......@@ -42,6 +42,12 @@ namespace ResetOutofstock
//report.ShopifyJitInventory();
//daily.ResetOrders7();
//lm_dao.ChangeWarehouseStockUp();
//report_invest_return_dao.SynchPpsSku();
// report_invest_return_dao.SynchBtmAdFees();
//report_invest_return_dao.ShareAdFee();
//report_invest_return_dao.SynchBtmOrderRefund();
}
catch (Exception ex)
{
......
......@@ -517,6 +517,78 @@ namespace ResetOutofstock
}
});
Task.Factory.StartNew(() =>
{
while (true)
{
try
{
Console.WriteLine($"开始 拉取pps sku,线程Id:{Thread.CurrentThread.ManagedThreadId},{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
report_invest_return_dao.SynchPpsSku();
Console.WriteLine($"结束 拉取pps sku,线程Id:{Thread.CurrentThread.ManagedThreadId},{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
Thread.Sleep(10 * 60 * 1000);
}
catch (Exception ex)
{
Console.WriteLine(" 拉取pps sku:" + ex.Message);
Console.WriteLine(" 拉取 pps sku:" + ex.StackTrace);
}
}
});
Task.Factory.StartNew(() =>
{
while (true)
{
try
{
Console.WriteLine($"开始 拉取btm fee,线程Id:{Thread.CurrentThread.ManagedThreadId},{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
report_invest_return_dao.SynchBtmAdFees();
report_invest_return_dao.SynchBtmOrderRefund();
Console.WriteLine($"结束 拉取 btm fee,线程Id:{Thread.CurrentThread.ManagedThreadId},{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
Thread.Sleep(10 * 60 * 1000);
}
catch (Exception ex)
{
Console.WriteLine(" 拉取 btm fee:" + ex.Message);
Console.WriteLine(" 拉取 btm fee:" + ex.StackTrace);
}
}
});
Task.Factory.StartNew(() =>
{
while (true)
{
try
{
Console.WriteLine($"开始 分摊广告费,线程Id:{Thread.CurrentThread.ManagedThreadId},{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
report_invest_return_dao.ShareAdFee();
Console.WriteLine($"结束 分摊广告费,线程Id:{Thread.CurrentThread.ManagedThreadId},{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
Thread.Sleep(10 * 60 * 1000);
}
catch (Exception ex)
{
Console.WriteLine(" 分摊广告费:" + ex.Message);
Console.WriteLine(" 分摊广告费 :" + ex.StackTrace);
}
}
});
......
......@@ -29,7 +29,8 @@
"api_trans_temp_schedule": "http://api.wms.bailuntec.com/api/services/app/AllotScheduleService/GetTempSchedulePageList",
"pps-sys": {
"review": "https://pps.bailuntec.com/Api/amazon/analyze/Download/GetReviewInfoBy",
"pps_sell_product": "http://pps.bailuntec.com/WalmartApi/Publish/GetWithSellProductAsync"
"pps_sell_product": "http://pps.bailuntec.com/WalmartApi/Publish/GetWithSellProductAsync",
"GetSkus": "https://pps.bailuntec.com/Api/ShopifyPublish/PublishDetail/GetShopifySkuStocks"
},
"prod-sys": {
"order": "http://mjzz.bailuntec.com/api/ApiOrderList"
......@@ -48,5 +49,9 @@
},
"Trans": {
"AimsCreateAllotSchedule": "http://api.wms.bailuntec.com/api/services/app/AllotScheduleService/AimsCreateAllotSchedule"
},
"btm-sys": {
"ad-fee": "http://btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeDayFull",
"order-refund": "http://btm.bailuntec.com/ScrmApi/api/ApiGetOrderRefundLog"
}
}
......@@ -30,7 +30,8 @@
"api_trans_temp_schedule": "http://api.wms.bailuntec.com/api/services/app/AllotScheduleService/GetTempSchedulePageList",
"pps-sys": {
"review": "https://pps.bailuntec.com/Api/amazon/analyze/Download/GetReviewInfoBy",
"pps_sell_product": "http://pps.bailuntec.com/WalmartApi/Publish/GetWithSellProductAsync"
"pps_sell_product": "http://pps.bailuntec.com/WalmartApi/Publish/GetWithSellProductAsync",
"GetSkus": "https://pps.bailuntec.com/Api/ShopifyPublish/PublishDetail/GetShopifySkuStocks"
},
"prod-sys": {
"order": "http://mjzz.bailuntec.com/api/ApiOrderList"
......@@ -49,5 +50,9 @@
},
"Trans": {
"AimsCreateAllotSchedule": "http://api.wms.bailuntec.com/api/services/app/AllotScheduleService/AimsCreateAllotSchedule"
},
"btm-sys": {
"ad-fee": "http://btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeDayFull",
"order-refund": "http://btm.bailuntec.com/ScrmApi/api/ApiGetOrderRefundLog"
}
}
......@@ -29,7 +29,8 @@
"api_trans_temp_schedule": "http://api.wms.bailuntec.com/api/services/app/AllotScheduleService/GetTempSchedulePageList",
"pps-sys": {
"review": "https://pps.bailuntec.com/Api/amazon/analyze/Download/GetReviewInfoBy",
"pps_sell_product": "http://pps.bailuntec.com/WalmartApi/Publish/GetWithSellProductAsync"
"pps_sell_product": "http://pps.bailuntec.com/WalmartApi/Publish/GetWithSellProductAsync",
"GetSkus": "https://pps.bailuntec.com/Api/ShopifyPublish/PublishDetail/GetShopifySkuStocks"
},
"prod-sys": {
"order": "http://mjzz.bailuntec.com/api/ApiOrderList"
......@@ -48,6 +49,10 @@
},
"Trans": {
"AimsCreateAllotSchedule": "http://api.wms.bailuntec.com/api/services/app/AllotScheduleService/AimsCreateAllotSchedule"
},
"btm-sys": {
"ad-fee": "http://btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeDayFull",
"order-refund": "http://btm.bailuntec.com/ScrmApi/api/ApiGetOrderRefundLog"
}
}
\ No newline at end of file
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