/// <summary>
 /// 创建一个新实例
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Create(VipCouponMappingEntity pEntity)
 {
     _currentDAO.Create(pEntity);
 }
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param>
 public void Update(VipCouponMappingEntity pEntity, IDbTransaction pTran)
 {
     _currentDAO.Update(pEntity, pTran);
 }
 /// <summary>
 /// 分页根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public PagedQueryResult <VipCouponMappingEntity> PagedQueryByEntity(VipCouponMappingEntity 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 VipCouponMappingEntity[] QueryByEntity(VipCouponMappingEntity pQueryEntity, OrderBy[] pOrderBys)
 {
     return(_currentDAO.QueryByEntity(pQueryEntity, pOrderBys));
 }
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="pEntity"></param>
 public void Delete(VipCouponMappingEntity pEntity)
 {
     _currentDAO.Delete(pEntity);
 }
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Update(VipCouponMappingEntity pEntity)
 {
     _currentDAO.Update(pEntity);
 }
        protected override EmptyResponseData ProcessRequest(DTO.Base.APIRequest <ExchangeCouponRP> pRequest)
        {
            var rd                 = new EmptyResponseData();
            var para               = pRequest.Parameters;
            var pointMarkBLL       = new X_VipPointMarkBLL(CurrentUserInfo);
            var pointMarkDetailBLL = new X_VipPointMarkDetailBLL(CurrentUserInfo);

            var activityPrizesBLL = new X_ActivityPrizesBLL(CurrentUserInfo);
            var activityJoinBLL   = new X_ActivityJoinBLL(CurrentUserInfo);

            var couponBLL           = new CouponBLL(CurrentUserInfo);
            var vipCouponMappingBLL = new VipCouponMappingBLL(CurrentUserInfo);
            var couponTypeBLL       = new CouponTypeBLL(CurrentUserInfo);


            var activityPrizeInfo = activityPrizesBLL.GetByID(para.PrizesID);

            if (activityPrizeInfo != null)
            {
                //扣减积点
                var pointMarkInfo = pointMarkBLL.QueryByEntity(new X_VipPointMarkEntity()
                {
                    VipID = CurrentUserInfo.UserID
                }, null).FirstOrDefault();
                if (pointMarkInfo != null)
                {
                    pointMarkInfo.Count = pointMarkInfo.Count - activityPrizeInfo.UsePoint;
                    pointMarkBLL.Update(pointMarkInfo);

                    X_VipPointMarkDetailEntity detail = new X_VipPointMarkDetailEntity()
                    {
                        VipID      = CurrentUserInfo.UserID,
                        Count      = -activityPrizeInfo.UsePoint,
                        Source     = 2,//抽奖兑换
                        CustomerID = CurrentUserInfo.ClientID
                    };
                    pointMarkDetailBLL.Create(detail);
                }
                //更改参与信息
                var activityJoinInfo = activityJoinBLL.QueryByEntity(new X_ActivityJoinEntity()
                {
                    VipID = CurrentUserInfo.UserID
                }, new OrderBy[] { new OrderBy {
                                       FieldName = "CreateTime", Direction = OrderByDirections.Desc
                                   } }).FirstOrDefault();
                if (activityJoinInfo != null)
                {
                    activityJoinInfo.IsExchange = 1;
                    activityJoinBLL.Update(activityJoinInfo);
                }
                //兑换优惠券
                string couponID = couponBLL.GetUsableCouponID(activityPrizeInfo.CouponTypeID.ToString());
                VipCouponMappingEntity vipCouponMappingInfo = new VipCouponMappingEntity()
                {
                    VIPID    = CurrentUserInfo.UserID,
                    CouponID = couponID
                };
                vipCouponMappingBLL.Create(vipCouponMappingInfo);
                //修改券产品个数
                var couponTypeInfo = couponTypeBLL.GetByID(activityPrizeInfo.CouponTypeID);
                if (couponTypeInfo != null)
                {
                    couponTypeInfo.IsVoucher = couponTypeInfo.IsVoucher + 1;
                    couponTypeBLL.Update(couponTypeInfo);
                }
            }
            return(rd);
        }