Пример #1
0
    private void SaveRevard(PrizeInfo PrizeInfo)
    {
        if (PrizeInfo.IsCharacter)
        {
            AddCharacterToCollection();
        }
        switch (PrizeInfo.PrizeTypeID)
        {
        case 0:
        {
            AddCoints(PrizeInfo.CurrentCount);
            break;
        }

        case 1:
        {
            AddGems(PrizeInfo.CurrentCount);
            break;
        }

        case 2:
        {
            AddEnergy(PrizeInfo.CurrentCount);
            break;
        }

        case 3:
        {
            AddSpecialMaterials(PrizeInfo.CurrentCount);
            break;
        }
        }
    }
Пример #2
0
        public static short _currMaxLv = GameConfigSet.CurrMaxLv.ToShort(); //玩家最大等级

        /// <summary>
        /// 将星佣兵完成任务后奖励物品名称
        /// </summary>
        /// <param name="prize"></param>
        /// <returns></returns>
        public static string PrizeItemName(PrizeInfo prize)
        {
            string name = string.Empty;

            switch (prize.Type)
            {
            case RewardType.CrystalId:
                CrystalInfo crystal = new ConfigCacheSet <CrystalInfo>().FindKey(prize.ItemID);
                name = crystal == null ? string.Empty : crystal.CrystalName;
                break;

            case RewardType.Item:
                ItemBaseInfo itemInfo = new ConfigCacheSet <ItemBaseInfo>().FindKey(prize.ItemID);
                name = itemInfo == null ? string.Empty : itemInfo.ItemName;
                break;

            case RewardType.Spare:
                SparePartInfo sparePartInfo = new ConfigCacheSet <SparePartInfo>().FindKey(prize.ItemID);
                name = sparePartInfo == null ? string.Empty : sparePartInfo.Name;
                break;

            case RewardType.CrystalType:
                name = string.Format(LanguageManager.GetLang().St_Crystal,
                                     CrystalHelper.GetQualityName(prize.CrystalType.ToEnum <CrystalQualityType>()),
                                     string.Empty);
                break;
            }
            return(name);
        }
Пример #3
0
    public void OnStartClick()
    {
        //
        SQDebug.Log("获取当前转盘奖励");

        if (prizeData.drawNum - prizeData.drawTotal <= 0)
        {
            Global.Inst.GetController <CommonTipsController>().ShowTips("您没有抽奖次数");
            return;
        }

        Global.Inst.GetController <MainController>().SendPrizeBack((data) =>
        {
            prizeData.drawTotal++;

            mCount.text     = string.Format("{0}次", prizeData.drawNum - prizeData.drawTotal);
            mPlayCount.text = string.Format("[7F6E36]游戏局数:[-][FFA70B]{0}[-]  [7F6E36]已抽奖次数:[-][FFA70B]{1}[-]",
                                            prizeData.games, prizeData.drawTotal);

            int index = prizeData.info.FindIndex((p) => p.prizeId == data.prizeInfo.prizeId);
            reward    = data.prizeInfo;

            float angle = 18 + index * mItemAgle + UnityEngine.Random.Range(-mItemAgle * 0.35f, mItemAgle * 0.35f);

            angle += 360 * UnityEngine.Random.Range(6, 10);

            StartCoroutine(StartRun(Vector3.forward * angle));
        });
    }
Пример #4
0
 public void SendChat(PrizeInfo prize, string NickName, string ItemName)
 {
     if (prize.Desc != null && prize.Desc != string.Empty)
     {
         new TjxChatService().SystemSend(ChatType.World, string.Format(prize.Desc,
                                                                       NickName, ItemName));
     }
 }
Пример #5
0
        /// <summary>
        /// 领取神秘礼包
        /// </summary>
        /// <returns></returns>
        public static void MysteriousSpree(UserItemInfo item, GameUser user)
        {
            ItemBaseInfo itemInfo = new ShareCacheStruct <ItemBaseInfo>().FindKey(item.ItemID);

            if (itemInfo != null)
            {
                var       prizeInfosArray = itemInfo.ItemPack;
                int       randomNum       = RandomUtils.GetRandom(0, prizeInfosArray.Count);
                PrizeInfo prizeInfo       = prizeInfosArray[randomNum];
                ActivitiesAward.GameUserReward(user.UserID, prizeInfo.Type, prizeInfo.ItemID, prizeInfo.Num);
            }
        }
Пример #6
0
 private void SetPrivatePrizeInfoToPrizeInfo(PrivatePrizeInfo From, PrizeInfo To)
 {
     if (From.IsCharacter)
     {
         To.PrizeTypeID = From.PrizeTypeID;
         To.PrizeName   = From.PrizeName;
         To.IsCharacter = From.IsCharacter;
     }
     else
     {
         To.PrizeTypeID  = From.PrizeTypeID;
         To.PrizeName    = From.PrizeName;
         To.IsCharacter  = From.IsCharacter;
         To.CurrentCount = From.CurrentCount;
     }
 }
