public object GetCanBuy(long id, int count) { CheckUserLogin(); var userInte = MemberIntegralApplication.GetMemberIntegral(CurrentUser.Id); //礼品信息 var giftdata = GiftApplication.GetById(id); if (giftdata == null) { return(Json(ErrorResult <bool>("礼品不存在!", code: -2))); } if (giftdata.GetSalesStatus != Mall.Entities.GiftInfo.GiftSalesStatus.Normal) { return(Json(ErrorResult <bool>("礼品已失效!", code: -2))); } //库存判断 if (count > giftdata.StockQuantity) { return(Json(ErrorResult <bool>("礼品库存不足,仅剩 " + giftdata.StockQuantity.ToString() + " 件!", code: -3))); } //积分数 if (giftdata.NeedIntegral < 1) { return(Json(ErrorResult <bool>("礼品关联等级信息有误或礼品积分数据有误!", code: -5))); } //限购数量 if (giftdata.LimtQuantity > 0) { int ownbuynumber = GiftsOrderApplication.GetOwnBuyQuantity(CurrentUser.Id, id); if (ownbuynumber + count > giftdata.LimtQuantity) { return(Json(ErrorResult <bool>("超过礼品限兑数量!", code: -4))); } } if (giftdata.NeedIntegral * count > userInte.AvailableIntegrals) { return(Json(ErrorResult <bool>("积分不足!", code: -6))); } //等级判定 if (!MemberGradeApplication.IsAllowGrade(CurrentUser.Id, giftdata.NeedGrade)) { return(Json(ErrorResult <bool>("用户等级不足!", code: -6))); } return(Json(new { success = true, msg = "可以购买!", code = 1 })); }
public object PostSubmitOrder(GiftConfirmOrderModel value) { CheckUserLogin(); long id = value.ID; var addressId = value.AddressId; if (addressId < 1) { return(Json(ErrorResult <bool>("错误的收货地址!", code: -8))); } int count = value.Count; if (count < 1) { return(Json(ErrorResult <bool>("错误的兑换数量!", code: -8))); } List <GiftOrderItemModel> gorditemlist = new List <GiftOrderItemModel>(); var curUser = MemberApplication.GetMember(CurrentUser.Id); if (curUser == null) { return(Json(ErrorResult <bool>("用户登录错误!", code: -6))); } var userInte = MemberIntegralApplication.GetMemberIntegral(curUser.Id); //礼品信息 var giftdata = GiftApplication.GetById(id); if (giftdata == null) { return(Json(ErrorResult <bool>("礼品不存在!", code: -2))); } if (giftdata.GetSalesStatus != Entities.GiftInfo.GiftSalesStatus.Normal) { return(Json(ErrorResult <bool>("礼品已失效!", code: -2))); } //库存判断 if (count > giftdata.StockQuantity) { return(Json(ErrorResult <bool>("礼品库存不足,仅剩 " + giftdata.StockQuantity.ToString() + " 件!", code: -3))); } //积分数 if (giftdata.NeedIntegral < 1) { return(Json(ErrorResult <bool>("礼品关联等级信息有误或礼品积分数据有误!", code: -5))); } //限购数量 if (giftdata.LimtQuantity > 0) { int ownbuynumber = GiftsOrderApplication.GetOwnBuyQuantity(CurrentUser.Id, id); if (ownbuynumber + count > giftdata.LimtQuantity) { return(Json(ErrorResult <bool>("超过礼品限兑数量!", code: -4))); } } if (giftdata.NeedIntegral * count > userInte.AvailableIntegrals) { return(Json(ErrorResult <bool>("积分不足!", code: -6))); } //等级判定 if (!MemberGradeApplication.IsAllowGrade(CurrentUser.Id, giftdata.NeedGrade)) { return(Json(ErrorResult <bool>("用户等级不足!", code: -6))); } Entities.ShippingAddressInfo shipdata = GetShippingAddress(addressId); if (shipdata == null) { return(Json(ErrorResult <bool>("错误的收货人地址信息!", code: -6))); } gorditemlist.Add(new GiftOrderItemModel { GiftId = giftdata.Id, Counts = count }); GiftOrderModel createorderinfo = new GiftOrderModel(); createorderinfo.Gifts = gorditemlist; createorderinfo.CurrentUser = curUser; createorderinfo.ReceiveAddress = shipdata; var orderdata = GiftsOrderApplication.CreateOrder(createorderinfo); return(Json(new { success = true, msg = orderdata.Id.ToString(), code = 1 })); }
public object GetGiftDetail(long id) { GiftsDetailModel result = new GiftsDetailModel(); var data = GiftApplication.GetById(id); // Mapper.CreateMap<Entities.GiftInfo, GiftsDetailModel>(); result = data.Map <GiftsDetailModel>(); if (data == null) { throw new Exception("礼品信息无效!"); } result.EndDateStr = data.EndDate.ToString("yyyy-MM-dd HH:mm:ss"); string tmpdefaultimg = result.GetImage(ImageSize.Size_100); result.DefaultShowImage = MallIO.GetRomoteImagePath(tmpdefaultimg); result.Images = new List <string>(); result.Description = result.Description.Replace("src=\"/Storage/", "src=\"" + Core.MallIO.GetRomoteImagePath("/Storage/") + "/"); //补充图片信息 for (var _n = 1; _n < 6; _n++) { string _imgpath = data.ImagePath + "/" + _n.ToString() + ".png"; if (MallIO.ExistFile(_imgpath)) { var tmp = MallIO.GetRomoteImagePath(result.GetImage(ImageSize.Size_500, _n)); result.Images.Add(tmp); } } #region 礼品是否可兑 result.CanBuy = true; //礼品信息 if (result.CanBuy) { if (result.GetSalesStatus != Mall.Entities.GiftInfo.GiftSalesStatus.Normal) { result.CanBuy = false; result.CanNotBuyDes = "礼品" + result.ShowSalesStatus; } } if (result.CanBuy) { //库存判断 if (result.StockQuantity < 1) { result.CanBuy = false; result.CanNotBuyDes = "已兑完"; } } if (result.CanBuy) { //积分数 if (result.NeedIntegral < 1) { result.CanBuy = false; result.CanNotBuyDes = "礼品信息错误"; } } #endregion #region 用户信息判断 if (result.CanBuy && CurrentUser != null) { //限购数量 if (result.LimtQuantity > 0) { int ownbuynumber = GiftsOrderApplication.GetOwnBuyQuantity(CurrentUser.Id, id); if (ownbuynumber >= result.LimtQuantity) { result.CanBuy = false; result.CanNotBuyDes = "限兑数量已满"; } } if (result.CanBuy) { var userInte = MemberIntegralApplication.GetMemberIntegral(CurrentUserId); if (userInte.AvailableIntegrals < result.NeedIntegral) { result.CanBuy = false; result.CanNotBuyDes = "积分不足"; } } } #endregion return(Json(result)); }