public ActionResult AddOrEditUserReceiveAddress(int addressId, string consignee, string mobile, string tel, int countyID, string address, int isDefault) { if (string.IsNullOrWhiteSpace(consignee)) { return this.Json(new AjaxResponse(0, "收货人地址不正确")); } if (!string.IsNullOrWhiteSpace(mobile) && !CustomValidator.IsMobile(mobile)) { return this.Json(new AjaxResponse(0, "收货人手机号码不正确")); } if (!string.IsNullOrWhiteSpace(tel) && !CustomValidator.IsPhone(tel)) { return this.Json( new AjaxResponse(0, "收货人电话号码不正确")); } if (string.IsNullOrWhiteSpace(mobile) && string.IsNullOrWhiteSpace(tel)) { return this.Json(new AjaxResponse(0,"收货人电话号码和手机号码不能都为空")); } if (countyID < 1) { return this.Json(new AjaxResponse(0, "收货人省市区地址不正确")); } if (string.IsNullOrWhiteSpace(address)) { return this.Json(new AjaxResponse(0, "收货人详细地址信息不能为空")); } var userReceiveAddressService = new UserReceiveAddressService(); var model = new UserReceiveAddressModel { Consignee = consignee, Mobile = mobile, Tel = tel, CountyID = countyID, UserID = this.UserSession.UserID, IsDefault = false, Address = address }; SqlTransaction transaction = null; try { if (addressId > 0) { var userReceiveAddress = DataTransfer.Transfer<User_RecieveAddress>(model, typeof(UserReceiveAddressModel)); userReceiveAddress.ID = addressId; userReceiveAddress.IsDefault = isDefault == 1; userReceiveAddressService.Modify(userReceiveAddress, out transaction); transaction.Commit(); } else { var userReceiveAddress = DataTransfer.Transfer<User_RecieveAddress>(model, typeof(UserReceiveAddressModel)); userReceiveAddress.IsDefault = isDefault == 1; addressId = userReceiveAddressService.Add(userReceiveAddress, null); } model.ID = addressId; return this.PartialView("Partial/NewAddress", model); } catch (Exception exception) { if (transaction != null) { transaction.Rollback(); } LogUtils.Log( "前台用户下单时添加或修改收货地址出错,错误原因:" + exception.Message, "前台添加用户收货信息", Category.Error, this.Session.SessionID, this.UserSession.UserID, "Order/AddOrEditUserReceiveAddress"); TextLogger.Instance.Log("前台用户下单时添加或修改收货地址出错", Category.Error, exception); return Json(new AjaxResponse(-1, "操作失败")); } }
public ActionResult OrderInfo(int[] proIds, int[] quantity) { try { var orderInfo = new OrderInfoViewModel(); var addresses = new UserReceiveAddressService().QueryReceiveAddressByUserID(this.UserSession.UserID); if (addresses != null) { orderInfo.UserReceiveAddressList = new List<UserReceiveAddressModel>(); foreach (var userRecieveAddress in addresses) { orderInfo.UserReceiveAddressList.Add( DataTransfer.Transfer<UserReceiveAddressModel>(userRecieveAddress, typeof(User_RecieveAddress))); } } var userCart = MongoDBHelper.GetModel<UserCartModel>(m => m.VisitorKey == this.UserSession.VisitorKey); CartController.WriteUserCartOperationLog( new UserCartOperationLog() { OperateTime = DateTime.Now, SessionKey = this.Session.SessionID, VisitorKey = this.UserSession.VisitorKey, OperationType = "Get", Message = "订单确认获取当前User购物车(" + this.UserSession.VisitorKey + "):Selector:m => m.UserId == this.UserSession.UserID || m.VisitorKey == this.UserSession.VisitorKey", UserCart = userCart ?? new UserCartModel() { BuyList = new List<CartProduct>(), ProductItems = new List<CartProduct>() }, UserID = this.UserSession.UserID }); var products = BuildCartProducts(proIds, quantity); if (userCart == null) { userCart = new UserCartModel { ProductItems = products, UserId = this.UserSession.UserID, VisitorKey = this.UserSession.VisitorKey }; } if (userCart.ProductItems == null) { userCart.ProductItems = new List<CartProduct>(); } foreach (var cartProduct in products) { if (userCart.ProductItems.FirstOrDefault(p => p.ProductID == cartProduct.ProductID) == null) { if (cartProduct != null) { userCart.ProductItems.Add(cartProduct); } } } userCart.BuyList = products; MongoDBHelper.UpdateModel<UserCartModel>(userCart, u => u.VisitorKey == this.UserSession.VisitorKey); CartController.WriteUserCartOperationLog( new UserCartOperationLog() { OperateTime = DateTime.Now, SessionKey = this.Session.SessionID, VisitorKey = this.UserSession.VisitorKey, OperationType = "Get", Message = "订单确认已更新User购物车(" + this.UserSession.VisitorKey + "):Selector:m => m.UserId == this.UserSession.UserID || m.VisitorKey == this.UserSession.VisitorKey", UserCart = MongoDBHelper.GetModel<UserCartModel>( m => m.VisitorKey == this.UserSession.VisitorKey) ?? new UserCartModel() { BuyList = new List<CartProduct>(), ProductItems = new List<CartProduct>() }, UserID = this.UserSession.UserID }); orderInfo.Products = userCart.BuyList; //获取促销相关信息 var productDictionary = new Dictionary<int, int>(); foreach (var cartProduct in orderInfo.Products) { productDictionary.Add(cartProduct.ProductID, cartProduct.Quantity); } var orderBill = this.GetOrderBill(productDictionary); foreach (var product in orderBill.Products) { if (product.ProductID == 4153) { orderBill.TotalPrice -= product.GoujiuPrice; product.PromotePrice = 0; product.Quantity = 1; } } orderInfo.BillDetail = orderBill; return this.View(orderInfo); } catch (Exception exception) { LogUtils.Log( string.Format( "订单核对出错,参数信息:proIds:{0},quantity:{1},错误消息:{2},堆栈:{3}", proIds, quantity, exception.Message, exception.StackTrace), "OrderInfo", Category.Error); throw; } }
public ActionResult SetAddressDefault(int addressID) { if (addressID < 1) { return this.Json(new AjaxResponse(0, "参数错误")); } var service = new UserReceiveAddressService(); var userID = service.QueryByID(addressID).UserID; if (this.UserSession.UserID != userID) { return this.Json(new AjaxResponse(-1, "无权修改本地址信息")); } service.SetDefault(addressID, userID); return this.Json(new AjaxResponse(1, "操作成功")); }
public ActionResult Add(int addressID, int payMethod, string productIds, string intro, int isRequireInvoice, string invoiceTitle, int invoiceContent, int ctype, int cId, double account) { /*************** * 前台添加订单流程: * 1.检查是否用券,若用,则检查券是否存在,是否符合使用条件。 * 2.检查是否用余额抵扣,若用,则检查用户是否有足够余额。 * 3.检查用户是否开发票,若是,检查发票内容是否填写。 * 4.检查用户收货地址ID是否填写正确 * 5.检查商品ID列表是否正确 * todo:下单时检查商品库存 * ********************/ #region 检查是否用券 //todo:券检查 #endregion #region 余额抵用检查 if (account > 0) { if (!CheckAccountBalance(account)) { return this.Json(new AjaxResponse(-1, "账户余额不足")); } } #endregion #region 检查发票信息 if (isRequireInvoice > 0) { if (invoiceContent < 0) { return this.Json(new AjaxResponse(-1, "发票内容错误")); } } #endregion #region 检查收货地址ID是否填写正确 if (addressID <= 0) { return this.Json(new AjaxResponse(-1, "收货地址错误")); } var address = new UserReceiveAddressService().QueryByID(addressID); //收货地址必须与用户对应 if (address == null || address.UserID != this.UserSession.UserID) { return this.Json(new AjaxResponse(-1, "收货地址错误")); } var addressModel = DataTransfer.Transfer<UserReceiveAddressModel>(address, typeof(User_RecieveAddress)); if (!new UtilityController().ValidSupportRegion(addressModel.ProvinceID)) { return this.Json(new AjaxResponse(-1, "对不起," + addressModel.CountyName("-") + "暂不支持。")); } #endregion var orderService = new OrderService(this.UserSession.UserID, false); try { var cart = MongoDBHelper.GetModel<UserCartModel>(u => u.VisitorKey == this.UserSession.VisitorKey); if (cart == null || cart.BuyList == null || cart.BuyList.Count < 1) { return this.Json(new AjaxResponse(-1, "商品不存在或已下架。")); } string message; #region 检查商品列表信息 if (!CheckBuyProducts(cart.BuyList, out message)) { LogUtils.Log( message, "前台提交订单:Add", Category.Info, this.UserSession.SessionId, this.UserSession.UserID, "Order/Add"); return this.Json(new AjaxResponse(0, message)); } #endregion //获取促销相关信息 var productDictionary = new Dictionary<int, int>(); foreach (var orderProduct in cart.BuyList) { productDictionary.Add(orderProduct.ProductID, orderProduct.Quantity); } var orderBill = this.GetOrderBill(productDictionary); //new OrderBillServices().QueryOrderBill(productDictionary, this.UserSession.UserID); if (orderBill == null || ((orderBill.Products == null || orderBill.Products.Count < 1) && (orderBill.SuitPromoteInfos == null || orderBill.SuitPromoteInfos.Count < 1))) { LogUtils.Log("没有获取订单促销信息", "Add", Category.Warn); return this.Json(new AjaxResponse(-1, "商品不存在或者已下架。")); } #region 检查促销活动 //限购验证 foreach (var cartProduct in orderBill.Products) { //验证是否有多选一情况 if (cartProduct.DenyFlag > 0) { switch (cartProduct.DenyFlag) { case 1: return this.Json(new AjaxResponse(0, string.Format("对不起,{0} 只允许新会员购买!", cartProduct.ProductName))); case 2: return this.Json(new AjaxResponse(0, string.Format("对不起,{0} 只允许老会员购买!", cartProduct.ProductName))); case 3: return this.Json(new AjaxResponse(0, string.Format("对不起,{0} 只允许通过手机验证会员购买!", cartProduct.ProductName))); case 4: return this.Json(new AjaxResponse(0, string.Format("对不起,{0} 只允许通过邮箱验证会员购买。", cartProduct.ProductName))); case 5: return this.Json(new AjaxResponse(0, string.Format("对不起,{0} 请先登录。", cartProduct.ProductName))); default: return this.Json(new AjaxResponse(0, string.Format("对不起,{0} 您不满足此商品的购买条件。", cartProduct.ProductName))); } } //验证多选一互斥促销 if (cartProduct.Promotes!=null&&cartProduct.Promotes.FirstOrDefault(p => p.PromoteType == 4) != null && !string.IsNullOrWhiteSpace(cartProduct.Exclude)) { var userCart = MongoDBHelper.GetModel<UserCartModel>(u => u.VisitorKey == this.UserSession.VisitorKey); if (userCart != null && userCart.ProductItems.Count > 0) { var excludes = cartProduct.Exclude.Split(','); if (excludes.Length > 0) { foreach (var item in userCart.ProductItems) { if (item.ProductID != cartProduct.ProductID && excludes.Contains(item.ProductID.ToString())) { return this.Json( new AjaxResponse( 0, string.Format( "对不起,【{0}】与【{1}】不能同时购买。", item.ProductName, cartProduct.ProductName))); } } } } } //判断是否是限时抢购,且是否超出了限制量。 if (cartProduct.LimitedBuyQuantity > 0 && cartProduct.MaxBuyQuantity < cartProduct.Quantity) { LogUtils.Log("用户订单商品数量超出了限时抢购数量", "Add", Category.Info); return this.Json( new AjaxResponse( 0, string.Format( "对不起,{0} 每人限购{1}件,你还可以购买{2}件。", cartProduct.ProductName, cartProduct.LimitedBuyQuantity, cartProduct.MaxBuyQuantity))); } //若是限时抢购,判断是否还有活动库存 if (cartProduct.LimitedBuyQuantity > 0 && cartProduct.PromoteResidueQuantity < cartProduct.Quantity) { LogUtils.Log( string.Format( "{0} 活动库存不满足,库存仅剩 {1},用户下单{2}", cartProduct.ProductName, cartProduct.PromoteResidueQuantity, cartProduct.Quantity), "Add", Category.Info); return this.Json( new AjaxResponse( 0, string.Format( "对不起,{0} 活动库存不满足,库存仅剩 {1}件。", cartProduct.ProductName, cartProduct.PromoteResidueQuantity))); } } //检查组合促销商品限购情况 if (orderBill.SuitPromoteInfos != null) { foreach (var suitPromoteInfo in orderBill.SuitPromoteInfos) { if (suitPromoteInfo.Products != null) { foreach (var cartProduct in suitPromoteInfo.Products) { //判断是否是限时抢购,且是否超出了限制量。 if (cartProduct.LimitedBuyQuantity > 0 && cartProduct.MaxBuyQuantity < cartProduct.Quantity) { LogUtils.Log("用户订单商品数量超出了限时抢购数量", "Add", Category.Info); return this.Json( new AjaxResponse( 0, string.Format( "对不起,{0} 每人限购{1}件,你还可以购买{2}件。", cartProduct.ProductName, cartProduct.LimitedBuyQuantity, cartProduct.MaxBuyQuantity))); } //若是限时抢购,判断是否还有活动库存 if (cartProduct.LimitedBuyQuantity > 0 && cartProduct.PromoteResidueQuantity < cartProduct.Quantity) { LogUtils.Log( string.Format( "{0} 活动库存不满足,库存仅剩 {1},用户下单{2}", cartProduct.ProductName, cartProduct.PromoteResidueQuantity, cartProduct.Quantity), "Add", Category.Info); return this.Json( new AjaxResponse( 0, string.Format( "对不起,{0} 活动库存不满足,库存仅剩 {1}件。", cartProduct.ProductName, cartProduct.PromoteResidueQuantity))); } } } } } #endregion DateTime createTime; var orderCode = MadeCodeService.GetOrderCode(out createTime); var order = new Order { UserID = this.UserSession.UserID, RecieveAddressID = addressID, CpsID = 0, PaymentMethodID = payMethod, OrderCode = orderCode, OrderNumber = MadeCodeService.ReverseOrderCode(orderCode, createTime), TotalMoney = 0, TotalIntegral = 0, PaymentStatus = 0, IsRequireInvoice = isRequireInvoice != 0, Status = payMethod == 0 ? 100 : 0, // 若是在线支付,则设置为等待付款,否则设置为等待确认 Remark = intro, CreateTime = createTime }; //获取CPS信息 order.CpsID = this.GetCpsID(); Order_Invoice invoice = null; if (isRequireInvoice!=0) //需要开发票 { invoice = new Order_Invoice { InvoiceContentID = invoiceContent, InvoiceTitle = string.IsNullOrWhiteSpace(invoiceTitle) ? "个人" : invoiceTitle, InvoiceTypeID = 0 }; } var promoteList = new List<Order_Product_Promote>(); var buyProducts=new List<Order_Product>(); var giftCoupons = new List<Gift_Coupon>(); double totalAmount = 0, totalDiscount = 0, tempDiscount = 0; totalAmount += SetBuyList(order.ID, orderBill.Products, ref buyProducts, ref promoteList, out tempDiscount); totalDiscount += tempDiscount; //组合促销商品 if (orderBill.SuitPromoteInfos != null) { foreach (var suitPromote in orderBill.SuitPromoteInfos) { totalDiscount += suitPromote.PromoteDiscount; totalAmount += SetBuyList( order.ID, suitPromote.Products, ref buyProducts, ref promoteList, out tempDiscount); totalDiscount += tempDiscount; //成交价 = 单品成交价 - 组合优惠摊牌金额 if (suitPromote.PromoteDiscount > 0) { for (var i = 0; i < buyProducts.Count; i++) { if (suitPromote.Products.Exists(p => p.ProductID == buyProducts[i].ProductID)) { buyProducts[i].TransactPrice -= buyProducts[i].TransactPrice / suitPromote.TotalPrice * suitPromote.PromoteDiscount; //组合促销信息 promoteList.Add( new Order_Product_Promote { ProductID = buyProducts[i].ProductID, PromoteID = suitPromote.PromoteID, PromoteDiscount = Math.Round( buyProducts[i].TransactPrice / suitPromote.TotalPrice * suitPromote.PromoteDiscount, 2), PromoteType = suitPromote.PromoteType }); } } } //赠品 if (suitPromote.GiftProducts != null) { foreach (var giftProduct in suitPromote.GiftProducts) { var product = new Order_Product { ProductID = giftProduct.ProductID, ProductName = "【赠品】" + giftProduct.ProductName, Quantity = giftProduct.Quantity, PromotionID = giftProduct.PromotID, PromotionType = giftProduct.PromotType, TransactPrice = 0, PromotionResult = 1, Integral = 0, RebateRate = 0, Commission = 0, CreateTime = DateTime.Now }; buyProducts.Add(product); promoteList.Add( new Order_Product_Promote { OrderID = order.ID, ProductID = giftProduct.ProductID, PromoteID = giftProduct.PromotID, PromoteType = giftProduct.PromotType, ExtField = "赠品" }); } } if (suitPromote.GiftCoupons != null) { giftCoupons.AddRange(suitPromote.GiftCoupons); } } } order.TotalMoney = orderBill.TotalPrice - orderBill.TotalDiscount; //todo:特殊促销处理,此处为了快速开发,硬编码 foreach (var cartProduct in buyProducts) { if (cartProduct.ProductID == 4153) { order.TotalMoney = order.TotalMoney - cartProduct.TransactPrice; cartProduct.TransactPrice = 0; cartProduct.Quantity = 1; } } order.DeliveryCost = order.TotalMoney >= 100 ? 0 : 10; //todo:需要改掉 order.Discount = totalDiscount; var orderId = orderService.Add(order, buyProducts, invoice, giftCoupons, promoteList); this.ResetUserCart(cart, buyProducts); //更新特殊活动 foreach (var orderProduct in buyProducts) { var specialPromotes = MongoDBHelper.GetModels<SpecialPromote>(p => p.GiftProductID == orderProduct.ProductID && p.ID > 0); if (specialPromotes != null && specialPromotes.Count > 0) //若不是,则直接跳过 { var specialPromote = specialPromotes[0]; //一个赠品只能参加一个活动 var userPromote = specialPromote.UserPromotes.FirstOrDefault(u => u.UserID == this.UserSession.UserID); //即使找不到参加活动的记录,但领取了商品,我们依然认为此用户已经参加了活动 if (userPromote == null) { userPromote = new UserPromote { UserID = this.UserSession.UserID }; } userPromote.OrderID = order.ID; userPromote.HasGetGift=true; userPromote.GetGiftTime = DateTime.Now; userPromote.GiftID = orderProduct.ProductID; specialPromote.UserPromotes.Remove(u => u.UserID == userPromote.UserID); specialPromote.UserPromotes.Add(userPromote); MongoDBHelper.UpdateModel<SpecialPromote>(specialPromote, sp => sp.ID == specialPromote.ID); } } LogUtils.Log( "前台添加订单成功,订单编码:" + orderId + "\n\r", "Order.Add", Category.Info, this.UserSession.SessionId, this.UserSession.UserID); return this.Json(new AjaxResponse(1, "订单提交成功", order.OrderCode)); } catch (Exception ex) { LogUtils.Log( "前台添加订单出错了,错误信息:"+ex.Message+"\n\r"+ex.StackTrace, "Order.Add", Category.Error, this.UserSession.SessionId, this.UserSession.UserID); return this.Json(new AjaxResponse(-2, "对不起,提交订单出错了。")); } }
/// <summary> /// 删除地址 /// </summary> /// <param name="addressId"></param> /// <returns></returns> public ActionResult DeleteAddress(int addressId) { var recevid = new UserReceiveAddressService().RemoveByID(addressId); if (recevid > 0) { return Json(new AjaxResponse(1, "删除成功")); } return Json(""); }
public ActionResult RemoveAddress(int addressID) { if (addressID < 1) { return this.Json(new AjaxResponse(0, "没有操作")); } var service = new UserReceiveAddressService(); var userID = service.QueryByID(addressID).UserID; if (this.UserSession.UserID != userID) { return this.Json(new AjaxResponse(-1, "无权修改本地址信息")); } service.RemoveByID(addressID); return this.Json(new AjaxResponse(1, "删除成功")); }
/// <summary> /// 根据会员编码查询送货地址信息 /// </summary> /// <param name="request"> /// 请求对象 /// </param> /// <param name="currentUserID"> /// The current User ID. /// </param> /// <returns> /// The <see cref="ActionResult"/>. /// </returns> public ActionResult QueryUserReceiveAddress([DataSourceRequest] DataSourceRequest request, int currentUserID) { var service = new UserReceiveAddressService(); var list = service.QueryReceiveAddressByUserID(currentUserID); if (list == null || list.Count == 0) return null; var modelList = new List<UserReceiveAddressModel>(); foreach (var item in list) { modelList.Add( DataTransfer.Transfer<UserReceiveAddressModel>( item, typeof(User_RecieveAddress))); } return Json(modelList.ToDataSourceResult(request)); }
private bool PushOrderToHwErp(Order order, List<Order_Product> orderProducts, SqlTransaction transaction, out string errorMsg, Order_Payment payment = null) { #region 订单推送ERP #region 订单基本信息 errorMsg = string.Empty; var hi = new HwRest.HwOrderInfo(); hi.orderNumber = order.OrderCode; hi.orderDate = order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"); if (order.PaymentStatus == 1) { //var orderPayment = new OrderPaymentService().QueryByOrderID(order.ID); //if (orderPayment != null) hi.payTime = Convert.ToDateTime(orderPayment.CreateTime).ToString(); //todo:若订单已在线支付,则认为是当前时间支付,因为在线支付订单是有系统在支付时自动确认的。当时不够准确。 hi.payTime = payment == null ? DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : payment.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"); } if (string.IsNullOrWhiteSpace(hi.payTime)) { hi.payTime = ""; } var orderReceiveAddress = new UserReceiveAddressService().QueryByID(order.RecieveAddressID); hi.buyerNick = string.IsNullOrWhiteSpace(order.UserName) ? orderReceiveAddress.Consignee : order.UserName; hi.totalAmount = Math.Round(order.TotalMoney + order.DeliveryCost, 2).ToString(); hi.payment = payment == null ? (order.TotalMoney + order.DeliveryCost).ToString() : Math.Round(payment.PaymentMoney, 2).ToString(); hi.postAmount = order.DeliveryCost.ToString(); hi.discount = order.Discount.ToString(); hi.points = ""; hi.pointsAmount = ""; hi.couponsAmount = ""; hi.virtualAmount = ""; hi.fullMinus = ""; var orderInvoice = new OrderInvoiceService().SelectByOrderID(order.ID); hi.invoiceTitle = orderInvoice != null ? orderInvoice.InvoiceTitle : ""; hi.invoiceContent = orderInvoice != null ? orderInvoice.InvoiceContent : ""; hi.invoiceAmount = orderInvoice != null ? orderInvoice.InvoiceCost.ToString() : ""; hi.tradeFrom = "官网订单"; if (order.PaymentMethodID == 0) { if (payment != null) { hi.paymentType = payment.PaymentOrgName; } else { hi.paymentType = "网上支付"; } hi.sellerMemo = ""; } else { hi.paymentType = "货到付款"; hi.sellerMemo = ""; } hi.consignee = orderReceiveAddress != null ? orderReceiveAddress.Consignee : order.UserName; if (orderReceiveAddress != null) { if (!string.IsNullOrWhiteSpace(orderReceiveAddress.CountyName(","))) { var strs = orderReceiveAddress.CountyName(",").Split(','); if (strs.Length == 3) { hi.province = strs[0]; hi.city = strs[1]; hi.cityarea = strs[2]; } else { hi.cityarea = orderReceiveAddress.CountyName(","); hi.province = ""; hi.city = ""; } } } else { hi.cityarea = ""; hi.province = ""; hi.city = ""; } hi.address = orderReceiveAddress != null ? orderReceiveAddress.Address : ""; hi.mobilePhone = orderReceiveAddress != null ? orderReceiveAddress.Mobile : ""; hi.telephone = orderReceiveAddress != null ? orderReceiveAddress.Tel : ""; hi.zip = orderReceiveAddress != null ? orderReceiveAddress.ZipCode : ""; hi.buyerMessage ="客户备注:"+ order.Remark + ";客服备注:" + order.Description; #endregion #region 商品列表 List<HwRest.HwProductList> hplist = new List<HwRest.HwProductList>(); if (orderProducts == null || orderProducts.Count < 1) { orderProducts = new OrderProductService().QueryByOrderId(order.ID); } foreach (var orderProduct in orderProducts) { var hwProduct = hplist.FirstOrDefault(p => p.productNumber == orderProduct.Barcode && orderProduct.TransactPrice <= 0); //赠品与正常商品合并 if (hwProduct != null) { hwProduct.orderCount = (int.Parse(hwProduct.orderCount) + orderProduct.Quantity).ToString(); hwProduct.giftCount = (int.Parse(hwProduct.giftCount) + orderProduct.Quantity).ToString(); //将商品价格当做优惠金额进行处理 hwProduct.discountFee = (int.Parse(hwProduct.discountFee) + int.Parse(hwProduct.price) * orderProduct.Quantity).ToString(); } else { HwRest.HwProductList hpl = new HwRest.HwProductList(); hpl.productNumber = orderProduct.Barcode; //新系统中没有商品编号,此处设为商品条形码 hpl.productName = orderProduct.ProductName; hpl.skuNumber = orderProduct.Barcode; hpl.skuName = ""; hpl.price = orderProduct.TransactPrice.ToString(); hpl.orderCount = orderProduct.Quantity.ToString(); hpl.giftCount = (orderProduct.TransactPrice > 0 ? 0 : orderProduct.Quantity).ToString(); hpl.amount = (orderProduct.TransactPrice * orderProduct.Quantity).ToString(); hpl.memo = orderProduct.TransactPrice > 0 ? "" : "【赠品】"; hpl.discountFee = "0"; hpl.barcode = orderProduct.Barcode; hplist.Add(hpl); } } #endregion HwRest.OWebOrderItems OWebOrderItems = new HwRest.OWebOrderItems(); OWebOrderItems.OWebOrderItem = hplist.ToArray(); HwRest.HwOrderAdd_Info hai = new HwRest.HwOrderAdd_Info(); hi.OWebOrderItems = OWebOrderItems; hai.OWebOrder = hi; HwRest.HwClient HwClient = new HwRest.HwClient(); HwClient.XmlValues = hai.ToXmlParameter(); HwClient.OrderNumber = hi.orderNumber; string HwBackXml = HwClient.Execute(); XmlDocument doc = new XmlDocument(); doc.LoadXml(HwBackXml); XmlNode root = doc.SelectSingleNode("//Response"); var log = new Order_Erp_Log { ERP = "HW_ERP", OrderID = order.ID, OperateType = 1, ReqContent = HwClient.XmlValues, ResContent = HwBackXml, UserID = order.UserID, Operator = isBackage ? this.userID : 0, CreateTime = DateTime.Now }; if (payment != null) { log.ExtField = "在线支付订单,支付时间:" + payment.CreateTime; } var result = false; if (HwBackXml.Contains("推单异常") || root.FirstChild.InnerText.ToLower() != "true") { log.IsSuccess = false; //获取退单错误信息 var errorNode = root.SelectSingleNode("//value"); if (errorNode != null) { errorMsg = errorNode.InnerText; } result = false; LogUtils.Log("订单推送失败,订单编码:" + order.ID + ",错误消息:" + HwBackXml, "订单推送ERP", Category.Error); } else { log.IsSuccess = true; result = true; LogUtils.Log("订单推送成功,订单编码:" + order.ID, "订单推送ERP"); } try { var orderErpLogService = new OrderERPLogService(); orderErpLogService.Add(log, null); //添加日志,无需事务,防止回滚 } catch(Exception exception) { LogUtils.Log( string.Format( "[Order_ERP]订单推送成功,但是写入日志信息发生错误。订单编号:{0},错误信息:{1}/{2}", order.OrderCode, exception.Message, exception.InnerException), "[Order_ERP]订单推送", Category.Error); } return result; #endregion }
/// <summary> /// 设为默认收货地址 /// </summary> /// <param name="addressId"></param> /// <returns></returns> public ActionResult SetAddressDefault(int addressId) { var recevid = new UserReceiveAddressService().SetDefault(addressId, this.UserSession.UserID); if (recevid > 0) { return Json(new AjaxResponse(1, "已设为默认收货地址")); } return Json(""); }
public ActionResult AddUserReceiveAddress([DataSourceRequest] DataSourceRequest request, string consignee, string mobile, string tel, int currentCountyID, string address, int currentUserID) { var userReceiveAddressService = new UserReceiveAddressService(); var model = new UserReceiveAddressModel { Consignee = consignee, Mobile = mobile, Tel = tel, CountyID = currentCountyID, UserID = currentUserID, IsDefault = false, Address = address }; var userReceiveAddress = DataTransfer.Transfer<User_RecieveAddress>(model, typeof(UserReceiveAddressModel)); int addressId = userReceiveAddressService.Add(userReceiveAddress, null); model.ID = addressId; return Json(new[] { model }.ToDataSourceResult(request, ModelState)); }
/// <summary> /// 保存用户地址的修改 /// </summary> /// <param name="id">主键编号</param> /// <param name="consignee">用户名</param> /// <param name="address">地址</param> /// <param name="mobile">手机号码</param> /// <param name="Isdefault">是否默认</param> /// <param name="email">邮箱</param> /// <param name="zipCode">区号</param> /// <param name="countryId">地区标识</param> /// <param name="tel"></param> /// <returns></returns> public ActionResult SaveModifyAddress(int id, string consignee, string address, string mobile, bool Isdefault, string email, string zipCode, int countryId, string tel) { try { if (id == -1) { var receAddress = new User_RecieveAddress() { UserID = this.GetUserID(), Consignee = consignee, Address = address, Mobile = mobile, IsDefault = Isdefault, Email = email, ZipCode = zipCode, CountyID = countryId, Tel = tel }; var recevid = new UserReceiveAddressService().Add(receAddress, null); if (recevid > 0) { return Json(new AjaxResponse { State = 1, Message = "添加成功", Data = recevid }); } } else { var receAddress = new User_RecieveAddress() { UserID = this.GetUserID(), Consignee = consignee, Address = address, Mobile = mobile, IsDefault = Isdefault, Email = email, ZipCode = zipCode, CountyID = countryId, ID = id, Tel = tel }; var recevid = new UserReceiveAddressService().UpdateAddresss(receAddress); if (recevid > 0) { return Json(new AjaxResponse(1, "修改成功")); } } } catch (Exception exception) { throw new Exception(exception.Message); } return Json(""); }
/// <summary> /// 根据ID查询Adress /// </summary> /// <returns></returns> public ActionResult GetReceivedAddressById(int id) { var userAddress = new UserReceiveAddressService().QueryByID(id); if (userAddress != null) { return Json(userAddress); } return Json(""); }
public ActionResult GetAddressByUserId() { List<User_RecieveAddress> addressList = new UserReceiveAddressService().QueryReceiveAddressByUserID(this.GetUserID()); if (addressList != null && addressList.Any()) { return this.Json(new AjaxResponse { State = 1, Data = addressList }); } return Json(new AjaxResponse { State = 0, Data = 0 }); }
/// <summary> /// 根据地址编码查询收货地址信息 /// </summary> /// <param name="addressId">地址编码</param> /// <returns>返回地址信息Json</returns> public ActionResult GetReceiveAddressByID(int addressId) { var address = new UserReceiveAddressService().QueryByID(addressId); return Json( DataTransfer.Transfer<UserReceiveAddressModel>(address, typeof(User_RecieveAddress)), JsonRequestBehavior.AllowGet); }
public ActionResult SearchUserInfo(string searchStr) { AjaxResponse response = null; try { var userService = new UserService(); var user = userService.QueryUserByMobileOrEmail(searchStr); if (user == null) { response = new AjaxResponse(2, "用户不存在"); return this.Json(response); } var userAddressService = new UserReceiveAddressService(); var userDefaultAddress = userAddressService.QueryDefaultReceiveAddressByUserID(user.ID); if (userDefaultAddress != null) { var addressModel = DataTransfer.Transfer<UserReceiveAddressModel>( userDefaultAddress, typeof(User_RecieveAddress)); addressModel.UserID = user.ID; addressModel.UserName = user.Name; response = new AjaxResponse(1, string.Empty, addressModel); return this.Json(response); } else { var userModel = DataTransfer.Transfer<UserModel>(user, typeof(User)); response = new AjaxResponse(3, "没有地址信息", userModel); return this.Json(response); } } catch (Exception exception) { response = new AjaxResponse(-1, exception.Message); return this.Json(response); } }
/// <summary> /// 获取邮编 /// </summary> /// <param name="countyId"> /// 地区编码 /// </param> /// <returns> /// The <see cref="ActionResult"/>. /// </returns> public ActionResult QueryPostCodeByCountyID(int countyId) { var postCode = new UserReceiveAddressService().QueryPostCodeByID(countyId); return this.Json(postCode, JsonRequestBehavior.AllowGet); }
public ActionResult Detail(int id) { try { this.userService = new UserService(); this.userReceiveAddressService = new UserReceiveAddressService(); var userInfo = this.userService.QueryUserByID(id); if (userInfo == null) { return null; } var user = DataTransfer.Transfer<UserModel>(userInfo, typeof(User)); if (user.Account == null) { user.Account=new UserAccountModel(); } user.Account.Balance = userInfo.Balance; var userRecieveAddress = this.userReceiveAddressService.QueryDefaultReceiveAddressByUserID(user.ID); if (userRecieveAddress != null) { user.DefaultAddress = userRecieveAddress.Address; var postCode = this.userReceiveAddressService.QueryPostCodeByID(userRecieveAddress.ID); user.PostCode = postCode ?? string.Empty; } user.Head = user.Head == null ? @"../../../Images/member-phone.gif" : string.Empty; user.StateName = user.Status == 1 ? "正常" : "锁定"; return this.View("Detail", user); } catch (Exception exception) { throw new Exception(exception.Message, exception); } }
/// <summary> /// 添加用户基本信息和收件地址 /// </summary> /// <param name="user"> /// 用户对象 /// </param> public void AddUserInfo(User user) { if (user != null) { var userService = new UserService(); var userReceiceAddressService = new UserReceiveAddressService(); SqlTransaction sqlTransact = null; try { var userId = userService.AddUser(user, out sqlTransact); var userReceiveAddress = new User_RecieveAddress { UserID = userId, CountyID = user.CountyID, Address = user.Address, Consignee = user.Name, Mobile = user.Mobile, Tel = user.Tel, IsDefault = true, CreateTime = DateTime.Now }; userReceiceAddressService.Add(userReceiveAddress, sqlTransact); sqlTransact.Commit(); user.ID = userId; } catch { if (sqlTransact != null) { sqlTransact.Rollback(); } throw; } } }
public ActionResult API() { string orderCode = Server.UrlDecode(Request.QueryString["orderid"]);//订单编号 string strMsg = ""; SqlTransaction transaction = null; try { string username = Server.UrlDecode(Request.QueryString["username"]);//ERP昵称 string password = Server.UrlDecode(Request.QueryString["password"]);//ERP密码 string key = Server.UrlDecode(Request.QueryString["key"]);//公钥 string sign = Server.UrlDecode(Request.QueryString["sign"]);//检验码 string method = Server.UrlDecode(Request.QueryString["method"]);//调用接口 #region 访问日志 try { new OrderERPLogService().AddHwLog(new Hw_Log { Content = Request.Url.ToString(), Number = orderCode }, null); LogUtils.Log(string.Format("成功写入ERP系统访问日志,订单编号:{0},日志信息:{1}", orderCode, Request.Url.ToString()), "ERP订单回写", Category.Error); } catch (Exception exception) { LogUtils.Log(string.Format("写入ERP系统访问日志失败,订单编号:{0},日志信息:{1},错误信息:{2}", orderCode, Request.Url.ToString(), exception.Message + "/" + exception.InnerException), "ERP订单回写", Category.Error); } #endregion #region 基本参数验证 if (string.IsNullOrEmpty(username)) { strMsg = SetMsg("0", "昵称不能为空", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } if (string.IsNullOrEmpty(orderCode)) { strMsg = SetMsg("0", "订单不正确", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } if (username != "hongware") { strMsg = SetMsg("0", "昵称不正确", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } if (string.IsNullOrEmpty(password)) { strMsg = SetMsg("0", "密码不能为空", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } if (password != "bir19ming19ham") { strMsg = SetMsg("0", "密码不正确", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } if (string.IsNullOrEmpty(key)) { strMsg = SetMsg("0", "公钥不能为空", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } if (key != "g1w9j1r9w") { strMsg = SetMsg("0", "公钥不正确", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } if (string.IsNullOrEmpty(sign)) { strMsg = SetMsg("0", "检验码不能为空", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } if (string.IsNullOrEmpty(orderCode)) { strMsg = SetMsg("0", "订单编号不能为空", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } string sign_Md5 = Encrypt.HwErpMd5(username + password + orderCode + key); if (sign != sign_Md5) { strMsg = SetMsg("0", "检验码不正确", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } if (string.IsNullOrEmpty(method)) { strMsg = SetMsg("0", "调用方法名不能为空", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } method = method.ToLower(); #endregion #region 订单当前状态 var orderService = new OrderService(); var orderTracking = new OrderStatusTrackingService(); var order = orderService.QueryByOrderCode(orderCode); if (order == null || order.ID < 1) { strMsg = SetMsg("0", "未查到此订单号,请核实", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } int OrderID = order.ID; int State = order.Status; #endregion if (method == "api.order.send") { #region 订单发货 if (State == 0) { strMsg = SetMsg("0", "订单还未确认", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } else if (State == 2) { strMsg = SetMsg("0", "订单已发货", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } else if (State == 3) { strMsg = SetMsg("0", "订单已签收", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } else if (State == 4 || State == 5 || State == 8) { strMsg = SetMsg("0", "订单已取消", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } string expressno = string.Empty; expressno = Server.UrlDecode(Request.QueryString["expressno"]);//快递代码 string expressnum = Server.UrlDecode(Request.QueryString["expressnum"]);//快递单号 string deliverydate = Server.UrlDecode(Request.QueryString["deliverydate"]);//发货日期 #region 参数验证 if (string.IsNullOrEmpty(expressno)) { strMsg = SetMsg("0", "快递代码不能为空", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } if (string.IsNullOrEmpty(expressnum)) { strMsg = SetMsg("0", "快递单号不能为空", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } if (string.IsNullOrEmpty(deliverydate)) { strMsg = SetMsg("0", "发货日期不能为空", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } #endregion Config_Delivery_Corporation deliveryCorporation = null; #region 更新订单发货状态 /* 订单发货: * 1.更改订单状态, * 2.更改订单跟踪状态 */ try { var deliveryCorporations = new ConfigDeliveryCorporationService().QueryAllConfigDeliveryCorporations(); if (deliveryCorporations != null && deliveryCorporations.Count > 1) { deliveryCorporation = deliveryCorporations.Find(dc => expressno.Equals(dc.Number, StringComparison.OrdinalIgnoreCase)); } if (deliveryCorporation == null) { deliveryCorporation = new Config_Delivery_Corporation(); LogUtils.Log("没有获取到代号为:" + expressno.ToUpper() + "的配送公司", "API", Category.Warn); } var tracking = new Order_Status_Tracking(); tracking.MailNo = expressnum; tracking.ExpressNumber = expressno.ToUpper(); tracking.OrderID = OrderID; tracking.Status = 2; tracking.EmployeeID = 0; tracking.UserID = 0; tracking.Remark = string.Format( "订单已发货,配送单位:{0} {1}; 快递单号:{2}", deliveryCorporation.Name, deliveryCorporation.URL, expressnum); tracking.CreateTime = Convert.ToDateTime(deliverydate); orderService.SqlServer.BeginTransaction(); transaction = orderService.SqlServer.Transaction; orderTracking.Add(tracking, transaction); order.Status = 2; order.DeliveryCorporationID = deliveryCorporation.ID; orderService.Edit(order, transaction); transaction.Commit(); } catch (Exception exception) { if (transaction != null) { transaction.Rollback(); } LogUtils.Log( string.Format( "[Order_ERP]ERP回写发货订单时发生错误,订单编号:{0},错误消息:{1}", orderCode, exception.Message + "/" + exception.InnerException), "[Order_ERP]ERP订单发货回写官网", Category.Error); strMsg = SetMsg("0", "更新订单发货状态发生异常", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } finally { if (transaction != null && transaction.Connection != null && transaction.Connection.State != ConnectionState.Closed) { transaction.Connection.Close(); } } #endregion #region 短信发送 try { var orderReceiver = new UserReceiveAddressService().QueryByID(order.UserID); if (orderReceiver != null && orderReceiver.Mobile != null) { var moList = new List<string>(); moList.Add(orderReceiver.Mobile); var sm = new ShortMessage { ReceiveMobiles = moList, Content = string.Format( "亲爱的购酒网会员,您的订单(订单号:{0})支付方式为:{1},已经发货,配送公司:{2}, 单号:{3}。请注意保持手机畅通。", orderCode, order.PaymentMethodName, deliveryCorporation.Name, deliveryCorporation.Number) }; sm.Send(); LogUtils.Log( "用户:" + orderReceiver.Consignee + "电话:" + orderReceiver.Mobile + "成功发送短信", "SendSms", Category.Info, Session.SessionID); } else { LogUtils.Log("[Order_ERP]由于没有获取到订单收货人或收货人的手机号不存在,因此订单(" + order.OrderCode + ")发货,未发送通知短信", "[Order_ERP]订单发货回写发送短信SendSms", Category.Error); } } catch (Exception ex) { LogUtils.Log("[Order_ERP]ERP订单发货发送短信发生错误,错误消息:" + ex.Message + "/" + ex.InnerException, "[Order_ERP]订单发货回写发送短信SendSms", Category.Error); } #endregion strMsg = SetMsg("1", "订单状态更新成功", orderCode); //Response.Write(strMsg); return this.Content(strMsg); #endregion } else if (method == "api.order.cancel") { #region 订单取 if (State == 0) { strMsg = SetMsg("0", "订单还未确认", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } else if (State == 2) { strMsg = SetMsg("0", "订单已发货", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } else if (State == 3) { strMsg = SetMsg("0", "订单已确认收货", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } else if (State == 4 || State == 5 || State == 8) { strMsg = SetMsg("0", "订单已取消", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } try { orderService.SetInvalidByERP(order.ID, "订单作废"); } catch (Exception exception) { LogUtils.Log( string.Format( "[Order_ERP]ERP订单取消回写发生错误,订单号:{0},错误消息:{1}", orderCode, exception.Message + "/" + exception.InnerException), "[Order_ERP]ERP订单取消回写", Category.Error); strMsg = SetMsg("0", "订单作废发生错误", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } strMsg = SetMsg("1", "订单作废成功", orderCode); //Response.Write(strMsg); return this.Content(strMsg); #endregion } strMsg = SetMsg("0", "调用方法名不正确", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } catch (Exception) { strMsg = SetMsg("0", "订单回写发生异常", orderCode); //Response.Write(strMsg); return this.Content(strMsg); } }