public object BindCoupon(BindCouponRP bindCouponRP) { var rd = new EmptyRD(); ErrorResponse er = new ErrorResponse(); SuccessResponse <IAPIResponseData> sr = new SuccessResponse <IAPIResponseData>(); //If coupon exists var coupon = _currentDAO.Query( new IWhereCondition[] { new EqualsCondition() { FieldName = "CouponCode", Value = bindCouponRP.CouponCode } , new EqualsCondition() { FieldName = "CustomerID", Value = CurrentUserInfo.ClientID } , new EqualsCondition() { FieldName = "Status", Value = "0" } , new EqualsCondition() { FieldName = "IsDelete", Value = "0" } }, null); if (coupon.Length == 0) { er.Message = "该优惠券编号不存在或已被使用!"; } else { //if coupon bound VipCouponMappingBLL vipCouponMappingBLL = new VipCouponMappingBLL(CurrentUserInfo); var mapping = vipCouponMappingBLL.Query( new IWhereCondition[] { new EqualsCondition() { FieldName = "CouponID", Value = coupon[0].CouponID } , new EqualsCondition() { FieldName = "IsDelete", Value = "0" } }, null); if (mapping.Length > 0) { er.Message = "该优惠券已分发!"; } else { //bind coupon vipCouponMappingBLL.Create( new VipCouponMappingEntity() { VipCouponMapping = Guid.NewGuid().ToString(), VIPID = bindCouponRP.VipID, CouponID = coupon[0].CouponID, IsDelete = 0, CreateBy = CurrentUserInfo.UserID, CreateTime = DateTime.Now }); sr.Message = "分发成功!"; } } object result; if (!string.IsNullOrEmpty(er.Message)) { result = er; } else { result = sr; } return(result); }
public void SetEventPrizes(string vipId, string eventId) { var tranHelper = new TransactionHelper(this.CurrentUserInfo); var tran = tranHelper.CreateTransaction(); using (tran.Connection) { LLotteryLogBLL lotteryService = new LLotteryLogBLL(this.CurrentUserInfo); var lotterys = lotteryService.QueryByEntity(new LLotteryLogEntity() { EventId = eventId, VipId = vipId }, null); if (lotterys != null && lotterys.Length > 0) { //更新 var lotteryEntity = lotterys.FirstOrDefault(); lotteryEntity.LotteryCount += 1; lotteryService.Update(lotteryEntity, tran); } else { //新增 var lotteryEntity = new LLotteryLogEntity() { LogId = CPOS.Common.Utils.NewGuid(), VipId = vipId, EventId = eventId, LotteryCount = 1 }; lotteryService.Create(lotteryEntity, tran); } //1、判断用户是否中奖 //2、用户中奖 添加优惠券表(Coupon)和优惠券用户关系表(VipCouponMapping) //3、added by zhangwei用户中奖类型为积分则更新用户积分 LPrizeWinnerBLL winnerService = new LPrizeWinnerBLL(this.CurrentUserInfo); var prize = winnerService.GetWinnerInfo(vipId, eventId); if (prize.Read()) { //取得奖品信息,看奖品类型是积分还是优惠券 var prizeMapping = winnerService.GetPrizeCouponTypeMapping(prize["PrizeWinnerID"].ToString(), tran); if (prizeMapping.Tables[0].Rows.Count > 0) { //奖品如果是积分,则插入积分表 if (!string.IsNullOrEmpty(prizeMapping.Tables[0].Rows[0]["AwardPoints"].ToString())) { //新的积分方法 zhangwei2013-2-13 int IntegralSourceID = 16; if (eventId.ToUpper() == "E5A304D716D14CD2B96560EBD2B6A29C") { IntegralSourceID = 16; } if (eventId.ToUpper() == "BFC41A8BF8564B6DB76AE8A8E43557BA") { IntegralSourceID = 17; } var objectID = prizeMapping.Tables[0].Rows[0]["PrizesID"].ToString(); if (!string.IsNullOrEmpty(objectID)) { Loggers.DEFAULT.Debug(new DebugLogInfo { Message = "抽奖成功:+IntegralSourceID:" + IntegralSourceID + "ClientID:" + CurrentUserInfo.ClientID + "VipID:" + vipId + "ObjectID:" + objectID }); new VipIntegralBLL(CurrentUserInfo).ProcessPoint(IntegralSourceID, CurrentUserInfo.ClientID, vipId, objectID); } else { Loggers.DEFAULT.Debug(new DebugLogInfo { Message = "抽奖失败:+IntegralSourceID:" + IntegralSourceID + "ClientID:" + CurrentUserInfo.ClientID + "VipID:" + vipId }); } /* * //插入积分 * VipIntegralBLL vipIntegralBLL = new VipIntegralBLL(CurrentUserInfo); * VipIntegralEntity vipIntegralEntity = new VipIntegralEntity(); * decimal integralValue = decimal.Parse(prizeMapping.Tables[0].Rows[0]["AwardPoints"].ToString()); * var vipIntegralDataList = vipIntegralBLL.QueryByEntity( * new VipIntegralEntity() { VipID = vipId }, null); * if (vipIntegralDataList == null || vipIntegralDataList.Length == 0 || * vipIntegralDataList[0] == null) * { * * vipIntegralEntity.VipID = vipId; * vipIntegralEntity.InIntegral = integralValue; //累计积分 * vipIntegralEntity.EndIntegral = integralValue; //积分余额 * vipIntegralEntity.ValidIntegral = integralValue; // 当前有效积分 * vipIntegralBLL.Create(vipIntegralEntity, tran); * } * else * { * vipIntegralEntity = vipIntegralDataList[0]; * vipIntegralEntity.VipID = vipId; * vipIntegralEntity.InIntegral = (vipIntegralEntity.InIntegral.HasValue ? vipIntegralEntity.InIntegral : 0) + integralValue; //累计积分 * vipIntegralEntity.EndIntegral = (vipIntegralEntity.EndIntegral.HasValue ? vipIntegralEntity.EndIntegral : 0) + integralValue; //积分余额 * vipIntegralEntity.ValidIntegral = (vipIntegralEntity.ValidIntegral.HasValue ? vipIntegralEntity.ValidIntegral : 0) + integralValue; // 当前有效积分 * vipIntegralBLL.Update(vipIntegralEntity, false, tran); * } * * //更新vip表积分记录 * VipBLL vipBll = new VipBLL(CurrentUserInfo); * VipEntity vipEntity = vipBll.GetByID(vipId); * if (vipEntity != null) * { * vipEntity.Integration = (vipEntity.Integration.HasValue ? vipEntity.Integration.Value : 0) + integralValue; * vipBll.Update(vipEntity); * } * * * VipIntegralDetailBLL vipIntegralDetailBLL = new VipIntegralDetailBLL(CurrentUserInfo); * VipIntegralDetailEntity vipIntegralDetailEntity = new VipIntegralDetailEntity(); * vipIntegralDetailEntity.VipIntegralDetailID = CPOS.Common.Utils.NewGuid(); * vipIntegralDetailEntity.VIPID = vipId; * vipIntegralDetailEntity.FromVipID = vipId; * vipIntegralDetailEntity.Integral = integralValue; * if (eventId.ToUpper() == "E5A304D716D14CD2B96560EBD2B6A29C") * vipIntegralDetailEntity.IntegralSourceID = "16"; * if (eventId.ToUpper() == "BFC41A8BF8564B6DB76AE8A8E43557BA") * vipIntegralDetailEntity.IntegralSourceID = "17"; * * vipIntegralDetailBLL.Create(vipIntegralDetailEntity); */ }//奖品如果是优惠券 else if (!string.IsNullOrEmpty(prizeMapping.Tables[0].Rows[0]["CouponTypeID"].ToString())) { var couponId = Utils.NewGuid(); //生成优惠券 this._currentDAO.CreateCoupon(vipId, eventId, couponId, tran); //添加优惠券用户关系 VipCouponMappingBLL mappingService = new VipCouponMappingBLL(this.CurrentUserInfo); mappingService.Create(new VipCouponMappingEntity { VipCouponMapping = Utils.NewGuid(), VIPID = vipId, CouponID = couponId, UrlInfo = "" }, tran); } } //设置奖品为已兑换 var prizeWinner = winnerService.Query(new IWhereCondition[] { new EqualsCondition() { FieldName = "PrizeWinnerID", Value = prize["PrizeWinnerID"].ToString() } }, null).FirstOrDefault(); if (prizeWinner != null) { prizeWinner.HasConvert = 1; winnerService.Update(prizeWinner, false, tran); } } tran.Commit(); } }