コード例 #1
0
        public ActionResult Void(StoreCouponDetailRequest request, int? authuid, UserModel authUser)
        {
            request.AuthUser = authUser;
            var coupon = _storecouponRepo.Get(sp => sp.Id == request.StoreCouponId && sp.UserId.Value == authUser.Id && sp.Status!=(int)CouponStatus.Used && sp.ValidEndDate >= DateTime.Now).FirstOrDefault();
            if (coupon == null)
                return new RestfulResult
                {
                    Data = new ExecuteResult { StatusCode = StatusCode.InternalServerError, Message = "代金券已失效或使用!" }

                };
           
            using (var ts = new TransactionScope())
            {
                // step1: void coupon
                coupon.Status = (int)CouponStatus.Deleted;
                _storecouponRepo.Update(coupon);
                //step2: rebate points of app

               var newPoint = _pointRepo.Insert(new PointHistoryEntity()
                {
                    CreatedDate = DateTime.Now,
                    CreatedUser = authUser.Id,
                    Description = "取消代金券退回积点",
                    Name = string.Format("取消代金券,返回{0}",ConfigManager.Point2GroupRatio * coupon.Points.Value),
                    PointSourceId = request.StoreCouponId,
                    PointSourceType = (int)PointSourceType.Group,
                    Status = (int)DataStatus.Normal,
                    UpdatedDate = DateTime.Now,
                    UpdatedUser = authUser.Id,
                    User_Id = authUser.Id,
                    Type = (int)PointType.VoidCoupon,
                    Amount = ConfigManager.Point2GroupRatio * coupon.Points.Value

                });

                //step3: insert coupon log
               _couponlogRepo.Insert(new CouponLogEntity()
               {
                   ActionType = (int)CouponActionType.Void,
                   Code = coupon.Code,
                   CreateDate = DateTime.Now,
                   CreateUser = authUser.Id,
                   Type = (int)CouponType.StorePromotion
               });
               
                 // step4: void action should call aws service directly to check the real time coupon status
               string message = string.Empty;
                bool isVoidSuccess = AwsHelper.SendHttpMessage(ConfigManager.AwsHttpUrlVoidCoupon,
                        new {
                          code = coupon.Code  
                        },
                        ConfigManager.AwsHttpPublicKey,
                        ConfigManager.AwsHttpPrivateKey,
                        r => message = r.message,
                        null);

                // step3: commit
               if (newPoint != null && isVoidSuccess)
               {
                   ts.Complete();
               }
               else
               {
                   return new RestfulResult
                   {
                       Data = new ExecuteResult { StatusCode = StatusCode.InternalServerError, Message = "取消代金券异常!" }

                   };
               }
            }
            return new RestfulResult
            {
                Data = new ExecuteResult { StatusCode = StatusCode.Success, Message = "取消代金券成功,积点将于1个工作日后返回会员卡账户!" }

            };
        }
コード例 #2
0
        public ActionResult Detail(StoreCouponDetailRequest request, int? authuid, UserModel authUser)
        {
            request.AuthUser = authUser;
            if (request == null)
                return new RestfulResult { Data = new ExecuteResult<StoreCouponListRequest>(null) };
            var linq = _storecouponRepo.Get(c => c.Id == request.StoreCouponId && c.UserId== authUser.Id && c.Status != (int)CouponStatus.Deleted);
            var linq2 = linq.Join(_storeproRepo.GetAll(), o => o.StorePromotionId, i => i.Id, (o, i) => new { SC = o, SP = i })
                            .Join(_storeproscopeRepo.Get(s => s.Status != (int)DataStatus.Deleted), o => new { o.SC.StorePromotionId, o.SC.StoreId }, i => new { i.StorePromotionId, i.StoreId }, (o, i) => new { SC=o.SC,SP=o.SP,SS=i}); ;
                           
            var responseData = from l in linq2.ToList()
                               select new StoreCouponDetailResponse().FromEntity<StoreCouponDetailResponse>(l.SC,
                                            c =>
                                            {
                                                c.Promotion = new StorePromotionDetailResponse().FromEntity<StorePromotionDetailResponse>(l.SP, sp => {
                                                    sp.InScopeNotice_S = new[] { new StorePromotionScopeDetailResponse(){
                                                         Excludes = l.SS.Excludes,
                                                         StoreName = l.SS.StoreName
                                                    }};
                                                });
                                                c.StoreName = l.SS.StoreName;
                                                c.Exclude = l.SS.Excludes;

                                            });
            return new RestfulResult { Data = new ExecuteResult<StoreCouponDetailResponse>(responseData.FirstOrDefault()) };
        }