Esempio n. 1
0
        protected override GetEventPrizesRD ProcessRequest(DTO.Base.APIRequest <GetEventPrizesRP> pRequest)
        {
            GetEventPrizesRD rd = new GetEventPrizesRD();

            string vipID = pRequest.UserID;

            //string vipID = "f3d925e364e34bf69dfda34fcedc58f8";
            string vipName           = string.Empty;
            string reCommandId       = pRequest.Parameters.RecommandId;
            string eventId           = pRequest.Parameters.EventId;
            float  longitude         = pRequest.Parameters.Longitude;
            float  latitude          = pRequest.Parameters.Latitude;
            string customerId        = this.CurrentUserInfo.ClientID;
            int    pointsLotteryFlag = pRequest.Parameters.PointsLotteryFlag;

            if (string.IsNullOrEmpty(customerId))
            {
                customerId = "f6a7da3d28f74f2abedfc3ea0cf65c01";
            }

            var loggingSessionInfo = Default.GetBSLoggingSession(customerId, "1");

            #region 是否在活动现场
            //respData.content.isSite = "1";
            rd.content = new EventPrizesInfo {
                IsSite = 1
            };

            #endregion

            #region 判断活动是否需要注册

            var leventsBll = new LEventsBLL(this.CurrentUserInfo);

            var enableFlag = leventsBll.GetEnableFlagByEventId(eventId);

            var vipService = new VipBLL(loggingSessionInfo);
            rd.SignFlag = 1;
            //如果需要注册,则判断该会员有没有注册,没有返回
            if (enableFlag.Substring(0, 1) == "1")
            {
                var vipEntity = vipService.GetByID(vipID);
                if (vipEntity == null)
                {
                    rd.SignFlag = 0;
                    return(rd);
                }
                else
                {
                    rd.SignFlag = 1;
                    vipID       = vipEntity.VIPID;
                    vipName     = vipEntity.VipName;
                }
            }



            #endregion

            #region 获取VIPID

            #endregion



            #region

            Loggers.Debug(new DebugLogInfo()
            {
                Message = "vipName = " + vipName
                          + ",vipID =" + vipID
                          + ",eventId=" + eventId
                          + ",longitude" + longitude
                          + ",latitude" + latitude
                          + ",customerId" + customerId
                          + ",reCommandId" + reCommandId
            });
            LPrizePoolsBLL poolsServer = new LPrizePoolsBLL(loggingSessionInfo);
            var            ds          = poolsServer.GetEventWinningInfo(vipName, vipID, eventId, longitude, latitude, customerId, reCommandId, pointsLotteryFlag);

            int    isLottery  = Convert.ToInt32(ds.Tables[0].Rows[0]["IsLottery"]);
            int    winnerFlag = Convert.ToInt32(ds.Tables[0].Rows[0]["WinnerFlag"]);//是否中奖
            string prizeName  = ds.Tables[0].Rows[0]["prizeName"].ToString();
            string prizesId   = ds.Tables[0].Rows[0]["prizesId"].ToString();


            rd.content.IsLottery      = isLottery;
            rd.content.IsWinning      = winnerFlag;
            rd.content.WinningDesc    = prizeName;
            rd.content.Remark         = ds.Tables[0].Rows[0]["Remark"].ToString();
            rd.content.WinningExplan  = ds.Tables[0].Rows[0]["PrizeDesc"].ToString();
            rd.content.EventRound     = ds.Tables[0].Rows[0]["EventRoundId"].ToString();
            rd.content.Status         = Convert.ToInt32(ds.Tables[0].Rows[0]["step"].ToString());
            rd.content.PrizesTypeName = ds.Tables[0].Rows[0]["prizeTypeName"].ToString();
            rd.content.PrizesName     = ds.Tables[0].Rows[0]["prizesName"].ToString();
            rd.content.EventPoints    = Convert.ToInt32(ds.Tables[0].Rows[0]["EventPoints"].ToString());

            #region update by wzq 2014/07/01 积分兑换标识(活动,个人)
            rd.content.PersonPointsLotteryFlag = Convert.ToInt32(ds.Tables[0].Rows[0]["PersonPointsLotteryFlag"].ToString());
            rd.content.EventPointsLotteryFlag  = Convert.ToInt32(ds.Tables[0].Rows[0]["EventPointsLotteryFlag"].ToString());
            #endregion

            #endregion


            #region 推荐人
            //活动是否分享


            var isShare = leventsBll.GetIsShareByEventId(eventId);

            rd.IsShare = isShare;
            Loggers.Debug(new DebugLogInfo()
            {
                Message = "isShare = " + isShare
            });

            CouponBLL couponService = new CouponBLL(loggingSessionInfo);

            //Updated by Willie Yan on 2014-05-30   必须是新推荐的会员
            if (isShare == 1 && !couponService.IfRecordedRecommendTrace(vipID, reCommandId))
            {
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = "reCommandId = " + reCommandId + ", VipID = " + vipID
                });
                if (reCommandId != "" && !string.IsNullOrEmpty(reCommandId))
                {
                    if (reCommandId != vipID)
                    {
                        var vipEntity = vipService.GetByID(vipID);
                        vipEntity.HigherVipID = reCommandId;
                        vipService.Update(vipEntity);

                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = "Update HigherVipID = " + reCommandId + "for vipid=" + vipID
                        });

                        //查看推荐人成功推荐人数,满足条件给奖励

                        //TODO:added by zhangwei20141009,保存上下线记录
                        couponService.UpdateVipRecommandTrace(vipID, reCommandId);
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = "UpdateVipRecommandTrace vipid=" + vipID + ",reCommandId= " + reCommandId
                        });

                        couponService.RecommenderPrize(reCommandId, eventId);
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = "RecommenderPrize reCommandId= " + reCommandId
                        });
                    }
                }
            }

            //推荐人是否为空

            //推荐人跟vipId是否相同
            #endregion

            #region 奖品集合

            LPrizesBLL prizesService = new LPrizesBLL(loggingSessionInfo);

            var orderby = new List <OrderBy> {
                new OrderBy()
                {
                    FieldName = "DisplayIndex", Direction = OrderByDirections.Asc
                }
            };


            var prizesList = prizesService.QueryByEntity(new LPrizesEntity()
            {
                EventId = eventId
            }, orderby.ToArray());

            rd.content.PrizesList = new List <PrizesEntity>();
            if (prizesList != null && prizesList.Length > 0)
            {
                foreach (var item in prizesList)
                {
                    var entity = new PrizesEntity()
                    {
                        PrizesID     = item.PrizesID,
                        PrizeName    = item.PrizeName,
                        PrizeDesc    = item.PrizeDesc,
                        DisplayIndex = item.DisplayIndex.ToString(),
                        CountTotal   = item.CountTotal.ToString(),
                        ImageUrl     = item.ImageUrl,
                        Sponsor      = item.ContentText
                    };

                    if (prizesId == item.PrizesID)
                    {
                        rd.content.PrizeIndex = item.DisplayIndex;
                    }
                    rd.content.PrizesList.Add(entity);
                }
            }

            #endregion


            #region 中奖集合
            var winDs = poolsServer.GetPersonWinnerList(vipID, eventId);
            rd.content.WinnerList = new List <WinnerList>();
            if (winDs != null && winDs.Tables.Count > 0 && winDs.Tables[0].Rows.Count > 0)
            {
                rd.content.WinnerList = DataTableToObject.ConvertToList <WinnerList>(winDs.Tables[0]);
            }

            #endregion


            #region  新增字段



            var leventsInfoDs = leventsBll.GetLeventsInfoDataSet(eventId);

            if (leventsInfoDs.Tables[0].Rows.Count > 0)
            {
                rd.BootUrl        = leventsInfoDs.Tables[0].Rows[0]["BootUrl"].ToString();
                rd.OverRemark     = leventsInfoDs.Tables[0].Rows[0]["OverRemark"].ToString();
                rd.PosterImageUrl = leventsInfoDs.Tables[0].Rows[0]["PosterImageUrl"].ToString();
                rd.ShareRemark    = leventsInfoDs.Tables[0].Rows[0]["ShareRemark"].ToString();
                rd.ShareLogoUrl   = leventsInfoDs.Tables[0].Rows[0]["ShareLogoUrl"].ToString();
            }

            #endregion

            #region 添加引导页URL

            //var bootDs = leventsBll.GetBootUrlByEventId(eventId);

            //if (bootDs.Tables[0].Rows.Count > 0)
            //{
            //    rd.ShareRemark = bootDs.Tables[0].Rows[0]["ShareRemark"].ToString();
            //    rd.OverRemark = bootDs.Tables[0].Rows[0]["OverRemark"].ToString();
            //    rd.PosterImageUrl = bootDs.Tables[0].Rows[0]["PosterImageUrl"].ToString();
            //    rd.BootUrl = bootDs.Tables[0].Rows[0]["BootUrl"].ToString();
            //}

            #endregion
            return(rd);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取活动奖项信息
        /// </summary>
        public string getEventPrizes()
        {
            string content = string.Empty;

            var respData = new getEventPrizesRespData();

            try
            {
                string reqContent = Request["ReqContent"];
                var    reqObj     = reqContent.DeserializeJSONTo <getEventPrizesReqData>();

                string openId    = reqObj.common.openId;
                string weixinId  = reqObj.common.weiXinId ?? reqObj.common.openId;
                string eventId   = reqObj.special.eventId;  //活动ID
                string vipId     = reqObj.common.userId;
                string vipName   = string.Empty;
                string longitude = reqObj.special.longitude;   //经度
                string latitude  = reqObj.special.latitude;    //纬度

                if (string.IsNullOrEmpty(eventId))
                {
                    eventId = "E5A304D716D14CD2B96560EBD2B6A29C";
                }

                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("getEventPrizes: {0}", reqContent)
                });

                //判断客户ID是否传递
                if (!string.IsNullOrEmpty(reqObj.common.customerId))
                {
                    customerId = reqObj.common.customerId;
                }
                var loggingSessionInfo = Default.GetBSLoggingSession(customerId, "1");

                respData.content           = new getEventPrizesRespContentData();
                respData.content.prizeList = new List <PrizesEntity>();

                var eventList = new LEventsBLL(loggingSessionInfo).QueryByEntity(new LEventsEntity {
                    EventID = eventId
                }, null);

                if (eventList != null && eventList.Length > 0)
                {
                    var eventEntity = eventList.FirstOrDefault();

                    if (Convert.ToDateTime(eventEntity.EndTime).AddDays(1) > DateTime.Now)  //当天还是有效的   updated by Willie Yan on 2014-04-28
                    {
                        #region 获取VIPID

                        VipBLL vipService = new VipBLL(loggingSessionInfo);
                        var    vipList    = vipService.QueryByEntity(new VipEntity()
                        {
                            WeiXinUserId = openId
                        }, null);

                        if (vipList == null || vipList.Length == 0)
                        {
                            respData.code        = "103";
                            respData.description = "未查找到匹配的VIP信息";
                            return(respData.ToJSON());
                        }
                        else
                        {
                            vipId   = vipList.FirstOrDefault().VIPID;
                            vipName = vipList.FirstOrDefault().VipName;
                        }

                        #endregion

                        //查询抽奖日志
                        LLotteryLogBLL lotteryService = new LLotteryLogBLL(loggingSessionInfo);
                        var            lotteryList    = lotteryService.QueryByEntity(new LLotteryLogEntity()
                        {
                            EventId = eventId, VipId = vipId
                        }, null);

                        #region 奖品信息

                        LPrizesBLL prizesService = new LPrizesBLL(loggingSessionInfo);

                        var prizesList = prizesService.QueryByEntity(new LPrizesEntity()
                        {
                            EventId = eventId
                        },
                                                                     new OrderBy[] { new OrderBy {
                                                                                         FieldName = " DisplayIndex ", Direction = OrderByDirections.Asc
                                                                                     } });

                        if (prizesList != null && prizesList.Length > 0)
                        {
                            foreach (var item in prizesList)
                            {
                                var entity = new PrizesEntity()
                                {
                                    prizesID     = item.PrizesID,
                                    prizeName    = item.PrizeName,
                                    prizeDesc    = item.PrizeDesc,
                                    displayIndex = item.DisplayIndex.ToString(),
                                    countTotal   = item.CountTotal.ToString(),
                                    imageUrl     = item.ImageUrl
                                };

                                respData.content.prizeList.Add(entity);
                            }
                        }

                        #endregion

                        #region 抽奖信息

                        //respData.content.lotteryCount = eventEntity.PrizesCount.ToString();
                        respData.content.lotteryNumber = "0";
                        respData.content.validTime     = ConfigurationManager.AppSettings["ValidTime"];
                        int totalLotteryCount = 0;

                        //获取剩余抽奖次数
                        VwVipCenterInfoBLL vwVipCenterInfoBLL = new VwVipCenterInfoBLL(loggingSessionInfo);
                        var vwVipCenterInfo = vwVipCenterInfoBLL.GetByID(vipId);
                        totalLotteryCount = vwVipCenterInfo.LotteryCount ?? 0;

                        //获取已抽奖次数
                        if (lotteryList != null && lotteryList.Length > 0)
                        {
                            respData.content.lotteryNumber = lotteryList.FirstOrDefault().LotteryCount.ToString();
                        }
                        else
                        {
                            totalLotteryCount++; //如果未抽奖,活动默认有一次抽奖机会
                        }
                        //判断抽奖次数是否有效
                        if (Convert.ToInt32(respData.content.lotteryNumber) >= totalLotteryCount)
                        {
                            respData.content.isLottery   = "0";
                            respData.content.lotteryDesc = "您已经没有抽奖机会了,想得到更多抽奖机会,请在对话栏内发送中文“分享”给我们,获得图文消息后多多转发。详情关注“推荐有礼”菜单。";
                        }
                        else
                        {
                            //判断之前是否已经中奖
                            LPrizeWinnerBLL winnerService = new LPrizeWinnerBLL(loggingSessionInfo);
                            var             prize         = winnerService.GetWinnerInfo(vipId, eventId);

                            if (!prize.Read())
                            {
                                //抽奖
                                LPrizePoolsBLL poolsServer   = new LPrizePoolsBLL(loggingSessionInfo);
                                var            returnDataObj = poolsServer.SetShakeOffLottery(vipName, vipId, eventId, ToFloat(longitude), ToFloat(latitude));

                                if (returnDataObj.Params.result_code.Equals("1"))   //中奖
                                {
                                    //获取奖品信息
                                    prize = winnerService.GetWinnerInfo(vipId, eventId);
                                    if (prize.Read())
                                    {
                                        var prizeValue = GetPrizeValue(prize["PrizeShortDesc"].ToString());

                                        respData.content.isLottery    = "1";
                                        respData.content.lotteryDesc  = returnDataObj.Params.result_message;// "恭喜您中奖了";
                                        respData.content.isWinning    = "1";
                                        respData.content.winningValue = prizeValue;
                                    }
                                    //added by zhangwei 中奖后绑定推荐关系,设置奖项
                                    BindRecommender();
                                    setEventPrizes();
                                }
                                else    //没有中奖,一直能抽奖
                                {
                                    respData.content.isLottery    = "1";
                                    respData.content.isWinning    = "0";
                                    respData.content.winningValue = "0";
                                    respData.content.lotteryDesc  = "恭喜您中奖了";//张伟,为泸州老窖新人有礼前台判断使用
                                }
                            }
                            else
                            {
                                var prizeValue = GetPrizeValue(prize["PrizeShortDesc"].ToString());

                                respData.content.isLottery    = "1";
                                respData.content.lotteryDesc  = "恭喜您中奖了";
                                respData.content.isWinning    = "1";
                                respData.content.winningValue = prizeValue;
                            }
                            prize.Close();
                            respData.content.lotteryCount = totalLotteryCount.ToString();
                        }

                        #endregion
                    }
                    else
                    {
                        respData.content.isLottery   = "0";
                        respData.content.lotteryDesc = "活动已经结束";
                    }
                }
                else
                {
                    respData.content.isLottery   = "0";
                    respData.content.lotteryDesc = "指定的活动不存在";
                }
            }
            catch (Exception ex)
            {
                respData.code        = "103";
                respData.description = "数据库操作错误";
                //respData.exception = ex.ToString();
            }
            content = respData.ToJSON();
            return(content);
        }