public NormalResult UpdateLotteryPeriod(Campaign_LotteryPeriodEntity lotteryPeriod)
        {
            if (lotteryPeriod == null)
            {
                Debug.Assert(false, "lotteryPeriod == null");
                return(new NormalResult("参数错误。"));
            }

            //所属活动如果已结束则不允许修改
            EnumCampaignStatus?campaignStatus = _campaignManager.GetStatus(lotteryPeriod.CampaignId);

            if (campaignStatus == null)
            {
                return(new NormalResult("活动不存在。"));
            }

            if (campaignStatus.Value == EnumCampaignStatus.End)
            {
                return(new NormalResult("已结束活动的周期不允许修改。"));
            }

            Campaign_LotteryPeriodEntity current = GetLotteryPeriod(lotteryPeriod.Id);

            if (current == null)
            {
                return(new NormalResult("要修改的周期不存在。"));
            }

            if (current.Drawn)
            {
                return(new NormalResult("已完成抽奖的周期不允许修改。"));
            }

            //对于正在进行中的活动,已经结束或抽过奖的周期不允许修改
            if (campaignStatus.Value == EnumCampaignStatus.Ongoing)
            {
                if (current.EndTime <= DateTime.Now || current.Drawn)
                {
                    return(new NormalResult("已结束的周期不可修改。"));
                }
            }

            _campaignManager.DataBase.Update(lotteryPeriod);

            return(new NormalResult());
        }
Beispiel #2
0
        public string MemberQRCodeLanding(Guid campaignId, Guid qrCodeOwnMemberId, string visitorOpenId)
        {
            Campaign_MemberQRCodeBundle campaignBundle = GetMemberQRCodeBundle(campaignId);

            if (campaignBundle.Empty)
            {
                return(null);
            }

            if (String.IsNullOrEmpty(campaignBundle.MemberQRCode.LandingUrl))
            {
                return(null);
            }

            //判断活动状态
            EnumCampaignStatus?status = _campaignManager.GetStatus(campaignId);

            if (status == null || status.Value != EnumCampaignStatus.Ongoing)
            {
                //允许落地,但是不奖励了
                return(campaignBundle.MemberQRCode.LandingUrl);
            }

            //如果同一个OpenId扫描过,则不奖励,但是日志还是会记录,用于统计
            List <CommandParameter> logParameterList = new List <CommandParameter>();

            logParameterList.Add(new CommandParameter("@campaignId", campaignId));
            logParameterList.Add(new CommandParameter("@qrCodeOwnMember", qrCodeOwnMemberId));
            logParameterList.Add(new CommandParameter("@visitorOpenId", visitorOpenId));

            //同一个访问者扫了多少次
            int sameVisitorCount = 0;

            _campaignManager.DataBase.ExecuteScalar <int>(
                "SELECT Count(1) FROM [Campaign_MemberQRCodeLandingLog] WHERE [CampaignId] = @campaignId AND [QRCodeOwnMember] = @qrCodeOwnMember AND [VisitorOpenId] = @visitorOpenId",
                logParameterList, (scalarValue) => { sameVisitorCount = scalarValue; });


            #region 奖励积分

            if (campaignBundle.MemberQRCode.LandingPoint > 0 && sameVisitorCount == 0)
            {
                //奖励积分
                PointTrackArgs args = new PointTrackArgs();
                args.DomainId = campaignBundle.Campaign.Domain;
                args.MemberId = qrCodeOwnMemberId;
                args.Quantity = campaignBundle.MemberQRCode.LandingPoint;
                args.Type     = MemberPointTrackType.Campaign;
                args.TagName  = campaignBundle.Campaign.Name;
                args.TagId    = campaignId;

                _campaignManager.MemberManager.PointTrack(args);
            }

            #endregion

            #region 计数

            //LandingCount 直接+1 LandingPersonCount 要判断人员是否重复
            //查询已经有多少人扫过
            List <CommandParameter> parameterList = new List <CommandParameter>();
            parameterList.Add(new CommandParameter("@campaignId", campaignId));
            parameterList.Add(new CommandParameter("@qrCodeOwnMember", qrCodeOwnMemberId));

            if (sameVisitorCount == 0)
            {
                _campaignManager.DataBase.ExecuteNonQuery(
                    "UPDATE [Campaign_MemberQRCodeItem] SET [LandingCount] = [LandingCount] + 1,[LandingPersonCount] = [LandingPersonCount] + 1 WHERE [CampaignId] = @campaignId AND [Member] = @qrCodeOwnMember ",
                    parameterList);
            }
            else
            {
                _campaignManager.DataBase.ExecuteNonQuery(
                    "UPDATE [Campaign_MemberQRCodeItem] SET [LandingCount] = [LandingCount] + 1 WHERE [CampaignId] = @campaignId AND [Member] = @qrCodeOwnMember ",
                    parameterList);
            }

            #endregion

            //记录落地日志
            Campaign_MemberQRCodeLandingLogEntity log = new Campaign_MemberQRCodeLandingLogEntity();
            log.CampaignId      = campaignId;
            log.Domain          = campaignBundle.Campaign.Domain;
            log.QRCodeOwnMember = qrCodeOwnMemberId;
            log.VisitorOpenId   = visitorOpenId;
            log.LandingTime     = DateTime.Now;

            _campaignManager.DataBase.Insert(log);

            return(campaignBundle.MemberQRCode.LandingUrl);
        }