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); }
/// <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 }