Пример #1
0
        public CommonActionResult BJDCPrize(string schemeId, bool isBonus, decimal preTaxBonusMoney, decimal afterTaxBonusMoney, string userToken)
        {
            // 验证用户身份及权限
            string userId;

            GameBizAuthBusiness.ValidateAuthentication(userToken, "W", "C040", out userId);
            try
            {
                //! 执行扩展功能代码 - 启动事务前
                Plugin.Core.PluginRunner.ExecPlugin <IPrizeOrder_BeforeTranBegin>(new object[] { schemeId, isBonus, preTaxBonusMoney, afterTaxBonusMoney });

                lock (UsefullHelper.moneyLocker)
                {
                    var result = new PrizeResult();
                    using (var biz = new GameBizBusinessManagement())
                    {
                        biz.BeginTran();

                        //! 执行扩展功能代码 - 启动事务后
                        Plugin.Core.PluginRunner.ExecPlugin <IPrizeOrder_AfterTranBegin>(new object[] { schemeId, isBonus, preTaxBonusMoney, afterTaxBonusMoney });

                        result = new BJDCBusiness().BJDCPrize(schemeId, isBonus ? BonusStatus.Win : BonusStatus.Lose, preTaxBonusMoney, afterTaxBonusMoney);
                        //! 执行扩展功能代码 - 启动提交前
                        Plugin.Core.PluginRunner.ExecPlugin <IPrizeOrder_BeforeTranCommit>(new object[] { result });

                        biz.CommitTran();
                    }
                    //if (isBonus)
                    //{
                    //    GameBizWcfServiceCache.RefreshLastBonusList(result.GameCode);
                    //}
                    //! 执行扩展功能代码 - 启动事务后
                    Plugin.Core.PluginRunner.ExecPlugin <IPrizeOrder_AfterTranCommit>(new object[] { result });
                }

                return(new CommonActionResult(true, "派奖完成"));
            }
            catch (Exception ex)
            {
                //! 执行扩展功能代码 - 发生异常
                Plugin.Core.PluginRunner.ExecPlugin <IPrizeOrder_OnError>(new object[] { schemeId, isBonus, preTaxBonusMoney, afterTaxBonusMoney, ex });
                throw new Exception(string.Format("订单{0} 派奖失败 - {1} ! ", schemeId, ex.Message), ex);
            }
        }
        public void PrizeOrder_AfterTranCommit(PrizeResult result)
        {
            if (!result.IsBonus)
            {
                // 未中奖
                return;
            }
            if (result.SchemeType == SchemeType.TogetherBetting)
            {
                // 合买订单不参与加奖活动
                return;
            }
            var appendMoney      = 0M;
            var appendRatio      = 0M;
            var appendMultiple   = 1;
            var appendTotalMoney = 0M;

            var startIssueNumber        = 0;
            var endIssueNumber          = 500;
            var bonusMoneyStartMultiple = 0;

            ArrayList arrGameType = new ArrayList();
            ArrayList arrBonusMoneyStartMultiple = new ArrayList();
            ArrayList arrTotalBonusMoney         = new ArrayList();
            ArrayList arrAppendMoney             = new ArrayList();

            foreach (var item in result.BonusInfo)
            {
                //获取配置
                var config = new AppendBonusConfigManager().GetAppendBonusConfig(result.GameCode, item.GameTypeCode);

                if (config == null)
                {
                    continue;
                }

                appendMoney    = config.AppendBonusMoney;
                appendRatio    = config.AppendRatio;
                appendMultiple = config.StartMultiple;

                startIssueNumber        = config.StartIssueNumber;
                endIssueNumber          = config.EndIssueNumber;
                bonusMoneyStartMultiple = config.BonusMoneyStartMultiple;

                if (appendMoney < 0 || appendRatio < 0 || appendMultiple < 1 ||
                    startIssueNumber < 0 || endIssueNumber < 0 || bonusMoneyStartMultiple < 0)
                {
                    //配置错误直接返回
                    continue;
                }

                var currentIssueNumber = result.IssuseNumber;
                currentIssueNumber = currentIssueNumber.Substring(currentIssueNumber.IndexOf("-") + 1);

                if (Convert.ToInt32(currentIssueNumber) >= startIssueNumber && Convert.ToInt32(currentIssueNumber) <= endIssueNumber)
                {
                    if (bonusMoneyStartMultiple > 0)
                    {
                        //订单每中xx元加奖xx元
                        int index = arrGameType.IndexOf(item.GameTypeCode);
                        if (index < 0)
                        {
                            arrGameType.Add(item.GameTypeCode);
                            arrBonusMoneyStartMultiple.Add(bonusMoneyStartMultiple);
                            arrTotalBonusMoney.Add(item.TotalMoney);
                            arrAppendMoney.Add(appendMoney);
                        }
                        else
                        {
                            var totalBonusMoney = Convert.ToDecimal(arrTotalBonusMoney[index]);
                            totalBonusMoney += item.TotalMoney;

                            arrTotalBonusMoney[index] = totalBonusMoney;
                        }
                    }
                    else
                    {
                        //每中xx倍加奖xx元
                        appendTotalMoney += item.TotalMoney * (appendRatio / 100.00M) + (appendMoney * (item.Amount / appendMultiple) * item.Count);
                    }
                }
            }

            //订单每中xx元加奖xx元
            for (int i = 0; i < arrGameType.Count; i++)
            {
                appendTotalMoney += Convert.ToDecimal(arrAppendMoney[i].ToString()) * (Convert.ToInt32(Convert.ToDecimal(arrTotalBonusMoney[i].ToString())) / Convert.ToInt32(arrBonusMoneyStartMultiple[i].ToString()));
            }

            if (appendTotalMoney <= 0M)
            {
                //没的任何加奖的,直接退出
                return;
            }

            var totalMoney = result.AfterTaxBonusMoney + appendTotalMoney;

            string displayName = Common.Business.LotteryHelper.GetDisplayNameFromGameCode(result.GameCode);

            string desc = string.Format("{0} 第{1}期 中奖:¥{2:N2}", displayName, result.IssuseNumber, result.AfterTaxBonusMoney, appendTotalMoney);

            if (appendTotalMoney > 0)
            {
                desc += string.Format("【加奖:¥{0:N2}】", appendTotalMoney);
            }

            lock (Common.Utilities.UsefullHelper.moneyLocker)
            {
                using (var biz = new FacaiActivityBusinessManagement())
                {
                    biz.BeginTran();

                    if (appendTotalMoney > 0)
                    {
                        // 添加加奖记录
                        var record = new A20120101_通用加奖_AppendBonus
                        {
                            GameCode         = result.GameCode,
                            GameType         = result.GameTypeList,
                            SchemeId         = result.OrderId,
                            SchemeType       = result.SchemeType,
                            UserId           = result.UserId,
                            IssueMoney       = result.IssuseMoney,
                            BonusMoney       = result.AfterTaxBonusMoney,
                            AppendBonusMoney = appendTotalMoney,
                            AppendRatio      = appendRatio,
                            TotalBonusMoney  = totalMoney,
                            Desc             = desc
                        };

                        var recordManager = new A20120101_通用加奖Manager();
                        recordManager.AddAppendBonusRecord(record);

                        // 添加加奖资金明细
                        BusinessHelper.Payin_2Balance(BusinessHelper.FundCategory_ActivityGiveMoney, result.OrderId, result.OrderId, false, "", "", result.UserId, AccountType.Bonus, appendTotalMoney
                                                      , string.Format("{0} 方案加奖,中奖:¥{0:N2},加奖:¥{1:N2}", result.GameDisplayName, result.TotalBonusMoney, appendTotalMoney));
                    }

                    biz.CommitTran();
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 参与刮刮卡活动
        /// </summary>
        /// <param name="unid"></param>
        /// <returns></returns>
        public PrizeResult Do_ScratchCard(string unid)
        {
            PrizeResult result = new PrizeResult();

            result.IsPrize = false;
            if (!unid.IsNotNullOrEmpty())
            {
                result.Result = "数据为空";
                return(result);
            }
            using (DbRepository entities = new DbRepository())
            {
                //找到实体
                var scratchScardEntity = entities.ScratchCard.Find(unid);
                //奖品设置
                var prizeEntity = entities.Prize.Where(x => x.TargetCode == (int)TargetCode.ScratchCard && x.TargetID.Equals(unid)).FirstOrDefault();
                if (prizeEntity == null || scratchScardEntity == null)
                {
                    result.Result = "数据为空";
                    return(result);
                }

                if (scratchScardEntity.OngoingTime > DateTime.Now)
                {
                    result.Result = "还没到活动时间,请耐心等待";
                    return(result);
                }
                else if (scratchScardEntity.OverTime < DateTime.Now)
                {
                    result.Result = "活动已经结束,敬请期待下次活动";
                    return(result);
                }

                //当前的微信 openid
                string openId = CacheHelper.Get <string>("scra-openId");
                if (!openId.IsNotNullOrEmpty())
                {
                    result.Result = "身份授权已过期,请重新刷新页面授权";
                    return(result);
                }
                //参与抽奖的参与情况
                var hadPrizeList = entities.UserJoinCounter.Where(x => x.TargetCode == (int)TargetCode.ScratchCard && x.TargetID.Equals(unid)).ToList();
                //一等奖个数
                int onePrizeNum = hadPrizeList.Where(x => x.IsPrize == 1 && x.PrizeGrade == 1).Count();
                //二等奖个数
                int twoPrizeNum = hadPrizeList.Where(x => x.IsPrize == 1 && x.PrizeGrade == 2).Count();
                //三等奖个数
                int threePrizeNum = hadPrizeList.Where(x => x.IsPrize == 1 && x.PrizeGrade == 3).Count();
                //个人参与总次数
                int hadJoinCount = hadPrizeList.Where(x => x.OpenID.Equals(openId)).Count();
                if (prizeEntity.AllCountLimt <= hadPrizeList.Count)
                {
                    result.Result = "对不起,您活动次数已经达到最大次数限制";
                    return(result);
                }
                //当前参与情况
                var startDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
                var endDate   = DateTime.Parse(DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"));
                //当天参与情况
                if (hadPrizeList.Where(x => x.OpenID.Equals(openId) && x.CreatedTime >= startDate && x.CreatedTime < endDate).Count() >= prizeEntity.DayLimt)
                {
                    result.Result = scratchScardEntity.RepeatNotice;
                    return(result);
                }

                //随机概率
                Random randow = new Random();
                int    num    = randow.Next(1, prizeEntity.ExpectedPeopleCount - onePrizeNum - twoPrizeNum - threePrizeNum);

                //保存的参与抽奖情况
                var userJoin = new UserJoinCounter();
                userJoin.UNID        = Guid.NewGuid().ToString("N");
                userJoin.TargetCode  = (int)TargetCode.ScratchCard;
                userJoin.TargetID    = unid;
                userJoin.CreatedTime = DateTime.Now;
                userJoin.SN          = userJoin.UNID.SubString(16);
                result.SN            = userJoin.SN;
                userJoin.OpenID      = openId;
                userJoin.IsCach      = 0;

                //减去已中奖个数
                if (num <= prizeEntity.OnePrizeCount - onePrizeNum)
                {
                    userJoin.IsPrize    = 1;
                    userJoin.PrizeGrade = 1;
                    result.Result       = "一等奖";
                    result.IsPrize      = true;
                }
                else if (prizeEntity.OnePrizeCount - onePrizeNum < num && num <= (prizeEntity.OnePrizeCount - onePrizeNum + prizeEntity.TwoPrizeCount - twoPrizeNum))
                {
                    userJoin.IsPrize    = 1;
                    userJoin.PrizeGrade = 2;
                    result.Result       = "二等奖";
                    result.IsPrize      = true;
                }
                else if ((prizeEntity.OnePrizeCount - onePrizeNum + prizeEntity.TwoPrizeCount - twoPrizeNum) < num && num <= (prizeEntity.AllCount - onePrizeNum - twoPrizeNum - threePrizeNum))
                {
                    userJoin.IsPrize    = 1;
                    userJoin.PrizeGrade = 3;
                    result.Result       = "三等奖";
                    result.IsPrize      = true;
                }
                else
                {
                    userJoin.IsPrize    = 0;
                    userJoin.PrizeGrade = 0;
                    result.Result       = "谢谢参与";
                    userJoin.SN         = null;
                    result.SN           = null;
                }
                if (result.IsPrize)
                {
                    prizeEntity.hadPrizeCount++;
                    if (prizeEntity.hadPrizeCount > prizeEntity.OnePrizeCount + prizeEntity.TwoPrizeCount + prizeEntity.ThreePrizeCount)
                    {
                        result.Result = "很抱歉,奖品已经全部派送完了";
                        return(result);
                    }
                }


                entities.UserJoinCounter.Add(userJoin);
                int effect = entities.SaveChanges();
                //保存
                if (effect < 0)
                {
                    //并发修改异常再次执行
                    if (effect == -1)
                    {
                        return(Do_ScratchCard(unid));
                    }
                    else
                    {
                        return new PrizeResult()
                               {
                                   IsError = true
                               }
                    };
                }
                else
                {
                    result.IsError = false;
                    return(result);
                }
            }
        }