Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
DataCenter_Core2.1_20190520
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bltdc
DataCenter_Core2.1_20190520
Commits
fa8675d4
Commit
fa8675d4
authored
Oct 09, 2022
by
jianshuqin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加ShopifyGoogle平台广告费
parent
0af4a598
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
25 deletions
+31
-25
Services.cs
Bailun.DC.SyncShopifyFee/Services.cs
+31
-25
No files found.
Bailun.DC.SyncShopifyFee/Services.cs
View file @
fa8675d4
...
...
@@ -13,19 +13,20 @@ namespace Bailun.DC.SyncShopifyFee
public
class
Services
:
BackgroundService
{
IDictionary
<
string
,
string
>
dicWebsiteUrl
=
new
Dictionary
<
string
,
string
>
{
{
"scrm"
,
"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
{
"au2"
,
"http://au2.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
{
"fr"
,
"http://fr.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
{
"td"
,
"http://td.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
{
"us"
,
"http://us.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
{
"us3"
,
"http://us3.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
IDictionary
<
string
,
string
>
dicWebsitePlatform
=
new
Dictionary
<
string
,
string
>
{
{
"scrm_Facebook"
,
"http://scrm.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
{
"au_Facebook"
,
"http://au.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
{
"de_Facebook"
,
"http://de.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
{
"my_Facebook"
,
"http://my.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
{
"uk_Facebook"
,
"http://uk.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
{
"us2_Facebook"
,
"http://us2.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
;
...
...
@@ -59,15 +60,19 @@ namespace Bailun.DC.SyncShopifyFee
public
void
Init
(
DateTime
?
btime
=
null
,
DateTime
?
etime
=
null
)
{
foreach
(
KeyValuePair
<
string
,
string
>
website
Url
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
pagesize
=
1000
;
var
count
=
0
;
if
(!
btime
.
HasValue
)
{
btime
=
this
.
GetBtime
(
website
Url
.
Key
);
btime
=
this
.
GetBtime
(
website
,
platform
);
}
if
(!
etime
.
HasValue
)
{
...
...
@@ -78,7 +83,7 @@ namespace Bailun.DC.SyncShopifyFee
{
try
{
var
result
=
Common
.
HttpHelper
.
NetHelper
.
Request
(
$"
{
website
Url
.
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
))
{
var
json
=
JsonConvert
.
DeserializeObject
<
response_result
>(
result
);
...
...
@@ -86,7 +91,7 @@ namespace Bailun.DC.SyncShopifyFee
if
(
json
.
success
&&
count
>
0
)
{
//保存数据
Save
(
website
Url
.
Key
,
json
.
data
);
Save
(
website
,
platform
,
json
.
data
);
}
page
++;
}
...
...
@@ -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
insertCount
=
0
;
...
...
@@ -115,7 +120,8 @@ namespace Bailun.DC.SyncShopifyFee
var
m
=
JsonConvert
.
DeserializeObject
<
dc_base_finance_shopify_fee
>(
JsonConvert
.
SerializeObject
(
item
));
m
.
gmt_modified
=
DateTime
.
Now
;
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
)
{
m
.
gmt_create
=
DateTime
.
Now
;
...
...
@@ -127,11 +133,11 @@ namespace Bailun.DC.SyncShopifyFee
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
);
using
(
var
db
=
new
MySqlConnection
(
Common
.
GlobalConfig
.
ConnectionString_Data
))
...
...
@@ -140,9 +146,9 @@ namespace Bailun.DC.SyncShopifyFee
{
db
.
Open
();
}
string
sql
=
"select DATE_FORMAT(max(ts),'%Y-%m-%d %H:00:00') from dc_base_finance_shopify_fee where website = @website"
;
btime
=
db
.
QueryFirstOrDefault
<
DateTime
?>(
sql
,
new
{
website
=
website
})
??
DateTime
.
Now
.
AddHours
(-
2
);
Console
.
WriteLine
(
$"同步
{
website
}
的shopify广告费开始时间为
{
btime
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
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
,
platform
=
platform
})
??
DateTime
.
Now
.
AddHours
(-
2
);
Console
.
WriteLine
(
$"同步
{
website
}
的shopify广告费开始时间为
{
btime
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
"
);
}
return
btime
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment