From 75fad082a71c09da282ae25df7d5ac5fd577c852 Mon Sep 17 00:00:00 2001
From: Client_PangDeRong <593317293@qq.com>
Date: 星期一, 15 十月 2018 11:10:09 +0800
Subject: [PATCH] 4074  【前端】限时抢购开发

---
 System/OpenServerActivity/FlashRushToBuyModel.cs |   99 ++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 85 insertions(+), 14 deletions(-)

diff --git a/System/OpenServerActivity/FlashRushToBuyModel.cs b/System/OpenServerActivity/FlashRushToBuyModel.cs
index 00d49a4..12a0265 100644
--- a/System/OpenServerActivity/FlashRushToBuyModel.cs
+++ b/System/OpenServerActivity/FlashRushToBuyModel.cs
@@ -25,6 +25,10 @@
 
         public void OnPlayerLoginOk()
         {
+            if(!WindowCenter.Instance.IsOpen<OpenServerActivityNotifyWin>())
+            {
+                WindowCenter.Instance.Open<OpenServerActivityNotifyWin>();
+            }
             //UpdateRedpoint();
         }
 
@@ -68,7 +72,7 @@
         public void SetDefaultSelectSaleTime()
         {
             OperationFlashRushToBuy operation = GetOperationFlashRushToBuy();
-            if (!presentFlashShop.Equals(default(OperationFlashRushToBuy.FlashSaleShop)))
+            if (presentFlashShop != null)
             {
                 int seconds = 0;
                 int buyState = operation.GetBuyTimeState(TimeUtility.ServerNow,presentFlashShop.dayIndex,presentFlashShop.timeIndex, out seconds);
@@ -99,7 +103,7 @@
 
         public void ResetFlashShop()
         {
-            presentFlashShop = default(OperationFlashRushToBuy.FlashSaleShop);
+            presentFlashShop = null;
         }
 
         #region 鏈湴鏁版嵁澶勭悊
@@ -107,7 +111,7 @@
         public event Action UpdateSelectSaleTimeEvent;
         public void UpdateSelectFlashSaleTime(int dayIndex,int timeIndex)
         {
-            presentFlashShop = default(OperationFlashRushToBuy.FlashSaleShop);
+            presentFlashShop = null;
             OperationFlashRushToBuy operation = GetOperationFlashRushToBuy();
             if(operation != null)
             {
@@ -134,29 +138,55 @@
         #endregion
 
         #region 鍗忚
-        public event Action UpdateAppointmentEvent;
+        public event Action UpdateAllAppointmentEvent;
+        public event Action<int> UpdateAppointmentEvent;
         public void UpdateFlashSaleAppointmentInfo(HAA18_tagMCFlashSaleAppointmentInfo appointmentInfo)
         {
             var operation = GetOperationFlashRushToBuy();
             if (operation == null) return;
-            for(int i = 0; i < appointmentInfo.GoodsCount; i++)
+
+            if (appointmentInfo.IsAll == 1)
             {
-               for(int j = 0; j < operation.flashShops.Count; j++)
+                for (int j = 0; j < operation.flashShops.Count; j++)
                 {
                     var saleItems = operation.flashShops[j].items;
                     for (int k = 0; k < saleItems.Length; k++)
                     {
-                       if(saleItems[k].shopGuid == appointmentInfo.GoodsList[i])
+                        saleItems[k].isAppointment = 0;
+                    }
+                }
+            }
+
+            for (int i = 0; i < appointmentInfo.GoodsCount; i++)
+            {
+                var saleItemInfo = appointmentInfo.GoodsList[i];
+                for (int j = 0; j < operation.flashShops.Count; j++)
+                {
+                    var saleItems = operation.flashShops[j].items;
+                    for (int k = 0; k < saleItems.Length; k++)
+                    {
+                       if (saleItems[k].shopGuid == saleItemInfo.GoodsMark)
                         {
-                            saleItems[k].isAppointment = 1;
+                            if(saleItems[k].isAppointment != saleItemInfo.State)
+                            {
+                                saleItems[k].isAppointment = saleItemInfo.State;
+                                if(UpdateAppointmentEvent != null)
+                                {
+                                    UpdateAppointmentEvent((int)saleItemInfo.GoodsMark);
+                                }
+                            }
                         }
                     }
                 }
             }
-            if(UpdateAppointmentEvent != null)
+            if(appointmentInfo.IsAll == 1)
             {
-                UpdateAppointmentEvent();
+                if (UpdateAllAppointmentEvent != null)
+                {
+                    UpdateAllAppointmentEvent();
+                }
             }
+
         }
         /// <summary>
         /// Value1  鍟嗗搧ID  Value2 鍏ㄦ湇璐拱娆℃暟
@@ -189,9 +219,10 @@
         /// </summary>
         /// <param name="seconds"></param>
         /// <returns></returns>
-        public FlashRushToBuySate GetActivityState(out int seconds,out OperationTime operationTime)
+        public FlashRushToBuySate GetActivityState(out int seconds,out OperationTime operationTime,out OperationFlashRushToBuy.FlashSaleShop saleShop)
         {
             seconds = 0;
+            saleShop = null;
             operationTime = default(OperationTime);
             var operation = GetOperationFlashRushToBuy();
             if (!IsOpen || operation == null) return FlashRushToBuySate.NoOpen;
@@ -200,11 +231,19 @@
             int endState = 0;
             int openSeconds = 0;
             int endSeconds = 0;
+            for(int i = 0; i < operation.flashShops.Count;i++)
+            {
+                OperationFlashRushToBuy.FlashSaleShop openSaleShop = operation.flashShops[i];
+                operationTime = operation.times[openSaleShop.timeIndex];
+                openState = operation.GetBuyTimeState(TimeUtility.ServerNow, openSaleShop.dayIndex, openSaleShop.timeIndex, out openSeconds);
+                if(openState != 1)
+                {
+                    saleShop = openSaleShop;
+                    break;
+                }
+            }
             if(operation.flashShops.Count > 0)
             {
-                OperationFlashRushToBuy.FlashSaleShop openSaleShop = operation.flashShops[0];
-                operationTime = operation.times[openSaleShop.timeIndex];
-                openState = operation.GetBuyTimeState(TimeUtility.ServerNow, openSaleShop.dayIndex, openSaleShop.timeIndex,out openSeconds);
                 OperationFlashRushToBuy.FlashSaleShop endSaleShop = operation.flashShops[operation.flashShops.Count - 1];
                 endState = operation.GetBuyTimeState(TimeUtility.ServerNow, endSaleShop.dayIndex, endSaleShop.timeIndex, out endSeconds);
             }
@@ -214,6 +253,8 @@
                 case -1:
                     seconds = openSeconds;
                     return FlashRushToBuySate.InAdvance;
+                case 0:
+                    return FlashRushToBuySate.Begining;
             }
 
             switch(endState)
@@ -229,6 +270,36 @@
             }
         }
 
+        public bool CheckIsPush(out OperationFlashRushToBuy.FlashSaleShop saleShop)
+        {
+            int seconds = 0;
+            OperationTime operationTime;
+            saleShop = null;
+            var buyState = GetActivityState(out seconds,out operationTime,out saleShop);
+            switch (buyState)
+            {
+                case FlashRushToBuySate.NoOpen:
+                    break;
+                case FlashRushToBuySate.InAdvance:
+                    if(saleShop != null && seconds <= 180)
+                    {
+                       for(int i = 0; i < saleShop.items.Length; i++)
+                        {
+                            if(saleShop.items[i].isAppointment == 1)
+                            {
+                                return true;
+                            }
+                        }
+                    }
+                    break;
+                case FlashRushToBuySate.Begining:
+                    return true;
+                case FlashRushToBuySate.End:
+                    break;
+            }
+            return false;
+        }
+
         private void OperationEndEvent(Operation type, int state)
         {
             if (type == Operation.FlashRushToBuy && state == 0)

--
Gitblit v1.8.0