|
|
@@ -18,6 +18,7 @@ namespace molilian.core
|
|
|
|
|
|
private static readonly object _lockObj = new();
|
|
|
private static IEnumerable<CpsLinksDTO> _links_cached;
|
|
|
+ private static IEnumerable<CpsApiStyleDTO> _api_style_cached;
|
|
|
private static IEnumerable<CpsPoolDTO> _cached;
|
|
|
|
|
|
public static CpsLinksDTO? GetOne(string channel)
|
|
|
@@ -49,7 +50,6 @@ namespace molilian.core
|
|
|
if (randomValue < accumulatedWeight)
|
|
|
return link;
|
|
|
}
|
|
|
-
|
|
|
// 保险起见返回第一个
|
|
|
return eligibleLinks.First();
|
|
|
}
|
|
|
@@ -114,11 +114,6 @@ namespace molilian.core
|
|
|
|
|
|
public static IEnumerable<CpsPoolDTO> List(bool force = false)
|
|
|
{
|
|
|
-#if DEBUG
|
|
|
- return new DBContext.Table("cps_pool")
|
|
|
- .Where("status=@status", new { status = 1 })
|
|
|
- .Select<CpsPoolDTO>();
|
|
|
-#else
|
|
|
|
|
|
if (!force && _cached != null) return _cached;
|
|
|
|
|
|
@@ -137,23 +132,10 @@ namespace molilian.core
|
|
|
}
|
|
|
_cached = list;
|
|
|
return list;
|
|
|
-#endif
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
public static IEnumerable<CpsLinksDTO> LinksList(bool force = false)
|
|
|
{
|
|
|
-#if DEBUG
|
|
|
- var list = new DBContext.Table("cps_links")
|
|
|
- .Where("status=@status", new { status = 1 })
|
|
|
- .Select<CpsLinksDTO>();
|
|
|
- foreach (var item in list)
|
|
|
- {
|
|
|
- RiskControlCore.SetCallsAsync(TkChannelEnum.cps, item.id, DateTime.Now.ToString("yyyyMMddHH"), item.current_hourly_calls);
|
|
|
- RiskControlCore.SetCallsAsync(TkChannelEnum.cps, item.id, DateTime.Now.ToString("yyyyMMdd"), item.current_daily_calls);
|
|
|
- }
|
|
|
- return list;
|
|
|
-
|
|
|
-#else
|
|
|
if (!force && _links_cached != null) return _links_cached;
|
|
|
|
|
|
string cache_key = $"cache:cps_links";
|
|
|
@@ -176,7 +158,27 @@ namespace molilian.core
|
|
|
}
|
|
|
_links_cached = list;
|
|
|
return list;
|
|
|
-#endif
|
|
|
+ }
|
|
|
+
|
|
|
+ public static IEnumerable<CpsApiStyleDTO> ApiStyleList(bool force = false)
|
|
|
+ {
|
|
|
+ if (!force && _api_style_cached != null) return _api_style_cached;
|
|
|
+
|
|
|
+ string cache_key = $"cache:cps_api_style";
|
|
|
+ var list = RedisHelper.Get<IEnumerable<CpsApiStyleDTO>>(cache_key);
|
|
|
+ if (force || list == null)
|
|
|
+ {
|
|
|
+ lock (_lockObj)
|
|
|
+ {
|
|
|
+ list = new DBContext.Table("cps_api_syle")
|
|
|
+ .Where("status=@status", new { status = 1 })
|
|
|
+ .Select<CpsApiStyleDTO>();
|
|
|
+ if (list == null) return default;
|
|
|
+ RedisHelper.Set(cache_key, list, 30 * 86400);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _api_style_cached = list;
|
|
|
+ return list;
|
|
|
}
|
|
|
public static int Update(CpsLinksDTO account)
|
|
|
{
|
|
|
@@ -191,6 +193,7 @@ namespace molilian.core
|
|
|
{
|
|
|
_ = List(true);
|
|
|
_ = LinksList(true);
|
|
|
+ _ = ApiStyleList(true);
|
|
|
}
|
|
|
|
|
|
internal static void AccountExhausted()
|
|
|
@@ -208,6 +211,19 @@ namespace molilian.core
|
|
|
_ = NotifyCore.QYWeixinPushNotifyAsync("没账号", $"【CPS优惠券】没有匹配账号");
|
|
|
}
|
|
|
|
|
|
+ public static CpsApiStyleDTO? GetTitle(CpsLinksDTO account, string style)
|
|
|
+ {
|
|
|
+ CpsApiStyleDTO result = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(account.style_code)) return null;
|
|
|
+ var list = ApiStyleList();
|
|
|
+ var record = list?.Where(e => e.style_code == account.style_code && e.style_name == style).FirstOrDefault();
|
|
|
+ if (record != null) result = record;
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|