public abstract bool AddPurchaseOrderGift(string purchaseOrderId, GiftInfo gift, int quantity, System.Data.Common.DbTransaction dbTran);
private void btnCreate_Click(object sender, EventArgs e) { int shippingTemplateId = 0; decimal weight = default(decimal); decimal volume = default(decimal); bool isExemptionPostage = false; decimal?costPrice = default(decimal?); decimal?marketPrice = default(decimal?); int needPoint = default(int); if (this.ValidateValues(out costPrice, out marketPrice, out needPoint, out shippingTemplateId, out weight, out volume, out isExemptionPostage)) { GiftInfo giftInfo = new GiftInfo { CostPrice = costPrice, MarketPrice = marketPrice, NeedPoint = needPoint, Name = Globals.HtmlEncode(this.txtGiftName.Text.Trim()), Unit = this.txtUnit.Text.Trim(), ShortDescription = Globals.HtmlEncode(this.txtShortDescription.Text.Trim()), LongDescription = (string.IsNullOrEmpty(this.fcDescription.Text) ? null : this.fcDescription.Text.Trim()), Title = Globals.HtmlEncode(this.txtGiftTitle.Text.Trim()), Meta_Description = Globals.HtmlEncode(this.txtTitleDescription.Text.Trim()), Meta_Keywords = Globals.HtmlEncode(this.txtTitleKeywords.Text.Trim()), IsPromotion = this.chkPromotion.SelectedValue, IsExemptionPostage = isExemptionPostage, ShippingTemplateId = shippingTemplateId, Weight = weight, Volume = volume, IsPointExchange = this.onoffIsPointExchange.SelectedValue }; ProductImagesInfo productImagesInfo = this.SaveGiftImage(); if (productImagesInfo != null) { giftInfo.ImageUrl = productImagesInfo.ImageUrl1; this.hidOldImages.Value = giftInfo.ImageUrl; giftInfo.ThumbnailUrl40 = productImagesInfo.ThumbnailUrl40; giftInfo.ThumbnailUrl60 = productImagesInfo.ThumbnailUrl60; giftInfo.ThumbnailUrl100 = productImagesInfo.ThumbnailUrl100; giftInfo.ThumbnailUrl160 = productImagesInfo.ThumbnailUrl160; giftInfo.ThumbnailUrl180 = productImagesInfo.ThumbnailUrl180; giftInfo.ThumbnailUrl220 = productImagesInfo.ThumbnailUrl220; giftInfo.ThumbnailUrl310 = productImagesInfo.ThumbnailUrl310; giftInfo.ThumbnailUrl410 = productImagesInfo.ThumbnailUrl410; } else if (this.hidUploadImages.Value.Trim().Length == 0) { this.ShowMsg("必须上传礼品图片", false); return; } ValidationResults validationResults = Validation.Validate(giftInfo, "ValGift"); string text = string.Empty; if (!validationResults.IsValid) { foreach (ValidationResult item in (IEnumerable <ValidationResult>)validationResults) { text += Formatter.FormatErrorMessage(item.Message); } } if (!string.IsNullOrEmpty(text)) { this.ShowMsg(text, false); } else if (GiftHelper.AddGift(giftInfo)) { base.Response.Redirect("Gifts.aspx?flag=1"); } else { this.ShowMsg("已经存在相同的礼品名称", false); } } }
public JsonResult OrderSubmit(long id, long regionId, int count) { Result result = new Result() { success = false, msg = "未知错误", status = 0 }; bool isdataok = true; if (count < 1) { isdataok = false; result.success = false; result.msg = "错误的兑换数量!"; result.status = -8; return(Json(result)); } //Checkout List <GiftOrderItemModel> gorditemlist = new List <GiftOrderItemModel>(); #region 礼品信息判断 //礼品信息 GiftInfo giftdata = _iGiftService.GetById(id); if (giftdata == null) { isdataok = false; result.success = false; result.msg = "礼品不存在!"; result.status = -2; return(Json(result)); } if (giftdata.GetSalesStatus != GiftInfo.GiftSalesStatus.Normal) { isdataok = false; result.success = false; result.msg = "礼品已失效!"; result.status = -2; return(Json(result)); } //库存判断 if (count > giftdata.StockQuantity) { isdataok = false; result.success = false; result.msg = "礼品库存不足,仅剩 " + giftdata.StockQuantity.ToString() + " 件!"; result.status = -3; return(Json(result)); } //积分数 if (giftdata.NeedIntegral < 1) { isdataok = false; result.success = false; result.msg = "礼品关联等级信息有误或礼品积分数据有误!"; result.status = -5; return(Json(result)); } #endregion #region 用户信息判断 //限购数量 if (giftdata.LimtQuantity > 0) { int ownbuynumber = _iGiftsOrderService.GetOwnBuyQuantity(CurrentUser.Id, id); if (ownbuynumber + count > giftdata.LimtQuantity) { isdataok = false; result.success = false; result.msg = "超过礼品限兑数量!"; result.status = -4; return(Json(result)); } } var userInte = MemberIntegralApplication.GetMemberIntegral(CurrentUser.Id); if (giftdata.NeedIntegral * count > userInte.AvailableIntegrals) { isdataok = false; result.success = false; result.msg = "积分不足!"; result.status = -6; return(Json(result)); } if (giftdata.NeedGrade > 0) { //等级判定 if (!MemberGradeApplication.IsAllowGrade(CurrentUser.Id, giftdata.NeedGrade)) { isdataok = false; result.success = false; result.msg = "用户等级不足!"; result.status = -6; return(Json(result)); } } #endregion Entities.ShippingAddressInfo shipdata = GetShippingAddress(regionId); if (shipdata == null) { isdataok = false; result.success = false; result.msg = "错误的收货人地址信息!"; result.status = -6; return(Json(result)); } if (isdataok) { gorditemlist.Add(new GiftOrderItemModel { GiftId = giftdata.Id, Counts = count }); GiftOrderModel createorderinfo = new GiftOrderModel(); createorderinfo.Gifts = gorditemlist; createorderinfo.CurrentUser = CurrentUser; createorderinfo.ReceiveAddress = shipdata; Mall.Entities.GiftOrderInfo orderdata = _iGiftsOrderService.CreateOrder(createorderinfo); result.success = true; result.msg = orderdata.Id.ToString(); result.status = 1; } return(Json(result)); }
public abstract bool UpdateMyGifts(GiftInfo giftInfo);
private void btnCreate_Click(object sender, System.EventArgs e) { decimal?costPrice; decimal?marketPrice; int needPoint; if (!this.ValidateValues(out costPrice, out marketPrice, out needPoint)) { return; } GiftInfo giftInfo = new GiftInfo { CostPrice = costPrice, MarketPrice = marketPrice, NeedPoint = needPoint, Name = Globals.HtmlEncode(this.txtGiftName.Text.Trim()), Unit = this.txtUnit.Text.Trim(), ShortDescription = Globals.HtmlEncode(this.txtShortDescription.Text.Trim()), LongDescription = string.IsNullOrEmpty(this.fcDescription.Text) ? null : this.fcDescription.Text.Trim(), Title = Globals.HtmlEncode(this.txtGiftTitle.Text.Trim()), Meta_Description = Globals.HtmlEncode(this.txtTitleDescription.Text.Trim()), Meta_Keywords = Globals.HtmlEncode(this.txtTitleKeywords.Text.Trim()), IsPromotion = this.chkPromotion.Checked }; giftInfo.ImageUrl = this.uploader1.UploadedImageUrl; giftInfo.ThumbnailUrl40 = this.uploader1.ThumbnailUrl40; giftInfo.ThumbnailUrl60 = this.uploader1.ThumbnailUrl60; giftInfo.ThumbnailUrl100 = this.uploader1.ThumbnailUrl100; giftInfo.ThumbnailUrl160 = this.uploader1.ThumbnailUrl160; giftInfo.ThumbnailUrl180 = this.uploader1.ThumbnailUrl180; giftInfo.ThumbnailUrl220 = this.uploader1.ThumbnailUrl220; giftInfo.ThumbnailUrl310 = this.uploader1.ThumbnailUrl310; giftInfo.ThumbnailUrl410 = this.uploader1.ThumbnailUrl410; ValidationResults validationResults = Validation.Validate <GiftInfo>(giftInfo, new string[] { "ValGift" }); string text = string.Empty; if (!validationResults.IsValid) { foreach (ValidationResult current in (System.Collections.Generic.IEnumerable <ValidationResult>)validationResults) { text += Formatter.FormatErrorMessage(current.Message); } } if (!string.IsNullOrEmpty(text)) { this.ShowMsg(text, false); return; } GiftActionStatus giftActionStatus = GiftHelper.AddGift(giftInfo); if (giftActionStatus == GiftActionStatus.Success) { this.ShowMsg("成功的添加了一件礼品", true); return; } if (giftActionStatus == GiftActionStatus.UnknowError) { this.ShowMsg("未知错误", false); return; } if (giftActionStatus == GiftActionStatus.DuplicateSKU) { this.ShowMsg("已经存在相同的商家编码", false); return; } if (giftActionStatus == GiftActionStatus.DuplicateName) { this.ShowMsg("已经存在相同的礼品名称", false); } }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { //根节点 TreeNode parentNode = catalogTree.RootNode; //获取checked的节点List ArrayList nodeList = new ArrayList(); this.catalogTree.ArrCheckbox(nodeList, parentNode); ArrayList catalogIds = new ArrayList(nodeList.Count); foreach (TreeNode node in nodeList) { catalogIds.Add(new Guid(node.Value)); } if (catalogIds.Count == 0) { this.ShowMessage(this, "没有选择分类,上传失败!"); return; } GiftBiz biz = new GiftBiz(); GiftInfo model = new GiftInfo(); if (ViewState["Id"] != null) { model = biz.GetModel(ViewState["Id"].ToString()); } else { model.Id = biz.GetNewId(); } model.Title = txtTitle.Text.Trim(); model.Quantity = int.Parse(txtQuantity.Text.Trim()); model.Status = 1; model.Remark = txtRemark.Text.Trim(); model.TypeId = ddlGiftType.SelectedValue; if (ViewState["Id"] == null) { //model.ImageId = UploadImage(); model.ImageId = newUploadImage(); if (model.ImageId == null) { return; } biz.AddGift(model); } else { if (fuImage.FileName != string.Empty) { model.ImageId = UploadImage(); if (model.ImageId == null) { return; } } int i = biz.UpdateGift(model); } Resource objResource = new Resource(); objResource.CreateRelationshipResourceAndCatalog(new Guid(model.ImageId), (Guid[])catalogIds.ToArray(typeof(Guid))); //ImageStorageClass imageClass = new ImageStorageClass(); //imageClass.CreateRelationshipImageAndCatalog(new Guid(model.ImageId), (Guid[])catalogIds.ToArray(typeof(Guid))); this.ShowMessage(this, "保存成功!"); Response.Redirect("Gift_List.aspx"); }
public abstract GiftActionStatus CreateUpdateDeleteGift(GiftInfo gift, DataProviderAction action);
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)); }
public static bool DownLoadGift(GiftInfo giftInfo) { return(SubsitePromotionsProvider.Instance().DownLoadGift(giftInfo)); }
public abstract bool AddOrderGift(string orderId, GiftInfo gift, int quantity, int promotype, DbTransaction dbTran);
public abstract bool AddPurchaseOrderGift(string purchaseOrderId, GiftInfo gift, int quantity, DbTransaction dbTran);
/// <summary> /// 提交并处理订单 /// </summary> /// <param name="id"></param> /// <param name="regionId"></param> /// <param name="count"></param> /// <returns></returns> public Result SubmitOrder(GiftConfirmOrder value) { Result result = new Result() { success = false, msg = "未知错误", status = 0 }; bool isdataok = true; long id = value.ID; var regionId = value.RegionId; if (regionId < 1) { result.success = false; result.msg = "错误的收货地址!"; result.status = -8; return(result); } int count = value.Count; if (count < 1) { isdataok = false; result.success = false; result.msg = "错误的兑换数量!"; result.status = -8; return(result); } if (CurrentUser == null) { isdataok = false; result.success = false; result.msg = "用户未登录!"; result.status = -6; return(result); } //Checkout List <GiftOrderItemModel> gorditemlist = new List <GiftOrderItemModel>(); var curUser = _iMemberService.GetMember(CurrentUser.Id); if (curUser == null) { isdataok = false; result.success = false; result.msg = "用户登录错误!"; result.status = -6; return(result); } var userInte = MemberIntegralApplication.GetMemberIntegral(curUser.Id); #region 礼品信息判断 //礼品信息 GiftInfo giftdata = _iGiftService.GetById(id); if (giftdata == null) { isdataok = false; result.success = false; result.msg = "礼品不存在!"; result.status = -2; return(result); } if (giftdata.GetSalesStatus != GiftInfo.GiftSalesStatus.Normal) { isdataok = false; result.success = false; result.msg = "礼品已失效!"; result.status = -2; return(result); } //库存判断 if (count > giftdata.StockQuantity) { isdataok = false; result.success = false; result.msg = "礼品库存不足,仅剩 " + giftdata.StockQuantity.ToString() + " 件!"; result.status = -3; return(result); } //积分数 if (giftdata.NeedIntegral < 1) { isdataok = false; result.success = false; result.msg = "礼品关联等级信息有误或礼品积分数据有误!"; result.status = -5; return(result); } #endregion #region 用户信息判断 //限购数量 if (giftdata.LimtQuantity > 0) { int ownbuynumber = _iGiftsOrderService.GetOwnBuyQuantity(CurrentUser.Id, id); if (ownbuynumber + count > giftdata.LimtQuantity) { isdataok = false; result.success = false; result.msg = "超过礼品限兑数量!"; result.status = -4; return(result); } } if (giftdata.NeedIntegral * count > userInte.AvailableIntegrals) { isdataok = false; result.success = false; result.msg = "积分不足!"; result.status = -6; return(result); } if (giftdata.NeedGrade > 0) { var memgradeid = _iMemberGradeService.GetMemberGradeByUserId(curUser.Id); //等级判定 if (!_iMemberGradeService.IsOneGreaterOrEqualTwo(memgradeid, giftdata.NeedGrade)) { isdataok = false; result.success = false; result.msg = "用户等级不足!"; result.status = -6; return(result); } } #endregion ShippingAddressInfo shipdata = GetShippingAddress(regionId); if (shipdata == null) { isdataok = false; result.success = false; result.msg = "错误的收货人地址信息!"; result.status = -6; return(result); } if (isdataok) { gorditemlist.Add(new GiftOrderItemModel { GiftId = giftdata.Id, Counts = count }); GiftOrderModel createorderinfo = new GiftOrderModel(); createorderinfo.Gifts = gorditemlist; createorderinfo.CurrentUser = curUser; createorderinfo.ReceiveAddress = shipdata; GiftOrderInfo orderdata = _iGiftsOrderService.CreateOrder(createorderinfo); result.success = true; result.msg = orderdata.Id.ToString(); result.status = 1; } return(result); }
public static GiftActionStatus UpdateGift(GiftInfo gift) { Globals.EntityCoding(gift, true); return(new GiftDao().CreateUpdateDeleteGift(gift, DataProviderAction.Update)); }
private void btnUpdate_Click(object sender, System.EventArgs e) { GiftInfo giftDetails = GiftHelper.GetGiftDetails(this.giftId); new System.Text.RegularExpressions.Regex("^(?!_)(?!.*?_$)(?!-)(?!.*?-$)[a-zA-Z0-9_一-龥-]+$"); decimal?costPrice; decimal purchasePrice; decimal?marketPrice; int needPoint; if (!this.ValidateValues(out costPrice, out purchasePrice, out marketPrice, out needPoint)) { return; } giftDetails.PurchasePrice = purchasePrice; giftDetails.CostPrice = costPrice; giftDetails.MarketPrice = marketPrice; giftDetails.NeedPoint = needPoint; giftDetails.Name = Globals.HtmlEncode(this.txtGiftName.Text.Trim()); giftDetails.Unit = this.txtUnit.Text.Trim(); giftDetails.ShortDescription = Globals.HtmlEncode(this.txtShortDescription.Text.Trim()); giftDetails.LongDescription = this.fcDescription.Text.Trim(); giftDetails.Title = Globals.HtmlEncode(this.txtGiftTitle.Text.Trim()); giftDetails.Meta_Description = Globals.HtmlEncode(this.txtTitleDescription.Text.Trim()); giftDetails.Meta_Keywords = Globals.HtmlEncode(this.txtTitleKeywords.Text.Trim()); giftDetails.IsDownLoad = this.chkDownLoad.Checked; giftDetails.IsPromotion = this.chkPromotion.Checked; giftDetails.ImageUrl = this.uploader1.UploadedImageUrl; giftDetails.ThumbnailUrl40 = this.uploader1.ThumbnailUrl40; giftDetails.ThumbnailUrl60 = this.uploader1.ThumbnailUrl60; giftDetails.ThumbnailUrl100 = this.uploader1.ThumbnailUrl100; giftDetails.ThumbnailUrl160 = this.uploader1.ThumbnailUrl160; giftDetails.ThumbnailUrl180 = this.uploader1.ThumbnailUrl180; giftDetails.ThumbnailUrl220 = this.uploader1.ThumbnailUrl220; giftDetails.ThumbnailUrl310 = this.uploader1.ThumbnailUrl310; giftDetails.ThumbnailUrl410 = this.uploader1.ThumbnailUrl410; ValidationResults validationResults = Validation.Validate <GiftInfo>(giftDetails, new string[] { "ValGift" }); string text = string.Empty; if (giftDetails.PurchasePrice < giftDetails.CostPrice) { text += Formatter.FormatErrorMessage("礼品采购价不能小于成本价"); } if (!validationResults.IsValid) { foreach (ValidationResult current in (System.Collections.Generic.IEnumerable <ValidationResult>)validationResults) { text += Formatter.FormatErrorMessage(current.Message); } } if (!string.IsNullOrEmpty(text)) { this.ShowMsg(text, false); return; } GiftActionStatus giftActionStatus = GiftHelper.UpdateGift(giftDetails); GiftActionStatus giftActionStatus2 = giftActionStatus; switch (giftActionStatus2) { case GiftActionStatus.Success: this.ShowMsg("成功修改了一件礼品的基本信息", true); return; case GiftActionStatus.DuplicateName: this.ShowMsg("已经存在相同的礼品名称", false); return; case GiftActionStatus.DuplicateSKU: this.ShowMsg("已经存在相同的商家编码", false); return; default: if (giftActionStatus2 != GiftActionStatus.UnknowError) { return; } this.ShowMsg("未知错误", false); return; } }
public static GiftActionStatus AddGift(GiftInfo gift) { Globals.EntityCoding(gift, true); return(PromotionsProvider.Instance().CreateUpdateDeleteGift(gift, DataProviderAction.Create)); }
public static bool UpdateMyGifts(GiftInfo giftInfo) { return(SubsitePromotionsProvider.Instance().UpdateMyGifts(giftInfo)); }
protected override void AttachChildControls() { if (!int.TryParse(this.Page.Request.QueryString["GiftId"], out this.giftId)) { base.GotoResourceNotFound(""); } this.imgGift = (HiImage)this.FindControl("imgGift"); this.litName = (Literal)this.FindControl("litName"); this.litMarketPrice = (Literal)this.FindControl("litMarketPrice"); this.litNeedPoints = (Literal)this.FindControl("litNeedPoints"); this.litHasPoints = (Literal)this.FindControl("litHasPoints"); this.litMeta_Description = (Literal)this.FindControl("litMeta_Description"); this.hidGiftId = (HtmlInputHidden)this.FindControl("hidGiftId"); this.btnClearCart = (ImageLinkButton)this.FindControl("btnClearCart"); this.btnClearCart.Click += this.btnClearCart_Click; GiftInfo giftDetails = ProductBrowser.GetGiftDetails(this.giftId); if (giftDetails == null) { this.Page.Response.Redirect("ResourceNotFound?errorMsg=" + Globals.UrlEncode("该件礼品已经不再参与积分兑换;或被管理员删除")); } else { this.isExemptionPostage = giftDetails.IsExemptionPostage; this.imgGift.ImageUrl = giftDetails.ImageUrl; this.litName.Text = giftDetails.Name; this.litMarketPrice.Text = Math.Round((!giftDetails.MarketPrice.HasValue) ? decimal.Zero : giftDetails.MarketPrice.Value, 2).ToString(); Literal literal = this.litNeedPoints; int num = giftDetails.NeedPoint; literal.Text = num.ToString(); this.litMeta_Description.Text = giftDetails.LongDescription.ToNullString().Replace("src", "data-url"); this.hidGiftId.Value = this.giftId.ToString(); if (HiContext.Current.UserId != 0 && giftDetails.NeedPoint > 0) { if (HiContext.Current.User.Points < giftDetails.NeedPoint) { this.btnClearCart.Enabled = false; this.btnClearCart.Text = "无法兑换"; } else { this.btnClearCart.Enabled = true; this.btnClearCart.Text = "立即兑换"; } Literal literal2 = this.litHasPoints; num = HiContext.Current.User.Points; literal2.Text = num.ToString(); } else if (giftDetails.NeedPoint <= 0) { this.btnClearCart.Enabled = false; this.btnClearCart.Text = "礼品不允许兑换"; } else { this.btnClearCart.Text = "请登录方能兑换"; } if (!giftDetails.IsPointExchange) { this.btnClearCart.Enabled = false; this.btnClearCart.Text = "该件礼品不再参与积分兑换"; } PageTitle.AddSiteNameTitle("积分商城"); } }
private void btnUpdate_Click(object sender, EventArgs e) { decimal? nullable; decimal num; decimal? nullable2; int num2; GiftInfo giftDetails = GiftHelper.GetGiftDetails(giftId); if (ValidateValues(out nullable, out num, out nullable2, out num2)) { giftDetails.PurchasePrice = num; giftDetails.CostPrice = nullable; giftDetails.MarketPrice = nullable2; giftDetails.NeedPoint = num2; giftDetails.Name = txtGiftName.Text.Trim(); giftDetails.Unit = txtUnit.Text.Trim(); giftDetails.ShortDescription = txtShortDescription.Text.Trim(); giftDetails.LongDescription = fcDescription.Text.Trim(); giftDetails.Title = txtGiftTitle.Text.Trim(); giftDetails.Meta_Description = txtTitleDescription.Text.Trim(); giftDetails.Meta_Keywords = txtTitleKeywords.Text.Trim(); giftDetails.IsDownLoad = ckdown.Checked; giftDetails.ImageUrl = uploader1.UploadedImageUrl; giftDetails.ThumbnailUrl40 = uploader1.ThumbnailUrl40; giftDetails.ThumbnailUrl60 = uploader1.ThumbnailUrl60; giftDetails.ThumbnailUrl100 = uploader1.ThumbnailUrl100; giftDetails.ThumbnailUrl160 = uploader1.ThumbnailUrl160; giftDetails.ThumbnailUrl180 = uploader1.ThumbnailUrl180; giftDetails.ThumbnailUrl220 = uploader1.ThumbnailUrl220; giftDetails.ThumbnailUrl310 = uploader1.ThumbnailUrl310; giftDetails.ThumbnailUrl410 = uploader1.ThumbnailUrl410; ValidationResults results = Hishop.Components.Validation.Validation.Validate <GiftInfo>(giftDetails, new string[] { "ValGift" }); string str = string.Empty; if (giftDetails.PurchasePrice < giftDetails.CostPrice) { str = str + Formatter.FormatErrorMessage("礼品采购价不能小于成本价"); } if (!results.IsValid) { foreach (ValidationResult result in (IEnumerable <ValidationResult>)results) { str = str + Formatter.FormatErrorMessage(result.Message); } } if (!string.IsNullOrEmpty(str)) { ShowMsg(str, false); } else { switch (GiftHelper.UpdateGift(giftDetails)) { case GiftActionStatus.Success: ShowMsg("成功修改了一件礼品的基本信息", true); return; case GiftActionStatus.DuplicateName: ShowMsg("已经存在相同的礼品名称", false); return; case GiftActionStatus.DuplicateSKU: ShowMsg("已经存在相同的商家编码", false); return; case GiftActionStatus.UnknowError: ShowMsg("未知错误", false); return; } } } }
/// <summary> /// 创建订单 /// </summary> /// <param name="model"></param> /// <returns></returns> public GiftOrderInfo CreateOrder(GiftOrderModel model) { if (model.CurrentUser == null) { throw new MallException("错误的用户信息"); } if (model.ReceiveAddress == null) { throw new MallException("错误的收货人信息"); } GiftOrderInfo result = new GiftOrderInfo() { Id = GenerateOrderNumber(), UserId = model.CurrentUser.Id, RegionId = model.ReceiveAddress.RegionId, ShipTo = model.ReceiveAddress.ShipTo, Address = model.ReceiveAddress.Address + " " + model.ReceiveAddress.AddressDetail, RegionFullName = model.ReceiveAddress.RegionFullName, CellPhone = model.ReceiveAddress.Phone, TopRegionId = int.Parse(model.ReceiveAddress.RegionIdPath.Split(',')[0]), UserRemark = model.UserRemark, }; var giftOrderItemInfo = new List <GiftOrderItemInfo>(); DbFactory.Default .InTransaction(() => { //礼品信息处理,库存判断并减库存 foreach (var item in model.Gifts) { if (item.Counts < 1) { throw new MallException("错误的兑换数量!"); } GiftInfo giftdata = DbFactory.Default.Get <GiftInfo>().Where(d => d.Id == item.GiftId).FirstOrDefault(); if (giftdata != null && giftdata.GetSalesStatus == GiftInfo.GiftSalesStatus.Normal) { if (giftdata.StockQuantity >= item.Counts) { giftdata.StockQuantity = giftdata.StockQuantity - item.Counts; //先减库存 giftdata.RealSales += item.Counts; //加销量 GiftOrderItemInfo gorditem = new GiftOrderItemInfo() { GiftId = giftdata.Id, GiftName = giftdata.GiftName, GiftValue = giftdata.GiftValue, ImagePath = giftdata.ImagePath, OrderId = result.Id, Quantity = item.Counts, SaleIntegral = giftdata.NeedIntegral }; giftOrderItemInfo.Add(gorditem); DbFactory.Default.Update(giftdata); } else { throw new MallException("礼品库存不足!"); } } else { throw new MallException("礼品不存在或已失效!"); } } //建立订单 result.TotalIntegral = giftOrderItemInfo.Sum(d => d.Quantity * d.SaleIntegral); result.OrderStatus = GiftOrderInfo.GiftOrderStatus.WaitDelivery; result.OrderDate = DateTime.Now; DbFactory.Default.Add(result); DbFactory.Default.AddRange(giftOrderItemInfo); //减少积分 var userdata = DbFactory.Default.Get <MemberInfo>().Where(d => d.Id == model.CurrentUser.Id).FirstOrDefault(); DeductionIntegral(userdata, result.Id, (int)result.TotalIntegral); }); return(result); }
public JsonResult CanBuy(long id, int count) { Result result = new Result(); bool flag = true; if (base.CurrentUser == null) { flag = false; result.success = false; result.msg = "您还未登录!"; result.status = -1; return(Json(result)); } UserMemberInfo member = ServiceHelper.Create <IMemberService>().GetMember(base.CurrentUser.Id); GiftInfo byId = giftser.GetById(id); if (flag && byId == null) { flag = false; result.success = false; result.msg = "礼品不存在!"; result.status = -2; } if (flag && byId.GetSalesStatus != GiftInfo.GiftSalesStatus.Normal) { flag = false; result.success = false; result.msg = "礼品己失效!"; result.status = -2; } if (flag && count > byId.StockQuantity) { flag = false; result.success = false; int stockQuantity = byId.StockQuantity; result.msg = string.Concat("礼品库存不足,仅剩 ", stockQuantity.ToString(), " 件!"); result.status = -3; } if (flag && byId.NeedIntegral < 1) { flag = false; result.success = false; result.msg = "礼品关联等级信息有误或礼品积分数据有误!"; result.status = -5; return(Json(result)); } if (flag && byId.LimtQuantity > 0 && orderser.GetOwnBuyQuantity(base.CurrentUser.Id, id) + count > byId.LimtQuantity) { flag = false; result.success = false; result.msg = "超过礼品限兑数量!"; result.status = -4; } if (flag && byId.NeedIntegral * count > member.AvailableIntegrals) { flag = false; result.success = false; result.msg = "积分不足!"; result.status = -6; } if (flag && member.HistoryIntegral < byId.GradeIntegral) { flag = false; result.success = false; result.msg = "用户等级不足!"; result.status = -6; } if (flag) { result.success = true; result.msg = "可以购买!"; result.status = 1; } return(Json(result)); }
public abstract bool DownLoadGift(GiftInfo giftinfo);
protected override void AttachChildControls() { if (!int.TryParse(this.Page.Request.QueryString["giftId"], out this.giftId)) { base.GotoResourceNotFound(); } this.litGiftTite = (System.Web.UI.WebControls.Literal) this.FindControl("litGiftTite"); this.litGiftName = (System.Web.UI.WebControls.Literal) this.FindControl("litGiftName"); this.lblMarkerPrice = (FormatedMoneyLabel)this.FindControl("lblMarkerPrice"); this.litNeedPoint = (System.Web.UI.WebControls.Label) this.FindControl("litNeedPoint"); this.litCurrentPoint = (System.Web.UI.WebControls.Label) this.FindControl("litCurrentPoint"); this.litShortDescription = (System.Web.UI.WebControls.Literal) this.FindControl("litShortDescription"); this.litDescription = (System.Web.UI.WebControls.Literal) this.FindControl("litDescription"); this.imgGiftImage = (HiImage)this.FindControl("imgGiftImage"); this.btnChage = (System.Web.UI.WebControls.Button) this.FindControl("btnChage"); this.btnChage.Click += new System.EventHandler(this.btnChage_Click); GiftInfo gift = ProductBrowser.GetGift(this.giftId); if (gift == null) { this.Page.Response.Redirect(Globals.ApplicationPath + "/ResourceNotFound.aspx?errorMsg=" + Globals.UrlEncode("该件礼品已经不再参与积分兑换;或被管理员删除")); } else { if (!this.Page.IsPostBack) { this.litGiftName.Text = gift.Name; this.lblMarkerPrice.Money = gift.MarketPrice; this.litNeedPoint.Text = gift.NeedPoint.ToString(); this.litShortDescription.Text = gift.ShortDescription; this.litDescription.Text = gift.LongDescription; this.imgGiftImage.ImageUrl = gift.ThumbnailUrl310; this.LoadPageSearch(gift); } bool arg_209_0; if (Hidistro.Membership.Context.HiContext.Current.User.UserRole != Hidistro.Membership.Core.Enums.UserRole.Member) { if (Hidistro.Membership.Context.HiContext.Current.User.UserRole != Hidistro.Membership.Core.Enums.UserRole.Underling) { arg_209_0 = true; goto IL_209; } } arg_209_0 = (gift.NeedPoint <= 0); IL_209: if (!arg_209_0) { this.btnChage.Enabled = true; this.btnChage.Text = "立即兑换"; this.litCurrentPoint.Text = ((Hidistro.Membership.Context.Member)Hidistro.Membership.Context.HiContext.Current.User).Points.ToString(); } else { if (gift.NeedPoint <= 0) { this.btnChage.Enabled = false; this.btnChage.Text = "礼品不允许兑换"; } else { this.btnChage.Enabled = false; this.btnChage.Text = "请登录方能兑换"; this.litCurrentPoint.Text = string.Format("<a href=\"{0}\">请登录</a>", Globals.ApplicationPath + "/Login.aspx"); } } } }
public static bool AddOrderGift(OrderInfo order, GiftInfo giftinfo, int quantity, int promotype) { ManagerHelper.CheckPrivilege(Privilege.EditOrders); Database database = DatabaseFactory.CreateDatabase(); bool result; bool flag2; using (System.Data.Common.DbConnection dbConnection = database.CreateConnection()) { dbConnection.Open(); System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction(); try { SalesProvider salesProvider = SalesProvider.Instance(); OrderGiftInfo orderGiftInfo = new OrderGiftInfo(); orderGiftInfo.OrderId = order.OrderId; orderGiftInfo.Quantity = quantity; orderGiftInfo.GiftName = giftinfo.Name; decimal arg_5C_0 = orderGiftInfo.CostPrice; orderGiftInfo.CostPrice = Convert.ToDecimal(giftinfo.CostPrice); orderGiftInfo.GiftId = giftinfo.GiftId; orderGiftInfo.ThumbnailsUrl = giftinfo.ThumbnailUrl40; orderGiftInfo.PromoteType = promotype; bool flag = false; foreach (OrderGiftInfo current in order.Gifts) { if (giftinfo.GiftId == current.GiftId) { flag = true; current.Quantity = quantity; current.PromoteType = promotype; break; } } if (!flag) { order.Gifts.Add(orderGiftInfo); } if (!salesProvider.AddOrderGift(order.OrderId, orderGiftInfo, quantity, dbTransaction)) { dbTransaction.Rollback(); result = false; return(result); } if (!salesProvider.UpdateOrderAmount(order, dbTransaction)) { dbTransaction.Rollback(); result = false; return(result); } dbTransaction.Commit(); flag2 = true; } catch { dbTransaction.Rollback(); flag2 = false; } finally { dbConnection.Close(); } } if (flag2) { EventLogs.WriteOperationLog(Privilege.EditOrders, string.Format(CultureInfo.InvariantCulture, "成功的为订单号为\"{0}\"的订单添加了礼品", new object[] { order.OrderId })); } result = flag2; return(result); }
public static bool ManageWinningResult(int UserId, ActivityInfo Info, int AwardGrade, ref int FreeTimes) { lock (ActivityHelper.oWinning) { Database database = DatabaseFactory.CreateDatabase(); ActivityDao activityDao = new ActivityDao(); using (DbConnection dbConnection = database.CreateConnection()) { dbConnection.Open(); DbTransaction dbTransaction = dbConnection.BeginTransaction(); try { bool flag = false; bool flag2 = false; ActivityJoinStatisticsInfo activityJoinStatisticsInfo = activityDao.GetCurrUserActivityStatisticsInfo(UserId, Info.ActivityId, dbTransaction); MemberInfo memberInfo = new MemberDao().Get <MemberInfo>(UserId); if (activityJoinStatisticsInfo != null) { if (Info.ResetType == 2) { DateTime lastJoinDate = activityJoinStatisticsInfo.LastJoinDate; if (DateTime.Now.Date == lastJoinDate.Date) { if (activityJoinStatisticsInfo.FreeNum < Info.FreeTimes) { flag = true; activityJoinStatisticsInfo.FreeNum++; FreeTimes = Info.FreeTimes - activityJoinStatisticsInfo.FreeNum; } else { activityJoinStatisticsInfo.IntegralTotal += Info.ConsumptionIntegral; activityJoinStatisticsInfo.IntegralNum++; FreeTimes = 0; } } else { flag = true; activityJoinStatisticsInfo.FreeNum = 1; FreeTimes = Info.FreeTimes - 1; } } else if (activityJoinStatisticsInfo.FreeNum < Info.FreeTimes) { flag = true; activityJoinStatisticsInfo.FreeNum++; FreeTimes = Info.FreeTimes - activityJoinStatisticsInfo.FreeNum; } else { activityJoinStatisticsInfo.IntegralTotal += Info.ConsumptionIntegral; activityJoinStatisticsInfo.IntegralNum++; FreeTimes = 0; } } else { flag2 = true; activityJoinStatisticsInfo = new ActivityJoinStatisticsInfo(); activityJoinStatisticsInfo.ActivityId = Info.ActivityId; activityJoinStatisticsInfo.UserId = UserId; if (Info.FreeTimes > 0) { flag = true; activityJoinStatisticsInfo.FreeNum = 1; activityJoinStatisticsInfo.IntegralTotal = 0; activityJoinStatisticsInfo.IntegralNum = 0; FreeTimes = Info.FreeTimes - 1; } else { activityJoinStatisticsInfo.IntegralTotal = Info.ConsumptionIntegral; activityJoinStatisticsInfo.IntegralNum = 1; activityJoinStatisticsInfo.FreeNum = 0; FreeTimes = 0; } } activityJoinStatisticsInfo.JoinNum++; activityJoinStatisticsInfo.LastJoinDate = DateTime.Now; bool flag3 = false; CouponInfo couponInfo = null; GiftInfo giftInfo = null; ActivityAwardItemInfo activityAwardItemInfo = null; if (AwardGrade > 0) { activityAwardItemInfo = activityDao.GetActivityItem(Info.ActivityId, AwardGrade, dbTransaction); if (activityAwardItemInfo.WinningNum < activityAwardItemInfo.AwardNum) { if (activityAwardItemInfo.PrizeType == 2) { couponInfo = new CouponDao().Get <CouponInfo>(activityAwardItemInfo.PrizeValue); if (couponInfo != null) { int couponSurplus = new CouponDao().GetCouponSurplus(activityAwardItemInfo.PrizeValue); if (couponSurplus > 0 && couponInfo.ClosingTime > DateTime.Now) { flag3 = true; } } } else if (activityAwardItemInfo.PrizeType == 3) { giftInfo = new GiftDao().Get <GiftInfo>(activityAwardItemInfo.PrizeValue); if (giftInfo != null) { flag3 = true; } } else { flag3 = true; } } } else { flag3 = false; } if (!flag) { PointDetailInfo pointDetailInfo = new PointDetailInfo(); pointDetailInfo.Increased = 0; pointDetailInfo.OrderId = ""; pointDetailInfo.Points = memberInfo.Points - Info.ConsumptionIntegral; pointDetailInfo.Reduced = Info.ConsumptionIntegral; pointDetailInfo.Remark = "抽奖消耗积分"; pointDetailInfo.SignInSource = 0; pointDetailInfo.TradeDate = DateTime.Now; if (Info.ActivityType == 1) { pointDetailInfo.TradeType = PointTradeType.JoinRotaryTable; } else if (Info.ActivityType == 3) { pointDetailInfo.TradeType = PointTradeType.JoinSmashingGoldenEgg; } else { pointDetailInfo.TradeType = PointTradeType.JoinScratchCard; } pointDetailInfo.UserId = UserId; if (new PointDetailDao().Add(pointDetailInfo, dbTransaction) <= 0) { dbTransaction.Rollback(); return(false); } } if (!flag3) { if (flag2) { if (activityDao.Add(activityJoinStatisticsInfo, dbTransaction) <= 0) { dbTransaction.Rollback(); } } else if (!activityDao.UpdateActivityStatisticsInfo(activityJoinStatisticsInfo, dbTransaction)) { dbTransaction.Rollback(); } dbTransaction.Commit(); return(false); } activityJoinStatisticsInfo.WinningNum++; if (flag2) { if (activityDao.Add(activityJoinStatisticsInfo, dbTransaction) <= 0) { dbTransaction.Rollback(); } } else if (!activityDao.UpdateActivityStatisticsInfo(activityJoinStatisticsInfo, dbTransaction)) { dbTransaction.Rollback(); } activityAwardItemInfo.WinningNum++; if (!activityDao.Update(activityAwardItemInfo, dbTransaction)) { dbTransaction.Rollback(); return(false); } UserAwardRecordsInfo userAwardRecordsInfo = new UserAwardRecordsInfo(); userAwardRecordsInfo.ActivityId = Info.ActivityId; if (activityAwardItemInfo.PrizeType == 2) { userAwardRecordsInfo.AwardName = couponInfo.CouponName; userAwardRecordsInfo.AwardDate = DateTime.Now; userAwardRecordsInfo.Status = 2; CouponItemInfo couponItemInfo = new CouponItemInfo(); couponItemInfo.UserId = UserId; couponItemInfo.UserName = memberInfo.UserName; couponItemInfo.CanUseProducts = couponInfo.CanUseProducts; couponItemInfo.ClosingTime = couponInfo.ClosingTime; couponItemInfo.CouponId = couponInfo.CouponId; couponItemInfo.CouponName = couponInfo.CouponName; couponItemInfo.OrderUseLimit = couponInfo.OrderUseLimit; couponItemInfo.Price = couponInfo.Price; couponItemInfo.StartTime = couponInfo.StartTime; couponItemInfo.UseWithGroup = couponInfo.UseWithGroup; couponItemInfo.UseWithPanicBuying = couponInfo.UseWithPanicBuying; couponItemInfo.UseWithFireGroup = couponInfo.UseWithFireGroup; couponItemInfo.GetDate = DateTime.Now; couponItemInfo.ClaimCode = Guid.NewGuid().ToString(); if (new CouponDao().Add(couponItemInfo, dbTransaction) <= 0) { dbTransaction.Rollback(); return(false); } } else if (activityAwardItemInfo.PrizeType == 3) { userAwardRecordsInfo.AwardDate = null; userAwardRecordsInfo.AwardName = giftInfo.Name; userAwardRecordsInfo.AwardPic = giftInfo.ThumbnailUrl160; userAwardRecordsInfo.Status = 1; } else { userAwardRecordsInfo.AwardName = activityAwardItemInfo.PrizeValue + "积分"; userAwardRecordsInfo.AwardDate = DateTime.Now; userAwardRecordsInfo.Status = 2; PointDetailInfo pointDetailInfo2 = new PointDetailInfo(); pointDetailInfo2.Increased = activityAwardItemInfo.PrizeValue; pointDetailInfo2.OrderId = ""; if (flag) { pointDetailInfo2.Points = memberInfo.Points + activityAwardItemInfo.PrizeValue; } else { pointDetailInfo2.Points = memberInfo.Points - Info.ConsumptionIntegral + activityAwardItemInfo.PrizeValue; } pointDetailInfo2.Reduced = 0; pointDetailInfo2.Remark = "抽奖获得积分"; pointDetailInfo2.SignInSource = 0; pointDetailInfo2.TradeDate = DateTime.Now; if (Info.ActivityType == 1) { pointDetailInfo2.TradeType = PointTradeType.JoinRotaryTable; } else if (Info.ActivityType == 3) { pointDetailInfo2.TradeType = PointTradeType.JoinSmashingGoldenEgg; } else { pointDetailInfo2.TradeType = PointTradeType.JoinScratchCard; } pointDetailInfo2.UserId = UserId; if (new PointDetailDao().Add(pointDetailInfo2, dbTransaction) <= 0) { dbTransaction.Rollback(); return(false); } } userAwardRecordsInfo.AwardGrade = AwardGrade; userAwardRecordsInfo.AwardId = activityAwardItemInfo.AwardId; userAwardRecordsInfo.CreateDate = DateTime.Now; userAwardRecordsInfo.PrizeType = activityAwardItemInfo.PrizeType; userAwardRecordsInfo.PrizeValue = activityAwardItemInfo.PrizeValue; userAwardRecordsInfo.UserId = UserId; if (activityDao.Add(userAwardRecordsInfo, dbTransaction) <= 0) { dbTransaction.Rollback(); return(false); } dbTransaction.Commit(); return(true); } catch (Exception ex) { dbTransaction.Rollback(); Globals.WriteLog("ActivityLog.txt", "Methed:ManageWinningResult , Id:" + Info.ActivityId + " , Msg:" + ex.Message); return(false); } finally { dbConnection.Close(); } } } }
public JsonResult Edit(GiftViewModel model) { var result = new AjaxReturnData { success = false, msg = "未知错误" }; if (ModelState.IsValid) { GiftViewModel postdata = new GiftViewModel(); if (model.Id > 0) { GiftInfo dbdata = _iGiftService.GetByIdAsNoTracking(model.Id); //数据补充 if (dbdata == null) { result.success = false; result.msg = "编号有误"; return(Json(result)); } postdata = dbdata.Map <GiftViewModel>(); } else { if (model.StockQuantity < 1) { result.success = false; result.msg = "库存必须大于0"; return(Json(result)); } } // UpdateModel(postdata); GiftInfo data = new GiftInfo(); data = postdata.Map <GiftInfo>(); if (model.Id > 0) { _iGiftService.UpdateGift(data); } else { data.Sequence = 100; data.AddDate = DateTime.Now; data.SalesStatus = GiftInfo.GiftSalesStatus.Normal; _iGiftService.AddGift(data); } #region 转移图片 int index = 1; List <string> piclist = new List <string>(); piclist.Add(model.PicUrl1); piclist.Add(model.PicUrl2); piclist.Add(model.PicUrl3); piclist.Add(model.PicUrl4); piclist.Add(model.PicUrl5); string path = data.ImagePath; foreach (var item in piclist) { if (!string.IsNullOrWhiteSpace(item)) { string source = string.Empty; if (item.IndexOf("temp/") > 0) { source = item.Substring(item.LastIndexOf("/temp")); } else if (item.Contains(data.ImagePath)) { source = item.Substring(item.LastIndexOf(data.ImagePath)); } try { string dest = string.Format("{0}/{1}.png", path, index); if (source == dest) { index++; continue; } if (!string.IsNullOrWhiteSpace(source)) { Core.MallIO.CopyFile(source, dest, true); } var imageSizes = EnumHelper.ToDictionary <ImageSize>().Select(t => t.Key); foreach (var imageSize in imageSizes) { string size = string.Format("{0}/{1}_{2}.png", path, index, imageSize); Core.MallIO.CreateThumbnail(dest, size, imageSize, imageSize); } //using (Image image = Image.FromFile(source)) //{ // image.Save(dest, System.Drawing.Imaging.ImageFormat.Png); // var imageSizes = EnumHelper.ToDictionary<GiftInfo.ImageSize>().Select(t => t.Key); // foreach (var imageSize in imageSizes) // { // string size = string.Format("{0}/{1}_{2}.png", path, index, imageSize); // ImageHelper.CreateThumbnail(dest, size, imageSize, imageSize); // } //} index++; } catch (FileNotFoundException fex) { index++; Core.Log.Error("发布礼品时候,没有找到文件", fex); } catch (System.Runtime.InteropServices.ExternalException eex) { index++; Core.Log.Error("发布礼品时候,ExternalException异常", eex); } catch (Exception ex) { index++; Core.Log.Error("发布礼品时候,Exception异常", ex); } } else { string dest = string.Format("{0}/{1}.png", path, index); if (MallIO.ExistFile(dest)) { MallIO.DeleteFile(dest); } var imageSizes = EnumHelper.ToDictionary <ImageSize>().Select(t => t.Key); foreach (var imageSize in imageSizes) { string size = string.Format("{0}/{1}_{2}.png", path, index, imageSize); if (MallIO.ExistFile(size)) { MallIO.DeleteFile(size); } } index++; } } #endregion result.success = true; result.msg = "操作成功"; } else { result.success = false; result.msg = "数据有误"; } return(Json(result)); }
public GiftOrderInfo CreateOrder(GiftOrderModel model) { if (model.CurrentUser == null) { throw new HimallException("错误的用户信息"); } if (model.ReceiveAddress == null) { throw new HimallException("错误的收货人信息"); } GiftOrderInfo giftOrderInfo = new GiftOrderInfo() { Id = GenerateOrderNumber(), UserId = model.CurrentUser.Id, RegionId = new int?(model.ReceiveAddress.RegionId), ShipTo = model.ReceiveAddress.ShipTo, Address = model.ReceiveAddress.Address, RegionFullName = model.ReceiveAddress.RegionFullName, CellPhone = model.ReceiveAddress.Phone }; string regionIdPath = model.ReceiveAddress.RegionIdPath; char[] chrArray = new char[] { ',' }; giftOrderInfo.TopRegionId = new int?(int.Parse(regionIdPath.Split(chrArray)[0])); giftOrderInfo.UserRemark = model.UserRemark; GiftOrderInfo now = giftOrderInfo; using (TransactionScope transactionScope = new TransactionScope()) { foreach (GiftOrderItemModel gift in model.Gifts) { if (gift.Counts < 1) { throw new HimallException("错误的兑换数量!"); } GiftInfo stockQuantity = context.GiftInfo.FirstOrDefault((GiftInfo d) => d.Id == gift.GiftId); if (stockQuantity == null || stockQuantity.GetSalesStatus != GiftInfo.GiftSalesStatus.Normal) { throw new HimallException("礼品不存在或己失效!"); } if (stockQuantity.StockQuantity < gift.Counts) { throw new HimallException("礼品库存不足!"); } stockQuantity.StockQuantity = stockQuantity.StockQuantity - gift.Counts; GiftInfo realSales = stockQuantity; realSales.RealSales = realSales.RealSales + gift.Counts; GiftOrderItemInfo giftOrderItemInfo = new GiftOrderItemInfo() { GiftId = stockQuantity.Id, GiftName = stockQuantity.GiftName, GiftValue = stockQuantity.GiftValue, ImagePath = stockQuantity.ImagePath, OrderId = new long?(now.Id), Quantity = gift.Counts, SaleIntegral = new int?(stockQuantity.NeedIntegral) }; now.ChemCloud_GiftOrderItem.Add(giftOrderItemInfo); } now.TotalIntegral = now.ChemCloud_GiftOrderItem.Sum <GiftOrderItemInfo>((GiftOrderItemInfo d) => { int quantity = d.Quantity; int?saleIntegral = d.SaleIntegral; if (!saleIntegral.HasValue) { return(null); } return(new int?(quantity * saleIntegral.GetValueOrDefault())); }); now.OrderStatus = GiftOrderInfo.GiftOrderStatus.WaitDelivery; now.OrderDate = DateTime.Now; context.GiftOrderInfo.Add(now); context.SaveChanges(); UserMemberInfo userMemberInfo = context.UserMemberInfo.FirstOrDefault((UserMemberInfo d) => d.Id == model.CurrentUser.Id); DeductionIntegral(userMemberInfo, now.Id, now.TotalIntegral.Value); transactionScope.Complete(); } return(now); }
public JsonResult CanBuy(long id, int count) { Result result = new Result(); bool isdataok = true; if (CurrentUser == null) { isdataok = false; result.success = false; result.msg = "您还未登录!"; result.status = -1; return(Json(result)); } #region 礼品信息判断 //礼品信息 GiftInfo giftdata = _iGiftService.GetById(id); if (isdataok) { if (giftdata == null) { isdataok = false; result.success = false; result.msg = "礼品不存在!"; result.status = -2; } } if (isdataok) { if (giftdata.GetSalesStatus != GiftInfo.GiftSalesStatus.Normal) { isdataok = false; result.success = false; result.msg = "礼品已失效!"; result.status = -2; } } if (isdataok) { //库存判断 if (count > giftdata.StockQuantity) { isdataok = false; result.success = false; result.msg = "礼品库存不足,仅剩 " + giftdata.StockQuantity.ToString() + " 件!"; result.status = -3; } } if (isdataok) { //积分数 if (giftdata.NeedIntegral < 1) { isdataok = false; result.success = false; result.msg = "礼品关联等级信息有误或礼品积分数据有误!"; result.status = -5; return(Json(result)); } } #endregion #region 用户信息判断 if (isdataok) { //限购数量 if (giftdata.LimtQuantity > 0) { int ownbuynumber = _iGiftsOrderService.GetOwnBuyQuantity(CurrentUser.Id, id); if (ownbuynumber + count > giftdata.LimtQuantity) { isdataok = false; result.success = false; result.msg = "超过礼品限兑数量!"; result.status = -4; } } } if (isdataok) { var userInte = MemberIntegralApplication.GetMemberIntegral(CurrentUser.Id); if (giftdata.NeedIntegral * count > userInte.AvailableIntegrals) { isdataok = false; result.success = false; result.msg = "积分不足!"; result.status = -6; } } if (isdataok && giftdata.NeedGrade > 0) { //等级判定 if (!MemberGradeApplication.IsAllowGrade(CurrentUser.Id, giftdata.NeedGrade)) { isdataok = false; result.success = false; result.msg = "用户等级不足!"; result.status = -6; } } #endregion if (isdataok) { result.success = true; result.msg = "可以购买!"; result.status = 1; } return(Json(result)); }
/// <summary> /// 生成订单,并指定订单状态 /// </summary> private string CreateOrder(int orderState) { OrdersBiz biz = new OrdersBiz(); OrderInfo orderModel = new OrderInfo(); GiftBiz giftBiz = new GiftBiz(); //添加订单信息 orderModel.OrderId = biz.GetNewOrderId(); orderModel.UserId = CurrentUser.UserId.ToString(); orderModel.Operator = CurrentUser.OperatorId.ToString(); orderModel.State = orderState; orderModel.Address = address.Text; orderModel.Contactor = Contactor.Text; orderModel.Tel = Tel.Text; orderModel.Email = Email.Text; Orders_DetailInfo[] details = new Orders_DetailInfo[gvShoppingCartList.Rows.Count]; GiftInfo[] giftInfoList = new GiftInfo[gvShoppingCartList.Rows.Count]; int i = 0; //添加订单明细,先检查数量是否足够 foreach (GridViewRow row in gvShoppingCartList.Rows) { Label lblGiftId = row.FindControl("lblGiftId") as Label; TextBox txtCount = row.FindControl("txtCount") as TextBox; TextBox txtUsage = row.FindControl("txtUsage") as TextBox; Orders_DetailInfo detailModel = new Orders_DetailInfo(); detailModel.OrderId = orderModel.OrderId; detailModel.GiftId = lblGiftId.Text; detailModel.GiftCount = int.Parse(txtCount.Text); detailModel.Usage = txtUsage.Text; GiftInfo giftModel = giftBiz.GetModel(detailModel.GiftId); if (giftModel.Quantity < detailModel.GiftCount) { lErrorInfo.Text = "礼品【" + giftModel.Title + "】数量不足,剩余数量为:" + giftModel.Quantity.ToString() + "!"; return(string.Empty); } giftInfoList[i] = giftModel; details[i] = detailModel; i++; } //遍历更新 for (i = 0; i < details.Length; i++) { biz.AddOrders_Detail(details[i]); giftInfoList[i].Quantity -= details[i].GiftCount; giftBiz.UpdateGift(giftInfoList[i]); } biz.AddOrders(orderModel); //清除购物车 HttpCookie cookie = Request.Cookies["ShoppingCart"]; cookie.Expires = DateTime.Now.AddHours(-2); Response.Cookies.Add(cookie); return(orderModel.OrderId); }
/// <summary> /// 创建预约单 /// </summary> /// <param name="model"></param> /// <returns></returns> public GiftOrderInfo CreateOrder(GiftOrderModel model) { if (model.CurrentUser == null) { throw new HimallException("错误的用户信息"); } if (model.ReceiveAddress == null) { throw new HimallException("错误的收货人信息"); } GiftOrderInfo result = new GiftOrderInfo() { Id = GenerateOrderNumber(), UserId = model.CurrentUser.Id, RegionId = model.ReceiveAddress.RegionId, ShipTo = model.ReceiveAddress.ShipTo, Address = model.ReceiveAddress.Address, RegionFullName = model.ReceiveAddress.RegionFullName, CellPhone = model.ReceiveAddress.Phone, TopRegionId = int.Parse(model.ReceiveAddress.RegionIdPath.Split(',')[0]), UserRemark = model.UserRemark }; using (TransactionScope scope = new TransactionScope()) { //礼品信息处理,库存判断并减库存 foreach (var item in model.Gifts) { if (item.Counts < 1) { throw new HimallException("错误的兑换数量!"); } GiftInfo giftdata = Context.GiftInfo.FirstOrDefault(d => d.Id == item.GiftId); if (giftdata != null && giftdata.GetSalesStatus == GiftInfo.GiftSalesStatus.Normal) { if (giftdata.StockQuantity >= item.Counts) { giftdata.StockQuantity = giftdata.StockQuantity - item.Counts; //先减库存 giftdata.RealSales += item.Counts; //加销量 GiftOrderItemInfo gorditem = new GiftOrderItemInfo() { GiftId = giftdata.Id, GiftName = giftdata.GiftName, GiftValue = giftdata.GiftValue, ImagePath = giftdata.ImagePath, OrderId = result.Id, Quantity = item.Counts, SaleIntegral = giftdata.NeedIntegral }; result.Himall_GiftOrderItem.Add(gorditem); } else { throw new HimallException("礼品库存不足!"); } } else { throw new HimallException("礼品不存在或已失效!"); } } //建立预约单 result.TotalIntegral = result.Himall_GiftOrderItem.Sum(d => d.Quantity * d.SaleIntegral); result.OrderStatus = GiftOrderInfo.GiftOrderStatus.WaitDelivery; result.OrderDate = DateTime.Now; Context.GiftOrderInfo.Add(result); Context.SaveChanges(); //减少积分 var userdata = Context.UserMemberInfo.FirstOrDefault(d => d.Id == model.CurrentUser.Id); DeductionIntegral(userdata, result.Id, (int)result.TotalIntegral); scope.Complete(); } return(result); }
public abstract bool AddOrderGift(string orderId, GiftInfo gift, int quantity, int promotype, System.Data.Common.DbTransaction dbTran);