Browse Source

fix múi giờ

student 1 tháng trước cách đây
mục cha
commit
0a19d45226

+ 10 - 10
Kitty_Fall/Kitty_Fall/Kitty_Fall.Apis/Business/Game/GameBusinessImpl.cs

@@ -63,7 +63,7 @@ namespace Kitty_Fall.Apis.Business.Game
                 var pageNumber = request.pageNumber.GetValueOrDefault(1);
                 if (pageNumber <= 0) pageNumber = 1;
 
-                var today = DateTime.Now.Date;
+                var today = MyanmarClock.Now.Date;
                 var defaultFromDate = today.AddDays(-30);
                 var fromDate = ParseHistoryDate(request.fromDate) ?? defaultFromDate;
                 var toDate = ParseHistoryDate(request.toDate) ?? today;
@@ -122,7 +122,7 @@ namespace Kitty_Fall.Apis.Business.Game
                     .Where(x => pageSessionIds.Contains(x.SessionId))
                     .ToListAsync();
 
-                var now = DateTime.Now;
+                var now = MyanmarClock.Now;
                 var startOfMonth = new DateTime(now.Year, now.Month, 1);
                 var monthKey = now.Year * 100 + now.Month;
                 var totalTurn = await GetAvailableTurnAsync(msisdn, now);
@@ -255,7 +255,7 @@ namespace Kitty_Fall.Apis.Business.Game
                 var pageNumber = request.pageNumber.GetValueOrDefault(1);
                 if (pageNumber <= 0) pageNumber = 1;
 
-                var now = DateTime.Now;
+                var now = MyanmarClock.Now;
                 var startOfMonth = new DateTime(now.Year, now.Month, 1);
                 var monthKey = now.Year * 100 + now.Month;
 
@@ -401,7 +401,7 @@ namespace Kitty_Fall.Apis.Business.Game
                 if (pageSize <= 0) pageSize = 15;
                 if (pageSize > 50) pageSize = 50;
 
-                var today = DateTime.Now.Date;
+                var today = MyanmarClock.Now.Date;
                 var startOfCurrentMonth = new DateTime(today.Year, today.Month, 1);
                 var selectedDate = ParseHistoryDate(request.selectedDate) ?? today;
                 if (selectedDate < startOfCurrentMonth) selectedDate = startOfCurrentMonth;
@@ -418,7 +418,7 @@ namespace Kitty_Fall.Apis.Business.Game
                     return CommonLogic.BuildResponse(url, json, CommonErrorCode.Error, Lang.accountInvalid, new { });
                 }
 
-                var now = DateTime.Now;
+                var now = MyanmarClock.Now;
                 var startOfMonth = new DateTime(now.Year, now.Month, 1);
                 var monthKey = now.Year * 100 + now.Month;
                 var totalTurn = await GetAvailableTurnAsync(msisdn, now);
@@ -523,7 +523,7 @@ namespace Kitty_Fall.Apis.Business.Game
                     return CommonLogic.BuildResponse(url, json, CommonErrorCode.Error, Lang.msisdnInvalid, new { });
                 }
 
-                var today = DateTime.Now.Date;
+                var today = MyanmarClock.Now.Date;
                 var currentMonth = new DateTime(today.Year, today.Month, 1);
                 var minMonth = currentMonth.AddMonths(-11);
                 var maxMonthKey = ToMonthKey(currentMonth);
@@ -542,7 +542,7 @@ namespace Kitty_Fall.Apis.Business.Game
                     return CommonLogic.BuildResponse(url, json, CommonErrorCode.Error, Lang.accountInvalid, new { });
                 }
 
-                var now = DateTime.Now;
+                var now = MyanmarClock.Now;
                 var startOfMonth = new DateTime(now.Year, now.Month, 1);
                 var currentMonthKey = now.Year * 100 + now.Month;
                 var totalTurn = await GetAvailableTurnAsync(msisdn, now);
@@ -645,7 +645,7 @@ namespace Kitty_Fall.Apis.Business.Game
                     return CommonLogic.BuildResponse(url, json, CommonErrorCode.Error, Lang.missingTransactionId, new { });
                 }
 
-                var now = DateTime.Now;
+                var now = MyanmarClock.Now;
                 var mode = await GetGameModeAsync(request.gameType);
                 if (mode == null) return CommonLogic.BuildResponse(url, json, CommonErrorCode.Error, Lang.gameModeNotConfigured, new { });
                 var levelNo = NormalizeRequestedLevel(request.level);
@@ -759,7 +759,7 @@ namespace Kitty_Fall.Apis.Business.Game
                     return CommonLogic.BuildResponse(url, json, CommonErrorCode.Error, Lang.missingTransactionId, new { });
                 }
 
-                var now = DateTime.Now;
+                var now = MyanmarClock.Now;
                 var mode = await GetGameModeAsync(request.gameType);
                 if (mode == null) return CommonLogic.BuildResponse(url, json, CommonErrorCode.Error, Lang.gameModeNotConfigured, new { });
                 var levelNo = NormalizeRequestedLevel(request.level);
@@ -1393,7 +1393,7 @@ namespace Kitty_Fall.Apis.Business.Game
         {
             var year = monthKey / 100;
             var month = monthKey % 100;
-            if (year < 1900 || month < 1 || month > 12) return new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
+            if (year < 1900 || month < 1 || month > 12) return new DateTime(MyanmarClock.Now.Year, MyanmarClock.Now.Month, 1);
             return new DateTime(year, month, 1);
         }
 

+ 18 - 18
Kitty_Fall/Kitty_Fall/Kitty_Fall.Apis/Business/User/UserBusinessImpl.cs

@@ -182,7 +182,7 @@ namespace Kitty_Fall.Apis.Business.User
                 {
                     userPackage = new List<RegInfo>();
                 }
-                DateTime currentTime = DateTime.Now.Date;
+                DateTime currentTime = MyanmarClock.Now.Date;
                 DateTime startDate = currentTime.Date; // 00:00:00
                 DateTime endDate = currentTime.Date.AddDays(1).AddSeconds(-1); // 23:59:59
                 return CommonLogic.BuildResponse(
@@ -330,7 +330,7 @@ namespace Kitty_Fall.Apis.Business.User
                 {
                     userPackage = new List<RegInfo>();
                 }
-                var now = DateTime.Now;
+                var now = MyanmarClock.Now;
                 var startOfMonth = new DateTime(now.Year, now.Month, 1);
                 var startOfNextMonth = startOfMonth.AddMonths(1);
                 var monthKey = now.Year * 100 + now.Month;
@@ -921,8 +921,8 @@ namespace Kitty_Fall.Apis.Business.User
                         //Otp = mOtp,
                         Otp = "111111",
                         TimeLeft = 5,
-                        CreatedTime = DateTime.Now,
-                        ValidTime = DateTime.Now.AddMinutes(5),
+                        CreatedTime = MyanmarClock.Now,
+                        ValidTime = MyanmarClock.Now.AddMinutes(5),
                         TransactionId = transCode
                     };
 
@@ -930,7 +930,7 @@ namespace Kitty_Fall.Apis.Business.User
                 }
                 else
                 {
-                    if ((otpSender.ValidTime - DateTime.Now).TotalSeconds >= 0 && otpSender.TimeLeft == 0)
+                    if ((otpSender.ValidTime - MyanmarClock.Now).TotalSeconds >= 0 && otpSender.TimeLeft == 0)
                     {
                         return CommonLogic.BuildResponse(
                             url,
@@ -945,10 +945,10 @@ namespace Kitty_Fall.Apis.Business.User
                     otpSender.Otp = "111111";
                     otpSender.TransactionId = transCode;
                     otpSender.TimeLeft = otpSender.TimeLeft <= 0 ? 5 : otpSender.TimeLeft - 1;
-                    otpSender.CreatedTime = DateTime.Now;
-                    if ((otpSender.ValidTime - DateTime.Now).TotalSeconds <= 0 && otpSender.TimeLeft == 0)
+                    otpSender.CreatedTime = MyanmarClock.Now;
+                    if ((otpSender.ValidTime - MyanmarClock.Now).TotalSeconds <= 0 && otpSender.TimeLeft == 0)
                     {
-                        otpSender.ValidTime = DateTime.Now.AddMinutes(5);
+                        otpSender.ValidTime = MyanmarClock.Now.AddMinutes(5);
                     }
 
                 }
@@ -1041,15 +1041,15 @@ namespace Kitty_Fall.Apis.Business.User
                         Otp = mOtp,
                         //Otp = "11111",
                         TimeLeft = 5,
-                        CreatedTime = DateTime.Now,
-                        ValidTime = DateTime.Now.AddMinutes(5),
+                        CreatedTime = MyanmarClock.Now,
+                        ValidTime = MyanmarClock.Now.AddMinutes(5),
                         TransactionId = Logic.GenCode(8, 8) ?? ""
                     };
                     isTrans = true;
                 }
                 else
                 {
-                    if ((otpSender.ValidTime - DateTime.Now).TotalSeconds <= 0 && otpSender.TimeLeft <= 0)
+                    if ((otpSender.ValidTime - MyanmarClock.Now).TotalSeconds <= 0 && otpSender.TimeLeft <= 0)
                     {
                         return CommonLogic.BuildResponse(
                             url,
@@ -1066,9 +1066,9 @@ namespace Kitty_Fall.Apis.Business.User
                         otpSender.TimeLeft = otpSender.TimeLeft <= 0 ? 5 : otpSender.TimeLeft - 1;
                         if (otpSender.TimeLeft <= 0)
                         {
-                            otpSender.ValidTime = DateTime.Now.AddMinutes(5);
+                            otpSender.ValidTime = MyanmarClock.Now.AddMinutes(5);
                         }
-                        otpSender.CreatedTime = DateTime.Now;
+                        otpSender.CreatedTime = MyanmarClock.Now;
                     }
                 }
                 dbContext.TransactionActions.Add(otpSender);
@@ -1160,7 +1160,7 @@ namespace Kitty_Fall.Apis.Business.User
                 }
                 else
                 {
-                    if (otpSender.CreatedTime.AddMinutes(5) <= DateTime.Now)
+                    if (otpSender.CreatedTime.AddMinutes(5) <= MyanmarClock.Now)
                     {
                         return CommonLogic.BuildResponse(
                             url,
@@ -1188,7 +1188,7 @@ namespace Kitty_Fall.Apis.Business.User
                 }
 
 
-                var now = DateTime.Now;
+                var now = MyanmarClock.Now;
                 var startOfMonth = new DateTime(now.Year, now.Month, 1);
                 var endOfMonth = startOfMonth.AddMonths(1).AddDays(-1);
 
@@ -1257,7 +1257,7 @@ namespace Kitty_Fall.Apis.Business.User
                     }
                 }
 