Пример #7
0
        /// <summary>
        /// 随机获得金币、精力奖励
        /// </summary>
        /// <param name="item"></param>
        /// <param name="user"></param>
        public static void GetProbabilityReward(GameUser user, UserItemInfo item)
        {
            ItemBaseInfo itemInfo = new ShareCacheStruct <ItemBaseInfo>().FindKey(item.ItemID);

            if (itemInfo != null)
            {
                var      prizeInfosArray = itemInfo.ItemPack;
                double[] probability     = new double[prizeInfosArray.Count];
                for (int i = 0; i < prizeInfosArray.Count; i++)
                {
                    probability[i] = (double)prizeInfosArray[i].Probability;
                }
                int       index2    = RandomUtils.GetHitIndex(probability);
                PrizeInfo prizeInfo = prizeInfosArray[index2];
                ActivitiesAward.GameUserReward(user.UserID, prizeInfo.Type, prizeInfo.ItemID, prizeInfo.Num);
                UserItemHelper.UseUserItem(user.UserID, item.ItemID, 1);
            }
        }
Пример #8
0
    private void SwitchPrizeInfo(PrizeInfo From, PrizeInfo To)
    {
        var temp = gameObject.AddComponent <PrizeInfo>();

        temp.PrizeTypeID  = From.PrizeTypeID;
        temp.PrizeName    = From.PrizeName;
        temp.IsCharacter  = From.IsCharacter;
        temp.CurrentCount = From.CurrentCount;


        From.PrizeTypeID  = To.PrizeTypeID;
        From.PrizeName    = To.PrizeName;
        From.IsCharacter  = To.IsCharacter;
        From.CurrentCount = To.CurrentCount;


        To.PrizeTypeID  = temp.PrizeTypeID;
        To.PrizeName    = temp.PrizeName;
        To.IsCharacter  = temp.IsCharacter;
        To.CurrentCount = temp.CurrentCount;
        To = temp;
        Destroy(temp);
    }
Пример #9
0
    public void SetItem(float angel, PrizeInfo data, ActivityBigWheelConfig config)
    {
        id = data.prizeId;
        objTran.transform.localPosition = Vector3.zero;
        objTran.localRotation           = Quaternion.Euler(0, 0, angel);
        if (!data.type.Equals("nowinning"))
        {
            label_bet.gameObject.SetActive(true);
            label_bet.text = string.Format("x {0}", data.num);
            iconBG.gameObject.SetActive(true);
            iconBG.spriteName = config.iconUrl;
            iconBG.MakePixelPerfect();
            labelName.text = string.Empty;
        }
        else
        {
            iconBG.gameObject.SetActive(false);
            label_bet.gameObject.SetActive(false);
            labelName.text = data.name;
        }

        label_bet.color = Color.red;
    }
Пример #10
0
        public static void IsTriggerMyStery(GameUser user, MysteryType mysteryType, out string prizecontent)
        {
            prizecontent = string.Empty;
            int         mysteryNum  = GetMySteryNum(user.UserID, mysteryType);
            MysteryInfo mysteryInfo = new ShareCacheStruct <MysteryInfo>().FindKey(mysteryType);

            if (mysteryInfo != null && mysteryNum > 0)
            {
                var randomNum = RandomUtils.GetRandom(0, 1000);
                if (randomNum < mysteryInfo.Probability * 1000)
                {
                    CacheList <PrizeInfo> prizeInfoList = mysteryInfo.PrizeInfo;
                    double[] probability = new double[prizeInfoList.Count];
                    for (int i = 0; i < prizeInfoList.Count; i++)
                    {
                        probability[i] = (double)prizeInfoList[i].Probability;
                    }
                    int       index2    = RandomUtils.GetHitIndex(probability);
                    PrizeInfo prizeInfo = prizeInfoList[index2];
                    prizecontent = MysteryRewardName(user, prizeInfo);
                    UpdateRestrainExplore(user.UserID, mysteryType);
                }
            }
        }
