public ActionResult Submit(string cartItemIds, long?regionId) { int num; int num1; dynamic obj; IOrderService orderService = ServiceHelper.Create <IOrderService>(); IMemberIntegralService memberIntegralService = ServiceHelper.Create <IMemberIntegralService>(); MemberIntegralExchangeRules integralChangeRule = memberIntegralService.GetIntegralChangeRule(); MemberIntegral memberIntegral = memberIntegralService.GetMemberIntegral(base.CurrentUser.Id); int num2 = (integralChangeRule == null ? 0 : integralChangeRule.MoneyPerIntegral); dynamic viewBag = base.ViewBag; num = (integralChangeRule == null ? 0 : integralChangeRule.IntegralPerMoney); viewBag.IntegralPerMoney = num; dynamic viewBag1 = base.ViewBag; num1 = (memberIntegral == null ? 0 : memberIntegral.AvailableIntegrals); viewBag1.Integral = num1; ViewBag.Logo = ServiceHelper.Create <ISiteSettingService>().GetSiteSettings().Logo; ViewBag.Step = 2; ViewBag.Member = base.CurrentUser; ViewBag.cartItemIds = cartItemIds; GetOrderProductsInfo(cartItemIds, regionId); dynamic obj1 = base.ViewBag; obj = (num2 == 0 ? 0 : Math.Floor(ViewBag.totalAmount / num2)); obj1.TotalIntegral = obj; ViewBag.MoneyPerIntegral = num2; GetShippingAddress(regionId); ViewBag.InvoiceTitle = orderService.GetInvoiceTitles(base.CurrentUser.Id); ViewBag.InvoiceContext = orderService.GetInvoiceContexts(); return(View()); }
public void AddMemberIntegral(MemberIntegralRecord model, IConversionMemberIntegralBase conversionMemberIntegralEntity = null) { if (model == null) { throw new NullReferenceException("添加会员积分记录时,会员积分Model为空."); } if (0 == model.MemberId) { throw new NullReferenceException("添加会员积分记录时,会员Id为空."); } if (!context.UserMemberInfo.Any((UserMemberInfo a) => a.Id == model.MemberId && (a.UserName == model.UserName))) { throw new HimallException("不存在此会员"); } if (conversionMemberIntegralEntity != null) { model.Integral = conversionMemberIntegralEntity.ConversionIntegral(); } if (model.Integral == 0) { return; } MemberIntegral memberIntegral = context.MemberIntegral.FirstOrDefault((MemberIntegral a) => a.MemberId == model.MemberId); if (memberIntegral != null) { if (model.Integral > 0) { MemberIntegral historyIntegrals = memberIntegral; historyIntegrals.HistoryIntegrals = historyIntegrals.HistoryIntegrals + model.Integral; } else if (memberIntegral.AvailableIntegrals < Math.Abs(model.Integral)) { throw new HimallException("用户积分不足以扣减该积分!"); } MemberIntegral availableIntegrals = memberIntegral; availableIntegrals.AvailableIntegrals = availableIntegrals.AvailableIntegrals + model.Integral; } else { memberIntegral = new MemberIntegral() { MemberId = new long?(model.MemberId), UserName = model.UserName }; if (model.Integral <= 0) { throw new HimallException("用户积分不足以扣减该积分!"); } MemberIntegral historyIntegrals1 = memberIntegral; historyIntegrals1.HistoryIntegrals = historyIntegrals1.HistoryIntegrals + model.Integral; MemberIntegral availableIntegrals1 = memberIntegral; availableIntegrals1.AvailableIntegrals = availableIntegrals1.AvailableIntegrals + model.Integral; context.MemberIntegral.Add(memberIntegral); } context.MemberIntegralRecord.Add(model); context.SaveChanges(); }
public void AddMemberIntegral(MemberIntegralRecord model, IConversionMemberIntegralBase conversionMemberIntegralEntity = null) { if (null == model) { throw new NullReferenceException("添加会员积分记录时,会员积分Model为空."); } if (0 == model.MemberId) { throw new NullReferenceException("添加会员积分记录时,会员Id为空."); } if (!Context.UserMemberInfo.Any(a => a.Id == model.MemberId && a.UserName == model.UserName)) { throw new Himall.Core.HimallException("不存在此会员"); } if (null != conversionMemberIntegralEntity) { model.Integral = conversionMemberIntegralEntity.ConversionIntegral(); } if (model.Integral == 0) { return; } var userIntegral = Context.MemberIntegral.FirstOrDefault(a => a.MemberId == model.MemberId); if (userIntegral == null) { userIntegral = new MemberIntegral(); userIntegral.MemberId = model.MemberId; userIntegral.UserName = model.UserName; if (model.Integral > 0) { userIntegral.HistoryIntegrals += model.Integral; } else { throw new Himall.Core.HimallException("用户积分不足以扣减该积分!"); } userIntegral.AvailableIntegrals += model.Integral; Context.MemberIntegral.Add(userIntegral); } else { if (model.Integral > 0) { userIntegral.HistoryIntegrals += model.Integral; } else { if (userIntegral.AvailableIntegrals < Math.Abs(model.Integral)) { throw new Himall.Core.HimallException("用户积分不足以扣减该积分!"); } } userIntegral.AvailableIntegrals += model.Integral; } Context.MemberIntegralRecord.Add(model); Context.SaveChanges(); }
public MemberIntegral GetMemberIntegral(long userId) { var model = Context.MemberIntegral.FirstOrDefault(a => a.MemberId == userId); if (model == null) { model = new MemberIntegral(); } return(model); }
public ActionResult Index(int?type, int pageSize = 10, int pageNo = 1) { int num; int num1; MemberIntegralExchangeRules integralChangeRule = ServiceHelper.Create <IMemberIntegralService>().GetIntegralChangeRule(); dynamic viewBag = base.ViewBag; num = (integralChangeRule == null ? 0 : integralChangeRule.IntegralPerMoney); viewBag.IntegralPerMoney = num; MemberIntegral memberIntegral = ServiceHelper.Create <IMemberIntegralService>().GetMemberIntegral(base.CurrentUser.Id); dynamic obj = base.ViewBag; num1 = (memberIntegral == null ? 0 : memberIntegral.AvailableIntegrals); obj.Integral = num1; MemberIntegral.IntegralType?nullable = null; if (type.HasValue) { nullable = new MemberIntegral.IntegralType?((MemberIntegral.IntegralType)type.Value); } IntegralRecordQuery integralRecordQuery = new IntegralRecordQuery() { IntegralType = nullable, UserId = new long?(base.CurrentUser.Id), PageNo = pageNo, PageSize = pageSize }; PageModel <MemberIntegralRecord> integralRecordList = ServiceHelper.Create <IMemberIntegralService>().GetIntegralRecordList(integralRecordQuery); IEnumerable <MemberIntegralRecord> list = from item in integralRecordList.Models.ToList() select new MemberIntegralRecord() { Id = item.Id, UserName = item.UserName, RecordDate = item.RecordDate, Integral = item.Integral, TypeId = item.TypeId, ReMark = GetRemarkFromIntegralType(item.TypeId, item.Himall_MemberIntegralRecordAction, item.ReMark) }; PagingInfo pagingInfo = new PagingInfo() { CurrentPage = pageNo, ItemsPerPage = pageSize, TotalItems = integralRecordList.Total }; ViewBag.pageInfo = pagingInfo; return(View(list)); }
public ActionResult SubmitByProductId(string skuIds, string counts, long?regionId, string collpids = null) { int num; int num1; int num2; dynamic obj; IOrderService orderService = ServiceHelper.Create <IOrderService>(); ViewBag.Logo = ServiceHelper.Create <ISiteSettingService>().GetSiteSettings().Logo; ViewBag.Member = base.CurrentUser; GetOrderProductsInfo(skuIds, counts, collpids); GetShippingAddress(regionId); IMemberIntegralService memberIntegralService = ServiceHelper.Create <IMemberIntegralService>(); MemberIntegralExchangeRules integralChangeRule = memberIntegralService.GetIntegralChangeRule(); MemberIntegral memberIntegral = memberIntegralService.GetMemberIntegral(base.CurrentUser.Id); dynamic viewBag = base.ViewBag; num = (integralChangeRule == null ? 0 : integralChangeRule.IntegralPerMoney); viewBag.IntegralPerMoney = num; dynamic viewBag1 = base.ViewBag; num1 = (integralChangeRule == null ? 0 : integralChangeRule.MoneyPerIntegral); viewBag1.MoneyPerIntegral = num1; dynamic obj1 = base.ViewBag; num2 = (memberIntegral == null ? 0 : memberIntegral.AvailableIntegrals); obj1.Integral = num2; dynamic viewBag2 = base.ViewBag; obj = (ViewBag.MoneyPerIntegral == 0 ? 0 : Math.Floor(ViewBag.totalAmount / ViewBag.MoneyPerIntegral)); viewBag2.TotalIntegral = obj; ViewBag.collIds = collpids; ViewBag.skuIds = skuIds; ViewBag.counts = counts; ViewBag.InvoiceTitle = orderService.GetInvoiceTitles(base.CurrentUser.Id); ViewBag.InvoiceContext = orderService.GetInvoiceContexts(); return(View("Submit")); }
public MemberIntegral GetMemberIntegral(long userId) { MemberIntegral memberIntegral = context.MemberIntegral.FirstOrDefault((MemberIntegral a) => a.MemberId == userId) ?? new MemberIntegral(); return(memberIntegral); }
private void GetOrderProductsInfo(string cartItemIds) { CartHelper cartHelper = new CartHelper(); IEnumerable <ShoppingCartItem> cartItems = null; if (!string.IsNullOrWhiteSpace(cartItemIds)) { char[] chrArray = new char[] { ',' }; IEnumerable <long> nums = from t in cartItemIds.Split(chrArray) select long.Parse(t); cartItems = ServiceHelper.Create <ICartService>().GetCartItems(nums); } else { cartItems = cartHelper.GetCart(base.CurrentUser.Id).Items; } int cityId = 0; ShippingAddressInfo defaultUserShippingAddressByUserId = ServiceHelper.Create <IShippingAddressService>().GetDefaultUserShippingAddressByUserId(base.CurrentUser.Id); if (defaultUserShippingAddressByUserId != null) { cityId = Instance <IRegionService> .Create.GetCityId(defaultUserShippingAddressByUserId.RegionIdPath); } IProductService productService = ServiceHelper.Create <IProductService>(); IShopService shopService = ServiceHelper.Create <IShopService>(); List <CartItemModel> list = cartItems.Select <ShoppingCartItem, CartItemModel>((ShoppingCartItem item) => { ProductInfo product = productService.GetProduct(item.ProductId); SKUInfo sku = productService.GetSku(item.SkuId); return(new CartItemModel() { skuId = item.SkuId, id = product.Id, imgUrl = product.GetImage(ProductInfo.ImageSize.Size_100, 1), name = product.ProductName, price = sku.SalePrice, shopId = product.ShopId, count = item.Quantity }); }).ToList(); IEnumerable <IGrouping <long, CartItemModel> > groupings = from a in list group a by a.shopId; List <ShopCartItemModel> shopCartItemModels = new List <ShopCartItemModel>(); foreach (IGrouping <long, CartItemModel> nums1 in groupings) { IEnumerable <long> nums2 = from r in nums1 select r.id; IEnumerable <int> nums3 = from r in nums1 select r.count; ShopCartItemModel shopCartItemModel = new ShopCartItemModel() { shopId = nums1.Key }; if (ServiceHelper.Create <IVShopService>().GetVShopByShopId(shopCartItemModel.shopId) != null) { shopCartItemModel.vshopId = ServiceHelper.Create <IVShopService>().GetVShopByShopId(shopCartItemModel.shopId).Id; } else { shopCartItemModel.vshopId = 0; } shopCartItemModel.CartItemModels = ( from a in list where a.shopId == shopCartItemModel.shopId select a).ToList(); shopCartItemModel.ShopName = shopService.GetShop(shopCartItemModel.shopId, false).ShopName; if (cityId > 0) { shopCartItemModel.Freight = ServiceHelper.Create <IProductService>().GetFreight(nums2, nums3, cityId); } List <ShopBonusReceiveInfo> detailToUse = ServiceHelper.Create <IShopBonusService>().GetDetailToUse(shopCartItemModel.shopId, base.CurrentUser.Id, nums1.Sum <CartItemModel>((CartItemModel a) => a.price * a.count)); List <CouponRecordInfo> userCoupon = ServiceHelper.Create <ICouponService>().GetUserCoupon(shopCartItemModel.shopId, base.CurrentUser.Id, nums1.Sum <CartItemModel>((CartItemModel a) => a.price * a.count)); if (detailToUse.Count() > 0 && userCoupon.Count() > 0) { ShopBonusReceiveInfo shopBonusReceiveInfo = detailToUse.FirstOrDefault(); CouponRecordInfo couponRecordInfo = userCoupon.FirstOrDefault(); decimal?price = shopBonusReceiveInfo.Price; decimal num = couponRecordInfo.ChemCloud_Coupon.Price; if ((price.GetValueOrDefault() <= num ? true : !price.HasValue)) { shopCartItemModel.Coupon = new CouponModel() { CouponName = couponRecordInfo.ChemCloud_Coupon.CouponName, CouponId = couponRecordInfo.Id, CouponPrice = couponRecordInfo.ChemCloud_Coupon.Price, Type = 0 }; } else { shopCartItemModel.Coupon = new CouponModel() { CouponName = shopBonusReceiveInfo.ChemCloud_ShopBonusGrant.ChemCloud_ShopBonus.Name, CouponId = shopBonusReceiveInfo.Id, CouponPrice = shopBonusReceiveInfo.Price.Value, Type = 1 }; } } else if (detailToUse.Count() <= 0 && userCoupon.Count() <= 0) { shopCartItemModel.Coupon = null; } else if (detailToUse.Count() <= 0 && userCoupon.Count() > 0) { CouponRecordInfo couponRecordInfo1 = userCoupon.FirstOrDefault(); shopCartItemModel.Coupon = new CouponModel() { CouponName = couponRecordInfo1.ChemCloud_Coupon.CouponName, CouponId = couponRecordInfo1.Id, CouponPrice = couponRecordInfo1.ChemCloud_Coupon.Price, Type = 0 }; } else if (detailToUse.Count() > 0 && userCoupon.Count() <= 0) { ShopBonusReceiveInfo shopBonusReceiveInfo1 = detailToUse.FirstOrDefault(); shopCartItemModel.Coupon = new CouponModel() { CouponName = shopBonusReceiveInfo1.ChemCloud_ShopBonusGrant.ChemCloud_ShopBonus.Name, CouponId = shopBonusReceiveInfo1.Id, CouponPrice = shopBonusReceiveInfo1.Price.Value, Type = 1 }; } decimal num1 = shopCartItemModel.CartItemModels.Sum <CartItemModel>((CartItemModel d) => d.price * d.count); decimal num2 = num1 - (shopCartItemModel.Coupon == null ? new decimal(0) : shopCartItemModel.Coupon.CouponPrice); decimal freeFreight = shopService.GetShop(shopCartItemModel.shopId, false).FreeFreight; shopCartItemModel.isFreeFreight = false; if (freeFreight > new decimal(0)) { shopCartItemModel.shopFreeFreight = freeFreight; if (num2 >= freeFreight) { shopCartItemModel.Freight = new decimal(0); shopCartItemModel.isFreeFreight = true; } } shopCartItemModels.Add(shopCartItemModel); } decimal num3 = ( from a in shopCartItemModels where a.Coupon != null select a).Sum <ShopCartItemModel>((ShopCartItemModel b) => b.Coupon.CouponPrice); ViewBag.products = shopCartItemModels; base.ViewBag.totalAmount = list.Sum <CartItemModel>((CartItemModel item) => item.price * item.count); base.ViewBag.Freight = shopCartItemModels.Sum <ShopCartItemModel>((ShopCartItemModel a) => a.Freight); dynamic viewBag = base.ViewBag; dynamic obj = ViewBag.totalAmount; viewBag.orderAmount = obj + ViewBag.Freight - num3; IMemberIntegralService memberIntegralService = ServiceHelper.Create <IMemberIntegralService>(); MemberIntegral memberIntegral = memberIntegralService.GetMemberIntegral(base.CurrentUser.Id); int num4 = (memberIntegral == null ? 0 : memberIntegral.AvailableIntegrals); ViewBag.userIntegrals = num4; ViewBag.integralPerMoney = 0; ViewBag.memberIntegralInfo = memberIntegral; MemberIntegralExchangeRules integralChangeRule = memberIntegralService.GetIntegralChangeRule(); decimal num5 = new decimal(0); decimal num6 = new decimal(0); decimal viewBag1 = (decimal)ViewBag.totalAmount; if (integralChangeRule == null || integralChangeRule.IntegralPerMoney <= 0) { num5 = new decimal(0); num6 = new decimal(0); } else { if (((viewBag1 - num3) - Math.Round((decimal)num4 / integralChangeRule.IntegralPerMoney, 2)) <= new decimal(0)) { num5 = Math.Round(viewBag1 - num3, 2); num6 = Math.Round((viewBag1 - num3) * integralChangeRule.IntegralPerMoney); } else { num5 = Math.Round((decimal)num4 / integralChangeRule.IntegralPerMoney, 2); num6 = num4; } if (num5 <= new decimal(0)) { num5 = new decimal(0); num6 = new decimal(0); } } ViewBag.integralPerMoney = num5; ViewBag.userIntegrals = num6; }
private void GetOrderProductsInfo(IEnumerable <string> skuIds, IEnumerable <int> counts) { IProductService productService = ServiceHelper.Create <IProductService>(); IShopService shopService = ServiceHelper.Create <IShopService>(); int num3 = 0; int cityId = 0; ShippingAddressInfo defaultUserShippingAddressByUserId = ServiceHelper.Create <IShippingAddressService>().GetDefaultUserShippingAddressByUserId(base.CurrentUser.Id); if (defaultUserShippingAddressByUserId != null) { cityId = Instance <IRegionService> .Create.GetCityId(defaultUserShippingAddressByUserId.RegionIdPath); } List <CartItemModel> list = skuIds.Select <string, CartItemModel>((string item) => { SKUInfo sku = productService.GetSku(item); IEnumerable <int> nums = counts; int num = num3; int num1 = num; num3 = num + 1; int num2 = nums.ElementAt <int>(num1); LimitTimeMarketInfo limitTimeMarketItemByProductId = ServiceHelper.Create <ILimitTimeBuyService>().GetLimitTimeMarketItemByProductId(sku.ProductInfo.Id); if (limitTimeMarketItemByProductId != null && num2 > limitTimeMarketItemByProductId.MaxSaleCount) { throw new HimallException(string.Concat("超过最大限购数量:", limitTimeMarketItemByProductId.MaxSaleCount.ToString())); } return(new CartItemModel() { skuId = item, id = sku.ProductInfo.Id, imgUrl = sku.ProductInfo.GetImage(ProductInfo.ImageSize.Size_100, 1), name = sku.ProductInfo.ProductName, shopId = sku.ProductInfo.ShopId, price = (limitTimeMarketItemByProductId == null ? sku.SalePrice : limitTimeMarketItemByProductId.Price), count = num2, productCode = sku.ProductInfo.ProductCode }); }).ToList(); IEnumerable <IGrouping <long, CartItemModel> > groupings = from a in list group a by a.shopId; List <ShopCartItemModel> shopCartItemModels = new List <ShopCartItemModel>(); foreach (IGrouping <long, CartItemModel> nums1 in groupings) { IEnumerable <long> nums2 = from r in nums1 select r.id; IEnumerable <int> nums3 = from r in nums1 select r.count; ShopCartItemModel shopCartItemModel = new ShopCartItemModel() { shopId = nums1.Key }; shopCartItemModel.CartItemModels = ( from a in list where a.shopId == shopCartItemModel.shopId select a).ToList(); shopCartItemModel.ShopName = shopService.GetShop(shopCartItemModel.shopId, false).ShopName; if (cityId != 0) { shopCartItemModel.Freight = ServiceHelper.Create <IProductService>().GetFreight(nums2, nums3, cityId); } List <ShopBonusReceiveInfo> detailToUse = ServiceHelper.Create <IShopBonusService>().GetDetailToUse(shopCartItemModel.shopId, base.CurrentUser.Id, nums1.Sum <CartItemModel>((CartItemModel a) => a.price * a.count)); List <CouponRecordInfo> userCoupon = ServiceHelper.Create <ICouponService>().GetUserCoupon(shopCartItemModel.shopId, base.CurrentUser.Id, nums1.Sum <CartItemModel>((CartItemModel a) => a.price * a.count)); if (detailToUse.Count() > 0 && userCoupon.Count() > 0) { ShopBonusReceiveInfo shopBonusReceiveInfo = detailToUse.FirstOrDefault(); CouponRecordInfo couponRecordInfo = userCoupon.FirstOrDefault(); decimal?price = shopBonusReceiveInfo.Price; decimal price1 = couponRecordInfo.ChemCloud_Coupon.Price; if ((price.GetValueOrDefault() <= price1 ? true : !price.HasValue)) { shopCartItemModel.Coupon = new CouponModel() { CouponName = couponRecordInfo.ChemCloud_Coupon.CouponName, CouponId = couponRecordInfo.Id, CouponPrice = couponRecordInfo.ChemCloud_Coupon.Price, Type = 0 }; } else { shopCartItemModel.Coupon = new CouponModel() { CouponName = shopBonusReceiveInfo.ChemCloud_ShopBonusGrant.ChemCloud_ShopBonus.Name, CouponId = shopBonusReceiveInfo.Id, CouponPrice = shopBonusReceiveInfo.Price.Value, Type = 1 }; } } else if (detailToUse.Count() <= 0 && userCoupon.Count() <= 0) { shopCartItemModel.Coupon = null; } else if (detailToUse.Count() <= 0 && userCoupon.Count() > 0) { CouponRecordInfo couponRecordInfo1 = userCoupon.FirstOrDefault(); shopCartItemModel.Coupon = new CouponModel() { CouponName = couponRecordInfo1.ChemCloud_Coupon.CouponName, CouponId = couponRecordInfo1.Id, CouponPrice = couponRecordInfo1.ChemCloud_Coupon.Price, Type = 0 }; } else if (detailToUse.Count() > 0 && userCoupon.Count() <= 0) { ShopBonusReceiveInfo shopBonusReceiveInfo1 = detailToUse.FirstOrDefault(); shopCartItemModel.Coupon = new CouponModel() { CouponName = shopBonusReceiveInfo1.ChemCloud_ShopBonusGrant.ChemCloud_ShopBonus.Name, CouponId = shopBonusReceiveInfo1.Id, CouponPrice = shopBonusReceiveInfo1.Price.Value, Type = 1 }; } decimal num4 = shopCartItemModel.CartItemModels.Sum <CartItemModel>((CartItemModel d) => d.price * d.count); decimal num5 = num4 - (shopCartItemModel.Coupon == null ? new decimal(0) : shopCartItemModel.Coupon.CouponPrice); decimal freeFreight = shopService.GetShop(shopCartItemModel.shopId, false).FreeFreight; shopCartItemModel.isFreeFreight = false; if (freeFreight > new decimal(0)) { shopCartItemModel.shopFreeFreight = freeFreight; if (num5 >= freeFreight) { shopCartItemModel.Freight = new decimal(0); shopCartItemModel.isFreeFreight = true; } } shopCartItemModels.Add(shopCartItemModel); } decimal num6 = ( from a in shopCartItemModels where a.Coupon != null select a).Sum <ShopCartItemModel>((ShopCartItemModel b) => b.Coupon.CouponPrice); ViewBag.products = shopCartItemModels; base.ViewBag.totalAmount = list.Sum <CartItemModel>((CartItemModel item) => item.price * item.count); base.ViewBag.Freight = shopCartItemModels.Sum <ShopCartItemModel>((ShopCartItemModel a) => a.Freight); dynamic viewBag = base.ViewBag; dynamic obj = ViewBag.totalAmount; viewBag.orderAmount = obj + ViewBag.Freight - num6; IMemberIntegralService memberIntegralService = ServiceHelper.Create <IMemberIntegralService>(); MemberIntegral memberIntegral = memberIntegralService.GetMemberIntegral(base.CurrentUser.Id); int num7 = (memberIntegral == null ? 0 : memberIntegral.AvailableIntegrals); ViewBag.userIntegrals = num7; ViewBag.integralPerMoney = 0; ViewBag.memberIntegralInfo = memberIntegral; MemberIntegralExchangeRules integralChangeRule = memberIntegralService.GetIntegralChangeRule(); decimal viewBag1 = new decimal(0); decimal viewBag2 = new decimal(0); if (integralChangeRule == null || integralChangeRule.IntegralPerMoney <= 0) { viewBag1 = new decimal(0); viewBag2 = new decimal(0); } else { if (ViewBag.totalAmount - num6 - Math.Round((decimal)num7 / integralChangeRule.IntegralPerMoney, 2) <= 0) { viewBag1 = Math.Round(ViewBag.totalAmount - num6, 2); viewBag2 = Math.Round((ViewBag.totalAmount - num6) * integralChangeRule.IntegralPerMoney); } else { viewBag1 = Math.Round((decimal)num7 / integralChangeRule.IntegralPerMoney, 2); viewBag2 = num7; } if (viewBag1 <= new decimal(0)) { viewBag1 = new decimal(0); viewBag2 = new decimal(0); } } ViewBag.integralPerMoney = viewBag1; ViewBag.userIntegrals = viewBag2; }
public void ConfirmRefund(long refundId, string managerRemark, string managerName) { decimal? nullable; OrderRefundInfo now = context.OrderRefundInfo.FindById <OrderRefundInfo>(refundId); if (now.RefundPayType.HasValue) { switch (now.RefundPayType.Value) { case OrderRefundInfo.OrderRefundPayType.BackOut: { if (now.RefundPayStatus.HasValue && now.RefundPayStatus.Value == OrderRefundInfo.OrderRefundPayStatus.PaySuccess) { break; } string paymentTypeGateway = now.OrderItemInfo.OrderInfo.PaymentTypeGateway; IEnumerable <Plugin <IPaymentPlugin> > plugins = from item in PluginsManagement.GetPlugins <IPaymentPlugin>(true) where item.PluginInfo.PluginId == paymentTypeGateway select item; if (plugins.Count <Plugin <IPaymentPlugin> >() <= 0) { throw new HimallException("退款时,未找到支付方式!"); } OrderPayInfo orderPayInfo = context.OrderPayInfo.FirstOrDefault((OrderPayInfo e) => e.PayState && e.OrderId == now.OrderId); IQueryable <long> nums = from item in context.OrderPayInfo where item.PayId == orderPayInfo.PayId && item.PayState select item into e select e.OrderId; decimal num = ( from o in context.OrderInfo where nums.Contains(o.Id) select o).ToList().Sum <OrderInfo>((OrderInfo e) => e.OrderTotalAmount); if (orderPayInfo == null) { throw new HimallException("退款时,未找到原支付订单信息!"); } PaymentPara paymentPara = new PaymentPara() { out_refund_no = now.Id.ToString(), out_trade_no = orderPayInfo.PayId.ToString(), refund_fee = now.Amount, total_fee = num }; PaymentPara paymentPara1 = paymentPara; PaymentInfo paymentInfo = plugins.FirstOrDefault <Plugin <IPaymentPlugin> >().Biz.ProcessRefundFee(paymentPara1); if (paymentInfo.OrderIds == null || paymentInfo.OrderIds.Count() <= 0) { break; } now.RefundPayStatus = new OrderRefundInfo.OrderRefundPayStatus?(OrderRefundInfo.OrderRefundPayStatus.PaySuccess); context.SaveChanges(); break; } case OrderRefundInfo.OrderRefundPayType.BackCapital: { if (now.RefundPayStatus.HasValue && now.RefundPayStatus.Value == OrderRefundInfo.OrderRefundPayStatus.PaySuccess) { break; } CapitalInfo capitalInfo = context.CapitalInfo.FirstOrDefault((CapitalInfo e) => e.MemId == now.UserId); OrderBO orderBO = new OrderBO(); if (capitalInfo != null) { CapitalDetailInfo capitalDetailInfo = new CapitalDetailInfo() { Amount = now.Amount, CapitalID = capitalInfo.Id, CreateTime = new DateTime?(DateTime.Now), SourceType = CapitalDetailInfo.CapitalDetailType.Refund, SourceData = now.Id.ToString(), Id = orderBO.GenerateOrderNumber() }; CapitalDetailInfo capitalDetailInfo1 = capitalDetailInfo; CapitalInfo capitalInfo1 = capitalInfo; decimal? balance = capitalInfo1.Balance; decimal amount = now.Amount; if (balance.HasValue) { nullable = new decimal?(balance.GetValueOrDefault() + amount); } else { nullable = null; } capitalInfo1.Balance = nullable; context.CapitalDetailInfo.Add(capitalDetailInfo1); } else { CapitalInfo capitalInfo2 = new CapitalInfo() { Balance = new decimal?(now.Amount), MemId = now.UserId, FreezeAmount = new decimal?(new decimal(0)), ChargeAmount = new decimal?(new decimal(0)) }; List <CapitalDetailInfo> capitalDetailInfos = new List <CapitalDetailInfo>(); CapitalDetailInfo capitalDetailInfo2 = new CapitalDetailInfo() { Amount = now.Amount, CreateTime = new DateTime?(DateTime.Now), SourceData = now.Id.ToString(), SourceType = CapitalDetailInfo.CapitalDetailType.Refund, Id = orderBO.GenerateOrderNumber() }; capitalDetailInfos.Add(capitalDetailInfo2); capitalInfo2.ChemCloud_CapitalDetail = capitalDetailInfos; capitalInfo = capitalInfo2; context.CapitalInfo.Add(capitalInfo); } now.RefundPayStatus = new OrderRefundInfo.OrderRefundPayStatus?(OrderRefundInfo.OrderRefundPayStatus.PaySuccess); context.SaveChanges(); break; } } } if (now.ManagerConfirmStatus != OrderRefundInfo.OrderRefundConfirmStatus.UnConfirm) { throw new HimallException("只有未确认状态的退款/退货才能进行确认操作"); } now.ManagerConfirmStatus = OrderRefundInfo.OrderRefundConfirmStatus.Confirmed; now.ManagerConfirmDate = DateTime.Now; now.ManagerRemark = managerRemark; OrderOperationLogInfo orderOperationLogInfo = new OrderOperationLogInfo() { Operator = managerName, OrderId = now.OrderId, OperateDate = DateTime.Now, OperateContent = "确认退款/退货" }; context.OrderOperationLogInfo.Add(orderOperationLogInfo); UserMemberInfo userMemberInfo = context.UserMemberInfo.FindById <UserMemberInfo>(now.UserId); OrderInfo orderInfo = context.OrderInfo.FindById <OrderInfo>(now.OrderId); decimal orderTotalAmount = orderInfo.OrderTotalAmount - orderInfo.Freight; decimal amount1 = now.Amount - (orderInfo.IntegralDiscount * (now.Amount / orderTotalAmount)); amount1 = Math.Round(amount1, 2); if (amount1 > new decimal(0)) { OrderInfo refundTotalAmount = orderInfo; refundTotalAmount.RefundTotalAmount = refundTotalAmount.RefundTotalAmount + amount1; if (orderInfo.RefundTotalAmount > orderTotalAmount) { orderInfo.RefundTotalAmount = orderTotalAmount; } } if (now.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund) { MemberIntegralExchangeRules integralChangeRule = Instance <IMemberIntegralService> .Create.GetIntegralChangeRule(); if (integralChangeRule != null) { int moneyPerIntegral = integralChangeRule.MoneyPerIntegral; int num1 = (int)Math.Floor(now.Amount / moneyPerIntegral); MemberIntegral memberIntegral = userMemberInfo.ChemCloud_MemberIntegral.FirstOrDefault(); int num2 = (memberIntegral == null ? 0 : memberIntegral.AvailableIntegrals); if (num1 > 0 && num2 > 0 && orderInfo.OrderStatus == OrderInfo.OrderOperateStatus.Finish) { MemberIntegralRecord memberIntegralRecord = new MemberIntegralRecord() { UserName = userMemberInfo.UserName, MemberId = userMemberInfo.Id, RecordDate = new DateTime?(DateTime.Now), TypeId = MemberIntegral.IntegralType.Others }; object[] id = new object[] { "售后编号【", now.Id, "】退款应扣除积分", num1.ToString() }; memberIntegralRecord.ReMark = string.Concat(id); num1 = (num1 > num2 ? num2 : num1); num1 = -num1; IConversionMemberIntegralBase conversionMemberIntegralBase = Instance <IMemberIntegralConversionFactoryService> .Create.Create(MemberIntegral.IntegralType.Others, num1); Instance <IMemberIntegralService> .Create.AddMemberIntegral(memberIntegralRecord, conversionMemberIntegralBase); } } } context.SaveChanges(); MessageOrderInfo messageOrderInfo = new MessageOrderInfo() { OrderId = orderInfo.Id.ToString(), ShopId = orderInfo.ShopId, ShopName = orderInfo.ShopName, RefundMoney = now.Amount, SiteName = Instance <ISiteSettingService> .Create.GetSiteSettings().SiteName, TotalMoney = orderInfo.OrderTotalAmount }; Task.Factory.StartNew(() => Instance <IMessageService> .Create.SendMessageOnOrderRefund(orderInfo.UserId, messageOrderInfo)); if (orderInfo.PayDate.HasValue) { UpdateShopVisti(now, orderInfo.PayDate.Value); UpdateProductVisti(now, orderInfo.PayDate.Value); } }
protected void btnSave_Click(object sender, EventArgs e) { SOSOshop.BLL.PromptInfo.Popedom("008009004", "对不起,您没有权限进行编辑"); SOSOshop.BLL.MemberInfo bll = new SOSOshop.BLL.MemberInfo(); int uid = ChangeHope.WebPage.PageRequest.GetQueryInt("uid"); bool edit = (uid > 0); //try //{ //if (ChangeHope.WebPage.PageRequest.GetFormString("ParentId").Replace("0,", "").Trim(',') == "") //{ // this.ltlMsg.Text = "保存失败" + "\r\n上级单位不能为空!"; // this.pnlMsg.Visible = true; // this.pnlMsg.CssClass = "actionErr"; // return; //} if (this.txtTrueName.Text.Trim() == "") { this.ltlMsg.Text = "保存失败" + "\r\n联系人不能为空!"; this.pnlMsg.Visible = true; this.pnlMsg.CssClass = "actionErr"; return; } if (this.txtMobilePhone.Text.Trim() == "") { this.ltlMsg.Text = "保存失败" + "\r\n手机号不能为空!"; this.pnlMsg.Visible = true; this.pnlMsg.CssClass = "actionErr"; return; } else if (!Regex.IsMatch(this.txtMobilePhone.Text.Trim(), @"^[0-9\-/ ]+$", RegexOptions.IgnoreCase)) { this.ltlMsg.Text = "保存失败" + "\r\n手机号填写错误!"; this.pnlMsg.Visible = true; this.pnlMsg.CssClass = "actionErr"; return; } else if ((!edit && bll.ExecuteScalar("select 1 from memberaccount where MobilePhone like '" + this.txtMobilePhone.Text.Trim() + "%'") != null) || (edit && bll.ExecuteScalar("select 1 from memberaccount where MobilePhone like '" + this.txtMobilePhone.Text.Trim() + "%' and UID!=" + uid) != null)) { this.ltlMsg.Text = "保存失败" + "\r\n手机号填写错误!此手机号已经在使用,请检查后再填写正确!"; this.pnlMsg.Visible = true; this.pnlMsg.CssClass = "actionErr"; return; } if (this.txtEmail.Text.Trim() != string.Empty) { if (!Regex.IsMatch(this.txtEmail.Text.Trim(), @"^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$", RegexOptions.IgnoreCase)) { this.ltlMsg.Text = "保存失败" + "\r\n邮箱填写错误!"; this.pnlMsg.Visible = true; this.pnlMsg.CssClass = "actionErr"; return; } else if (bll.ExecuteScalar("select 1 from memberaccount where Email = '" + this.txtEmail.Text.Trim() + "' and UID!=" + uid) != null) { this.ltlMsg.Text = "保存失败" + "\r\n邮箱填写错误!此邮箱已经在使用,请检查后再填写正确!"; this.pnlMsg.Visible = true; this.pnlMsg.CssClass = "actionErr"; return; } } if (this.txtEmail_QQ.Text.Trim() != string.Empty) { if (!Regex.IsMatch(this.txtEmail_QQ.Text.Trim(), @"^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$", RegexOptions.IgnoreCase)) { this.ltlMsg.Text = "保存失败" + "\r\n邮箱填写错误!"; this.pnlMsg.Visible = true; this.pnlMsg.CssClass = "actionErr"; return; } else if (bll.ExecuteScalar("select 1 from memberaccount where Email_QQ = '" + this.txtEmail_QQ.Text.Trim() + "' and UID!=" + uid) != null) { this.ltlMsg.Text = "保存失败" + "\r\n邮箱填写错误!此邮箱已经在使用,请检查后再填写正确!"; this.pnlMsg.Visible = true; this.pnlMsg.CssClass = "actionErr"; return; } } //if (ddl_Editer.SelectedValue == "0" || ddl_Editer.SelectedValue == "") //{ // this.ltlMsg.Text = "保存失败" + "\r\n请选择交易人员后再保存!"; // this.pnlMsg.Visible = true; // this.pnlMsg.CssClass = "actionErr"; // return; //} //if (CRM_InterunitStyle_ID.Value == "0" || CRM_InterunitStyle_ID.Value == "") //{ // this.ltlMsg.Text = "保存失败" + "\r\n请选择CRM客户分类后再保存!"; // this.pnlMsg.Visible = true; // this.pnlMsg.CssClass = "actionErr"; // return; //} string Province = ChangeHope.WebPage.PageRequest.GetFormString("province"); string City = ChangeHope.WebPage.PageRequest.GetFormString("city"); string Borough = ChangeHope.WebPage.PageRequest.GetFormString("county"); if (Province == null || Province.Trim() == string.Empty || !Regex.IsMatch(Province, @"^[0-9]{1,4}$", RegexOptions.IgnoreCase) || City == null || City.Trim() == string.Empty || !Regex.IsMatch(City, @"^[0-9]{1,4}$", RegexOptions.IgnoreCase)) { this.ltlMsg.Text = "保存失败" + "\r\n没有选择省份城市!请检查!"; this.pnlMsg.Visible = true; this.pnlMsg.CssClass = "actionErr"; return; } if (edit) { if (!UpdateAccount()) { return; } UpdateInfo(); if (DropDownList2.SelectedValue == "0") { MemberIntegral bllmi = new MemberIntegral(); MemberIntegralLock ml = new MemberIntegralLock(); if (ml.isAllow(uid, MemberIntegralTemplateEnum.建档通过)) { //注册送积分(建档成功才开始送会员积分) bllmi.AddIntegral(uid, 0, SOSOshop.BLL.Integral.MemberIntegralTemplateEnum.会员注册, ""); bllmi.AddIntegral(uid, 0, MemberIntegralTemplateEnum.建档通过, ""); } } #region 后台用户操作日志记录 SOSOshop.Model.AdminInfo adminInfo = SOSOshop.BLL.AdministrorManager.Get(); SOSOshop.BLL.Logs.Log.LogAdminAdd("修改买家信息", (adminInfo == null ? 0 : adminInfo.AdminId), (adminInfo == null ? "" : adminInfo.AdminName), 1); #endregion #region 清除缓存 SOSOshop.BLL.DbBase db1 = new SOSOshop.BLL.DbBase(); db1.ClearCache(); #endregion } else { AddAccount(); #region 后台用户操作日志记录 SOSOshop.Model.AdminInfo adminInfo = SOSOshop.BLL.AdministrorManager.Get(); SOSOshop.BLL.Logs.Log.LogAdminAdd("添加买家信息", (adminInfo == null ? 0 : adminInfo.AdminId), (adminInfo == null ? "" : adminInfo.AdminName), 1); #endregion } //} //catch (Exception ex) //{ // this.ltlMsg.Text = (edit ? "编辑" : "添加") + "买家资料失败" + "\r\n" + ex.Message; // this.pnlMsg.Visible = true; // this.pnlMsg.CssClass = "actionErr"; //} }