Пример #1
0
        /// <summary>
        /// 使用某个礼品码
        /// </summary>
        /// <param name="dbMgr"></param>
        /// <param name="fileName"></param>
        public static int UseLiPinMa(DBManager dbMgr, int roleID, int songLiID, string liPinMa, bool insertLiPinMa = false)
        {
            if (null == _LiPinMaDict)
            {
                return(-1010);
            }
            Dictionary <string, LiPinMaItem> liPinMaDict = _LiPinMaDict; //先得到

            int usedNum = 0;

            liPinMa = liPinMa.ToUpper(); //转成大写

            //防止多用户重入
            lock (Mutex)
            {
                LiPinMaItem liPinMaItem = null;
                if (!liPinMaDict.TryGetValue(liPinMa, out liPinMaItem))
                {
                    return(-1020);
                }

                if (liPinMaItem.HuodongID != songLiID)
                {
                    return(-1030);
                }

                if (liPinMaItem.MaxNum > 0 && liPinMaItem.UsedNum >= liPinMaItem.MaxNum)
                {
                    return(-1040);
                }

                //如果不允许平台内的礼品码重复领取
                if (liPinMaItem.PingTaiRepeat <= 0)
                {
                    //通过活动ID查询平台ID
                    int pingTaiID = DBQuery.QueryPingTaiIDByHuoDongID(dbMgr, liPinMaItem.HuodongID, roleID, liPinMaItem.PingTaiID);
                    if (pingTaiID == liPinMaItem.PingTaiID)
                    {
                        return(-10000);
                    }
                }

                //添加使用礼品码的平台记录
                DBWriter.AddUsedLiPinMa(dbMgr, liPinMaItem.HuodongID, liPinMaItem.LiPinMa, liPinMaItem.PingTaiID, roleID);

                liPinMaItem.UsedNum++;
                usedNum = liPinMaItem.UsedNum;
            }

            //修改一个礼品码的使用次数
            DBWriter.UpdateLiPinMaUsedNum(dbMgr, liPinMa, usedNum);

            return(0);
        }
Пример #2
0
        public static int UseLiPinMa(DBManager dbMgr, int roleID, int songLiID, string liPinMa, bool insertLiPinMa = false)
        {
            int result;

            if (null == LiPinMaManager._LiPinMaDict)
            {
                result = -1010;
            }
            else
            {
                Dictionary <string, LiPinMaItem> liPinMaDict = LiPinMaManager._LiPinMaDict;
                int usedNum = 0;
                liPinMa = liPinMa.ToUpper();
                lock (LiPinMaManager.Mutex)
                {
                    LiPinMaItem liPinMaItem = null;
                    if (!liPinMaDict.TryGetValue(liPinMa, out liPinMaItem))
                    {
                        return(-1020);
                    }
                    if (liPinMaItem.HuodongID != songLiID)
                    {
                        return(-1030);
                    }
                    if (liPinMaItem.MaxNum > 0 && liPinMaItem.UsedNum >= liPinMaItem.MaxNum)
                    {
                        return(-1040);
                    }
                    if (liPinMaItem.PingTaiRepeat <= 0)
                    {
                        int pingTaiID = DBQuery.QueryPingTaiIDByHuoDongID(dbMgr, liPinMaItem.HuodongID, roleID, liPinMaItem.PingTaiID);
                        if (pingTaiID == liPinMaItem.PingTaiID)
                        {
                            return(-10000);
                        }
                    }
                    DBWriter.AddUsedLiPinMa(dbMgr, liPinMaItem.HuodongID, liPinMaItem.LiPinMa, liPinMaItem.PingTaiID, roleID);
                    liPinMaItem.UsedNum++;
                    usedNum = liPinMaItem.UsedNum;
                }
                DBWriter.UpdateLiPinMaUsedNum(dbMgr, liPinMa, usedNum);
                result = 0;
            }
            return(result);
        }