Пример #11
0
        protected override CommandResult <PrizeModel> OnExecute(object commandParameter)
        {
            var result = new CommandResult <PrizeModel>();
            var param  = commandParameter as NewYearDrawPrizeParameter;

            result.Data = new PrizeModel();
            using (CoreContext context = new CoreContext())
            {
                var act = context.ActivityInfo.Where(a => a.StartTime <= DateTime.Now && a.EndTime >= DateTime.Now && a.Status == 1 && a.Kind == param.Kind).FirstOrDefault();
                if (act == null)
                {
                    result.ErrorCode    = -1;
                    result.ErrorMessage = "活动已结束";
                    return(result);
                }

                Hashtable pconfig = JsonConvert.DeserializeObject <Hashtable>(act.ProductConfig);

                var zlopenid = context.MemberInfo.Where(m => m.AccountId == param.MemberAccount).Select(m => m.ZlOpenId).FirstOrDefault();

                //扣减次数,使用数据库锁
                if (context.Database.ExecuteSqlCommand(@"update member_draw_count set current_count=(current_count-1) 
                                                        where member_account=@p0 and act_id=@p1 and current_count-1>=0", zlopenid, act.Recid) > 0)
                {
                    PrizeModel prize = null;

                    var LogCount = context.ActivityLog.Where(l => l.MemberAccount == zlopenid && l.ActivityId == act.Recid).Count();

                    {
                        var     connect = ConfigurationUtil.GetSection("ConnectionStrings")["ShopConnectString"];
                        decimal payFee  = 0;
                        using (MySqlConnection con = new MySqlConnection(connect))
                        {
                            con.Open();
                            MySqlCommand com1 = new MySqlCommand("select sum(payment_fee) as PayFee from shop_order_info " +
                                                                 "where member_account=?acc and pay_status=1 and order_no like '%00' and date(payment_time)>='2019-01-16' and date(payment_time)<='2019-01-25' ", con);
                            com1.Parameters.Add(new MySqlParameter("?acc", zlopenid));
                            var Reader1 = com1.ExecuteReader();
                            while (Reader1.Read())
                            {
                                if (Reader1["PayFee"] != DBNull.Value)
                                {
                                    payFee = Convert.ToDecimal(Reader1["PayFee"]);
                                }
                            }
                            Reader1.Close();
                            con.Close();
                        }
                        var plist = new List <PrizeModel>();
                        //遍历奖品规则
                        var redisdb = RedisClient.GetDatabase(2);
                        foreach (var item in (pconfig["PayPrize"] as JArray).ToObject <List <Hashtable> >())
                        {
                            JObject condiction = item["Condition"] as JObject;
                            if (payFee >= condiction["Fee"].Value <decimal>())
                            {
                                var _plist = new List <PrizeModel>();
                                foreach (var hash in (item["Prize"] as JArray).ToObject <List <Hashtable> >())
                                {
                                    if (!hash.ContainsKey("end") || DateTime.Parse(hash["start"] as string) <= DateTime.Now && DateTime.Parse(hash["end"] as string) >= DateTime.Now)
                                    {
                                        _plist.Add(new PrizeModel()
                                        {
                                            PrizeCode = hash["PrizeCode"] as string,
                                            PrizeName = hash["PrizeName"] as string,
                                            Kind      = hash["Kind"] as string,
                                            Ratio     = Convert.ToInt32(hash["Ratio"]),
                                            CouponId  = hash.ContainsKey("CouponId")? Convert.ToInt32(hash["CouponId"]):0
                                        });
                                    }
                                }
                                if (_plist.Count > 0)
                                {
                                    var p = GetPrize(_plist);
                                    if (p != null)
                                    {
                                        string key = p.PrizeCode.IndexOf("prize") > -1 ? "RealPrize" : p.PrizeCode;
                                        //判断中奖次数
                                        if (condiction["Limit"] != null && ValidateCount(redisdb, key, param.MemberAccount, Convert.ToInt32(condiction["Limit"])))
                                        {
                                            continue;
                                        }
                                        //处理实物奖品
                                        if (p.Kind == "RealPrize")
                                        {
                                            string RealPrize = "";
                                            RealPrize = redisdb.ListLeftPop("Prize:" + p.PrizeCode);
                                            if (!string.IsNullOrEmpty(RealPrize))
                                            {
                                                prize = JsonConvert.DeserializeObject <PrizeModel>(RealPrize);
                                            }
                                            else
                                            {
                                                continue;//实物不中继续往下抽奖
                                            }
                                        }
                                        else
                                        {
                                            prize = p;
                                        }

                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (prize != null)
                    {
                        result.Data = prize;
                        var p = new PrizeInfo()
                        {
                            Status        = 1,
                            ActId         = act.Recid,
                            CouponId      = prize.CouponId,
                            CreateDate    = DateTime.Now,
                            MemberAccount = zlopenid,
                            PrizeCode     = prize.PrizeCode,
                            PrizeName     = prize.PrizeName,
                            Kind          = prize.Kind,
                        };
                        context.PrizeInfo.Add(p);
                        if (prize.Kind == "Coupon")
                        {
                            //调用获取优惠券
                            var url = ConfigurationUtil.GetSection("CouponUrl").Value as string;
                            //领取抵扣优惠券
                            try
                            {
                                ActiveMQMessagePusher.Push("Command",
                                                           new Dictionary <string, string>
                                {
                                    { "caller", "Restful" },
                                    { "url", url }
                                }, new
                                {
                                    MemberAccount = zlopenid,
                                    RuleId        = Convert.ToInt32(prize.CouponId)
                                }
                                                           );
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    else
                    {
                        result.ErrorMessage = "未中奖,换个姿势再试试吧";
                        result.ErrorCode    = -22;
                    }
                }
                else
                {
                    result.ErrorCode    = -21;
                    result.ErrorMessage = "";
                }
                context.ActivityLog.Add(new ActivityLog()
                {
                    MemberAccount = zlopenid,
                    ActivityId    = act.Recid,
                    CreateTime    = DateTime.Now,
                    Memo          = result.Data != null ? "抽中:" + result.Data.PrizeName : result.ErrorMessage
                });
                context.SaveChanges();
            }

            return(result);
        }
Пример #12
0
        public static UserTakePrize GetUserTake(PrizeInfo prize, string userID, FestivalInfo info)
        {
            UserTakePrize userPrize = new UserTakePrize();

            userPrize.CreateDate     = DateTime.Now;
            userPrize.ID             = Guid.NewGuid().ToString();
            userPrize.UserID         = Convert.ToInt32(userID);
            userPrize.MailContent    = info.FestivalExtend.KeyWord;
            userPrize.IsTasked       = false;
            userPrize.TaskDate       = MathUtils.SqlMinDate;
            userPrize.ItemPackage    = string.Empty;
            userPrize.SparePackage   = string.Empty;
            userPrize.CrystalPackage = string.Empty;
            userPrize.EnchantPackage = string.Empty;
            userPrize.OpUserID       = 10000;
            switch (prize.Type)
            {
            case RewardType.GameGoin:
                userPrize.GameCoin     = prize.Num;
                userPrize.MailContent += string.Format(LanguageManager.GetLang().St_GameCoin, prize.Num);
                break;

            case RewardType.Obtion:
                userPrize.ObtainNum    = prize.Num;
                userPrize.MailContent += string.Format(LanguageManager.GetLang().St_ObtionNum, prize.Num);
                break;

            case RewardType.ExpNum:
                userPrize.ExpNum       = prize.Num;
                userPrize.MailContent += string.Format(LanguageManager.GetLang().St_ExpNum, prize.Num);
                break;

            case RewardType.EnergyNum:
                userPrize.EnergyNum    = prize.Num;
                userPrize.MailContent += string.Format(LanguageManager.GetLang().St_EnergyNum, prize.Num);
                break;

            case RewardType.Experience:
                break;

            case RewardType.Gold:
                userPrize.Gold         = prize.Num;
                userPrize.MailContent += string.Format(LanguageManager.GetLang().St_GiftGoldNum, prize.Num);
                break;

            case RewardType.Item:
                userPrize.ItemPackage = string.Format("{0}={1}={2}", prize.ItemID, prize.UserLv, prize.Num);
                ItemBaseInfo itemInfo = new ShareCacheStruct <ItemBaseInfo>().FindKey(prize.ItemID);
                if (itemInfo != null)
                {
                    userPrize.MailContent += string.Format("{0}*{1}", itemInfo.ItemName, prize.Num);
                }
                break;

            case RewardType.CrystalType:
                //List<CrystalInfo> crystalArray2 = new ShareCacheStruct<CrystalInfo>().FindAll(CrystalInfo.Index_CrystalQuality, prize.CrystalType);
                //userPrize.CrystalPackage = string.Format("{0}={1}={2}", itemID, prize.UserLv, itemNum);
                break;

            case RewardType.CrystalId:

                userPrize.CrystalPackage = string.Format("{0}={1}={2}", prize.ItemID, prize.UserLv, prize.Num);
                CrystalInfo crystal = new ShareCacheStruct <CrystalInfo>().FindKey(prize.ItemID);
                if (crystal != null)
                {
                    userPrize.MailContent += string.Format("{0}*{1}", crystal.CrystalName, prize.Num);
                }
                break;

            case RewardType.Spare:
                userPrize.SparePackage = string.Format("{0}={1}={2}", prize.ItemID, prize.Num, prize.Num);
                SparePartInfo spare = new ShareCacheStruct <SparePartInfo>().FindKey(prize.ItemID);
                if (spare != null)
                {
                    userPrize.MailContent += string.Format("{0}*{1}", spare.Name, prize.Num);
                }
                break;

            case RewardType.Enchant:
                userPrize.EnchantPackage = string.Format("{0}={1}={2}", prize.ItemID, prize.UserLv, prize.Num);
                EnchantInfo enchantInfo = new ShareCacheStruct <EnchantInfo>().FindKey(prize.ItemID);
                if (enchantInfo != null)
                {
                    userPrize.MailContent += string.Format("{0}*{1}", enchantInfo.EnchantName, prize.Num);
                }
                break;

            default:
                break;
            }
            return(userPrize);
        }
        public string PrizeProbability(dynamic requestData)
        {
            try
            {
                Random    random    = rand;
                PrizeInfo dd        = new PrizeInfo();
                int       memberId  = JsonConvert.DeserializeObject <int>(JsonConvert.SerializeObject(requestData.MemberId));
                DateTime  beginTime = DateTime.Parse("2018-01-22 10:00");
                DateTime  EndTime   = DateTime.Parse("2018-10-30 23:59");
                DateTime  dayNow    = DateTime.Now;
                //活动结束
                if (dayNow < beginTime || dayNow >= EndTime)
                {
                    return("-3");
                }
                var sqlCount  = " select sum(Count) as sumRedPacket from [PrizeInfo]";
                var dataTable = dataContext.ExecuteDataTable(CommandType.Text, sqlCount);
                var count     = Convert.ToInt32(dataTable.Rows[0][0]);
                if (count <= 0)
                {
                    return("-3");
                }


                lock (olock)
                {
                    //整个活动中是否中过奖
                    var IsPrize = (from v in db.PrizeInfoWinner
                                   where v.MemberId == memberId && v.PrizeRank > 0
                                   select v).FirstOrDefault();
                    Thread.Sleep(50);

                    #region 整个活动中没有中奖
                    if (IsPrize == null)
                    {
                        int max              = 200;
                        int adjust           = 7;
                        var prizeProbability = random.Next(1, max + 1);
                        //prizeRank
                        int prizeRank = 0;
                        if (prizeProbability <= max * 5 / 100 - adjust)
                        {
                            prizeRank = 1;
                        }
                        if (prizeProbability > max * 5 / 100 && prizeProbability <= max * 13 / 100 - adjust)
                        {
                            prizeRank = 2;
                        }
                        if (prizeProbability > max * 13 / 100 && prizeProbability <= max * 23 / 100)
                        {
                            prizeRank = 3;
                        }
                        if (prizeProbability > max * 23 / 100 && prizeProbability <= max * 38 / 100)
                        {
                            prizeRank = 4;
                        }
                        if (prizeProbability > max * 38 / 100 && prizeProbability <= max * 58 / 100)
                        {
                            prizeRank = 5;
                        }
                        DateTime today = DateTime.Today;

                        //当天是否抽奖
                        var IsToday = (from v in db.PrizeInfoWinner
                                       where v.MemberId == memberId && v.CreateDay == today
                                       select v).FirstOrDefault();


                        #region 表明当天没有抽奖

                        if (IsToday == null)
                        {
                            #region 表明没有抽中奖

                            if (prizeRank == 0)
                            {
                                PrizeInfoWinner pw = new PrizeInfoWinner();
                                pw.MemberId            = memberId;
                                pw.PrizeRank           = 0;
                                pw.PrizeProbabilityNum = prizeProbability;
                                pw.CreateDay           = today;
                                db.PrizeInfoWinner.Add(pw);
                                db.SaveChanges();
                            }
                            #endregion

                            #region 表明抽中奖了
                            else
                            {
                                //看看奖品信息
                                var IsCount = (from v in db.PrizeInfo
                                               where v.PrizeRank == prizeRank
                                               select v).FirstOrDefault();

                                //如果不是5等奖,看看奖品数量是否充足
                                if (prizeRank != 5)
                                {
                                    //前4个奖品数量不足,让其转为第5名
                                    if (IsCount.Count < 1)
                                    {
                                        prizeRank = 5;
                                    }
                                }
                                #region 更新奖品数量,并把抽奖信息放入到抽奖单元里面

                                var sql = string.Format("Update  PrizeInfo set Count=Count-1 where PrizeRank={0}", prizeRank);

                                int updateCount = dataContext.ExecuteNonQuery(CommandType.Text, sql);

                                if (updateCount > 0)
                                {
                                    PrizeInfoWinner pw = new PrizeInfoWinner();
                                    pw.MemberId            = memberId;
                                    pw.PrizeRank           = prizeRank;
                                    pw.PrizeProbabilityNum = prizeProbability;
                                    pw.CreateDay           = today;
                                    db.PrizeInfoWinner.Add(pw);
                                    db.SaveChanges();
                                }

                                #endregion
                            }
                            #endregion
                        }
                        #endregion

                        //表明当天抽过奖了
                        else
                        {
                            prizeRank = -1;
                            PrizeInfoWinner pw = new PrizeInfoWinner();
                            pw.MemberId            = memberId;
                            pw.PrizeRank           = prizeRank;
                            pw.PrizeProbabilityNum = 0;
                            pw.CreateDay           = today;
                            db.PrizeInfoWinner.Add(pw);
                            db.SaveChanges();
                        }

                        Thread.Sleep(500);
                        return(prizeRank.ToString());
                    }
                    #endregion
                    else
                    {
                        PrizeInfoWinner pw = new PrizeInfoWinner();
                        pw.MemberId            = memberId;
                        pw.PrizeRank           = -2;
                        pw.PrizeProbabilityNum = 0;
                        pw.CreateDay           = DateTime.Today;
                        db.PrizeInfoWinner.Add(pw);
                        db.SaveChanges();
                        return("-2");
                    }
                }
            }
            catch (Exception)
            {
                return("No");
            }
        }
Пример #14
0
        /// <summary>
        /// 奖励物品名称,数量
        /// </summary>
        /// <param name="prize"></param>
        /// <returns></returns>
        public static string MysteryRewardName(GameUser user, PrizeInfo prize)
        {
            string prizeContent = string.Empty;

            switch (prize.Type)
            {
            case RewardType.GameGoin:
                prizeContent  = string.Format(LanguageManager.GetLang().St_GameCoin, prize.Num);
                user.GameCoin = MathUtils.Addition(user.GameCoin, prize.Num);
                break;

            case RewardType.Obtion:
                prizeContent   = string.Format(LanguageManager.GetLang().St_ObtionNum, prize.Num);
                user.ObtainNum = MathUtils.Addition(user.ObtainNum, prize.Num);
                break;

            case RewardType.ExpNum:
                prizeContent = string.Format(LanguageManager.GetLang().St_ExpNum, prize.Num);
                user.ExpNum  = MathUtils.Addition(user.ExpNum, prize.Num);
                break;

            case RewardType.EnergyNum:
                prizeContent   = string.Format(LanguageManager.GetLang().St_EnergyNum, prize.Num);
                user.EnergyNum = MathUtils.Addition(user.EnergyNum, prize.Num.ToShort());
                break;

            case RewardType.Experience:
                UserHelper.UserGeneralExp(user.UserID, prize.Num);
                break;

            case RewardType.Gold:
                prizeContent  = string.Format(LanguageManager.GetLang().St_GiftGoldNum, prize.Num);
                user.GiftGold = MathUtils.Addition(user.GiftGold, prize.Num);
                break;

            case RewardType.Item:
                short        itemLv   = prize.UserLv > 0 ? prize.UserLv : 1.ToShort();
                int          priNum   = prize.Num > 0 ? prize.Num : 1;
                ItemBaseInfo itemInfo = new ShareCacheStruct <ItemBaseInfo>().FindKey(prize.ItemID);
                if (itemInfo != null)
                {
                    UserItemHelper.AddUserItem(user.UserID, itemInfo.ItemID, priNum, itemLv);
                    prizeContent = string.Format("{0}*{1}", itemInfo.ItemName, prize.Num);
                }
                break;

            case RewardType.CrystalId:
                short       cLv     = prize.UserLv > 0 ? prize.UserLv : 1.ToShort();
                CrystalInfo crystal = new ShareCacheStruct <CrystalInfo>().FindKey(prize.ItemID);
                if (crystal != null)
                {
                    CrystalHelper.AppendCrystal(user.UserID, crystal.CrystalID, cLv);
                    prizeContent = string.Format("{0}*{1}", crystal.CrystalName, prize.Num);
                }
                break;

            case RewardType.Spare:
                break;

            case RewardType.Enchant:
                break;

            default:
                break;
            }
            return(prizeContent);
        }
Пример #15
0
        /// <summary>
        /// 获得奖励
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="prize"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public static UserTakePrize GetUserTake(string userID, PrizeInfo prize, string content)
        {
            GameUser user = new PersonalCacheStruct <GameUser>().FindKey(userID);

            if (user == null)
            {
                return(null);
            }
            UserTakePrize userPrize = new UserTakePrize();

            userPrize.CreateDate     = DateTime.Now;
            userPrize.ID             = Guid.NewGuid().ToString();
            userPrize.UserID         = Convert.ToInt32(userID);
            userPrize.MailContent    = content;
            userPrize.IsTasked       = false;
            userPrize.TaskDate       = MathUtils.SqlMinDate;
            userPrize.ItemPackage    = string.Empty;
            userPrize.SparePackage   = string.Empty;
            userPrize.CrystalPackage = string.Empty;
            userPrize.EnchantPackage = string.Empty;
            userPrize.OpUserID       = 10000;
            string prizeContent = string.Empty;

            switch (prize.Type)
            {
            case RewardType.GameGoin:
                userPrize.GameCoin = prize.Num;
                prizeContent       = string.Format(LanguageManager.GetLang().St_GameCoin, prize.Num);
                break;

            case RewardType.Obtion:
                userPrize.ObtainNum = prize.Num;
                prizeContent        = string.Format(LanguageManager.GetLang().St_ObtionNum, prize.Num);
                break;

            case RewardType.ExpNum:
                userPrize.ExpNum = prize.Num;
                prizeContent     = string.Format(LanguageManager.GetLang().St_ExpNum, prize.Num);
                break;

            case RewardType.EnergyNum:
                userPrize.EnergyNum = prize.Num;
                prizeContent        = string.Format(LanguageManager.GetLang().St_EnergyNum, prize.Num);
                break;

            case RewardType.Experience:
                break;

            case RewardType.Gold:
                userPrize.Gold = prize.Num;
                prizeContent   = string.Format(LanguageManager.GetLang().St_GiftGoldNum, prize.Num);
                break;

            case RewardType.Item:
                userPrize.ItemPackage = string.Format("{0}={1}={2}", prize.ItemID, prize.UserLv, prize.Num);
                ItemBaseInfo itemInfo = new ShareCacheStruct <ItemBaseInfo>().FindKey(prize.ItemID);
                if (itemInfo != null)
                {
                    prizeContent = string.Format("{0}*{1}", itemInfo.ItemName, prize.Num);
                }
                break;

            case RewardType.CrystalId:

                userPrize.CrystalPackage = string.Format("{0}={1}={2}", prize.ItemID, prize.UserLv, prize.Num);
                CrystalInfo crystal = new ShareCacheStruct <CrystalInfo>().FindKey(prize.ItemID);
                if (crystal != null)
                {
                    prizeContent = string.Format("{0}*{1}", crystal.CrystalName, prize.Num);
                }
                break;

            case RewardType.Spare:
                userPrize.SparePackage = string.Format("{0}={1}={2}", prize.ItemID, prize.UserLv, prize.Num);
                SparePartInfo spare = new ShareCacheStruct <SparePartInfo>().FindKey(prize.ItemID);
                if (spare != null)
                {
                    prizeContent = string.Format("{0}*{1}", spare.Name, prize.Num);
                }
                break;

            case RewardType.Enchant:
                userPrize.EnchantPackage = string.Format("{0}={1}={2}", prize.ItemID, prize.UserLv, prize.Num);
                EnchantInfo enchantInfo = new ShareCacheStruct <EnchantInfo>().FindKey(prize.ItemID);
                if (enchantInfo != null)
                {
                    prizeContent = string.Format("{0}*{1}", enchantInfo.EnchantName, prize.Num);
                }
                break;

            default:
                break;
            }
            if (!string.IsNullOrEmpty(prizeContent))
            {
                userPrize.MailContent = string.Format(content, user.NickName, prizeContent);
            }
            return(userPrize);
        }
Пример #16
0
        protected override CommandResult <Hashtable> OnExecute(object commandParameter)
        {
            var result = new CommandResult <Hashtable>();
            var param  = commandParameter as DrawPrizeParameter;

            result.Data = new Hashtable();
            using (CoreContext context = new CoreContext())
            {
                var act = context.ActivityInfo.Where(a => a.StartTime <= DateTime.Now && a.EndTime >= DateTime.Now && a.Status == 1 && a.Kind == param.Kind).FirstOrDefault();
                if (act == null)
                {
                    result.ErrorCode    = -1;
                    result.ErrorMessage = "活动已结束";
                    return(result);
                }

                Hashtable pconfig = JsonConvert.DeserializeObject <Hashtable>(act.ProductConfig);

                var zlopenid = context.MemberInfo.Where(m => m.AccountId == param.MemberAccount).Select(m => m.ZlOpenId).FirstOrDefault();

                //扣减次数,使用数据库锁
                if (context.Database.ExecuteSqlCommand(@"update member_draw_count set current_count=(current_count-1) 
                                                        where member_account=@p0 and current_count-1>=0", zlopenid) > 0)
                {
                    var LogCount = context.ActivityLog.Where(l => l.MemberAccount == zlopenid && l.ActivityId == act.Recid).Count();
                    var res      = new NewMemberSkillCommand().Execute(new NewMemberSkillParameter()
                    {
                        MemberAccount = zlopenid,
                        LogCount      = LogCount,
                        Prize         = pconfig
                    });
                    Hashtable prize = null;
                    if (res.ErrorCode == 0 && (Convert.ToBoolean(res.Data["isNew"]) || Convert.ToBoolean(res.Data["is30"])))
                    {
                        result.ErrorCode    = res.ErrorCode;
                        result.ErrorMessage = res.ErrorMessage;
                        prize = res.Data["Prize"] as Hashtable;
                    }
                    else
                    {
                        var     connect = ConfigurationUtil.GetSection("ConnectionStrings")["ShopConnectString"];
                        decimal payFee  = 0;
                        using (MySqlConnection con = new MySqlConnection(connect))
                        {
                            con.Open();
                            MySqlCommand com1 = new MySqlCommand("select sum(payment_fee) as PayFee from shop_order_info " +
                                                                 "where member_account=?acc and pay_status=1 and order_no like '%00' and date(payment_time)>='2018-11-01' and date(payment_time)<='2018-11-11' ", con);
                            com1.Parameters.Add(new MySqlParameter("?acc", zlopenid));
                            var Reader1 = com1.ExecuteReader();
                            while (Reader1.Read())
                            {
                                if (Reader1["PayFee"] != DBNull.Value)
                                {
                                    payFee = Convert.ToDecimal(Reader1["PayFee"]);
                                }
                            }
                            Reader1.Close();
                            con.Close();
                        }
                        //遍历奖品规则
                        var redisdb = RedisClient.GetDatabase(1);
                        foreach (var item in (pconfig["PayPrize"] as JArray).ToObject <List <Hashtable> >())
                        {
                            JObject condiction = item["Condition"] as JObject;

                            string key = "level:" + condiction["Fee"].Value <string>();
                            if (redisdb.HashExists(key, param.MemberAccount))
                            {
                                continue;
                            }
                            if (payFee >= condiction["Fee"].Value <decimal>())
                            {
                                prize = (item["Prize"] as JObject).ToObject <Hashtable>();
                                //处理实物奖品
                                if (prize["Kind"] as string == "RealPrize")
                                {
                                    //var hash = (prize["RealPrize"] as JObject).ToObject<Hashtable>();
                                    var _realprize = new List <PrizeModel>();
                                    foreach (var hash in (prize["RealPrize"] as JArray).ToObject <List <Hashtable> >())
                                    {
                                        if (DateTime.Parse(hash["start"] as string) <= DateTime.Now && DateTime.Parse(hash["end"] as string) >= DateTime.Now)
                                        {
                                            _realprize.Add(new PrizeModel()
                                            {
                                                PrizeCode = hash["PrizeCode"] as string,
                                                PrizeName = hash["PrizeName"] as string,
                                                Kind      = prize["Kind"] as string
                                            });
                                        }
                                    }
                                    string RealPrize = "";

                                    if (_realprize.Count != 0)
                                    {
                                        var r     = new Random(Guid.NewGuid().GetHashCode());
                                        var index = r.Next(0, _realprize.Count);
                                        RealPrize = redisdb.ListLeftPop("Prize:" + _realprize[index].PrizeCode);
                                    }
                                    if (!string.IsNullOrEmpty(RealPrize))
                                    {
                                        prize = JsonConvert.DeserializeObject <Hashtable>(RealPrize);
                                    }
                                    else
                                    {
                                        prize = null;
                                    }
                                }
                                if (prize != null)
                                {
                                    redisdb.HashIncrementAsync(key, param.MemberAccount);
                                }
                                break;
                            }
                        }
                    }
                    if (prize != null)
                    {
                        result.Data = prize;
                        var p = new PrizeInfo()
                        {
                            Status        = 1,
                            ActId         = act.Recid,
                            CouponId      = Convert.ToInt32(prize["CouponId"]),
                            CreateDate    = DateTime.Now,
                            MemberAccount = zlopenid,
                            PrizeCode     = prize["PrizeCode"] as string,
                            PrizeName     = prize["PrizeName"] as string,
                            Kind          = prize["Kind"] as string,
                        };
                        context.PrizeInfo.Add(p);
                        if (prize["Kind"] as string == "Coupon")
                        {
                            //调用获取优惠券
                            var url = ConfigurationUtil.GetSection("CouponUrl").Value as string;
                            //领取抵扣优惠券
                            try
                            {
                                ActiveMQMessagePusher.Push("Command",
                                                           new Dictionary <string, string>
                                {
                                    { "caller", "Restful" },
                                    { "url", url }
                                }, new
                                {
                                    MemberAccount = zlopenid,
                                    RuleId        = Convert.ToInt32(prize["CouponId"])
                                }
                                                           );
                            }
                            catch (Exception)
                            {
                            }
                            //var couponres = ZlanAPICaller.Call<CommandResult<string>>(url, new { MemberAccount = zlopenid, RuleId = Convert.ToInt32(prize["CouponId"]) });
                            //if (couponres.ErrorCode == 0)
                            //{
                            //    couponticket = couponres.Data;
                            //}
                            //else
                            //{
                            //    LogUtil.Log("DrawPrize_TakeCoupon", p.Recid.ToString(), $"input=>{JsonConvert.SerializeObject(new { MemberAccount = zlopenid, RuleId = Convert.ToInt32(prize["CouponId"]) })}#error=>{res.ErrorMessage}");
                            //}
                        }
                    }
                    else
                    {
                        result.ErrorMessage = "未中奖,换个姿势再试试吧";
                        result.ErrorCode    = -22;
                    }
                }
                else
                {
                    result.ErrorCode    = -21;
                    result.ErrorMessage = "每下单68元,即获得一次抽奖机会,上不封顶";
                }
                context.ActivityLog.Add(new ActivityLog()
                {
                    MemberAccount = zlopenid,
                    ActivityId    = act.Recid,
                    CreateTime    = DateTime.Now,
                    Memo          = result.Data.Keys.Count > 0 ? "抽中:" + result.Data["PrizeName"] as string : result.ErrorMessage
                });
                context.SaveChanges();
            }

            return(result);
        }