Commit fa8675d4 by jianshuqin

增加ShopifyGoogle平台广告费

parent 0af4a598
...@@ -13,19 +13,20 @@ namespace Bailun.DC.SyncShopifyFee ...@@ -13,19 +13,20 @@ namespace Bailun.DC.SyncShopifyFee
public class Services : BackgroundService public class Services : BackgroundService
{ {
IDictionary<string, string> dicWebsiteUrl = new Dictionary<string, string> { IDictionary<string, string> dicWebsitePlatform = new Dictionary<string, string> {
{"scrm", "http://scrm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog" }, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100 {"scrm_Facebook","http://scrm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog" }, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100
{"au", "http://au.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100 {"scrm_Google","http://scrm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLogFull" }, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100
{"au2", "http://au2.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100 {"au_Facebook","http://au.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100
{"de", "http://de.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100 {"au2_Facebook","http://au2.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100
{"fr", "http://fr.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100 {"de_Facebook","http://de.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100
{"my", "http://my.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100 {"fr_Facebook","http://fr.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100
{"td", "http://td.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100 {"my_Facebook","http://my.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100
{"uk", "http://uk.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100 {"td_Facebook","http://td.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100
{"us", "http://us.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100 {"uk_Facebook","http://uk.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100
{"us2", "http://us2.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100 {"us_Facebook","http://us.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100
{"us3", "http://us3.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100 {"us2_Facebook","http://us2.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100
{"us4", "http://us4.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100 {"us3_Facebook","http://us3.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100
{"us4_Facebook","http://us4.btm.bailuntec.com/ScrmApi/api/ApiGetAdFeeLog"}, //?btime=2021-10-01&etime=2021-10-03&page=1&rows=100
}; };
private Timer _timer; private Timer _timer;
...@@ -59,15 +60,19 @@ namespace Bailun.DC.SyncShopifyFee ...@@ -59,15 +60,19 @@ namespace Bailun.DC.SyncShopifyFee
public void Init(DateTime? btime = null, DateTime? etime = null) public void Init(DateTime? btime = null, DateTime? etime = null)
{ {
foreach (KeyValuePair<string, string> websiteUrl in dicWebsiteUrl) foreach (KeyValuePair<string, string> website_platform in dicWebsitePlatform)
{ {
string[] websitePlatform = website_platform.Key.Split("_");
//站点
string website = websitePlatform[0];
//平台
string platform = websitePlatform[1];
var page = 1; var page = 1;
var pagesize = 1000; var pagesize = 1000;
var count = 0; var count = 0;
if (!btime.HasValue) if (!btime.HasValue)
{ {
btime = this.GetBtime(websiteUrl.Key); btime = this.GetBtime(website, platform);
} }
if (!etime.HasValue) if (!etime.HasValue)
{ {
...@@ -78,7 +83,7 @@ namespace Bailun.DC.SyncShopifyFee ...@@ -78,7 +83,7 @@ namespace Bailun.DC.SyncShopifyFee
{ {
try try
{ {
var result = Common.HttpHelper.NetHelper.Request($"{websiteUrl.Value}?btime={btime.Value.ToString("yyyy-MM-dd HH:00:00")}&etime={etime.Value.ToString("yyyy-MM-dd")}&page={page}&rows={pagesize}"); var result = Common.HttpHelper.NetHelper.Request($"{website_platform.Value}?btime={btime.Value.ToString("yyyy-MM-dd HH:00:00")}&etime={etime.Value.ToString("yyyy-MM-dd")}&page={page}&rows={pagesize}");
if (!string.IsNullOrEmpty(result)) if (!string.IsNullOrEmpty(result))
{ {
var json = JsonConvert.DeserializeObject<response_result>(result); var json = JsonConvert.DeserializeObject<response_result>(result);
...@@ -86,7 +91,7 @@ namespace Bailun.DC.SyncShopifyFee ...@@ -86,7 +91,7 @@ namespace Bailun.DC.SyncShopifyFee
if (json.success && count > 0) if (json.success && count > 0)
{ {
//保存数据 //保存数据
Save(websiteUrl.Key, json.data); Save(website, platform, json.data);
} }
page++; page++;
} }
...@@ -100,7 +105,7 @@ namespace Bailun.DC.SyncShopifyFee ...@@ -100,7 +105,7 @@ namespace Bailun.DC.SyncShopifyFee
} }
} }
private void Save(string website, IList<response_shopify_fee> list) private void Save(string website, string platform, IList<response_shopify_fee> list)
{ {
int updateCount = 0; int updateCount = 0;
int insertCount = 0; int insertCount = 0;
...@@ -115,7 +120,8 @@ namespace Bailun.DC.SyncShopifyFee ...@@ -115,7 +120,8 @@ namespace Bailun.DC.SyncShopifyFee
var m = JsonConvert.DeserializeObject<dc_base_finance_shopify_fee>(JsonConvert.SerializeObject(item)); var m = JsonConvert.DeserializeObject<dc_base_finance_shopify_fee>(JsonConvert.SerializeObject(item));
m.gmt_modified = DateTime.Now; m.gmt_modified = DateTime.Now;
m.website = website; m.website = website;
int count = db.Execute("update dc_base_finance_shopify_fee set website = @website, ad_id = @ad_id, ts = @ts, bdate = @bdate, edate = @edate, fee = @fee, account_currency = @account_currency, cny_exchange_rate = @cny_exchange_rate,gmt_modified = @gmt_modified where data_id=@data_id and website=@website", m); m.platform = platform;
int count = db.Execute("update dc_base_finance_shopify_fee set ts = @ts, bdate = @bdate, edate = @edate, fee = @fee, account_currency = @account_currency, cny_exchange_rate = @cny_exchange_rate,gmt_modified = @gmt_modified where data_id=@data_id and website=@website and platform=@platform", m);
if (count == 0) if (count == 0)
{ {
m.gmt_create = DateTime.Now; m.gmt_create = DateTime.Now;
...@@ -127,11 +133,11 @@ namespace Bailun.DC.SyncShopifyFee ...@@ -127,11 +133,11 @@ namespace Bailun.DC.SyncShopifyFee
updateCount++; updateCount++;
} }
} }
Console.WriteLine($"同步{website}shopify广告费新增{insertCount}条数据,更新{updateCount}条数据"); Console.WriteLine($"同步{website}站点{platform}平台的shopify广告费新增{insertCount}条数据,更新{updateCount}条数据");
} }
} }
private DateTime GetBtime(string website) private DateTime GetBtime(string website, string platform)
{ {
DateTime btime = DateTime.Now.AddHours(-2); DateTime btime = DateTime.Now.AddHours(-2);
using (var db = new MySqlConnection(Common.GlobalConfig.ConnectionString_Data)) using (var db = new MySqlConnection(Common.GlobalConfig.ConnectionString_Data))
...@@ -140,9 +146,9 @@ namespace Bailun.DC.SyncShopifyFee ...@@ -140,9 +146,9 @@ namespace Bailun.DC.SyncShopifyFee
{ {
db.Open(); db.Open();
} }
string sql = "select DATE_FORMAT(max(ts),'%Y-%m-%d %H:00:00') from dc_base_finance_shopify_fee where website = @website"; string sql = "select DATE_FORMAT(max(ts),'%Y-%m-%d %H:00:00') from dc_base_finance_shopify_fee where website = @website and platform = @platform";
btime = db.QueryFirstOrDefault<DateTime?>(sql, new { website = website }) ?? DateTime.Now.AddHours(-2); btime = db.QueryFirstOrDefault<DateTime?>(sql, new { website = website, platform = platform }) ?? DateTime.Now.AddHours(-2);
Console.WriteLine($"同步{website}的shopify广告费开始时间为{ btime.ToString("yyyy-MM-dd HH:mm:ss")}"); Console.WriteLine($"同步{website}的shopify广告费开始时间为{btime.ToString("yyyy-MM-dd HH:mm:ss")}");
} }
return btime; return btime;
......
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