public object PostSetSkuStock(SetSkuStockModel model) { CheckUserLogin(); if (string.IsNullOrWhiteSpace(model.skus)) { return new { success = false, msg = "参数异常" } } ; var ids = model.skus.Split(',').ToList(); var stk = model.stock.Split(',').Select(e => { int id = 0; if (!int.TryParse(e, out id)) { id = 0; } return(id); }).ToList(); var changes = new Dictionary <string, long>(); for (var i = 0; i < ids.Count; i++) { changes.Add(ids[i], stk[i]); } var type = (CommonModel.StockOptionType)model.optype; ProductManagerApplication.SetSkuStock(type, changes); return(new { success = true, msg = "设置成功" }); }
public object PostSetSkuStock(SetSkuStockModel model) { CheckUserLogin(); if (string.IsNullOrWhiteSpace(model.skus)) { return(Json(new { success = false, msg = "参数异常" })); } var ids = model.skus.Split(',').ToList(); var stk = model.stock.Split(',').Select(e => { int id = 0; if (!int.TryParse(e, out id)) { id = 0; } return(id); }); var type = (CommonModel.StockOpType)model.optype; ProductManagerApplication.SetSkuStock(ids, stk, type); return(Json(new { success = true, msg = "设置成功" })); }
/// <summary> /// 更新库存 /// </summary> /// <param name="ItemID"></param> /// <param name="SkuID"></param> /// <param name="Quantity"></param> /// <returns></returns> public string AdjustQuantity(HttpContext context) { string ItemID = context.Request["ItemID"]; string SkuID = context.Request["SkuID"]; string Quantity = context.Request["Quantity"]; int productId = Convert.ToInt32(ItemID); string SkuId = SkuID.Trim(); int quantity = Convert.ToInt32(Quantity); string ids = ""; if (!string.IsNullOrWhiteSpace(SkuId)) { ids = SkuId; } else { ids = string.Format("{0}_0_0_0", productId); } StringBuilder sb = new StringBuilder(); try { sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); sb.Append("<Rsp>"); if (string.IsNullOrEmpty(SkuId) || string.IsNullOrWhiteSpace(SkuId)) { try { ProductManagerApplication.SetProductStock(productId, quantity, CommonModel.StockOptionType.Normal); var product = ProductManagerApplication.GetProduct(productId); sb.Append("<Result>1</Result>"); if (product != null && product.SaleStatus == Entities.ProductInfo.ProductSaleStatus.OnSale) { sb.Append("<GoodsType>Onsale</GoodsType>"); } else { sb.Append("<GoodsType>InStock</GoodsType>"); } sb.Append("<Cause></Cause>"); } catch { sb.Append("<Result>0</Result>"); sb.Append("<GoodsType></GoodsType>"); sb.Append("<Cause><![CDATA[{修改库存失败}]]></Cause>"); } } else { var skuIdArr = SkuId.Split(',').ToList(); var quantitys = Quantity.Split(',').Select(e => long.Parse(e)).ToList(); var changes = new System.Collections.Generic.Dictionary <string, long>(); for (var i = 0; i < skuIdArr.Count; i++) { changes.Add(skuIdArr[i], quantitys[i]); } ProductManagerApplication.SetSkuStock(CommonModel.StockOptionType.Normal, changes); var product = ProductManagerApplication.GetProduct(productId); if (product != null) { sb.Append("<Result>1</Result>"); if (product != null && product.SaleStatus == Entities.ProductInfo.ProductSaleStatus.OnSale) { sb.Append("<GoodsType>Onsale</GoodsType>"); } else { sb.Append("<GoodsType>InStock</GoodsType>"); } sb.Append("<Cause></Cause>"); } else { sb.Append("<Result>0</Result>"); sb.Append("<GoodsType></GoodsType>"); sb.Append("<Cause><![CDATA[{修改库存失败}]]></Cause>"); } } sb.Append("</Rsp>"); } catch (Exception ex) { sb.Clear(); sb.Append("<Result>0</Result>"); sb.Append("<GoodsType></GoodsType>"); sb.Append("<Cause>" + ex.Message + "</Cause>"); sb.Append("</Rsp>"); } return(sb.ToString()); }
/// <summary> /// 同步库存 /// </summary> /// <param name="context"></param> /// <returns></returns> public string SyncStock(HttpContext context) { string bizcontent = context.Request["bizcontent"]; JObject jo = (JObject)JsonConvert.DeserializeObject(bizcontent); long? ProductId = GetJObjectValue <long?>(jo, "PlatProductID"); string SkuId = GetJObjectValue <string>(jo, "SkuID"); string OuterID = GetJObjectValue <string>(jo, "OuterID"); int Quantity = GetJObjectValue <int>(jo, "Quantity"); string OutSkuID = GetJObjectValue <string>(jo, "OutSkuID"); string SyncStockType = GetJObjectValue <string>(jo, "SyncStockType"); string ids = SkuId; if (string.IsNullOrWhiteSpace(SkuId)) { ids = string.Format("{0}_0", ProductId); } if (!ProductId.HasValue || ProductId <= 0) { throw new HimallApiException("商品ID不存在"); } var stype = StockOptionType.Normal; if (SyncStockType == "JH_01") { stype = StockOptionType.Normal; } if (SyncStockType == "JH_02") { stype = StockOptionType.Add; } StringBuilder sb = new StringBuilder(); if (string.IsNullOrWhiteSpace(SkuId)) { ProductManagerApplication.SetProductStock(new List <long> { ProductId.Value }, Quantity, stype); sb.Append("{"); sb.Append("\"code\":" + "\"10000\""); sb.Append(",\"message\":" + "\"SUCCESS\""); sb.Append(",\"Quantity\":" + "\"" + Quantity + "\""); sb.Append("}"); } else { var changes = new Dictionary <string, long>() { { SkuId, Quantity } }; ProductManagerApplication.SetSkuStock(stype, changes); sb.Append("{"); sb.Append("\"code\":" + "\"10000\""); sb.Append(",\"message\":" + "\"SUCCESS\""); sb.Append(",\"Quantity\":" + "\"" + Quantity + "\""); sb.Append("}"); } return(sb.ToString()); }