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); try { C_ActivityEntity Data = ActivityBLL.GetByID(para.ActivityID); if (Data == null) { throw new APIException("营销活动对象为NULL!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS } } ; if (Data.Status == 0) { Data.Status = 1; } else { Data.Status = 0; } ActivityBLL.Update(Data); } catch (APIException apiEx) { throw new APIException(apiEx.ErrorCode, apiEx.Message); } return(rd); }
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 SetActivityRD ProcessRequest(DTO.Base.APIRequest <SetActivityRP> pRequest) { var rd = new SetActivityRD(); var para = pRequest.Parameters; var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo; var ActivityBLL = new C_ActivityBLL(loggingSessionInfo); var C_TargetGroupBLL = new C_TargetGroupBLL(loggingSessionInfo); var C_ActivityMessageBLL = new C_ActivityMessageBLL(loggingSessionInfo); if (string.IsNullOrWhiteSpace(para.StartTime)) { throw new APIException("请输入活动开始日期!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS } } ; //卡 if (para.VipCardTypeIDList == null || para.VipCardTypeIDList.Count == 0) { //throw new APIException("请选择目标人群!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS }; } //对充值活动,不允许时间重叠 if (ActivityBLL.IsActivityOverlap(loggingSessionInfo.ClientID, para.ActivityID, para.ActivityType, para.StartTime, para.EndTime, para.VipCardTypeIDList)) { throw new APIException("与已有活动时间重叠!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS } } ; //事务 var pTran = ActivityBLL.GetTran(); using (pTran.Connection) { try { if (!string.IsNullOrWhiteSpace(para.ActivityID)) { //编辑 C_ActivityEntity ChangeData = ActivityBLL.GetByID(para.ActivityID); if (ChangeData == null) { throw new APIException("活动对象为NULL!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS }; } string m_OldStarTime = ChangeData.StartTime.Value.ToString("yyyy-MM-dd"); ChangeData.ActivityName = para.ActivityName; if (para.IsAllCardType != null) { ChangeData.IsAllVipCardType = int.Parse(para.IsAllCardType); } ChangeData.ActivityType = para.ActivityType; ChangeData.StartTime = Convert.ToDateTime(para.StartTime); if (!string.IsNullOrWhiteSpace(para.EndTime)) { ChangeData.EndTime = Convert.ToDateTime(para.EndTime + " 23:59:59"); } else { ChangeData.EndTime = DateTime.Parse("2099-01-01 23:59:59"); } ChangeData.IsLongTime = para.IsLongTime; ChangeData.CustomerID = loggingSessionInfo.ClientID; ChangeData.TargetCount = 0; //执行 ActivityBLL.Update(ChangeData, pTran); #region 更新活动消息发送时间 List <C_ActivityMessageEntity> m_MessageList = C_ActivityMessageBLL.QueryByEntity(new C_ActivityMessageEntity() { ActivityID = new Guid(para.ActivityID) }, null).ToList(); if (m_MessageList.Count > 0) { if (!m_OldStarTime.Equals(para.StartTime)) { DateTime dt1 = Convert.ToDateTime(m_OldStarTime); DateTime dt2 = Convert.ToDateTime(para.StartTime); TimeSpan ts = (TimeSpan)(dt2 - dt1); int s = Convert.ToInt32(ts.TotalDays); foreach (var item in m_MessageList) { item.SendTime = item.SendTime.Value.AddDays(s); C_ActivityMessageBLL.Update(item, pTran); } } } #endregion #region 目标群日信息 //卡 List <C_TargetGroupEntity> UpdateData = C_TargetGroupBLL.QueryByEntity(new C_TargetGroupEntity() { ActivityID = new Guid(para.ActivityID), GroupType = 1 }, null).ToList(); foreach (var i in UpdateData) { C_TargetGroupBLL.Delete(i, pTran); } if (para.VipCardTypeIDList != null) { foreach (var i in para.VipCardTypeIDList) { C_TargetGroupEntity AddTargetGroupData = new C_TargetGroupEntity(); AddTargetGroupData.ActivityID = ChangeData.ActivityID; AddTargetGroupData.GroupType = 1; AddTargetGroupData.ObjectID = i; AddTargetGroupData.CustomerID = loggingSessionInfo.ClientID; C_TargetGroupBLL.Create(AddTargetGroupData); } } #endregion rd.ActivityID = ChangeData.ActivityID.ToString(); } else { //新增 if (!ActivityBLL.IsActivityNameValid(para.ActivityName)) { throw new APIException("名称重复!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS }; } C_ActivityEntity AddData = new C_ActivityEntity(); AddData.ActivityID = System.Guid.NewGuid(); AddData.ActivityType = para.ActivityType; AddData.ActivityName = para.ActivityName; AddData.StartTime = Convert.ToDateTime(para.StartTime); if (!string.IsNullOrWhiteSpace(para.EndTime)) { AddData.EndTime = Convert.ToDateTime(para.EndTime + " 23:59:59"); } else { AddData.EndTime = DateTime.Parse("2099-01-01 23:59:59"); } AddData.IsLongTime = para.IsLongTime; AddData.IsAllVipCardType = int.Parse(para.IsAllCardType); AddData.SendCouponQty = 0; AddData.Status = 5; AddData.CustomerID = loggingSessionInfo.ClientID; AddData.TargetCount = 0; //执行 ActivityBLL.Create(AddData); #region 新增目标群日信息 foreach (var i in para.VipCardTypeIDList) { C_TargetGroupEntity AddTargetGroupData = new C_TargetGroupEntity(); AddTargetGroupData.ActivityID = AddData.ActivityID; AddTargetGroupData.GroupType = 1; AddTargetGroupData.ObjectID = i; AddTargetGroupData.CustomerID = loggingSessionInfo.ClientID; C_TargetGroupBLL.Create(AddTargetGroupData, pTran); } #endregion rd.ActivityID = AddData.ActivityID.ToString(); } pTran.Commit(); } catch (APIException apiEx) { pTran.Rollback(); throw new APIException(apiEx.ErrorCode, apiEx.Message); } } return(rd); } } }
/// <summary> /// 更新 /// </summary> /// <param name="pEntity">实体实例</param> /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param> public void Update(C_ActivityEntity pEntity, IDbTransaction pTran) { _currentDAO.Update(pEntity, pTran); }
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); }
/// <summary> /// 创建一个新实例 /// </summary> /// <param name="pEntity">实体实例</param> public void Create(C_ActivityEntity pEntity) { _currentDAO.Create(pEntity); }
/// <summary> /// 分页根据实体条件查询实体 /// </summary> /// <param name="pQueryEntity">以实体形式传入的参数</param> /// <param name="pOrderBys">排序组合</param> /// <returns>符合条件的实体集</returns> public PagedQueryResult <C_ActivityEntity> PagedQueryByEntity(C_ActivityEntity pQueryEntity, OrderBy[] pOrderBys, int pPageSize, int pCurrentPageIndex) { return(_currentDAO.PagedQueryByEntity(pQueryEntity, pOrderBys, pPageSize, pCurrentPageIndex)); }
/// <summary> /// 根据实体条件查询实体 /// </summary> /// <param name="pQueryEntity">以实体形式传入的参数</param> /// <param name="pOrderBys">排序组合</param> /// <returns>符合条件的实体集</returns> public C_ActivityEntity[] QueryByEntity(C_ActivityEntity pQueryEntity, OrderBy[] pOrderBys) { return(_currentDAO.QueryByEntity(pQueryEntity, pOrderBys)); }
/// <summary> /// 删除 /// </summary> /// <param name="pEntity"></param> public void Delete(C_ActivityEntity pEntity) { _currentDAO.Delete(pEntity); }
/// <summary> /// 更新 /// </summary> /// <param name="pEntity">实体实例</param> public void Update(C_ActivityEntity pEntity) { _currentDAO.Update(pEntity); }