-                var now = DateTime.Now;
+                var now = MyanmarClock.Now;
                 var account = await dbContext.AccountUsers
                     .Where(x => x.Msisdn == msisdn)
                     .OrderByDescending(x => x.Id)
@@ -1431,7 +1431,7 @@ namespace Kitty_Fall.Apis.Business.User
                 {
                     userPackage = new List<RegInfo>();
                 }
-                DateTime currentTime = DateTime.Now.Date;
+                DateTime currentTime = MyanmarClock.Now.Date;
                 DateTime startDate = currentTime.Date; // 00:00:00
                 DateTime endDate = currentTime.Date.AddDays(1).AddSeconds(-1); // 23:59:59
                 return CommonLogic.BuildResponse(
@@ -1513,7 +1513,7 @@ namespace Kitty_Fall.Apis.Business.User
                 //}
                 if (!string.IsNullOrEmpty(request.picture)) user.Picture = request.picture;
 
-                user.UpdateDate = DateTime.Now;
+                user.UpdateDate = MyanmarClock.Now;
                 await dbContext.SaveChangesAsync();
 
                 return CommonLogic.BuildResponse(url, json, CommonErrorCode.SUCCESS, "Profile updated successfully", user);

+ 13 - 0
Kitty_Fall/Kitty_Fall/Kitty_Fall.Apis/Common/MyanmarClock.cs

@@ -0,0 +1,13 @@
+namespace Kitty_Fall.Apis.Common
+{
+    /// <summary>
+    /// Business clock used for Oracle DATE values and Myanmar calendar boundaries.
+    /// It does not depend on the operating system or container time zone.
+    /// </summary>
+    public static class MyanmarClock
+    {
+        private static readonly TimeSpan MyanmarOffset = TimeSpan.FromHours(6.5);
+
+        public static DateTime Now => DateTimeOffset.UtcNow.ToOffset(MyanmarOffset).DateTime;
+    }
+}

+ 1 - 1
Kitty_Fall/Kitty_Fall/Kitty_Fall.Apis/Common/SubscriptionAccessHelper.cs

@@ -55,7 +55,7 @@ namespace Kitty_Fall.Apis.Common
                 .ToListAsync();
             if (activeRegInfos.Count == 0) return false;
 
-            var now = DateTime.Now;
+            var now = MyanmarClock.Now;
             var todayStart = now.Date;
             var tomorrowStart = todayStart.AddDays(1);
 

+ 2 - 2
Kitty_Fall/Kitty_Fall/Kitty_Fall.Apis/appsettings.json

@@ -1,8 +1,8 @@
 {
   //"Connection": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORA12C)));User Id=KittyFall;Password=HHwx4ISVN51cDam;Connection Timeout=120;",
   "Connection": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1539))(CONNECT_DATA=(SERVICE_NAME=ORA12C)));User Id=Kitty_Fall;Password=123456;Connection Timeout=120;",
-  //"OracleSessionTimeZone": "+06:30",
-  "OracleSessionTimeZone": "+00:00",
+  "OracleSessionTimeZone": "+06:30",
+  // "OracleSessionTimeZone": "+00:00",
   "CountryCode": "95",
   "MyIdVerifySubscription": false,
   "MyIdSubscriptionUrl": "https://apis.mytel.com.mm/myid-login/v1.0/api/individual/subscription?offset=0&limit=20",

+ 1 - 1
Kitty_Fall/Kitty_Fall/Kitty_Fall.Woker/Services/GameRewardPayoutWorker.cs

@@ -184,7 +184,7 @@ namespace Kitty_Fall.Woker.Services
                         INSERT INTO CHARGE_LOG
                             (ID, MSISDN, FEE, CHARGE_TIME, INSERT_TIME, DESCRIPTION, ACCOUNT_ID, STATUS)
                         VALUES
-                            (CHARGE_LOG_SEQ.NEXTVAL, {rewardLog.Msisdn}, {chargeFee}, {now}, SYSDATE,
+                            (CHARGE_LOG_SEQ.NEXTVAL, {rewardLog.Msisdn}, {chargeFee}, {now}, {now},
                              {chargeDescription}, NULL, {chargeStatus})", cancellationToken);
                     await dbContext.SaveChangesAsync(cancellationToken);
                     await transaction.CommitAsync(cancellationToken);