少年修仙传客户端代码仓库
client_linchunjie
2018-08-23 522ca3468a56c88cb15eaa428eb7499d3dba386f
System/Store/StoreModel.cs
@@ -1,817 +1,865 @@
using Snxxz.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using TableConfig;
using UnityEngine;
using LitJson;
public class BuyShopItemLimit
{
    public uint ItemIndex;
    public ushort BuyCnt;        // 今日已购买次数
    public int isReset;         //是否属于每月重置  0 不重置 1重置
}
public struct ShopItemInfo
{
    public int itemId;
    public int count;
    public int isBind;
    public ShopItemInfo(int id,int count,int isBind)
    {
        this.itemId = id;
        this.count = count;
        this.isBind = isBind;
    }
}
public class StoreModel : Model,IBeforePlayerDataInitialize,IAfterPlayerDataInitialize,IPlayerLoginOk
{
    public int[] normalBuyCoinsTypes { get; private set; }
    public string UNIONSTORESAVE_KEY { get; private set; }
    public string StoreEffectRecord_Key { get; private set; }
    public List<StoreConfig> shoplist;
    public Dictionary<int,Dictionary<int,int>> JobReplaceIdDict = new Dictionary<int, Dictionary<int, int>>();
    public Dictionary<int, string> resetTimeDict { get; private set; }
    public Dictionary<int, int> showCoinsUIDict { get; private set; }
    public override void Init()
    {
        FuncConfigConfig buyItemHinit = ConfigManager.Instance.GetTemplate<FuncConfigConfig>("BuyItemHinit");
        normalBuyCoinsTypes = ConfigParse.GetMultipleStr<int>(buyItemHinit.Numerical1);
        FuncConfigConfig restTimeConfig = ConfigManager.Instance.GetTemplate<FuncConfigConfig>("RefreshText");
        resetTimeDict = ConfigParse.GetDic<int, string>(restTimeConfig.Numerical1);
        FuncConfigConfig mallCurrency = ConfigManager.Instance.GetTemplate<FuncConfigConfig>("MallCurrency");
        showCoinsUIDict = ConfigParse.GetDic<int, int>(mallCurrency.Numerical1);
    }
    public void OnBeforePlayerDataInitialize()
    {
        shopItemlimitDict.Clear();
        tagTowerModel = null;
        storeFuncType = StoreFunc.WeekStore;
        tcbRefreshDict.Clear();
    }
    public void OnAfterPlayerDataInitialize()
    {
        UNIONSTORESAVE_KEY = StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, LocalSaveStoreType.UnionStore);
        StoreEffectRecord_Key = StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, "StoreEffectRecord");
    }
    public void OnPlayerLoginOk()
    {
        PlayerDatas.Instance.fairyData.OnRefreshFairyInfo -= RefreshFamilyLv;
        PlayerDatas.Instance.fairyData.OnRefreshFairyInfo += RefreshFamilyLv;
        FuncOpen.Instance.OnFuncStateChangeEvent -= FuncStateChange;
        FuncOpen.Instance.OnFuncStateChangeEvent += FuncStateChange;
        PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= RefreshPlayerLv;
        PlayerDatas.Instance.PlayerDataRefreshInfoEvent += RefreshPlayerLv;
        TimeMgr.Instance.OnHourEvent -= RefreshServerHour;
        TimeMgr.Instance.OnHourEvent += RefreshServerHour;
        shoplist = null;
        CheckWeekStoreIsShopBuy(out shoplist);
        ControllerRedPoint();
        SetShopRedpoint();
        CheckShopRedpoint();
        SetJobReplaceIDDict();
    }
    public string GetStoreRefreshTimeByType(int type)
    {
        if (resetTimeDict == null || !resetTimeDict.ContainsKey(type)) return string.Empty;
        switch(type)
        {
            case 7:
                int willRefreshTime = GetWillRefreshTime();
                if(willRefreshTime == 0)
                {
                    return Language.Get("StoreWin201");
                }
                else
                {
                    return Language.Get(resetTimeDict[type],willRefreshTime);
                }
            default:
                return Language.Get(resetTimeDict[type]);
        }
    }
    private int GetWillRefreshTime()
    {
       int willRefresh = (3 - TimeUtility.OpenDay % 3);
       if(willRefresh == 3)
        {
            if(TimeUtility.ServerNow.Hour < 5)
            {
                willRefresh = 0;
            }
        }
        return willRefresh;
    }
    private void RefreshPlayerLv(PlayerDataRefresh type)
    {
        if (type != PlayerDataRefresh.LV && type != PlayerDataRefresh.VIPLv) return;
        CheckShopRedpoint();
    }
    public override void UnInit()
    {
    }
    ItemTipsModel _itemTipsModel;
    ItemTipsModel itemTipsModel
    {
        get
        {
            return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel<ItemTipsModel>());
        }
    }
    #region 职业替换商品逻辑处理
    public void SetJobReplaceIDDict()
    {
        JobReplaceIdDict.Clear();
        List<StoreConfig> storeConfigs = ConfigManager.Instance.GetAllValues<StoreConfig>();
        for(int i = 0; i < storeConfigs.Count; i++)
        {
            Dictionary<int, int> replaceItemDict = new Dictionary<int, int>();
            JobReplaceIdDict.Add(storeConfigs[i].ID,replaceItemDict);
            AnalysisJobReplace(storeConfigs[i]);
            List<ShopItemInfo> shopItems = GetShopItemlistByIndex(storeConfigs[i]);
            for(int j = 0; j < shopItems.Count; j++)
            {
                foreach (var index in jobReplaceDic.Keys)
                {
                    if (jobReplaceDic[index].Contains(shopItems[j].itemId))
                    {
                        int replaceIndex = PlayerDatas.Instance.baseData.Job - 1;
                        int replaceId = jobReplaceDic[index][replaceIndex];
                        replaceItemDict.Add(shopItems[j].itemId,replaceId);
                        break;
                    }
                }
            }
        }
    }
    Dictionary<int, List<int>> jobReplaceDic = new Dictionary<int, List<int>>();
    private void AnalysisJobReplace(StoreConfig storeConfig)
    {
        jobReplaceDic.Clear();
        JsonData jsonData = JsonMapper.ToObject(storeConfig.JobItem);
        if (jsonData.IsArray)
        {
            for (int i = 0; i < jsonData.Count; i++)
            {
                List<int> idlist = new List<int>();
                jobReplaceDic.Add(i, idlist);
                if (jsonData[i].IsArray)
                {
                    for (int j = 0; j < jsonData[i].Count; j++)
                    {
                        int itemId = int.Parse(jsonData[i][j].ToString());
                        idlist.Add(itemId);
                    }
                }
            }
        }
    }
    public int ReplaceItemIdByJob(int storeId,int itemId)
    {
       if(JobReplaceIdDict.ContainsKey(storeId))
        {
            if(JobReplaceIdDict[storeId].ContainsKey(itemId))
            {
                return JobReplaceIdDict[storeId][itemId];
            }
        }
        return itemId;
    }
    #endregion
    private void RefreshFamilyLv()
    {
        int familyLv = PlayerDatas.Instance.fairyData.fairy.FamilyLV;
        if(familyLv > GetSaveFairyLV())
        {
            ControllerRedPoint();
        }
    }
    private void RefreshServerHour()
    {
        ControllerRedPoint();
    }
    public Action RefreshBuyShopLimitEvent;
    public StoreFunc storeFuncType = StoreFunc.WeekStore;
    private Dictionary<uint, BuyShopItemLimit> shopItemlimitDict = new Dictionary<uint, BuyShopItemLimit>();
    private Dictionary<string, RuneTowerFloorConfig> tagTowerModel;
    /// <summary>
    /// 得到物品购买次数
    /// </summary>
    /// <param name="buylimit"></param>
    public void RefreshBuyShopLimitModel(HA802_tagMCShopItemDayBuyCntInfo buylimit)
    {
        DesignDebug.Log("RefreshBuyShopLimitModel" + buylimit.Count);
        if (buylimit.Count > 0)
        {
            int i = 0;
            for (i = 0; i < buylimit.Count; i++)
            {
                if (!shopItemlimitDict.ContainsKey(buylimit.DayBuyCntList[i].ItemIndex))
                {
                    BuyShopItemLimit shopItemLimit = new BuyShopItemLimit();
                    shopItemLimit.ItemIndex = buylimit.DayBuyCntList[i].ItemIndex;
                    shopItemLimit.BuyCnt = buylimit.DayBuyCntList[i].BuyCnt;
                    shopItemLimit.isReset = buylimit.DayBuyCntList[i].IsReset;
                    shopItemlimitDict.Add(shopItemLimit.ItemIndex, shopItemLimit);
                }
                else
                {
                    shopItemlimitDict[buylimit.DayBuyCntList[i].ItemIndex].BuyCnt = buylimit.DayBuyCntList[i].BuyCnt;
                    shopItemlimitDict[buylimit.DayBuyCntList[i].ItemIndex]. isReset = buylimit.DayBuyCntList[i].IsReset;
                }
            }
        }
        CheckShopRedpoint();
        if (RefreshBuyShopLimitEvent != null)
            RefreshBuyShopLimitEvent();
    }
    public BuyShopItemLimit GetBuyShopLimit(uint itemIndex)
    {
        if (shopItemlimitDict.ContainsKey(itemIndex))
        {
            return shopItemlimitDict[itemIndex];
        }
        return null;
    }
    private RuneConfig _tagRuneModel = null;
    public RuneTowerFloorConfig SetRuneSource(int itemId)
    {
        _tagRuneModel = ConfigManager.Instance.GetTemplate<RuneConfig>(itemId);
        if (_tagRuneModel == null)
            return null;
        var _tagRuneTowerModel = ConfigManager.Instance.GetTemplate<RuneTowerFloorConfig>(_tagRuneModel.TowerID);
        return _tagRuneTowerModel;
    }
    List<ShopItemInfo> shopItemlist = new List<ShopItemInfo>();
   public List<ShopItemInfo> GetShopItemlistByIndex(StoreConfig storeConfig)
    {
        if (storeConfig == null) return null;
        shopItemlist.Clear();
        ShopItemInfo shopItem = new ShopItemInfo(storeConfig.ItemID, storeConfig.ItemCnt, storeConfig.IsBind);
        shopItemlist.Add(shopItem);
        JsonData extraItem = JsonMapper.ToObject(storeConfig.ItemListEx);
        if (extraItem.IsArray)
        {
            for (int i = 0; i < extraItem.Count; i++)
            {
                if (extraItem[i].IsArray)
                {
                    if (extraItem[i].Count > 0)
                    {
                        ShopItemInfo shop = new ShopItemInfo(int.Parse(extraItem[i][0].ToString()), int.Parse(extraItem[i][1].ToString()), int.Parse(extraItem[i][2].ToString()));
                        shopItemlist.Add(shop);
                    }
                }
            }
        }
        return shopItemlist;
    }
    public bool TryGetShopItemInfo(StoreFunc _type, int _id, out List<ShopItemInfo> _shopItems)
    {
        _shopItems = null;
        var _list = StoreConfig.GetTypeStoreModel((int)_type, true);
        var _index = _list.FindIndex((x) =>
        {
            return x.ID == _id;
        });
        if (_index == -1)
        {
            return false;
        }
        _shopItems = GetShopItemlistByIndex(_list[_index]);
        return _shopItems != null;
    }
    #region 0418 数据处理
    private Dictionary<PlayerDataRefresh, int> tcbRefreshDict = new Dictionary<PlayerDataRefresh, int>();
    public event Action<PlayerDataRefresh> RefreshTCBPlayerDataEvent;
    public void RefreshTCBPlayerData(H0418_tagObjInfoRefresh info)
    {
        if(!tcbRefreshDict.ContainsKey((PlayerDataRefresh)info.RefreshType))
        {
            tcbRefreshDict.Add((PlayerDataRefresh)info.RefreshType,(int)info.Value);
        }
        else
        {
            tcbRefreshDict[(PlayerDataRefresh)info.RefreshType] = (int)info.Value;
        }
        if(RefreshTCBPlayerDataEvent != null)
        {
            RefreshTCBPlayerDataEvent((PlayerDataRefresh)info.RefreshType);
        }
    }
    public int GetTCBPlayerData(PlayerDataRefresh tCDBPlayer)
    {
        int value = 0;
        tcbRefreshDict.TryGetValue(tCDBPlayer,out value);
        return value;
    }
    #endregion
    #region 点击商店物品逻辑
    public void OnClickShopCell(StoreConfig shopInfo)
    {
        BuyItemPopModel.Instance.SetModel(shopInfo.ID);
        //SetOpenBuyType(chinModel);
        ItemAttrData attrData = new ItemAttrData(ReplaceItemIdByJob(shopInfo.ID,shopInfo.ItemID),true, (ulong)shopInfo.ItemCnt,-1,shopInfo.IsBind,true,PackType.rptDeleted
            ,"",null,ItemTipChildType.Buy);
        itemTipsModel.SetItemTipsModel(attrData);
    }
    #endregion
    private ulong _price;
    public void SendBuyShopItem(StoreConfig model, int count)
    {
        if ((StoreFunc)model.ShopType == StoreFunc.RuneStore)
        {
            _tagRuneModel = ConfigManager.Instance.GetTemplate<RuneConfig>(model.ItemID);
            if (_tagRuneModel != null)
            {
                if (!IsCanBuyItem(_tagRuneModel.TowerID))
                {
                    MessageWin.Inst.ShowFixedTip(Language.Get("Store101"));
                    return;
                }
            }
        }
        _price = (ulong)(model.MoneyNumber * count);
        if (MoneyIsEnough(model.MoneyType, _price))
        {
            C0803_tagCBuyItemList buyShop = new C0803_tagCBuyItemList();
            buyShop.NPCID = 0;
            buyShop.BuyItemIndex = (ushort)model.ID;
            buyShop.BuyCount = (ushort)count;
            GameNetSystem.Instance.SendInfo(buyShop);
        }
        else
        {
            switch(model.MoneyType)
            {
                case 1:
                    if (VersionConfig.Get().isBanShu)
                    {
                        SysNotifyMgr.Instance.ShowTip("GoldErr");
                        return;
                    }
                    WindowCenter.Instance.Open<RechargeTipWin>();
                    break;
                case 25:
                    SysNotifyMgr.Instance.ShowTip("LackXBMoney", model.MoneyType);
                    break;
                default:
                    SysNotifyMgr.Instance.ShowTip("LackMoney", model.MoneyType);
                    break;
            }
        }
    }
    public event Action<int> RefreshBuyResultEvent;
    public void GetBuyResult(HA811_tagMCShoppingResult result)
    {
        DesignDebug.Log("GetBuyResult");
        StoreConfig tagStore = ConfigManager.Instance.GetTemplate<StoreConfig>((int)result.ItemIndex);
        if (tagStore != null)
        {
            if (!normalBuyCoinsTypes.Contains(tagStore.MoneyType))
            {
                if (tagStore.RemindSuccess == 0)
                {
                    return;
                }
                BuySuccessModel.Instance.SetBuySuccessModel(tagStore.ItemID, (int)result.ItemCnt, tagStore.IsBind);
                if (!WindowCenter.Instance.CheckOpen<BuySuccessWin>())
                {
                    WindowCenter.Instance.Open<BuySuccessWin>();
                }
            }
            else
            {
                float costMoney = tagStore.MoneyNumber;
                ItemConfig itemConfig = ConfigManager.Instance.GetTemplate<ItemConfig>(tagStore.ItemID);
                SysNotifyMgr.Instance.ShowTip("BuyItemHinit",costMoney,tagStore.MoneyType,itemConfig.ItemName);
            }
            if (RefreshBuyResultEvent != null)
            {
                RefreshBuyResultEvent(tagStore.ItemID);
            }
        }
    }
    /// <summary>
    /// 用于判断符文塔兑换是否满足条件
    /// </summary>
    /// <param name="limitTower"></param>
    /// <returns></returns>
    public bool IsCanBuyItem(int limitTower)
    {
        int playerTower = (int)ModelCenter.Instance.GetModel<RuneModel>().RuneTowerOpenLV;
        int offset = playerTower - limitTower;
        if (offset >= 0)
            return true;
        else
            return false;
    }
    public bool MoneyIsEnough(int moneyType, ulong money)
    {
        if (UIHelper.GetMoneyCnt(moneyType) < money)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    public int jumpToItemId { get;set;}
    public void SetJumpToModel(int itemId)
    {
        jumpToItemId = itemId;
    }
   #region 仙盟商店逻辑处理
    #region 仙盟红点逻辑处理
    private bool CheckIsBuyNewItem(int fairyLv)
    {
        if(fairyLv > GetSaveFairyLV())
        {
            if (StoreConfig.GetCanBuyShopModel((int)StoreFunc.ToolStore, fairyLv).Count > 0
              || StoreConfig.GetCanBuyShopModel((int)StoreFunc.MountStoneStore, fairyLv).Count > 0
               || StoreConfig.GetCanBuyShopModel((int)StoreFunc.MountSkillBookStore, fairyLv).Count > 0)
            {
                return true;
            }
        }
        return false;
    }
    private bool CheckIsNewMonth()
    {
        GetSaveDateTime();
        if(datelist.Count > 0)
        {
            if(TimeUtility.ServerNow.Month == datelist[0])
            {
                if(TimeUtility.ServerNow.Day >= 1
                    && TimeUtility.ServerNow.Hour >= 5
                    && datelist[1] <= 1 && datelist[2] < 5)
                {
                    return true;
                }
            }
            else
            {
                if(TimeUtility.ServerNow.Day >= 1
                    && TimeUtility.ServerNow.Hour >= 5)
                {
                    return true;
                }
            }
        }
        else
        {
            return true;
        }
        return false;
    }
    List<int> datelist = new List<int>();
    public List<int> GetSaveDateTime()
    {
        datelist.Clear();
        int[] unionArray = LocalSave.GetIntArray(UNIONSTORESAVE_KEY);
        if (unionArray != null && unionArray.Length >= 4)
        {
            datelist.Add(unionArray[1]);
            datelist.Add(unionArray[2]);
            datelist.Add(unionArray[3]);
        }
        return datelist;
    }
    public int GetSaveFairyLV()
    {
        int[] unionArray = LocalSave.GetIntArray(UNIONSTORESAVE_KEY);
        int fairyLv = 0;
        if(unionArray != null)
        {
            return unionArray[0];
        }
        return fairyLv;
    }
    //1仙盟等级 2 月份 3 号 4 几点
    public void SetStoreLocalSave(LocalSaveStoreType saveStoreType,params int[] infos)
    {
        string key = StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, saveStoreType);
        LocalSave.SetIntArray(key,infos);
    }
    public void ControllerRedPoint(bool isLook = false)
    {
        MainRedDot.Instance.fairyStoreRedPoint.state = RedPointState.None;
        if(!ModelCenter.Instance.GetModel<FairyModel>().fairyStoreOpen)
        {
            return;
        }
        int familyLv = PlayerDatas.Instance.fairyData.fairy.FamilyLV;
        if(!isLook)
        {
            if (CheckIsBuyNewItem(familyLv))
            {
                MainRedDot.Instance.fairyStoreRedPoint.state = RedPointState.Simple;
                return;
            }
            if (CheckIsNewMonth())
            {
                MainRedDot.Instance.fairyStoreRedPoint.state = RedPointState.Simple;
                return;
            }
        }
        SetStoreLocalSave(LocalSaveStoreType.UnionStore, familyLv, TimeUtility.ServerNow.Month,
                TimeUtility.ServerNow.Day, TimeUtility.ServerNow.Hour);
    }
    #endregion
    #endregion
    public event Action StoreFuncOpenAct;
    private void FuncStateChange(int funcId)
    {
        if (funcId != (int)FuncOpenEnum.Store) return;
        shoplist = null;
        CheckWeekStoreIsShopBuy(out shoplist);
        if(shoplist.Count > 0)
        {
            if (StoreFuncOpenAct != null)
            {
                StoreFuncOpenAct();
            }
        }
        SetShopRedpoint();
        CheckShopRedpoint();
    }
    public bool CheckWeekStoreIsShopBuy(out List<StoreConfig> buylist)
    {
        buylist = new List<StoreConfig>();
        if (!IsNewDay()) return false;
        List<StoreConfig> shoplist = StoreConfig.GetTypeStoreModel((int)StoreFunc.WeekStore);
        for(int i = 0; i < shoplist.Count; i++)
        {
            int canBuyCnt = 0;
            int addBuyCnt = 0;
            bool isLimitBuy = BuyItemPopModel.Instance.CheckIsLimitBuyCnt(shoplist[i], out canBuyCnt, out addBuyCnt);
            BuyShopItemLimit shopItemLimit = GetBuyShopLimit((uint)shoplist[i].ID);
            if (isLimitBuy)
            {
                int remainNum = canBuyCnt;
                if (shopItemLimit != null)
                {
                    remainNum = canBuyCnt - shopItemLimit.BuyCnt;
                }
                if (remainNum > 0)
                {
                    buylist.Add(shoplist[i]);
                }
            }
            else
            {
                buylist.Add(shoplist[i]);
            }
        }
        if(buylist.Count > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    private bool IsNewDay()
    {
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Store)) return false;
        if (PlayerPrefs.HasKey(StoreEffectRecord_Key))
        {
            int day = LocalSave.GetInt(StoreEffectRecord_Key);
            if(day != TimeUtility.ServerNow.Day)
            {
                LocalSave.SetInt(StoreEffectRecord_Key,TimeUtility.ServerNow.Day);
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            LocalSave.SetInt(StoreEffectRecord_Key, TimeUtility.ServerNow.Day);
            return true;
        }
    }
    /// <summary>
    /// 检测唯一商品是否已售罄
    /// </summary>
    /// <param name="shopIndex"></param>
    /// <param name="isTheOnlyShop"></param>
    /// <returns></returns>
    public bool CheckTheOnlyShopSellOut(int shopIndex,out bool isTheOnlyShop)
    {
        StoreConfig storeConfig = ConfigManager.Instance.GetTemplate<StoreConfig>(shopIndex);
        isTheOnlyShop = false;
        if (storeConfig == null) return false;
        if(storeConfig.TheOnlyShop == 1)
        {
            if(StoreConfig.GetTheOnlyShopDict().ContainsKey(storeConfig.ItemID))
            {
                List<StoreConfig> storelist = StoreConfig.GetTheOnlyShopDict()[storeConfig.ItemID];
                for(int i = 0; i < storelist.Count; i++)
                {
                    BuyShopItemLimit shoplimit = GetBuyShopLimit((uint)storelist[i].ID);
                    if(shoplimit != null && shoplimit.BuyCnt >= storelist[i].PurchaseNumber[0])
                    {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    #region 商城红点
    public const int StoreFunc_RedKey = 22;
    public const int StoreFunc1_RedKey = 2201;
    public const int StoreFunc2_RedKey = 2202;
    public const int StoreFunc3_RedKey = 2203;
    public const int StoreFunc4_RedKey = 2204;
    public const int StoreFunc5_RedKey = 2205;
    public Redpoint storeFuncPoint = new Redpoint(MainRedDot.RedPoint_UpFuncBase,StoreFunc_RedKey);
    public Redpoint storeFunc1Point = new Redpoint(StoreFunc_RedKey,StoreFunc1_RedKey);
    public Redpoint storeFunc2Point = new Redpoint(StoreFunc_RedKey,StoreFunc2_RedKey);
    public Redpoint storeFunc3Point = new Redpoint(StoreFunc_RedKey,StoreFunc3_RedKey);
    public Redpoint storeFunc4Point = new Redpoint(StoreFunc_RedKey,StoreFunc4_RedKey);
    public Redpoint storeFunc5Point = new Redpoint(StoreFunc_RedKey,StoreFunc5_RedKey);
    public Dictionary<int, Redpoint> shopRedDict = new Dictionary<int, Redpoint>();
    public void SetShopRedpoint()
    {
        shopRedDict.Clear();
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Store)) return;
        List<StoreConfig> storelist = StoreConfig.GetAllShoplist();
        for(int i = 0; i < storelist.Count; i++)
        {
            StoreConfig storeConfig = storelist[i];
            int redKey = 0;
            Redpoint redpoint = null;
            switch (storeConfig.ShopType)
            {
                case 1:
                    redKey = StoreFunc1_RedKey*10000 + storeConfig.ID;
                    redpoint = new Redpoint(StoreFunc1_RedKey,redKey);
                    break;
                case 2:
                    redKey = StoreFunc2_RedKey * 10000 + storeConfig.ID;
                    redpoint = new Redpoint(StoreFunc2_RedKey, redKey);
                    break;
                case 3:
                    redKey = StoreFunc3_RedKey * 10000 + storeConfig.ID;
                    redpoint = new Redpoint(StoreFunc3_RedKey, redKey);
                    break;
                case 4:
                    redKey = StoreFunc4_RedKey * 10000 + storeConfig.ID;
                    redpoint = new Redpoint(StoreFunc4_RedKey, redKey);
                    break;
                case 5:
                    redKey = StoreFunc5_RedKey * 10000 + storeConfig.ID;
                    redpoint = new Redpoint(StoreFunc5_RedKey, redKey);
                    break;
            }
            shopRedDict.Add(storeConfig.ID,redpoint);
        }
    }
    public void CheckShopRedpoint()
    {
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Store)) return;
        foreach(var key in shopRedDict.Keys)
        {
            StoreConfig storeConfig = ConfigManager.Instance.GetTemplate<StoreConfig>(key);
            if (storeConfig.MoneyNumber == 0)
            {
                int canBuyCnt = 0;
                int addBuyCnt = 0;
                bool isLimitBuy = BuyItemPopModel.Instance.CheckIsLimitBuyCnt(storeConfig, out canBuyCnt, out addBuyCnt);
                BuyShopItemLimit shopItemLimit = GetBuyShopLimit((uint)storeConfig.ID);
                int remainNum = canBuyCnt;
                if (shopItemLimit != null)
                {
                    remainNum -= shopItemLimit.BuyCnt;
                }
                List<StoreConfig> list = StoreConfig.GetSellShoplist();
                if (remainNum > 0 && list.Contains(storeConfig))
                {
                    shopRedDict[storeConfig.ID].state = RedPointState.Simple;
                }
                else
                {
                    shopRedDict[storeConfig.ID].state = RedPointState.None;
                }
            }
            else
            {
                shopRedDict[storeConfig.ID].state = RedPointState.None;
            }
        }
    }
    #endregion
}
public enum StoreFunc
{
    WeekStore = 1, //1:每周限购
    CommonStore = 2, //2:常用道具
    GrowStrongerStore = 3, //3:成长变强
    BindStore = 4,  //4:绑玉商城
    IntegralStore = 5,  //5:积分商城
    BagStore = 6,  //6:随身商店
    RuneStore = 7,  //7:符印商店
    ToolStore = 8, // 道具商店
    MountStoneStore = 9, //坐骑魂石商店
    MountSkillBookStore = 10,//坐骑技能书商店
    XBEquipStore = 11, //寻宝装备商店
    XBRuneStore = 12, //寻宝符印商店
    XBToolStore = 13, //寻宝道具商店
    OSGift = 14,//开服礼包
    OSTimeLimitGift = 15,//限时特惠
}
public enum LocalSaveStoreType
{
    UnionStore, //仙盟商店
}
using Snxxz.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using TableConfig;
using UnityEngine;
using LitJson;
public class BuyShopItemLimit
{
    public uint ItemIndex;
    public ushort BuyCnt;        // 今日已购买次数
    public int isReset;         //是否属于每月重置  0 不重置 1重置
}
public struct ShopItemInfo
{
    public int itemId;
    public int count;
    public int isBind;
    public ShopItemInfo(int id,int count,int isBind)
    {
        this.itemId = id;
        this.count = count;
        this.isBind = isBind;
    }
}
public class StoreModel : Model,IBeforePlayerDataInitialize,IAfterPlayerDataInitialize,IPlayerLoginOk
{
    public int[] normalBuyCoinsTypes { get; private set; }
    public string UNIONSTORESAVE_KEY { get; private set; }
    public string StoreEffectRecord_Key { get; private set; }
    public List<StoreConfig> shoplist;
    public Dictionary<int,Dictionary<int,int>> JobReplaceIdDict = new Dictionary<int, Dictionary<int, int>>();
    public Dictionary<int, string> resetTimeDict { get; private set; }
    public Dictionary<int, int> showCoinsUIDict { get; private set; }
    public int[] StoreRedIdlist { get; private set;}
    public override void Init()
    {
        FuncConfigConfig buyItemHinit = Config.Instance.Get<FuncConfigConfig>("BuyItemHinit");
        normalBuyCoinsTypes = ConfigParse.GetMultipleStr<int>(buyItemHinit.Numerical1);
        FuncConfigConfig restTimeConfig = Config.Instance.Get<FuncConfigConfig>("RefreshText");
        resetTimeDict = ConfigParse.GetDic<int, string>(restTimeConfig.Numerical1);
        FuncConfigConfig mallCurrency = Config.Instance.Get<FuncConfigConfig>("MallCurrency");
        showCoinsUIDict = ConfigParse.GetDic<int, int>(mallCurrency.Numerical1);
        FuncConfigConfig mallPush = Config.Instance.Get<FuncConfigConfig>("MallPush");
        StoreRedIdlist = ConfigParse.GetMultipleStr<int>(mallPush.Numerical2);
    }
    public void OnBeforePlayerDataInitialize()
    {
        shopItemlimitDict.Clear();
        tagTowerModel = null;
        storeFuncType = StoreFunc.WeekStore;
        tcbRefreshDict.Clear();
    }
    public void OnAfterPlayerDataInitialize()
    {
        UNIONSTORESAVE_KEY = StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, LocalSaveStoreType.UnionStore);
        StoreEffectRecord_Key = StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, "StoreEffectRecord");
    }
    public void OnPlayerLoginOk()
    {
        PlayerDatas.Instance.fairyData.OnRefreshFairyInfo -= RefreshFamilyLv;
        PlayerDatas.Instance.fairyData.OnRefreshFairyInfo += RefreshFamilyLv;
        PlayerDatas.Instance.fairyData.OnRefreshFairyMine -= RefreshServerHour;
        PlayerDatas.Instance.fairyData.OnRefreshFairyMine += RefreshServerHour;
        FuncOpen.Instance.OnFuncStateChangeEvent -= FuncStateChange;
        FuncOpen.Instance.OnFuncStateChangeEvent += FuncStateChange;
        RefreshTCBPlayerDataEvent -= RefreshPlayerLv;
        RefreshTCBPlayerDataEvent += RefreshPlayerLv;
        TimeMgr.Instance.OnHourEvent -= RefreshServerHour;
        TimeMgr.Instance.OnHourEvent += RefreshServerHour;
        shoplist = null;
        CheckWeekStoreIsShopBuy(out shoplist);
        ControllerRedPoint();
        SetShopRedpoint();
        CheckShopRedpoint();
        SetJobReplaceIDDict();
    }
    public string GetStoreRefreshTimeByType(int type)
    {
        if (resetTimeDict == null || !resetTimeDict.ContainsKey(type)) return string.Empty;
        switch(type)
        {
            case 7:
                int willRefreshTime = GetWillRefreshTime();
                return Language.Get(resetTimeDict[type],UIHelper.GetTextColorByItemColor(TextColType.Green, TimeUtility.SecondsToHMS(willRefreshTime),true));
                //if(willRefreshTime == 0)
                //{
                //    return Language.Get("StoreWin201");
                //}
                //else
                //{
                //    return Language.Get(resetTimeDict[type],willRefreshTime);
                //}
            default:
                return Language.Get(resetTimeDict[type]);
        }
    }
    private int GetWillRefreshTime()
    {
        int willRefresh = (3 - TimeUtility.OpenDay % 3);
        if (willRefresh == 3)
        {
            if(TimeUtility.ServerNow.Hour < 5)
            {
                willRefresh = 0;
            }
        }
        int remainHour = 5 - TimeUtility.ServerNow.Hour;
        int remainMinute = 0 - TimeUtility.ServerNow.Minute;
        int remainSecond = willRefresh * 24 * 60 * 60 + remainHour * 60 * 60 + remainMinute * 60 - TimeUtility.ServerNow.Second;
        return remainSecond;
    }
    private void RefreshPlayerLv(PlayerDataRefresh type)
    {
        switch(type)
        {
            case PlayerDataRefresh.LV:
            case PlayerDataRefresh.VIPLv:
            case PlayerDataRefresh.Gold:
            case PlayerDataRefresh.GoldPaper:
            case PlayerDataRefresh.FBHelpPoint:
                CheckShopRedpoint();
                break;
        }
    }
    public override void UnInit()
    {
    }
    ItemTipsModel _itemTipsModel;
    ItemTipsModel itemTipsModel
    {
        get
        {
            return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel<ItemTipsModel>());
        }
    }
    #region 职业替换商品逻辑处理
    public void SetJobReplaceIDDict()
    {
        JobReplaceIdDict.Clear();
        List<StoreConfig> storeConfigs = Config.Instance.GetAllValues<StoreConfig>();
        for(int i = 0; i < storeConfigs.Count; i++)
        {
            Dictionary<int, int> replaceItemDict = new Dictionary<int, int>();
            JobReplaceIdDict.Add(storeConfigs[i].ID,replaceItemDict);
            AnalysisJobReplace(storeConfigs[i]);
            List<ShopItemInfo> shopItems = GetShopItemlistByIndex(storeConfigs[i]);
            for(int j = 0; j < shopItems.Count; j++)
            {
                foreach (var index in jobReplaceDic.Keys)
                {
                    if (jobReplaceDic[index].Contains(shopItems[j].itemId))
                    {
                        int replaceIndex = PlayerDatas.Instance.baseData.Job - 1;
                        int replaceId = jobReplaceDic[index][replaceIndex];
                        replaceItemDict.Add(shopItems[j].itemId,replaceId);
                        break;
                    }
                }
            }
        }
    }
    Dictionary<int, List<int>> jobReplaceDic = new Dictionary<int, List<int>>();
    private void AnalysisJobReplace(StoreConfig storeConfig)
    {
        jobReplaceDic.Clear();
        JsonData jsonData = JsonMapper.ToObject(storeConfig.JobItem);
        if (jsonData.IsArray)
        {
            for (int i = 0; i < jsonData.Count; i++)
            {
                List<int> idlist = new List<int>();
                jobReplaceDic.Add(i, idlist);
                if (jsonData[i].IsArray)
                {
                    for (int j = 0; j < jsonData[i].Count; j++)
                    {
                        int itemId = int.Parse(jsonData[i][j].ToString());
                        idlist.Add(itemId);
                    }
                }
            }
        }
    }
    public int ReplaceItemIdByJob(int storeId,int itemId)
    {
       if(JobReplaceIdDict.ContainsKey(storeId))
        {
            if(JobReplaceIdDict[storeId].ContainsKey(itemId))
            {
                return JobReplaceIdDict[storeId][itemId];
            }
        }
        return itemId;
    }
    #endregion
    private void RefreshFamilyLv()
    {
        int familyLv = PlayerDatas.Instance.fairyData.fairy.FamilyLV;
        if(familyLv > GetSaveFairyLV())
        {
            ControllerRedPoint();
        }
    }
    private void RefreshServerHour()
    {
        ControllerRedPoint();
    }
    public Action RefreshBuyShopLimitEvent;
    public StoreFunc storeFuncType = StoreFunc.WeekStore;
    private Dictionary<uint, BuyShopItemLimit> shopItemlimitDict = new Dictionary<uint, BuyShopItemLimit>();
    private Dictionary<string, RuneTowerFloorConfig> tagTowerModel;
    /// <summary>
    /// 得到物品购买次数
    /// </summary>
    /// <param name="buylimit"></param>
    public void RefreshBuyShopLimitModel(HA802_tagMCShopItemDayBuyCntInfo buylimit)
    {
        DebugEx.Log("RefreshBuyShopLimitModel" + buylimit.Count);
        if (buylimit.Count > 0)
        {
            int i = 0;
            for (i = 0; i < buylimit.Count; i++)
            {
                if (!shopItemlimitDict.ContainsKey(buylimit.DayBuyCntList[i].ItemIndex))
                {
                    BuyShopItemLimit shopItemLimit = new BuyShopItemLimit();
                    shopItemLimit.ItemIndex = buylimit.DayBuyCntList[i].ItemIndex;
                    shopItemLimit.BuyCnt = buylimit.DayBuyCntList[i].BuyCnt;
                    shopItemLimit.isReset = buylimit.DayBuyCntList[i].IsReset;
                    shopItemlimitDict.Add(shopItemLimit.ItemIndex, shopItemLimit);
                }
                else
                {
                    shopItemlimitDict[buylimit.DayBuyCntList[i].ItemIndex].BuyCnt = buylimit.DayBuyCntList[i].BuyCnt;
                    shopItemlimitDict[buylimit.DayBuyCntList[i].ItemIndex]. isReset = buylimit.DayBuyCntList[i].IsReset;
                }
            }
        }
        CheckShopRedpoint();
        if (RefreshBuyShopLimitEvent != null)
            RefreshBuyShopLimitEvent();
    }
    public BuyShopItemLimit GetBuyShopLimit(uint itemIndex)
    {
        if (shopItemlimitDict.ContainsKey(itemIndex))
        {
            return shopItemlimitDict[itemIndex];
        }
        return null;
    }
    private RuneConfig _tagRuneModel = null;
    public RuneTowerFloorConfig SetRuneSource(int itemId)
    {
        _tagRuneModel = Config.Instance.Get<RuneConfig>(itemId);
        if (_tagRuneModel == null)
            return null;
        var _tagRuneTowerModel = Config.Instance.Get<RuneTowerFloorConfig>(_tagRuneModel.TowerID);
        return _tagRuneTowerModel;
    }
    List<ShopItemInfo> shopItemlist = new List<ShopItemInfo>();
   public List<ShopItemInfo> GetShopItemlistByIndex(StoreConfig storeConfig)
    {
        if (storeConfig == null) return null;
        shopItemlist.Clear();
        ShopItemInfo shopItem = new ShopItemInfo(storeConfig.ItemID, storeConfig.ItemCnt, storeConfig.IsBind);
        shopItemlist.Add(shopItem);
        JsonData extraItem = JsonMapper.ToObject(storeConfig.ItemListEx);
        if (extraItem.IsArray)
        {
            for (int i = 0; i < extraItem.Count; i++)
            {
                if (extraItem[i].IsArray)
                {
                    if (extraItem[i].Count > 0)
                    {
                        ShopItemInfo shop = new ShopItemInfo(int.Parse(extraItem[i][0].ToString()), int.Parse(extraItem[i][1].ToString()), int.Parse(extraItem[i][2].ToString()));
                        shopItemlist.Add(shop);
                    }
                }
            }
        }
        return shopItemlist;
    }
    public bool TryGetShopItemInfo(StoreFunc _type, int _id, out List<ShopItemInfo> _shopItems)
    {
        _shopItems = null;
        var _list = StoreConfig.GetTypeStoreModel((int)_type, true);
        var _index = _list.FindIndex((x) =>
        {
            return x.ID == _id;
        });
        if (_index == -1)
        {
            return false;
        }
        _shopItems = GetShopItemlistByIndex(_list[_index]);
        return _shopItems != null;
    }
    #region 0418 数据处理
    private Dictionary<PlayerDataRefresh, int> tcbRefreshDict = new Dictionary<PlayerDataRefresh, int>();
    public event Action<PlayerDataRefresh> RefreshTCBPlayerDataEvent;
    public void RefreshTCBPlayerData(H0418_tagObjInfoRefresh info)
    {
        if(!tcbRefreshDict.ContainsKey((PlayerDataRefresh)info.RefreshType))
        {
            tcbRefreshDict.Add((PlayerDataRefresh)info.RefreshType,(int)info.Value);
        }
        else
        {
            tcbRefreshDict[(PlayerDataRefresh)info.RefreshType] = (int)info.Value;
        }
        if(RefreshTCBPlayerDataEvent != null)
        {
            RefreshTCBPlayerDataEvent((PlayerDataRefresh)info.RefreshType);
        }
    }
    public int GetTCBPlayerData(PlayerDataRefresh tCDBPlayer)
    {
        int value = 0;
        tcbRefreshDict.TryGetValue(tCDBPlayer,out value);
        return value;
    }
    #endregion
    #region 点击商店物品逻辑
    public void OnClickShopCell(StoreConfig shopInfo)
    {
        BuyItemPopModel.Instance.SetModel(shopInfo.ID);
        //SetOpenBuyType(chinModel);
        ItemAttrData attrData = new ItemAttrData(ReplaceItemIdByJob(shopInfo.ID,shopInfo.ItemID),true, (ulong)shopInfo.ItemCnt,-1,shopInfo.IsBind,true,PackType.rptDeleted
            ,"",null,ItemTipChildType.Buy);
        itemTipsModel.SetItemTipsModel(attrData);
    }
    #endregion
    private ulong _price;
    public void SendBuyShopItem(StoreConfig model, int count)
    {
        if ((StoreFunc)model.ShopType == StoreFunc.RuneStore)
        {
            _tagRuneModel = Config.Instance.Get<RuneConfig>(model.ItemID);
            if (_tagRuneModel != null)
            {
                if (!IsCanBuyItem(_tagRuneModel.TowerID))
                {
                    MessageWin.Inst.ShowFixedTip(Language.Get("Store101"));
                    return;
                }
            }
        }
        _price = (ulong)(model.MoneyNumber * count);
        if (MoneyIsEnough(model.MoneyType, _price))
        {
            C0803_tagCBuyItemList buyShop = new C0803_tagCBuyItemList();
            buyShop.NPCID = 0;
            buyShop.BuyItemIndex = (ushort)model.ID;
            buyShop.BuyCount = (ushort)count;
            GameNetSystem.Instance.SendInfo(buyShop);
        }
        else
        {
            switch(model.MoneyType)
            {
                case 1:
                    if (VersionConfig.Get().isBanShu)
                    {
                        SysNotifyMgr.Instance.ShowTip("GoldErr");
                        return;
                    }
                    WindowCenter.Instance.Open<RechargeTipWin>();
                    break;
                case 25:
                    SysNotifyMgr.Instance.ShowTip("LackXBMoney", model.MoneyType);
                    break;
                default:
                    SysNotifyMgr.Instance.ShowTip("LackMoney", model.MoneyType);
                    break;
            }
        }
    }
    public event Action<int> RefreshBuyResultEvent;
    public void GetBuyResult(HA811_tagMCShoppingResult result)
    {
        DebugEx.Log("GetBuyResult");
        StoreConfig tagStore = Config.Instance.Get<StoreConfig>((int)result.ItemIndex);
        if (tagStore != null)
        {
            ItemConfig chinModel = Config.Instance.Get<ItemConfig>(ReplaceItemIdByJob(tagStore.ID, tagStore.ItemID));
            if (!normalBuyCoinsTypes.Contains(tagStore.MoneyType))
            {
                if (tagStore.RemindSuccess == 0)
                {
                    return;
                }
                BuySuccessModel.Instance.SetBuySuccessModel(chinModel.ID, (int)result.ItemCnt, tagStore.IsBind);
                if (!WindowCenter.Instance.CheckOpen<BuySuccessWin>())
                {
                    WindowCenter.Instance.Open<BuySuccessWin>();
                }
            }
            else
            {
                float costMoney = tagStore.MoneyNumber;
                SysNotifyMgr.Instance.ShowTip("BuyItemHinit",costMoney,tagStore.MoneyType, chinModel.ItemName);
            }
            if (RefreshBuyResultEvent != null)
            {
                RefreshBuyResultEvent(chinModel.ID);
            }
        }
    }
    /// <summary>
    /// 用于判断符文塔兑换是否满足条件
    /// </summary>
    /// <param name="limitTower"></param>
    /// <returns></returns>
    public bool IsCanBuyItem(int limitTower)
    {
        int playerTower = (int)ModelCenter.Instance.GetModel<RuneModel>().RuneTowerOpenLV;
        int offset = playerTower - limitTower;
        if (offset >= 0)
            return true;
        else
            return false;
    }
    public bool MoneyIsEnough(int moneyType, ulong money)
    {
        if (UIHelper.GetMoneyCnt(moneyType) < money)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    public int jumpToItemId { get;set;}
    public void SetJumpToModel(int itemId)
    {
        jumpToItemId = itemId;
    }
   #region 仙盟商店逻辑处理
    #region 仙盟红点逻辑处理
    private bool CheckIsBuyNewItem(int fairyLv)
    {
        if(fairyLv > GetSaveFairyLV())
        {
            if (StoreConfig.GetCanBuyShopModel((int)StoreFunc.ToolStore, fairyLv).Count > 0
              || StoreConfig.GetCanBuyShopModel((int)StoreFunc.MountStoneStore, fairyLv).Count > 0
               || StoreConfig.GetCanBuyShopModel((int)StoreFunc.MountSkillBookStore, fairyLv).Count > 0)
            {
                return true;
            }
        }
        return false;
    }
    private bool CheckIsNewMonth()
    {
        GetSaveDateTime();
        if(datelist.Count > 0)
        {
            if(TimeUtility.ServerNow.Month == datelist[0])
            {
                if(TimeUtility.ServerNow.Day >= 1
                    && TimeUtility.ServerNow.Hour >= 5
                    && datelist[1] <= 1 && datelist[2] < 5)
                {
                    return true;
                }
            }
            else
            {
                if(TimeUtility.ServerNow.Day >= 1
                    && TimeUtility.ServerNow.Hour >= 5)
                {
                    return true;
                }
            }
        }
        else
        {
            return true;
        }
        return false;
    }
    List<int> datelist = new List<int>();
    public List<int> GetSaveDateTime()
    {
        datelist.Clear();
        int[] unionArray = LocalSave.GetIntArray(UNIONSTORESAVE_KEY);
        if (unionArray != null && unionArray.Length >= 4)
        {
            datelist.Add(unionArray[1]);
            datelist.Add(unionArray[2]);
            datelist.Add(unionArray[3]);
        }
        return datelist;
    }
    public int GetSaveFairyLV()
    {
        int[] unionArray = LocalSave.GetIntArray(UNIONSTORESAVE_KEY);
        int fairyLv = 0;
        if(unionArray != null)
        {
            return unionArray[0];
        }
        return fairyLv;
    }
    //1仙盟等级 2 月份 3 号 4 几点
    public void SetStoreLocalSave(LocalSaveStoreType saveStoreType,params int[] infos)
    {
        string key = StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, saveStoreType);
        LocalSave.SetIntArray(key,infos);
    }
    public void ControllerRedPoint(bool isLook = false)
    {
        MainRedDot.Instance.fairyStoreRedPoint.state = RedPointState.None;
        if(!ModelCenter.Instance.GetModel<FairyModel>().fairyStoreOpen)
        {
            return;
        }
        int familyLv = PlayerDatas.Instance.fairyData.fairy.FamilyLV;
        if(!isLook)
        {
            if (CheckIsBuyNewItem(familyLv))
            {
                MainRedDot.Instance.fairyStoreRedPoint.state = RedPointState.Simple;
                return;
            }
            if (CheckIsNewMonth())
            {
                MainRedDot.Instance.fairyStoreRedPoint.state = RedPointState.Simple;
                return;
            }
        }
        SetStoreLocalSave(LocalSaveStoreType.UnionStore, familyLv, TimeUtility.ServerNow.Month,
                TimeUtility.ServerNow.Day, TimeUtility.ServerNow.Hour);
    }
    #endregion
    #endregion
    public event Action StoreFuncOpenAct;
    private void FuncStateChange(int funcId)
    {
        if (funcId != (int)FuncOpenEnum.Store) return;
        shoplist = null;
        CheckWeekStoreIsShopBuy(out shoplist);
        if(shoplist.Count > 0)
        {
            if (StoreFuncOpenAct != null)
            {
                StoreFuncOpenAct();
            }
        }
        SetShopRedpoint();
        CheckShopRedpoint();
    }
    public bool CheckWeekStoreIsShopBuy(out List<StoreConfig> buylist)
    {
        buylist = new List<StoreConfig>();
        if (!IsNewDay()) return false;
        List<StoreConfig> shoplist = StoreConfig.GetTypeStoreModel((int)StoreFunc.WeekStore);
        for(int i = 0; i < shoplist.Count; i++)
        {
            int canBuyCnt = 0;
            int addBuyCnt = 0;
            bool isLimitBuy = BuyItemPopModel.Instance.CheckIsLimitBuyCnt(shoplist[i], out canBuyCnt, out addBuyCnt);
            BuyShopItemLimit shopItemLimit = GetBuyShopLimit((uint)shoplist[i].ID);
            if (isLimitBuy)
            {
                int remainNum = canBuyCnt;
                if (shopItemLimit != null)
                {
                    remainNum = canBuyCnt - shopItemLimit.BuyCnt;
                }
                if (remainNum > 0)
                {
                    buylist.Add(shoplist[i]);
                }
            }
            else
            {
                buylist.Add(shoplist[i]);
            }
        }
        if(buylist.Count > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    private bool IsNewDay()
    {
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Store)) return false;
        if (PlayerPrefs.HasKey(StoreEffectRecord_Key))
        {
            int day = LocalSave.GetInt(StoreEffectRecord_Key);
            if(day != TimeUtility.ServerNow.Day)
            {
                LocalSave.SetInt(StoreEffectRecord_Key,TimeUtility.ServerNow.Day);
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            LocalSave.SetInt(StoreEffectRecord_Key, TimeUtility.ServerNow.Day);
            return true;
        }
    }
    /// <summary>
    /// 检测唯一商品是否已售罄
    /// </summary>
    /// <param name="shopIndex"></param>
    /// <param name="isTheOnlyShop"></param>
    /// <returns></returns>
    public bool CheckTheOnlyShopSellOut(int shopIndex,out bool isTheOnlyShop)
    {
        StoreConfig storeConfig = Config.Instance.Get<StoreConfig>(shopIndex);
        isTheOnlyShop = false;
        if (storeConfig == null) return false;
        if(storeConfig.TheOnlyShop == 1)
        {
            if(StoreConfig.GetTheOnlyShopDict().ContainsKey(storeConfig.ItemID))
            {
                List<StoreConfig> storelist = StoreConfig.GetTheOnlyShopDict()[storeConfig.ItemID];
                for(int i = 0; i < storelist.Count; i++)
                {
                    BuyShopItemLimit shoplimit = GetBuyShopLimit((uint)storelist[i].ID);
                    if(shoplimit != null && shoplimit.BuyCnt >= storelist[i].PurchaseNumber[0])
                    {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    #region 商城红点
    public const int StoreFunc_RedKey = 22;
    public const int StoreFunc1_RedKey = 2201;
    public const int StoreFunc2_RedKey = 2202;
    public const int StoreFunc3_RedKey = 2203;
    public const int StoreFunc4_RedKey = 2204;
    public const int StoreFunc5_RedKey = 2205;
    public Redpoint storeFuncPoint = new Redpoint(MainRedDot.RedPoint_UpFuncBase,StoreFunc_RedKey);
    public Redpoint storeFunc1Point = new Redpoint(StoreFunc_RedKey,StoreFunc1_RedKey);
    public Redpoint storeFunc2Point = new Redpoint(StoreFunc_RedKey,StoreFunc2_RedKey);
    public Redpoint storeFunc3Point = new Redpoint(StoreFunc_RedKey,StoreFunc3_RedKey);
    public Redpoint storeFunc4Point = new Redpoint(StoreFunc_RedKey,StoreFunc4_RedKey);
    public Redpoint storeFunc5Point = new Redpoint(StoreFunc_RedKey,StoreFunc5_RedKey);
    public Dictionary<int, Redpoint> shopRedDict = new Dictionary<int, Redpoint>();
    public void SetShopRedpoint()
    {
        shopRedDict.Clear();
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Store)) return;
        List<StoreConfig> storelist = StoreConfig.GetAllShoplist();
        for(int i = 0; i < storelist.Count; i++)
        {
            StoreConfig storeConfig = storelist[i];
            int redKey = 0;
            Redpoint redpoint = null;
            switch (storeConfig.ShopType)
            {
                case 1:
                    redKey = StoreFunc1_RedKey*10000 + storeConfig.ID;
                    redpoint = new Redpoint(StoreFunc1_RedKey,redKey);
                    break;
                case 2:
                    redKey = StoreFunc2_RedKey * 10000 + storeConfig.ID;
                    redpoint = new Redpoint(StoreFunc2_RedKey, redKey);
                    break;
                case 3:
                    redKey = StoreFunc3_RedKey * 10000 + storeConfig.ID;
                    redpoint = new Redpoint(StoreFunc3_RedKey, redKey);
                    break;
                case 4:
                    redKey = StoreFunc4_RedKey * 10000 + storeConfig.ID;
                    redpoint = new Redpoint(StoreFunc4_RedKey, redKey);
                    break;
                case 5:
                    redKey = StoreFunc5_RedKey * 10000 + storeConfig.ID;
                    redpoint = new Redpoint(StoreFunc5_RedKey, redKey);
                    break;
            }
            shopRedDict.Add(storeConfig.ID,redpoint);
        }
    }
    public void CheckShopRedpoint()
    {
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Store)) return;
        foreach(var key in shopRedDict.Keys)
        {
            StoreConfig storeConfig = Config.Instance.Get<StoreConfig>(key);
            if (storeConfig.MoneyNumber == 0)
            {
                if(CheckShopIsCanBuy(storeConfig))
                {
                    shopRedDict[storeConfig.ID].state = RedPointState.Simple;
                }
                else
                {
                    shopRedDict[storeConfig.ID].state = RedPointState.None;
                }
            }
            else
            {
                if(CheckScoreStoreIsCanBuy(storeConfig))
                {
                    shopRedDict[storeConfig.ID].state = RedPointState.Simple;
                }
                else
                {
                    shopRedDict[storeConfig.ID].state = RedPointState.None;
                }
            }
        }
    }
    public bool CheckScoreStoreIsCanBuy(StoreConfig storeConfig)
    {
        List<StoreConfig> list = StoreConfig.GetSellShoplist();
        if(StoreRedIdlist.Contains(storeConfig.ID))
        {
            if (CheckShopIsCanBuy(storeConfig))
            {
                if(UIHelper.GetMoneyCnt(storeConfig.MoneyType) >= (ulong)storeConfig.MoneyNumber)
                {
                    return true;
                }
            }
        }
        return false;
    }
    public bool CheckShopIsCanBuy(StoreConfig storeConfig)
    {
        int canBuyCnt = 0;
        int addBuyCnt = 0;
        bool isLimitBuy = BuyItemPopModel.Instance.CheckIsLimitBuyCnt(storeConfig, out canBuyCnt, out addBuyCnt);
        BuyShopItemLimit shopItemLimit = GetBuyShopLimit((uint)storeConfig.ID);
        int remainNum = canBuyCnt;
        if (shopItemLimit != null)
        {
            remainNum -= shopItemLimit.BuyCnt;
        }
        List<StoreConfig> list = StoreConfig.GetSellShoplist();
        if (remainNum > 0 && list.Contains(storeConfig))
        {
            return true;
        }
        return false;
    }
    #endregion
}
public enum StoreFunc
{
    WeekStore = 1, //1:每周限购
    CommonStore = 2, //2:常用道具
    GrowStrongerStore = 3, //3:成长变强
    BindStore = 4,  //4:绑玉商城
    IntegralStore = 5,  //5:积分商城
    BagStore = 6,  //6:随身商店
    RuneStore = 7,  //7:符印商店
    ToolStore = 8, // 道具商店
    MountStoneStore = 9, //坐骑魂石商店
    MountSkillBookStore = 10,//坐骑技能书商店
    XBEquipStore = 11, //寻宝装备商店
    XBRuneStore = 12, //寻宝符印商店
    XBToolStore = 13, //寻宝道具商店
    OSGift = 14,//开服礼包
    OSTimeLimitGift = 15,//限时特惠
    DanDrugStore = 30, //丹药回收商店
}
public enum LocalSaveStoreType
{
    UnionStore, //仙盟商店
}