Beispiel #1
0
        protected override EmptyResponseData ProcessRequest(DTO.Base.APIRequest <GetActivityDeatilRP> pRequest)
        {
            var rd   = new EmptyResponseData();
            var para = pRequest.Parameters;
            var loggingSessionInfo          = new SessionManager().CurrentUserLoginInfo;
            var ActivityBLL                 = new C_ActivityBLL(loggingSessionInfo);
            var ActivityMessageBLL          = new C_ActivityMessageBLL(loggingSessionInfo);
            var ActivityTargetGroupBLL      = new C_TargetGroupBLL(loggingSessionInfo);
            var ActivityPrizesBLL           = new C_PrizesBLL(loggingSessionInfo);
            var ActivityPrizesDetailBLL     = new C_PrizesDetailBLL(loggingSessionInfo);
            var ActivityRechargeStrategyBLL = new RechargeStrategyBLL(loggingSessionInfo);
            var pTran = ActivityBLL.GetTran();

            using (pTran.Connection)
            {
                try
                {
                    //删除
                    C_ActivityEntity DelData = ActivityBLL.GetByID(para.ActivityID);
                    if (DelData == null)
                    {
                        throw new APIException("会员活动对象为NULL!")
                              {
                                  ErrorCode = ERROR_CODES.INVALID_BUSINESS
                              };
                    }
                    //执行
                    List <IWhereCondition> complexCondition = new List <IWhereCondition> {
                    };
                    complexCondition.Add(new EqualsCondition()
                    {
                        FieldName = "ActivityID", Value = para.ActivityID
                    });
                    ActivityMessageBLL.Delete(ActivityMessageBLL.Query(complexCondition.ToArray(), null), pTran);
                    ActivityTargetGroupBLL.Delete(ActivityTargetGroupBLL.Query(complexCondition.ToArray(), null), pTran);
                    ActivityRechargeStrategyBLL.Delete(ActivityRechargeStrategyBLL.Query(complexCondition.ToArray(), null), pTran);
                    var prize = ActivityPrizesBLL.Query(complexCondition.ToArray(), null).FirstOrDefault();
                    if (prize != null)
                    {
                        if (!string.IsNullOrWhiteSpace(prize.PrizesID.ToString()))
                        {
                            List <IWhereCondition> cCondition = new List <IWhereCondition> {
                            };
                            cCondition.Add(new EqualsCondition()
                            {
                                FieldName = "PrizesID", Value = prize.PrizesID
                            });
                            ActivityPrizesDetailBLL.Delete(ActivityPrizesDetailBLL.Query(cCondition.ToArray(), null),
                                                           pTran);
                        }
                        ActivityPrizesBLL.Delete(ActivityPrizesBLL.Query(complexCondition.ToArray(), null), pTran);
                    }
                    ActivityBLL.Delete(DelData, pTran);
                    pTran.Commit();
                }
                catch (APIException apiEx)
                {
                    pTran.Rollback();
                    throw new APIException(apiEx.ErrorCode, apiEx.Message);
                }
            }
            return(rd);
        }
        protected override GetActivityDeatilRD ProcessRequest(DTO.Base.APIRequest <GetActivityDeatilRP> pRequest)
        {
            var rd   = new GetActivityDeatilRD();
            var para = pRequest.Parameters;
            var loggingSessionInfo  = new SessionManager().CurrentUserLoginInfo;
            var activityBll         = new C_ActivityBLL(loggingSessionInfo);
            var prizesBll           = new C_PrizesBLL(loggingSessionInfo);
            var prizesDetailBll     = new C_PrizesDetailBLL(loggingSessionInfo);
            var activityMessageBll  = new C_ActivityMessageBLL(loggingSessionInfo);
            var targetGroupBll      = new C_TargetGroupBLL(loggingSessionInfo);
            var rechargeStrategyBll = new RechargeStrategyBLL(loggingSessionInfo);

            if (!string.IsNullOrWhiteSpace(para.ActivityID))
            {
                #region 基础信息
                C_ActivityEntity activityData = activityBll.GetByID(para.ActivityID);
                if (activityData != null)
                {
                    rd.ActivityID      = activityData.ActivityID.ToString();
                    rd.ActivityType    = activityData.ActivityType ?? 2;
                    rd.ActivityName    = activityData.ActivityName;
                    rd.StartTime       = activityData.StartTime == null ? "" : activityData.StartTime.Value.ToString("yyyy-MM-dd");
                    rd.EndTime         = activityData.EndTime == null ? "" : activityData.EndTime.Value.ToString("yyyy-MM-dd");
                    rd.IsLongTime      = activityData.IsLongTime == null ? "0" : activityData.IsLongTime.Value.ToString();
                    rd.IsAllCardType   = activityData.IsAllVipCardType ?? 0;
                    rd.VipCardTypeID   = activityBll.GetTargetGroupId(rd.IsAllCardType, rd.ActivityID);
                    rd.HolderCardCount = activityBll.GetTargetCount(rd.VipCardTypeID, rd.ActivityType, rd.StartTime, rd.EndTime, activityData.IsLongTime.Value);
                    rd.Status          = activityData.Status.Value;
                }
                #endregion
                #region 奖品
                var PrizesList = prizesBll.Query(new IWhereCondition[] { new EqualsCondition()
                                                                         {
                                                                             FieldName = "ActivityID", Value = para.ActivityID
                                                                         }, new EqualsCondition()
                                                                         {
                                                                             FieldName = "CustomerID", Value = loggingSessionInfo.ClientID
                                                                         } }, null).ToList();
                if (PrizesList.Count > 0)
                {
                    //奖品集合赋值
                    rd.PrizesInfoList = (from u in PrizesList
                                         select new PrizesInfo()
                    {
                        PrizesID = Convert.ToString(u.PrizesID),
                        PrizesType = u.PrizesType.Value
                    }).ToList();

                    foreach (var item in rd.PrizesInfoList)
                    {
                        item.PrizesDetailList = new List <PrizesDetailInfo>();
                        //奖品明细
                        var PrizesDetailList = prizesDetailBll.GetPrizesDetailList(item.PrizesID);
                        if (PrizesDetailList.Count > 0)
                        {
                            CouponTypeBLL ctbll = new CouponTypeBLL(CurrentUserInfo);
                            foreach (var itemes in PrizesDetailList)
                            {
                                PrizesDetailInfo m = new PrizesDetailInfo();
                                m.PrizesDetailID = Convert.ToString(itemes.PrizesDetailID);
                                m.CouponTypeID   = Convert.ToString(itemes.CouponTypeID);
                                m.CouponTypeName = itemes.CouponTypeName;
                                m.NumLimit       = itemes.NumLimit.Value;
                                m.CouponTypeDesc = itemes.CouponTypeDesc;
                                //ValidityPeriod = t.BeginTime == null ? ("领取后" + (t.ServiceLife == 0 ? "1天内有效" : t.ServiceLife.ToString() + "天内有效")) : (t.BeginTime.Value.ToString("yyyy-MM-dd") + "至" + t.EndTime.Value.ToString("yyyy-MM-dd")),
                                var t = ctbll.GetByID(m.CouponTypeID);
                                m.ValidityPeriod = t.BeginTime == null ? ("领取后" + (t.ServiceLife == 0 ? "1天内有效" : t.ServiceLife.ToString() + "天内有效")) : (t.BeginTime.Value.ToString("yyyy-MM-dd") + "至" + t.EndTime.Value.ToString("yyyy-MM-dd"));
                                //奖品明细集合额赋值
                                item.PrizesDetailList.Add(m);
                            }
                        }
                    }
                }
                #endregion
                #region 消息
                var ActivityMessageList = activityMessageBll.Query(new IWhereCondition[] { new EqualsCondition()
                                                                                           {
                                                                                               FieldName = "ActivityID", Value = para.ActivityID
                                                                                           }, new EqualsCondition()
                                                                                           {
                                                                                               FieldName = "CustomerID", Value = loggingSessionInfo.ClientID
                                                                                           } }, null).ToList();
                if (ActivityMessageList.Count > 0)
                {
                    //消息赋值
                    rd.ActivityMessageInfoList = (from u in ActivityMessageList
                                                  select new ActivityMessageInfo()
                    {
                        MessageID = u.MessageID.Value.ToString(),
                        MessageType = u.MessageType.Trim(),
                        Content = u.Content,
                        SendTime = u.SendTime == null ? "" : u.SendTime.Value.ToString(),
                        AdvanceDays = u.AdvanceDays,
                        SendAtHour = u.SendAtHour
                    }).ToList();
                }
                #endregion
                #region 充值策略

                var rechargeStrategyInfoList = rechargeStrategyBll.Query(new IWhereCondition[] { new EqualsCondition()
                                                                                                 {
                                                                                                     FieldName = "ActivityID", Value = para.ActivityID
                                                                                                 }, new EqualsCondition()
                                                                                                 {
                                                                                                     FieldName = "CustomerId", Value = loggingSessionInfo.ClientID
                                                                                                 } }, new[] {
                    new OrderBy()
                    {
                        FieldName = "RechargeAmount", Direction = OrderByDirections.Asc
                    }
                }).ToList();
                if (rechargeStrategyInfoList.Count > 0)
                {
                    //消息赋值
                    rd.RechargeStrategyInfoList = (from u in rechargeStrategyInfoList
                                                   select new RechargeStrategyInfo()
                    {
                        RechargeStrategyId = u.RechargeStrategyId.ToString(),
                        RuleType = u.RuleType,
                        RechargeAmount = u.RechargeAmount,
                        GiftAmount = u.GiftAmount.Value
                    }).ToList();
                }
                #endregion
            }
            return(rd);
        }
