public JsonResult SubmitOrder(long id, long regionId, int count) { Result result = new Result() { success = false, msg = "未知错误", status = 0 }; Result str = result; bool flag = true; if (count < 1) { flag = false; str.success = false; str.msg = "错误的兑换数量!"; str.status = -8; return(Json(str)); } List <GiftOrderItemModel> giftOrderItemModels = new List <GiftOrderItemModel>(); UserMemberInfo member = ServiceHelper.Create <IMemberService>().GetMember(base.CurrentUser.Id); GiftInfo byId = giftser.GetById(id); if (byId == null) { flag = false; str.success = false; str.msg = "礼品不存在!"; str.status = -2; return(Json(str)); } if (byId.GetSalesStatus != GiftInfo.GiftSalesStatus.Normal) { flag = false; str.success = false; str.msg = "礼品己失效!"; str.status = -2; return(Json(str)); } if (count > byId.StockQuantity) { flag = false; str.success = false; int stockQuantity = byId.StockQuantity; str.msg = string.Concat("礼品库存不足,仅剩 ", stockQuantity.ToString(), " 件!"); str.status = -3; return(Json(str)); } if (byId.NeedIntegral < 1) { flag = false; str.success = false; str.msg = "礼品关联等级信息有误或礼品积分数据有误!"; str.status = -5; return(Json(str)); } if (byId.LimtQuantity > 0 && orderser.GetOwnBuyQuantity(base.CurrentUser.Id, id) + count > byId.LimtQuantity) { flag = false; str.success = false; str.msg = "超过礼品限兑数量!"; str.status = -4; return(Json(str)); } if (byId.NeedIntegral * count > member.AvailableIntegrals) { flag = false; str.success = false; str.msg = "积分不足!"; str.status = -6; return(Json(str)); } if (member.HistoryIntegral < byId.GradeIntegral) { flag = false; str.success = false; str.msg = "用户等级不足!"; str.status = -6; return(Json(str)); } ShippingAddressInfo shippingAddress = GetShippingAddress(new long?(regionId)); if (shippingAddress == null) { flag = false; str.success = false; str.msg = "错误的收货人地址信息!"; str.status = -6; return(Json(str)); } if (flag) { GiftOrderItemModel giftOrderItemModel = new GiftOrderItemModel() { GiftId = byId.Id, Counts = count }; giftOrderItemModels.Add(giftOrderItemModel); GiftOrderModel giftOrderModel = new GiftOrderModel() { Gifts = giftOrderItemModels, CurrentUser = member, ReceiveAddress = shippingAddress }; GiftOrderInfo giftOrderInfo = orderser.CreateOrder(giftOrderModel); str.success = true; str.msg = giftOrderInfo.Id.ToString(); str.status = 1; } return(Json(str)); }
public JsonResult SubmitOrder(long id, long regionId, int count) { Result result = new Result() { success = false, msg = "Unknown error", status = 0 }; Result str = result; bool flag = true; if (count < 1) { flag = false; str.success = false; str.msg = "Exchange quantity error!"; str.status = -8; return(Json(str)); } List <GiftOrderItemModel> giftOrderItemModels = new List <GiftOrderItemModel>(); UserMemberInfo member = ServiceHelper.Create <IMemberService>().GetMember(base.CurrentUser.Id); GiftInfo byId = giftser.GetById(id); if (byId == null) { flag = false; str.success = false; str.msg = "Gift does not exist!"; str.status = -2; return(Json(str)); } if (byId.GetSalesStatus != GiftInfo.GiftSalesStatus.Normal) { flag = false; str.success = false; str.msg = "Gift expired!"; str.status = -2; return(Json(str)); } if (count > byId.StockQuantity) { flag = false; str.success = false; int stockQuantity = byId.StockQuantity; str.msg = string.Concat("Gift inventory shortage, only remain ", stockQuantity.ToString(), " items!"); str.status = -3; return(Json(str)); } if (byId.NeedIntegral < 1) { flag = false; str.success = false; str.msg = "Gifts associated level information is wrong or points wrong!"; str.status = -5; return(Json(str)); } if (byId.LimtQuantity > 0 && orderser.GetOwnBuyQuantity(base.CurrentUser.Id, id) + count > byId.LimtQuantity) { flag = false; str.success = false; str.msg = "Exceed gift exchange quantity!"; str.status = -4; return(Json(str)); } if (byId.NeedIntegral * count > member.AvailableIntegrals) { flag = false; str.success = false; str.msg = "Lack of points!"; str.status = -6; return(Json(str)); } if (member.HistoryIntegral < byId.GradeIntegral) { flag = false; str.success = false; str.msg = "Lack of Level!"; str.status = -6; return(Json(str)); } ShippingAddressInfo shippingAddress = GetShippingAddress(new long?(regionId)); if (shippingAddress == null) { flag = false; str.success = false; str.msg = "Shipping address error!"; str.status = -6; return(Json(str)); } if (flag) { GiftOrderItemModel giftOrderItemModel = new GiftOrderItemModel() { GiftId = byId.Id, Counts = count }; giftOrderItemModels.Add(giftOrderItemModel); GiftOrderModel giftOrderModel = new GiftOrderModel() { Gifts = giftOrderItemModels, CurrentUser = member, ReceiveAddress = shippingAddress }; GiftOrderInfo giftOrderInfo = orderser.CreateOrder(giftOrderModel); str.success = true; str.msg = giftOrderInfo.Id.ToString(); str.status = 1; } return(Json(str)); }