Пример #3
0
        public static int UseLiPinMaNX(DBManager dbMgr, int roleID, int songLiID, string liPinMa, int roleZoneID)
        {
            int result;

            if (null == LiPinMaManager._LiPinMaDict)
            {
                result = -1010;
            }
            else
            {
                Dictionary <string, LiPinMaItem> liPinMaDict = LiPinMaManager._LiPinMaDict;
                liPinMa = liPinMa.ToUpper();
                int ptid      = -1;
                int ptrepeat  = 0;
                int zoneID    = 0;
                int maxUseNum = 0;
                if (!LiPinMaParse.ParseLiPinMaNX2(liPinMa, out ptid, out ptrepeat, out zoneID, out maxUseNum))
                {
                    result = -1020;
                }
                else if (zoneID > 0 && roleZoneID != zoneID)
                {
                    result = -1021;
                }
                else
                {
                    lock (LiPinMaManager.Mutex)
                    {
                        LiPinMaItem liPinMaItem = null;
                        bool        bIsNew      = false;
                        if (!liPinMaDict.TryGetValue(liPinMa, out liPinMaItem))
                        {
                            liPinMaItem = new LiPinMaItem
                            {
                                LiPinMa       = liPinMa,
                                HuodongID     = 1,
                                MaxNum        = maxUseNum,
                                UsedNum       = 0,
                                PingTaiID     = ptid,
                                PingTaiRepeat = ptrepeat
                            };
                            liPinMaDict[liPinMa] = liPinMaItem;
                            bIsNew = true;
                        }
                        if (liPinMaItem.HuodongID != songLiID)
                        {
                            return(-1030);
                        }
                        if (liPinMaItem.MaxNum > 0 && liPinMaItem.UsedNum >= liPinMaItem.MaxNum)
                        {
                            return(-1040);
                        }
                        if (liPinMaItem.PingTaiRepeat <= 0)
                        {
                            int pingTaiID = DBQuery.QueryPingTaiIDByHuoDongID(dbMgr, liPinMaItem.HuodongID, roleID, liPinMaItem.PingTaiID);
                            if (pingTaiID == liPinMaItem.PingTaiID)
                            {
                                if (liPinMaItem.MaxNum <= 1 || !bIsNew)
                                {
                                    return(-10000);
                                }
                                int nUseNum = DBQuery.QueryUseNumByHuoDongID(dbMgr, liPinMaItem.HuodongID, roleID, liPinMaItem.PingTaiID);
                                if (nUseNum >= liPinMaItem.MaxNum)
                                {
                                    return(-1040);
                                }
                            }
                        }
                        DBWriter.AddUsedLiPinMa(dbMgr, liPinMaItem.HuodongID, liPinMaItem.LiPinMa, liPinMaItem.PingTaiID, roleID);
                        liPinMaItem.UsedNum++;
                        int usedNum = liPinMaItem.UsedNum;
                    }
                    DBWriter.InsertNewLiPinMa(dbMgr, liPinMa, songLiID.ToString(), "1", ptid.ToString(), ptrepeat.ToString(), "1");
                    result = 0;
                }
            }
            return(result);
        }
Пример #4
0
        /// <summary>
        /// 使用某个礼品码(自己生成的特定格式的礼品码)
        /// </summary>
        /// <param name="dbMgr"></param>
        /// <param name="fileName"></param>
        public static int UseLiPinMa2(DBManager dbMgr, int roleID, int songLiID, string liPinMa, int roleZoneID)
        {
            if (null == _LiPinMaDict)
            {
                return(-1010);
            }
            Dictionary <string, LiPinMaItem> liPinMaDict = _LiPinMaDict; //先得到

            int usedNum = 0;

            liPinMa = liPinMa.ToUpper(); //转成大写

            int ptid = -1, ptrepeat = 0, zoneID = 0;

            if (!LiPinMaParse.ParseLiPinMa(liPinMa, out ptid, out ptrepeat, out zoneID))
            {
                return(-1020);
            }

            if (zoneID > 0 && roleZoneID != zoneID)
            {
                return(-1021);
            }

            //防止多用户重入
            lock (Mutex)
            {
                LiPinMaItem liPinMaItem = null;
                if (!liPinMaDict.TryGetValue(liPinMa, out liPinMaItem))
                {
                    liPinMaItem = new LiPinMaItem()
                    {
                        LiPinMa       = liPinMa,
                        HuodongID     = 1,
                        MaxNum        = 1,
                        UsedNum       = 0,
                        PingTaiID     = ptid,
                        PingTaiRepeat = ptrepeat,
                    };

                    liPinMaDict[liPinMa] = liPinMaItem;
                }

                if (liPinMaItem.HuodongID != songLiID)
                {
                    return(-1030);
                }

                if (liPinMaItem.MaxNum > 0 && liPinMaItem.UsedNum >= liPinMaItem.MaxNum)
                {
                    return(-1040);
                }

                //如果不允许平台内的礼品码重复领取
                if (liPinMaItem.PingTaiRepeat <= 0)
                {
                    //通过活动ID查询平台ID
                    int pingTaiID = DBQuery.QueryPingTaiIDByHuoDongID(dbMgr, liPinMaItem.HuodongID, roleID, liPinMaItem.PingTaiID);
                    if (pingTaiID == liPinMaItem.PingTaiID)
                    {
                        return(-10000);
                    }
                }

                //添加使用礼品码的平台记录
                DBWriter.AddUsedLiPinMa(dbMgr, liPinMaItem.HuodongID, liPinMaItem.LiPinMa, liPinMaItem.PingTaiID, roleID);

                liPinMaItem.UsedNum++;
                usedNum = liPinMaItem.UsedNum;
            }

            //插入一个新的礼品码的数据
            DBWriter.InsertNewLiPinMa(dbMgr, liPinMa, songLiID.ToString(), "1", ptid.ToString(), ptrepeat.ToString(), "1");

            return(0);
        }