Beispiel #3
0
        protected override EmptyResponseData ProcessRequest(DTO.Base.APIRequest <SetPrizesRP> pRequest)
        {
            var rd   = new EmptyResponseData();
            var para = pRequest.Parameters;
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            var ActivityBLL        = new C_ActivityBLL(loggingSessionInfo);
            var PrizesBLL          = new C_PrizesBLL(loggingSessionInfo);
            var PrizesDetailBLL    = new C_PrizesDetailBLL(loggingSessionInfo);
            var pTran = ActivityBLL.GetTran();

            using (pTran.Connection)
            {
                try
                {
                    if (string.IsNullOrWhiteSpace(para.ActivityID))
                    {
                        throw new APIException("必须输入活动编号!")
                              {
                                  ErrorCode = ERROR_CODES.INVALID_BUSINESS
                              }
                    }
                    ;
                    if (string.IsNullOrWhiteSpace(para.PrizesID))
                    {//新增
                        C_PrizesEntity AddPrizesData = new C_PrizesEntity();
                        AddPrizesData.ActivityID = new Guid(para.ActivityID);
                        AddPrizesData.PrizesType = para.PrizesType;
                        AddPrizesData.PrizesName = para.PrizesDetailList.FirstOrDefault().CouponTypeName;
                        AddPrizesData.CustomerID = loggingSessionInfo.ClientID;
                        AddPrizesData.SendDate   = DateTime.Now;
                        List <IWhereCondition> complexCondition = new List <IWhereCondition> {
                        };
                        complexCondition.Add(new EqualsCondition()
                        {
                            FieldName = "ActivityID", Value = para.ActivityID
                        });
                        if (PrizesBLL.Query(complexCondition.ToArray(), null).ToList().Count > 0)
                        {
                            throw new APIException("不能重复创建奖品!")
                                  {
                                      ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                  }
                        }
                        ;
                        PrizesBLL.Create(AddPrizesData);

                        Guid?PrizesID = PrizesBLL.Query(complexCondition.ToArray(), null).ToList().FirstOrDefault().PrizesID;
                        foreach (var itemes in para.PrizesDetailList)
                        {
                            C_PrizesDetailEntity AddDetailData = new C_PrizesDetailEntity();
                            AddDetailData.PrizesID       = PrizesID;
                            AddDetailData.CouponTypeID   = new Guid(itemes.CouponTypeID);
                            AddDetailData.CustomerID     = loggingSessionInfo.ClientID;
                            AddDetailData.NumLimit       = itemes.NumLimit;
                            AddDetailData.CouponTypeName = itemes.CouponTypeName;
                            AddDetailData.CouponTypeDesc = itemes.CouponTypeDesc;
                            PrizesDetailBLL.Create(AddDetailData, pTran);
                        }
                    }
                    else
                    {//编辑奖品明细
                        foreach (var itemes in para.PrizesDetailList)
                        {
                            C_PrizesDetailEntity AddDetailData = new C_PrizesDetailEntity();
                            AddDetailData.PrizesID       = new Guid(para.PrizesID);
                            AddDetailData.CouponTypeID   = new Guid(itemes.CouponTypeID);
                            AddDetailData.CustomerID     = loggingSessionInfo.ClientID;
                            AddDetailData.NumLimit       = itemes.NumLimit;
                            AddDetailData.CouponTypeName = itemes.CouponTypeName;
                            AddDetailData.CouponTypeDesc = itemes.CouponTypeDesc;
                            if (string.IsNullOrWhiteSpace(itemes.PrizesDetailID))
                            {
                                PrizesDetailBLL.Create(AddDetailData, pTran);
                            }
                            else
                            {
                                AddDetailData.PrizesDetailID = new Guid(itemes.PrizesDetailID);
                                if (itemes.IsEnable == 1)
                                {
                                    PrizesDetailBLL.Update(AddDetailData, pTran);
                                }
                                else
                                {
                                    PrizesDetailBLL.Delete(AddDetailData, pTran);
                                }
                            }
                        }
                    }
                    pTran.Commit();
                    if (ActivityBLL.IsActivityValid(para.ActivityID))
                    {
                        var activity = ActivityBLL.GetByID(para.ActivityID);
                        if (activity != null)
                        {
                            activity.Status = 0;
                        }
                        ActivityBLL.Update(activity);
                    }
                }
                catch (APIException apiEx)
                {
                    pTran.Rollback();//回滚事物
                    throw new APIException(apiEx.ErrorCode, apiEx.Message);
                }
            }
            return(rd);
        }
        /// <summary>
        /// 活动服务送券业务方法
        /// </summary>
        private void ActivitySendCoupon()
        {
            #region 业务对象
            var activityBLL        = new C_ActivityBLL(c_loggingSessionInfo);
            var targetGroupBLL     = new C_TargetGroupBLL(c_loggingSessionInfo);
            var prizesBLL          = new C_PrizesBLL(c_loggingSessionInfo);
            var prizesDetailBLL    = new C_PrizesDetailBLL(c_loggingSessionInfo);
            var CouponTypeBLL      = new CouponTypeBLL(c_loggingSessionInfo);
            var ActivityMessageBLL = new C_ActivityMessageBLL(c_loggingSessionInfo);
            #endregion


            #region 获取当前商户活动集合
            List <IWhereCondition> complexCondition = new List <IWhereCondition> {
            };
            complexCondition.Add(new EqualsCondition()
            {
                FieldName = "CustomerID", Value = c_loggingSessionInfo.ClientID
            });
            //complexCondition.Add(new DirectCondition(" ((IsLongTime=1 and GETDATE()>=StartTime) OR (GETDATE()>=StartTime AND GETDATE()<=EndTime)) AND STATUS=0 and IsDelete=0 "));
            complexCondition.Add(new DirectCondition(" (IsLongTime=1 or (IsLongTime=0 and GETDATE()<=EndTime)) and STATUS=0 and IsDelete=0 "));
            var ActivityList = activityBLL.Query(complexCondition.ToArray(), null);//营销活动

            #endregion
            #region 轮循活动,送券业务处理
            foreach (var activity in ActivityList)
            {
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = "轮循营销活动"
                });
                #region 获取卡类型ID(目标卡人群)
                var targetGroupInfo = targetGroupBLL.QueryByEntity(new C_TargetGroupEntity()
                {
                    ActivityID = activity.ActivityID, GroupType = 1
                }, null).FirstOrDefault();
                int VipCardTypeID = targetGroupInfo == null ? -1 : int.Parse(targetGroupInfo.ObjectID);//卡类型ID
                #endregion



                #region 活动是否设置奖品控制
                //获取赠送礼券奖品
                var prizesData = prizesBLL.QueryByEntity(new C_PrizesEntity()
                {
                    ActivityID = activity.ActivityID, PrizesType = 1
                }, null).FirstOrDefault();
                //当前活动消息类型集合
                var ActivityMessageLsit = ActivityMessageBLL.QueryByEntity(new C_ActivityMessageEntity()
                {
                    ActivityID = activity.ActivityID
                }, null).ToList();

                List <IWhereCondition> PrizeDetailCondition = new List <IWhereCondition> {
                };
                if (prizesData != null)
                {
                    PrizeDetailCondition.Add(new DirectCondition(" PrizesID='" + prizesData.PrizesID + "' "));
                }
                var PrizeDetailList = prizesDetailBLL.Query(PrizeDetailCondition.ToArray(), null).ToList();
                #endregion

                #region 当前活动券处理

                #region 获取活动会员人数
                int SumVipCount = 0;//会员数
                if (activity.IsAllVipCardType == 0)
                {
                    SumVipCount = activityBLL.GetholderCardCount(VipCardTypeID.ToString(), null);//当前卡类型会员数
                }
                else
                {
                    SumVipCount = activityBLL.GetholderCardCount(null, null);//所有会员数
                }
                #endregion

                #region 获取当前活动送券集合
                List <IWhereCondition> CouponTypeCondition = new List <IWhereCondition> {
                };
                StringBuilder strWhere    = new StringBuilder();
                string        NewStrWhere = "";
                foreach (var itemPrizeDetail in PrizeDetailList)
                {
                    strWhere.Append("couponTypeID='" + itemPrizeDetail.CouponTypeID + "' or ");
                }
                if (PrizeDetailList.Count > 0)
                {
                    NewStrWhere = ((strWhere.ToString().TrimEnd()).TrimEnd('r')).Trim('o');
                }
                if (!string.IsNullOrWhiteSpace(NewStrWhere))
                {
                    CouponTypeCondition.Add(new DirectCondition(NewStrWhere));
                }
                //券集合
                var ActivityCouponTypeList = CouponTypeBLL.Query(CouponTypeCondition.ToArray(), null);
                #endregion

                #region 判断当前券数量是否充足,不充足:计算出缺省券数量,充足获取券数最少的一种券

                //券种数量集合
                List <int> CouponNumList = new List <int>();
                bool       CouponFlag    = true;
                string     Remark        = "";
                foreach (var CouponTypeitem in ActivityCouponTypeList)
                {
                    if (CouponTypeitem.IsVoucher >= CouponTypeitem.IssuedQty)
                    {
                        if (SumVipCount > activity.SendCouponQty)
                        {
                            int Math = SumVipCount - (activity.SendCouponQty ?? 0);//目标数-使用数
                            // Loggers.Debug(new DebugLogInfo() { Message = CouponTypeitem.CouponTypeName + "券数量库存不足!" + DateTime.Now });
                            Remark    += string.Format("{1}都已发完还少{0}张,", Math, CouponTypeitem.CouponTypeName);
                            CouponFlag = false;
                        }
                    }
                    else
                    {
                        CouponNumList.Add((CouponTypeitem.IssuedQty ?? 0) - (CouponTypeitem.IsVoucher ?? 0));
                    }
                }
                if (CouponFlag == false)
                {
                    Remark += "请追加券数量!";
                    //activity.Remark = Remark;
                    activityBLL.Update(activity);//更新当前活动备注
                    continue;
                }
                int MinCouponNum = 0;
                if (CouponNumList.Count > 0)
                {
                    MinCouponNum = CouponNumList.Min();//当前活动奖品券种数量最少的券数
                }
                if (MinCouponNum == 0)
                {
                    continue;
                }
                #endregion


                #endregion

                #region 批量新增券关系,修改券数量
                int    ResultConunt      = 0;
                string CouponTypeNameStr = "";//所有券名称
                foreach (var CouponTypeitem in ActivityCouponTypeList)
                {
                    CouponTypeNameStr += CouponTypeitem.CouponTypeName + ",";
                    ResultConunt       = BatchAddSendCoupon(MinCouponNum, activity.ActivityID.Value.ToString(), activity.ActivityType.Value, CouponTypeitem.CouponTypeID.Value.ToString(), VipCardTypeID);
                    System.Threading.Thread.Sleep(2000);//沉睡2秒
                }
                #endregion

                if (ResultConunt > 0)
                {
                    #region 修改活动领券人数
                    activity.SendCouponQty = activity.SendCouponQty + ResultConunt;
                    activityBLL.Update(activity);

                    #endregion

                    #region 批量新增活动获赠奖品预发送消息
                    //CouponTypeNameStr = CouponTypeNameStr.TrimEnd(',');
                    foreach (var ActMessageitem in ActivityMessageLsit)
                    {
                        string Content = ActMessageitem.Content + "," + CouponTypeNameStr; //消息内容
                        BatchAddMessageSend(ResultConunt, activity.ActivityID.Value.ToString(), VipCardTypeID, ActMessageitem.MessageID.Value.ToString(), ActMessageitem.MessageType, Content, ActMessageitem.SendTime.Value, activity.ActivityType ?? 2);
                        System.Threading.Thread.Sleep(2000);                               //沉睡2秒
                    }
                    #endregion

                    #region 批量新增获赠信息
                    BatchAddPrizeReceive(ResultConunt, activity.ActivityID.Value.ToString(), VipCardTypeID, activity.ActivityType ?? 2);
                    System.Threading.Thread.Sleep(2000);//沉睡2秒
                    #endregion
                }
            }

            #endregion
        }