|
|
@@ -499,7 +499,7 @@ namespace SicboSub.Web.Controllers
|
|
|
|
|
|
if (!string.IsNullOrEmpty(specificDate))
|
|
|
{
|
|
|
- if (rankType == "MONTHLY")
|
|
|
+ if (rankType == "MONTHLY" || rankType == "MONTHLYCOIN")
|
|
|
{
|
|
|
// Expected input: yyyy-MM
|
|
|
if (DateTime.TryParseExact(specificDate, "yyyy-MM", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out DateTime parsedMonth))
|
|
|
@@ -521,7 +521,23 @@ namespace SicboSub.Web.Controllers
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
+ else if (rankType == "DAILYCOIN")
|
|
|
+ {
|
|
|
+ if (DateTime.TryParseExact(specificDate, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out DateTime parsedDate))
|
|
|
+ {
|
|
|
+ fromDate = parsedDate.ToString("dd/MM/yyyy 00:00:00");
|
|
|
+ toDate = parsedDate.ToString("dd/MM/yyyy 23:59:59");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Fallback try basic parsing
|
|
|
+ if (DateTime.TryParse(specificDate, out DateTime parsed))
|
|
|
+ {
|
|
|
+ fromDate = parsed.ToString("dd/MM/yyyy 00:00:00");
|
|
|
+ toDate = parsed.ToString("dd/MM/yyyy 23:59:59");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else
|
|
|
{
|
|
|
// DAILY - Exact Date
|
|
|
// Convert yyyy-MM-dd to dd/MM/yyyy HH:mm:ss
|
|
|
@@ -541,12 +557,12 @@ namespace SicboSub.Web.Controllers
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if (rankType == "DAILY")
|
|
|
+ if (rankType == "DAILY" || rankType == "DAILYCOIN")
|
|
|
{
|
|
|
fromDate = DateTime.Now.ToString("dd/MM/yyyy 00:00:00");
|
|
|
toDate = DateTime.Now.ToString("dd/MM/yyyy 23:59:59");
|
|
|
}
|
|
|
- else if (rankType == "MONTHLY")
|
|
|
+ else if (rankType == "MONTHLY" || rankType == "MONTHLYCOIN")
|
|
|
{
|
|
|
var firstDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
|
|
|
var lastDay = firstDay.AddMonths(1).AddDays(-1);
|
|
|
@@ -559,11 +575,11 @@ namespace SicboSub.Web.Controllers
|
|
|
{
|
|
|
msisdn = msisdn, // Pass specific msisdn or null/empty
|
|
|
lang = GetLanguage(),
|
|
|
- rankType = rankType,
|
|
|
+ rankType = (rankType == "DAILY" || rankType == "DAILYCOIN") ? "DAILY" : "MONTHLY",
|
|
|
fromDate = fromDate,
|
|
|
toDate = toDate,
|
|
|
pageNumber = 0,
|
|
|
- pageSize = rankType == "DAILY" ? 50 : 5
|
|
|
+ pageSize = (rankType == "DAILY" || rankType == "DAILYCOIN" || rankType == "MONTHLYCOIN") ? 50 : 5
|
|
|
};
|
|
|
|
|
|
var url = GetParameter("Url") + ApiUrlConstant.RankingHistoryUrl;
|
|
|
@@ -583,6 +599,14 @@ namespace SicboSub.Web.Controllers
|
|
|
RankingHistoryRes response = new RankingHistoryRes(resData.data);
|
|
|
if (response.errorCode == CommonErrorCode.Success && response.data != null)
|
|
|
{
|
|
|
+ string currentMsisdn = GetMsisdn();
|
|
|
+ foreach (var item in response.data)
|
|
|
+ {
|
|
|
+ if (item.msisdn != currentMsisdn)
|
|
|
+ {
|
|
|
+ item.msisdn = MaskMsisdn(item.msisdn);
|
|
|
+ }
|
|
|
+ }
|
|
|
return response.data;
|
|
|
}
|
|
|
}
|
|
|
@@ -594,6 +618,150 @@ namespace SicboSub.Web.Controllers
|
|
|
return new List<RankingHistoryItem>();
|
|
|
}
|
|
|
|
|
|
+ [HttpPost]
|
|
|
+ public async Task<IActionResult> GetRankingCoinData([FromBody] RankingHistoryReq request)
|
|
|
+ {
|
|
|
+ if (!IsAuthenticated()) return Json(new { errorCode = CommonErrorCode.UnauthorizedAccess });
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string rankType = request?.rankType ?? "MONTHLYCOIN";
|
|
|
+
|
|
|
+ var specificDate = rankType == "DAILYCOIN" ? DateTime.Now.ToString("yyyy-MM-dd") : DateTime.Now.ToString("yyyy-MM");
|
|
|
+
|
|
|
+ var globalRankings = await LoadRankingCoinHistoryInternal(rankType, null, specificDate);
|
|
|
+ var userRanking = await LoadRankingCoinHistoryInternal(rankType, GetMsisdn(), specificDate);
|
|
|
+ var currentUserItem = userRanking?.FirstOrDefault(x => x.msisdn == GetMsisdn());
|
|
|
+
|
|
|
+ return Json(new {
|
|
|
+ errorCode = CommonErrorCode.Success,
|
|
|
+ data = new { global = globalRankings, user = currentUserItem }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ log.Error("GetRankingCoinData: Error", ex);
|
|
|
+ return Json(new { errorCode = CommonErrorCode.SystemError });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private async Task<List<RankingHistoryItem>> LoadRankingCoinHistoryInternal(string rankType, string msisdn = null, string specificDate = null)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var token = GetToken();
|
|
|
+ // Calculate date range based on rankType
|
|
|
+ string fromDate = "";
|
|
|
+ string toDate = DateTime.Now.ToString("dd/MM/yyyy");
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(specificDate))
|
|
|
+ {
|
|
|
+ if (rankType == "MONTHLYCOIN")
|
|
|
+ {
|
|
|
+ // Expected input: yyyy-MM
|
|
|
+ if (DateTime.TryParseExact(specificDate, "yyyy-MM", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out DateTime parsedMonth))
|
|
|
+ {
|
|
|
+ var firstDay = new DateTime(parsedMonth.Year, parsedMonth.Month, 1);
|
|
|
+ var lastDay = firstDay.AddMonths(1).AddDays(-1);
|
|
|
+
|
|
|
+ fromDate = firstDay.ToString("dd/MM/yyyy 00:00:00");
|
|
|
+ toDate = lastDay.ToString("dd/MM/yyyy 23:59:59");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Fallback try basic parsing
|
|
|
+ if (DateTime.TryParse(specificDate, out DateTime parsed))
|
|
|
+ {
|
|
|
+ var firstDay = new DateTime(parsed.Year, parsed.Month, 1);
|
|
|
+ var lastDay = firstDay.AddMonths(1).AddDays(-1);
|
|
|
+ fromDate = firstDay.ToString("dd/MM/yyyy 00:00:00");
|
|
|
+ toDate = lastDay.ToString("dd/MM/yyyy 23:59:59");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (rankType == "DAILYCOIN")
|
|
|
+ {
|
|
|
+ if (DateTime.TryParseExact(specificDate, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out DateTime parsedDate))
|
|
|
+ {
|
|
|
+ fromDate = parsedDate.ToString("dd/MM/yyyy 00:00:00");
|
|
|
+ toDate = parsedDate.ToString("dd/MM/yyyy 23:59:59");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Fallback try basic parsing
|
|
|
+ if (DateTime.TryParse(specificDate, out DateTime parsed))
|
|
|
+ {
|
|
|
+ fromDate = parsed.ToString("dd/MM/yyyy 00:00:00");
|
|
|
+ toDate = parsed.ToString("dd/MM/yyyy 23:59:59");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (rankType == "DAILYCOIN")
|
|
|
+ {
|
|
|
+ fromDate = DateTime.Now.ToString("dd/MM/yyyy 00:00:00");
|
|
|
+ toDate = DateTime.Now.ToString("dd/MM/yyyy 23:59:59");
|
|
|
+ }
|
|
|
+ else if (rankType == "MONTHLYCOIN")
|
|
|
+ {
|
|
|
+ var firstDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
|
|
|
+ var lastDay = firstDay.AddMonths(1).AddDays(-1);
|
|
|
+ fromDate = firstDay.ToString("dd/MM/yyyy 00:00:00");
|
|
|
+ toDate = lastDay.ToString("dd/MM/yyyy 23:59:59");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var request = new RankingHistoryReq
|
|
|
+ {
|
|
|
+ msisdn = msisdn, // Pass specific msisdn or null/empty
|
|
|
+ lang = GetLanguage(),
|
|
|
+ rankType = (rankType == "DAILY" || rankType == "DAILYCOIN") ? "DAILY" : "MONTHLY",
|
|
|
+ fromDate = fromDate,
|
|
|
+ toDate = toDate,
|
|
|
+ pageNumber = 0,
|
|
|
+ pageSize = (rankType == "DAILY" || rankType == "DAILYCOIN" || rankType == "MONTHLYCOIN") ? 50 : 5
|
|
|
+ };
|
|
|
+
|
|
|
+ var url = GetParameter("Url") + ApiUrlConstant.RankingCointHistoryUrl;
|
|
|
+
|
|
|
+ var resData = await DotnetLib.Rest.RestHandler.SendPostWithAuthen(
|
|
|
+ log,
|
|
|
+ url,
|
|
|
+ request,
|
|
|
+ token,
|
|
|
+ token,
|
|
|
+ "",
|
|
|
+ GetLanguage()
|
|
|
+ );
|
|
|
+
|
|
|
+ if (resData != null)
|
|
|
+ {
|
|
|
+ RankingHistoryRes response = new RankingHistoryRes(resData.data);
|
|
|
+ if (response.errorCode == CommonErrorCode.Success && response.data != null)
|
|
|
+ {
|
|
|
+ string currentMsisdn = GetMsisdn();
|
|
|
+ foreach (var item in response.data)
|
|
|
+ {
|
|
|
+ if (item.msisdn != currentMsisdn)
|
|
|
+ {
|
|
|
+ item.msisdn = MaskMsisdn(item.msisdn);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return response.data;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ log.Error($"LoadRankingInternal ({rankType}): Error", ex);
|
|
|
+ }
|
|
|
+ return new List<RankingHistoryItem>();
|
|
|
+ }
|
|
|
+
|
|
|
public async Task<IActionResult> DailyRanking(string date = null)
|
|
|
{
|
|
|
if (!IsAuthenticated()) return RedirectToLogin(_configuration);
|
|
|
@@ -929,5 +1097,30 @@ namespace SicboSub.Web.Controllers
|
|
|
var packages = await LoadPackagesInternal();
|
|
|
return Json(new { errorCode = CommonErrorCode.Success, data = packages });
|
|
|
}
|
|
|
+
|
|
|
+ private string MaskMsisdn(string msisdn)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(msisdn)) return msisdn;
|
|
|
+
|
|
|
+ int len = msisdn.Length;
|
|
|
+ if (len <= 5) return msisdn;
|
|
|
+
|
|
|
+ if (len == 10)
|
|
|
+ {
|
|
|
+ return msisdn.Substring(0, 3) + "xxxxx" + msisdn.Substring(8);
|
|
|
+ }
|
|
|
+ else if (len == 11)
|
|
|
+ {
|
|
|
+ return msisdn.Substring(0, 3) + "xxxxx" + msisdn.Substring(8);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (len > 5) {
|
|
|
+ int maskStart = (len - 5) / 2;
|
|
|
+ return msisdn.Substring(0, maskStart) + "xxxxx" + msisdn.Substring(maskStart + 5);
|
|
|
+ }
|
|
|
+ return msisdn;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|