public ActionResult Coupon(CreateCouponProductRequest request, int?authuid, UserModel authUser) { request.AuthUid = authuid.Value; request.AuthUser = authUser; if (System.String.Compare(request.Method, DefineRestfulMethod.Create, System.StringComparison.OrdinalIgnoreCase) == 0) { var result = this._productDataService.CreateCoupon(request); if (request.IsPass == 1 && result.Data != null && result.Data.CouponCodeResponse != null) { var code = result.Data.CouponCodeResponse; result.Data.CouponCodeResponse.Pass = _passHelper.GetPass(ControllerContext.HttpContext, code.Id, code.CouponId, code.User_Id); //result.Data.CouponCodeResponse.Pass = _passHelper.GetPass(ControllerContext,) //result.Data.CouponCodeResponse.Pass = PassController.GetPass(ControllerContext, result.Data.CouponCodeResponse.Id, // result.Data.CouponCodeResponse.CouponId, // result.Data.CouponCodeResponse // .ProductName, // result.Data.CouponCodeResponse // .ProductDescription, null, result.Data.CouponCodeResponse.User_Id); } return(new RestfulResult { Data = result }); } return(new RestfulResult { Data = new ExecuteResult { StatusCode = StatusCode.ClientError, Message = "参数错误" } }); }
public ExecuteResult <ProductInfoResponse> CreateCoupon(CreateCouponProductRequest request) { if (request == null) { return(new ExecuteResult <ProductInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "参数错误" }); } var product = _productRepository.GetItem(request.ProductId); if (product == null) { return(new ExecuteResult <ProductInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "参数错误" }); } //判断如果是v1.0版本 可以允许创建优惠券。 ExecuteResult <CouponCodeResponse> coupon; if (request.Client_Version != "1.0") { if (request.PromotionId == null || request.PromotionId.Value < 1) { //获取商品关联的活动 var promotionEntity = _promotionService.GetFristNormalForProductId(product.Id); if (promotionEntity == null) { return(new ExecuteResult <ProductInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "当前商品没有参加活动" }); } request.PromotionId = promotionEntity.Id; } else { //判断 if (!_promotionService.Exists(request.PromotionId ?? 0, request.ProductId)) { return(new ExecuteResult <ProductInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "当前商品没有参加该活动" }); } } var pr = _promotionDataService.CreateCoupon(new PromotionCouponCreateRequest { AuthUid = request.AuthUid, AuthUser = request.AuthUser, Client_Version = request.Client_Version, IsPass = request.IsPass, Method = request.Method, PromotionId = request.PromotionId ?? 0, Token = request.Token }); if (pr.IsSuccess && pr.Data != null && pr.Data.CouponCodeResponse != null) { coupon = new ExecuteResult <CouponCodeResponse>(pr.Data.CouponCodeResponse); } else { coupon = new ExecuteResult <CouponCodeResponse>(null) { Message = pr.Message, StatusCode = pr.StatusCode }; } } else { coupon = _couponDataService.CreateCoupon(new CouponCouponRequest { AuthUid = request.AuthUid, SourceId = product.Id, SourceType = (int)SourceType.Product, Token = request.Token, AuthUser = request.AuthUser, Method = request.Method, Client_Version = request.Client_Version }); } if (!coupon.IsSuccess) { return(new ExecuteResult <ProductInfoResponse>(null) { Message = coupon.Message, StatusCode = coupon.StatusCode }); } //+1 product = _productRepository.SetCount(ProductCountType.InvolvedCount, product.Id, 1); var response = MappingManager.ProductInfoResponseMapping(product); response.CouponCodeResponse = coupon.Data; if (request.AuthUser != null) { response = IsR(response, request.AuthUser, product.Id); } return(new ExecuteResult <ProductInfoResponse>(response)); }