public async Task <ActionResult <ItemResponse> > SaveItem(long id, [FromBody] ItemUpdateRequest request) { if (request == null) { return(BadRequest()); } var item = await itemRepository.FindById(id).ConfigureAwait(false); item.SellPrice = request.SellPrice; item.StockPrice = request.StockPrice; item.Stock = request.Stock; var success = await itemRepository.Update(item).ConfigureAwait(false); if (success) { await cache.Invalidate(item.CategoryId); return(Ok(ItemResponse.Of(item))); } else { return(Conflict()); } }
public Item UpdateGoods(Product product) { var req = new ItemUpdateRequest(); Util.CopyModel(product, req); return(UpdateGoodsBase(req, product.NumIid, product.OuterId, product.Title)); }
/// <summary> /// 更新商品价格 /// </summary> /// <param name="itemId"></param> /// <param name="onePrice"></param> /// <returns></returns> public ApiResult ItemUpdatePrice(long itemId, double onePrice) { ITopClient client = GetTopClient(); ItemUpdateRequest req = new ItemUpdateRequest(); req.NumIid = itemId; req.Price = onePrice.ToString("f2"); ItemUpdateResponse rsp = client.Execute(req, AccessToken); return(rsp.AsApiResult()); }
/// <summary> /// 定时上架商品,未测试。 /// </summary> /// <param name="itemId"></param> /// <param name="num"></param> /// <param name="listTime"></param> /// <returns></returns> public ApiResult ItemUpdateListWhenTime(long itemId, long?num, DateTime?listTime = null) { ITopClient client = GetTopClient(); ItemUpdateRequest req = new ItemUpdateRequest(); req.NumIid = itemId; req.ApproveStatus = "onsale"; req.ListTime = listTime; req.Num = num; ItemUpdateResponse rsp = client.Execute(req, AccessToken); return(rsp.AsApiResult()); }
protected void lbtnSave_Click(object sender, EventArgs e) { string html = ucTemplateEditor.GetHtml(); ITopClient client = GetProductTopClient(); ItemUpdateRequest req = new ItemUpdateRequest(); // SellerCatsGetRequest req = new SellerCatsGetRequest(); req.Desc = html; req.Iid = Request["Current"]; Item item = client.Execute(req, new ItemJsonParser(), CurrentSessionKey); Dictionary<string, string> parameters = GetParameterListByQuery(); parameters.Add("IsSuccess", "1"); parameters.Add("Message", "设置宝贝描述信息成功!"); Response.Redirect(Request.Url.AbsolutePath + "?" + GetQueryByParameterList(parameters)); }
/// <summary> /// /// </summary> /// <param name="outer_id"></param> /// <param name="mall_item_id"></param> /// <returns></returns> public bool MappingProduct(string outer_id, string mall_item_id) { ItemUpdateRequest req = new ItemUpdateRequest(); req.NumIid = long.Parse(mall_item_id); req.OuterId = outer_id; ItemUpdateResponse response = client.Execute(req, this.Access_Token.Access_Token1); if (response.IsError) { throw new KMJXCException(response.SubErrMsg); } return(true); }
protected void lbtnSave_Click(object sender, EventArgs e) { string html = ucTemplateEditor.GetHtml(); ITopClient client = GetProductTopClient(); ItemUpdateRequest req = new ItemUpdateRequest(); // SellerCatsGetRequest req = new SellerCatsGetRequest(); req.Desc = html; req.Iid = Request["Current"]; Item item = client.Execute(req, new ItemJsonParser(), CurrentSessionKey); Dictionary <string, string> parameters = GetParameterListByQuery(); parameters.Add("IsSuccess", "1"); parameters.Add("Message", "设置宝贝描述信息成功!"); Response.Redirect(Request.Url.AbsolutePath + "?" + GetQueryByParameterList(parameters)); }
void SetTaoBaoUpdateData(ItemUpdateRequest req, DataRow row) { req.StuffStatus = (row["StuffStatus"] == DBNull.Value) ? "" : ((string)row["StuffStatus"]); req.Cid = new long?((long)row["Cid"]); req.Price = ((decimal)row["SalePrice"]).ToString("F2"); req.Num = new long?((long)row["Num"]); req.OuterId = (row["ProductCode"] == DBNull.Value) ? "" : ((string)row["ProductCode"]); req.LocationState = (string)row["LocationState"]; req.LocationCity = (string)row["LocationCity"]; req.HasShowcase = true; req.HasInvoice = new bool?((bool)row["HasInvoice"]); req.HasWarranty = new bool?((bool)row["HasWarranty"]); req.HasDiscount = new bool?((bool)row["HasDiscount"]); if (row["ValidThru"] != DBNull.Value) { req.ValidThru = new long?((long)row["ValidThru"]); } if (row["ListTime"] != DBNull.Value) { req.ListTime = new DateTime?((DateTime)row["ListTime"]); } if (((string)row["FreightPayer"]) == "seller") { req.FreightPayer = "seller"; } else { req.FreightPayer = "buyer"; req.PostFee = (row["PostFee"] == DBNull.Value) ? "" : ((decimal)row["PostFee"]).ToString("F2"); req.ExpressFee = (row["ExpressFee"] == DBNull.Value) ? "" : ((decimal)row["ExpressFee"]).ToString("F2"); req.EmsFee = (row["EMSFee"] == DBNull.Value) ? "" : ((decimal)row["EMSFee"]).ToString("F2"); } req.Props = (row["PropertyAlias"] == DBNull.Value) ? "" : ((string)row["PropertyAlias"]); req.InputPids = (row["InputPids"] == DBNull.Value) ? "" : ((string)row["InputPids"]); req.InputStr = (row["InputStr"] == DBNull.Value) ? "" : ((string)row["InputStr"]); req.SkuProperties = (row["SkuProperties"] == DBNull.Value) ? "" : ((string)row["SkuProperties"]); req.SkuQuantities = (row["SkuQuantities"] == DBNull.Value) ? "" : ((string)row["SkuQuantities"]); req.SkuPrices = (row["SkuPrices"] == DBNull.Value) ? "" : ((string)row["SkuPrices"]); req.SkuOuterIds = (row["SkuOuterIds"] == DBNull.Value) ? "" : ((string)row["SkuOuterIds"]); req.Lang = "zh_CN"; }
private Item UpdateGoodsBase(ItemUpdateRequest req, long?numiid, string outerId, string title) { _log.LogInfo(Resource.Log_UpdateGoodsing.StringFormat(numiid, outerId)); var tContext = InstanceLocator.Current.GetInstance <AuthorizedContext>(); ItemUpdateResponse response = _client.Execute(req, tContext.SessionKey); if (response.IsError) { var ex = new TopResponseException(response.ErrCode, response.ErrMsg, response.SubErrCode, response.SubErrMsg, response.TopForbiddenFields); _log.LogError(Resource.Log_UpdateGoodsFailure.StringFormat(numiid, outerId), ex); throw ex; } Item item = response.Item; _log.LogInfo(Resource.Log_UpdateGoodsSuccess, title, item.NumIid); return(item); }
public void CopyModel() { BanggoProduct product = new BanggoProduct(); product.NumIid = 18623029094; product.PropertyAlias = "1627207:3232483:粉紫色组(70色);20509:28381:155/80A(S)(24242);20509:28313:160/84A(M)(24244);20509:28314:170/92A(XL)(24248);"; product.Props = "1627207:3232483;20509:28381;20509:28313;20509:28314;"; product.SkuOuterIds = "242591,242591,242591"; product.SkuPrices = "178,178,178"; product.SkuProperties = "1627207:3232483;20509:28381,1627207:3232483;20509:28313,1627207:3232483;20509:28314"; product.SkuQuantities = "2,5,1"; ItemUpdateRequest req = new ItemUpdateRequest(); Util.CopyModel(product, req); FileHelper.WriteText("ItemUpdateRequestTest.html", req.DumpProperties(), Encoding.UTF8); FileHelper.WriteText("ProductTest.html", product.DumpProperties(), Encoding.UTF8); }
/// <summary> /// 更新淘宝商品的描述内容 /// </summary> /// <param name="p"></param> /// <param name="newContent"></param> private void UpdateProductInfo(long p, string newContent) { TopXmlRestClient client = new TopXmlRestClient("http://gw.api.taobao.com/router/rest", "12132145", "1fdd2aadd5e2ac2909db2967cbb71e7f"); Cookie cookie = new Cookie(); string taobaoNick = cookie.getCookie("nick"); string session = cookie.getCookie("top_session"); ItemUpdateRequest request = new ItemUpdateRequest(); request.NumIid = p; request.Desc = newContent; client.ItemUpdate(request, session); Response.Write("http://item.taobao.com/item.htm?id=" + p); Response.Write("<br><br>"); Response.Write(newContent); Response.End(); }
public void ProcessRequest(HttpContext context) { string appkey = context.Request.Form["appkey"]; string appsecret = context.Request.Form["appsecret"]; string sessionkey = context.Request.Form["sessionkey"]; string productIds = context.Request.Form["productIds"]; string approve_status = context.Request.Form["approve_status"]; string morepic = context.Request.Form["morepic"]; string repub = context.Request.Form["repub"]; string chkdesc = context.Request.Form["chkdesc"]; string chknormal = context.Request.Form["chknormal"]; string chktitle = context.Request.Form["chktitle"]; if (!string.IsNullOrEmpty(appkey) && !string.IsNullOrEmpty(appsecret)) { this.client = new DefaultTopClient("http://gw.api.taobao.com/router/rest", appkey, appsecret, "json"); } DataTable taobaoProducts = SubSiteProducthelper.GetTaobaoProducts(productIds); if (null != taobaoProducts && taobaoProducts.Rows.Count > 0) { Dictionary<int, long> taobaoReturnProductIds = new Dictionary<int, long>(); StringBuilder builder = new StringBuilder(); string pname = ""; int num = 0; string imgurl = ""; int stock = 0; decimal markprice = 0M; string issuccess = "true"; string msg = ""; string imgmsg = ""; string proTitle = "";// (string)row["ProTitle"]; foreach (DataRow row in taobaoProducts.Rows) { proTitle = (string)row["ProTitle"]; ResponseData(row, out imgurl, out stock, out markprice); if ((row["taobaoproductid"] != DBNull.Value) && (repub.ToLower() == "true")) { ItemUpdateRequest req = new ItemUpdateRequest(); req.NumIid = new long?(Convert.ToInt64(row["taobaoproductid"])); req.ApproveStatus = approve_status; if (!string.IsNullOrEmpty(chknormal) && (chknormal.ToLower() == "true")) { this.SetTaoBaoUpdateData(req, row); } if (!string.IsNullOrEmpty(chktitle) && (chktitle.ToLower() == "true")) { req.Title = (row["ProTitle"] == DBNull.Value) ? "请修改商品标题" : ((string)row["ProTitle"]); } if (!string.IsNullOrEmpty(chkdesc) && (chkdesc.ToLower() == "true")) { req.Desc = (row["Description"] == DBNull.Value) ? "暂无该商品的描述信息" : ((string)row["Description"]); } ItemUpdateResponse response = client.Execute<ItemUpdateResponse>(req, sessionkey); if (response.IsError) { num = (int)row["ProductId"]; pname = string.Format("<a href='{0}' target=_blank>{1} </a>", Globals.GetSiteUrls().UrlData.FormatUrl("productDetails", new object[] { num }), proTitle); imgurl = string.Format("<a href='{0}' target=_blank><img src={1} /></a>", Globals.GetSiteUrls().UrlData.FormatUrl("productDetails", new object[] { num }), imgurl); msg = string.Format("商品更新失败<br/>({0})", ":" + response.ErrMsg + ":" + response.SubErrMsg); issuccess = "false"; } else { imgurl = string.Format("<a href='http://item.taobao.com/item.htm?id={0}' target=_blank><img src={1} /></a>", response.Item.NumIid, imgurl); pname = string.Format("<a href='http://item.taobao.com/item.htm?id={0}'>{1}</a>", response.Item.NumIid, proTitle); msg = "商品更新成功"; issuccess = "true"; taobaoReturnProductIds.Add((int)row["ProductId"], response.Item.NumIid); } } else { ItemAddRequest req = new ItemAddRequest(); req.ApproveStatus = approve_status; SetTaoBaoAddData(req, row); ItemAddResponse response2 = client.Execute<ItemAddResponse>(req, sessionkey); if (response2.IsError) { num = (int)row["ProductId"]; pname = string.Format("<a href='{0}' target=_blank>{1} </a>", Globals.GetSiteUrls().UrlData.FormatUrl("productDetails", new object[] { num }), proTitle); imgurl = string.Format("<a href='{0}' target=_blank><img src={1} /></a>", Globals.GetSiteUrls().UrlData.FormatUrl("productDetails", new object[] { num }), imgurl); msg = string.Format("发布失败<br/>({0})", response2.ErrMsg + ":" + response2.SubErrMsg); issuccess = "false"; } else { imgurl = string.Format("<a href='http://item.taobao.com/item.htm?id={0}' target=_blank><img src={1} /></a>", response2.Item.NumIid, imgurl); pname = string.Format("<a href='http://item.taobao.com/item.htm?id={0}'>{1}</a>", response2.Item.NumIid, proTitle); msg = "商品发布成功"; issuccess = "true"; taobaoReturnProductIds.Add((int)row["ProductId"], response2.Item.NumIid); if (morepic == "true") { List<TbImage> productsImgs = this.GetProductsImgs(row, response2); StringBuilder builder2 = new StringBuilder(); foreach (TbImage image in productsImgs) { string path = Globals.ApplicationPath + image.Imgpath; if (File.Exists(Globals.MapPath(path))) { FileItem item = new FileItem(Globals.MapPath(path)); ItemImgUploadRequest request = new ItemImgUploadRequest(); request.Image = item; request.NumIid = new long?(image.TbProductId); request.IsMajor = false; ItemImgUploadResponse itemImgUploadResponse = this.client.Execute<ItemImgUploadResponse>(request, sessionkey); if (itemImgUploadResponse.IsError) { builder2.AppendFormat("[\"{0}发布图片错误,错误原因:{1}\"],", proTitle, itemImgUploadResponse.ErrMsg + ";" + itemImgUploadResponse.SubErrMsg); } } } if (builder2.Length > 0) { imgmsg = builder2.ToString().Substring(0, builder2.ToString().Length - 1); } } } } builder.Append(string.Concat(new object[] { "{\"pname\":\"", pname, "\",\"pimg\":\"", imgurl, "\",\"pmarkprice\":\"", markprice.ToString("F2"), "\",\"pstock\":\"", stock, "\",\"issuccess\":\"", issuccess, "\",\"msg\":\"", msg, "\",\"imgmsg\":[", imgmsg, "]}," })); } if (taobaoReturnProductIds.Count > 0) { SubSiteProducthelper.AddTaobaoReturnProductIds(taobaoReturnProductIds, 0); } if (builder.ToString().Length > 0) { builder.Remove(builder.Length - 1, 1); } context.Response.Write("{\"Status\":\"OK\",\"Result\":[" + builder.ToString() + "]}"); context.Response.Flush(); context.Response.End(); } else { context.Response.Write("{\"Status\":\"Error\",\"Result\":\"发布商品到淘宝出错!\"}"); context.Response.Flush(); context.Response.End(); } }
void SetTaoBaoUpdateData(ItemUpdateRequest req, DataRow row) { req.StuffStatus = (row["StuffStatus"] == DBNull.Value) ? "" : ((string)row["StuffStatus"]); req.Cid = new long?((long)row["Cid"]); req.Price = ((decimal)row["SalePrice"]).ToString("F2"); req.Num = new long?((long)row["Num"]); req.OuterId = (row["ProductCode"] == DBNull.Value) ? "" : ((string)row["ProductCode"]); req.LocationState = (string)row["LocationState"]; req.LocationCity = (string)row["LocationCity"]; req.HasShowcase = true; req.HasInvoice = new bool?((bool)row["HasInvoice"]); req.HasWarranty = new bool?((bool)row["HasWarranty"]); req.HasDiscount = new bool?((bool)row["HasDiscount"]); if (row["ValidThru"] != DBNull.Value) { req.ValidThru = new long?((long)row["ValidThru"]); } if (row["ListTime"] != DBNull.Value) { req.ListTime = new DateTime?((DateTime)row["ListTime"]); } if (((string)row["FreightPayer"]) == "seller") { req.FreightPayer = "seller"; } else { req.FreightPayer = "buyer"; req.PostFee = (row["PostFee"] == DBNull.Value) ? "" : ((decimal)row["PostFee"]).ToString("F2"); req.ExpressFee = (row["ExpressFee"] == DBNull.Value) ? "" : ((decimal)row["ExpressFee"]).ToString("F2"); req.EmsFee = (row["EMSFee"] == DBNull.Value) ? "" : ((decimal)row["EMSFee"]).ToString("F2"); } req.Props = (row["PropertyAlias"] == DBNull.Value) ? "" : ((string)row["PropertyAlias"]); req.InputPids = (row["InputPids"] == DBNull.Value) ? "" : ((string)row["InputPids"]); req.InputStr = (row["InputStr"] == DBNull.Value) ? "" : ((string)row["InputStr"]); req.SkuProperties = (row["SkuProperties"] == DBNull.Value) ? "" : ((string)row["SkuProperties"]); req.SkuQuantities = (row["SkuQuantities"] == DBNull.Value) ? "" : ((string)row["SkuQuantities"]); req.SkuPrices = (row["SkuPrices"] == DBNull.Value) ? "" : ((string)row["SkuPrices"]); req.SkuOuterIds = (row["SkuOuterIds"] == DBNull.Value) ? "" : ((string)row["SkuOuterIds"]); req.Lang = "zh_CN"; }
public void ProcessRequest(HttpContext context) { string appkey = context.Request.Form["appkey"]; string appsecret = context.Request.Form["appsecret"]; string sessionkey = context.Request.Form["sessionkey"]; string productIds = context.Request.Form["productIds"]; string approve_status = context.Request.Form["approve_status"]; string morepic = context.Request.Form["morepic"]; string repub = context.Request.Form["repub"]; string chkdesc = context.Request.Form["chkdesc"]; string chknormal = context.Request.Form["chknormal"]; string chktitle = context.Request.Form["chktitle"]; if (!string.IsNullOrEmpty(appkey) && !string.IsNullOrEmpty(appsecret)) { this.client = new DefaultTopClient("http://gw.api.taobao.com/router/rest", appkey, appsecret, "json"); } DataTable taobaoProducts = SubSiteProducthelper.GetTaobaoProducts(productIds); if (null != taobaoProducts && taobaoProducts.Rows.Count > 0) { Dictionary <int, long> taobaoReturnProductIds = new Dictionary <int, long>(); StringBuilder builder = new StringBuilder(); string pname = ""; int num = 0; string imgurl = ""; int stock = 0; decimal markprice = 0M; string issuccess = "true"; string msg = ""; string imgmsg = ""; string proTitle = "";// (string)row["ProTitle"]; foreach (DataRow row in taobaoProducts.Rows) { proTitle = (string)row["ProTitle"]; ResponseData(row, out imgurl, out stock, out markprice); if ((row["taobaoproductid"] != DBNull.Value) && (repub.ToLower() == "true")) { ItemUpdateRequest req = new ItemUpdateRequest(); req.NumIid = new long?(Convert.ToInt64(row["taobaoproductid"])); req.ApproveStatus = approve_status; if (!string.IsNullOrEmpty(chknormal) && (chknormal.ToLower() == "true")) { this.SetTaoBaoUpdateData(req, row); } if (!string.IsNullOrEmpty(chktitle) && (chktitle.ToLower() == "true")) { req.Title = (row["ProTitle"] == DBNull.Value) ? "请修改商品标题" : ((string)row["ProTitle"]); } if (!string.IsNullOrEmpty(chkdesc) && (chkdesc.ToLower() == "true")) { req.Desc = (row["Description"] == DBNull.Value) ? "暂无该商品的描述信息" : ((string)row["Description"]); } ItemUpdateResponse response = client.Execute <ItemUpdateResponse>(req, sessionkey); if (response.IsError) { num = (int)row["ProductId"]; pname = string.Format("<a href='{0}' target=_blank>{1} </a>", Globals.GetSiteUrls().UrlData.FormatUrl("productDetails", new object[] { num }), proTitle); imgurl = string.Format("<a href='{0}' target=_blank><img src={1} /></a>", Globals.GetSiteUrls().UrlData.FormatUrl("productDetails", new object[] { num }), imgurl); msg = string.Format("商品更新失败<br/>({0})", ":" + response.ErrMsg + ":" + response.SubErrMsg); issuccess = "false"; } else { imgurl = string.Format("<a href='http://item.taobao.com/item.htm?id={0}' target=_blank><img src={1} /></a>", response.Item.NumIid, imgurl); pname = string.Format("<a href='http://item.taobao.com/item.htm?id={0}'>{1}</a>", response.Item.NumIid, proTitle); msg = "商品更新成功"; issuccess = "true"; taobaoReturnProductIds.Add((int)row["ProductId"], response.Item.NumIid); } } else { ItemAddRequest req = new ItemAddRequest(); req.ApproveStatus = approve_status; SetTaoBaoAddData(req, row); ItemAddResponse response2 = client.Execute <ItemAddResponse>(req, sessionkey); if (response2.IsError) { num = (int)row["ProductId"]; pname = string.Format("<a href='{0}' target=_blank>{1} </a>", Globals.GetSiteUrls().UrlData.FormatUrl("productDetails", new object[] { num }), proTitle); imgurl = string.Format("<a href='{0}' target=_blank><img src={1} /></a>", Globals.GetSiteUrls().UrlData.FormatUrl("productDetails", new object[] { num }), imgurl); msg = string.Format("发布失败<br/>({0})", response2.ErrMsg + ":" + response2.SubErrMsg); issuccess = "false"; } else { imgurl = string.Format("<a href='http://item.taobao.com/item.htm?id={0}' target=_blank><img src={1} /></a>", response2.Item.NumIid, imgurl); pname = string.Format("<a href='http://item.taobao.com/item.htm?id={0}'>{1}</a>", response2.Item.NumIid, proTitle); msg = "商品发布成功"; issuccess = "true"; taobaoReturnProductIds.Add((int)row["ProductId"], response2.Item.NumIid); if (morepic == "true") { List <TbImage> productsImgs = this.GetProductsImgs(row, response2); StringBuilder builder2 = new StringBuilder(); foreach (TbImage image in productsImgs) { string path = Globals.ApplicationPath + image.Imgpath; if (File.Exists(Globals.MapPath(path))) { FileItem item = new FileItem(Globals.MapPath(path)); ItemImgUploadRequest request = new ItemImgUploadRequest(); request.Image = item; request.NumIid = new long?(image.TbProductId); request.IsMajor = false; ItemImgUploadResponse itemImgUploadResponse = this.client.Execute <ItemImgUploadResponse>(request, sessionkey); if (itemImgUploadResponse.IsError) { builder2.AppendFormat("[\"{0}发布图片错误,错误原因:{1}\"],", proTitle, itemImgUploadResponse.ErrMsg + ";" + itemImgUploadResponse.SubErrMsg); } } } if (builder2.Length > 0) { imgmsg = builder2.ToString().Substring(0, builder2.ToString().Length - 1); } } } } builder.Append(string.Concat(new object[] { "{\"pname\":\"", pname, "\",\"pimg\":\"", imgurl, "\",\"pmarkprice\":\"", markprice.ToString("F2"), "\",\"pstock\":\"", stock, "\",\"issuccess\":\"", issuccess, "\",\"msg\":\"", msg, "\",\"imgmsg\":[", imgmsg, "]}," })); } if (taobaoReturnProductIds.Count > 0) { SubSiteProducthelper.AddTaobaoReturnProductIds(taobaoReturnProductIds, 0); } if (builder.ToString().Length > 0) { builder.Remove(builder.Length - 1, 1); } context.Response.Write("{\"Status\":\"OK\",\"Result\":[" + builder.ToString() + "]}"); context.Response.Flush(); context.Response.End(); } else { context.Response.Write("{\"Status\":\"Error\",\"Result\":\"发布商品到淘宝出错!\"}"); context.Response.Flush(); context.Response.End(); } }
private Item UpdateGoodsBase(ItemUpdateRequest req, long? numiid, string outerId, string title) { _log.LogInfo(Resource.Log_UpdateGoodsing.StringFormat(numiid, outerId)); var tContext = InstanceLocator.Current.GetInstance<AuthorizedContext>(); ItemUpdateResponse response = _client.Execute(req, tContext.SessionKey); if (response.IsError) { var ex = new TopResponseException(response.ErrCode, response.ErrMsg, response.SubErrCode, response.SubErrMsg, response.TopForbiddenFields); _log.LogError(Resource.Log_UpdateGoodsFailure.StringFormat(numiid, outerId), ex); throw ex; } Item item = response.Item; _log.LogInfo(Resource.Log_UpdateGoodsSuccess, title, item.NumIid); return item; }
public Item UpdateGoods(Product product) { var req = new ItemUpdateRequest(); Util.CopyModel(product, req); return UpdateGoodsBase(req, product.NumIid, product.OuterId, product.Title); }
public async Task <IActionResult> UpdateItem([FromForm] ItemUpdateRequest request) { Item item = await _itemRepository.FindByID(request.ItemID); if (item == null) { return(StatusCode((int)HttpStatusCode.NotFound, new ErrorResponse(ErrorReasons.NotFound, "Item with such ID was not found"))); } if (request.SKU != item.SKU && await _itemRepository.SkuExists(request.SKU)) { return(StatusCode((int)HttpStatusCode.BadRequest, new ErrorResponse(ErrorReasons.BadRequest, "Item with this SKU already exists!"))); } Category category = await _categoryRepository.FindByID(request.CategoryID); if (category == null) { _logger.LogInformation($"No category found with id {request.CategoryID}"); return(StatusCode((int)HttpStatusCode.NotFound, new ErrorResponse(ErrorReasons.NotFound, "Category was not found"))); } if (request.SubcategoryID.HasValue) { SubCategory subCategory = await _categoryRepository.FindSubCategoryByID(request.SubcategoryID.Value); if (subCategory == null) { _logger.LogInformation($"No subcategory found with id {request.SubcategoryID.Value}"); return(StatusCode((int)HttpStatusCode.NotFound, new ErrorResponse(ErrorReasons.NotFound, "Subcategory was not found"))); } } List <string> pictureURLs = BuildPictureUrlList(request.PictureURLs, request.PictureFiles); using (var transaction = await _attributeRepository.Context.Database.BeginTransactionAsync()) { await CreateNewAttributes(request.Attributes); Item modifiedItem = new Item() { Description = request.Description, Name = request.Name, Price = request.Price, SKU = request.SKU, CategoryID = request.CategoryID, SubCategoryID = request.SubcategoryID, Pictures = pictureURLs.Select(x => new ItemPicture() { URL = x }).ToList(), Attributes = request.Attributes ?.Select(x => new AttributeValue() { AttributeID = x.AttributeID, Value = x.Value }) ?.ToList(), Timestamp = request.Force ? item.Timestamp : request.OptLockVersion }; await _itemRepository.Update(item, modifiedItem); try { await _itemRepository.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(StatusCode((int)HttpStatusCode.Conflict)); } transaction.Commit(); } return(StatusCode((int)HttpStatusCode.NoContent)); }
/// <summary> /// 更新商品信息 /// </summary> internal bool UpdateGood(string sessionKey, ItemUpdate goods, out string ErrorMsg) { ErrorMsg = null; ITopClient client = new DefaultTopClient(StaticSystemConfig.soft.ApiURL, StaticSystemConfig.soft.AppKey, StaticSystemConfig.soft.AppSecret, "json"); ItemUpdateRequest req = new ItemUpdateRequest(); #region 将页面数据填充到request中 if (goods.NumIid == null) { ErrorMsg = "商品ID不能为空"; return(false); } else { req.NumIid = goods.NumIid; } if (goods.Cid != null) { req.Cid = goods.Cid; } if (goods.Props != null) { req.Props = goods.Props; } if (goods.Num != null) { req.Num = goods.Num; } if (goods.Price != null) { req.Price = goods.Price; } if (goods.Title != null) { req.Title = goods.Title; } if (goods.Desc != null) { req.Desc = goods.Desc; } if (goods.LocationState != null) { req.LocationState = goods.LocationState; } if (goods.LocationCity != null) { req.LocationCity = goods.LocationCity; } if (goods.PostFee != null) { req.PostFee = goods.PostFee; } if (goods.ExpressFee != null) { req.ExpressFee = goods.ExpressFee; } if (goods.EmsFee != null) { req.EmsFee = goods.EmsFee; } if (goods.ListTime != null) { DateTime dateTime = DateTime.Parse("2000-01-01 00:00:00"); req.ListTime = dateTime; } if (goods.Cid != null) { req.Increment = goods.Increment; } if (goods.Image != null) { //括号中中填文件路径 FileItem fItem = new FileItem(goods.Image[0].ToString()); req.Image = fItem; } if (goods.StuffStatus != null) { req.StuffStatus = goods.StuffStatus; } if (goods.AuctionPoint != null) { req.AuctionPoint = goods.AuctionPoint; } if (goods.PropertyAlias != null) { req.PropertyAlias = goods.PropertyAlias; } if (goods.InputPids != null) { req.InputPids = goods.InputPids; } if (goods.SkuQuantities != null) { req.SkuQuantities = goods.SkuQuantities; } if (goods.SkuPrices != null) { req.SkuPrices = goods.SkuPrices; } if (goods.SkuProperties != null) { req.SkuProperties = "pid:vid;pid:vid"; } if (goods.SellerCids != null) { req.SellerCids = goods.SellerCids; } if (goods.PostageId != null) { req.PostageId = goods.PostageId; } if (goods.OuterId != null) { req.OuterId = goods.OuterId; } if (goods.ProductId != null) { req.ProductId = goods.ProductId; } if (goods.PicPath != null) { req.PicPath = goods.PicPath; } if (goods.AutoFill != null) { req.AutoFill = goods.AutoFill; } if (goods.SkuOuterIds != null) { req.SkuOuterIds = goods.SkuOuterIds; } if (goods.IsTaobao != null) { req.IsTaobao = goods.IsTaobao; } if (goods.IsEx != null) { req.IsEx = goods.IsEx; } if (goods.Is3D != null) { req.Is3D = goods.Is3D; } if (goods.IsReplaceSku != null) { req.IsReplaceSku = goods.IsReplaceSku; } if (goods.InputStr != null) { req.InputStr = goods.InputStr; } if (goods.Lang != null) { req.Lang = goods.Lang; } if (goods.HasDiscount != null) { req.HasDiscount = goods.HasDiscount; } if (goods.HasShowcase != null) { req.HasShowcase = goods.HasShowcase; } if (goods.ApproveStatus != null) { req.ApproveStatus = goods.ApproveStatus; } if (goods.FreightPayer != null) { req.FreightPayer = goods.FreightPayer; } if (goods.ValidThru != null) { req.ValidThru = goods.ValidThru; } if (goods.HasInvoice != null) { req.HasInvoice = goods.HasInvoice; } if (goods.HasWarranty != null) { req.HasWarranty = goods.HasWarranty; } if (goods.AfterSaleId != null) { req.AfterSaleId = goods.AfterSaleId; } if (goods.SellPromise != null) { req.SellPromise = goods.SellPromise; } if (goods.CodPostageId != null) { req.CodPostageId = goods.CodPostageId; } if (goods.IsLightningConsignment != null) { req.IsLightningConsignment = goods.IsLightningConsignment; } if (goods.Weight != null) { req.Weight = goods.Weight; } if (goods.IsXinpin != null) { req.IsXinpin = goods.IsXinpin; } if (goods.SubStock != null) { req.SubStock = goods.SubStock; } if (goods.FoodSecurityPrdLicenseNo != null) { req.FoodSecurityPrdLicenseNo = goods.FoodSecurityPrdLicenseNo; } if (goods.FoodSecurityDesignCode != null) { req.FoodSecurityDesignCode = goods.FoodSecurityDesignCode; } if (goods.FoodSecurityFactory != null) { req.FoodSecurityFactory = goods.FoodSecurityFactory; } if (goods.FoodSecurityFactorySite != null) { req.FoodSecurityFactorySite = goods.FoodSecurityFactorySite; } if (goods.FoodSecurityContact != null) { req.FoodSecurityContact = goods.FoodSecurityContact; } if (goods.FoodSecurityMix != null) { req.FoodSecurityMix = goods.FoodSecurityMix; } if (goods.FoodSecurityPlanStorage != null) { req.FoodSecurityPlanStorage = goods.FoodSecurityPlanStorage; } if (goods.FoodSecurityPeriod != null) { req.FoodSecurityPeriod = goods.FoodSecurityPeriod; } if (goods.FoodSecurityFoodAdditive != null) { req.FoodSecurityFoodAdditive = goods.FoodSecurityFoodAdditive; } if (goods.FoodSecuritySupplier != null) { req.FoodSecuritySupplier = goods.FoodSecuritySupplier; } if (goods.FoodSecurityProductDateStart != null) { req.FoodSecurityProductDateStart = goods.FoodSecurityProductDateStart; } if (goods.FoodSecurityProductDateEnd != null) { req.FoodSecurityProductDateEnd = goods.FoodSecurityProductDateEnd; } if (goods.FoodSecurityStockDateStart != null) { req.FoodSecurityStockDateStart = goods.FoodSecurityStockDateStart; } if (goods.FoodSecurityStockDateEnd != null) { req.FoodSecurityStockDateEnd = goods.FoodSecurityStockDateEnd; } if (goods.SkuSpecIds != null) { req.SkuSpecIds = goods.SkuSpecIds; } if (goods.ItemSize != null) { req.ItemSize = goods.ItemSize; } if (goods.ItemWeight != null) { req.ItemWeight = goods.ItemWeight; } if (goods.ChangeProp != null) { req.ChangeProp = goods.ChangeProp; } if (goods.SellPoint != null) { req.SellPoint = goods.SellPoint; } if (goods.DescModules != null) { req.DescModules = goods.DescModules; } if (goods.FoodSecurityHealthProductNo != null) { req.FoodSecurityHealthProductNo = goods.FoodSecurityHealthProductNo; } if (goods.Barcode != null) { req.Barcode = goods.Barcode; } if (goods.SkuBarcode != null) { req.SkuBarcode = goods.SkuBarcode; } if (goods.Newprepay != null) { req.Newprepay = goods.Newprepay; } if (goods.IsOffline != null) { req.IsOffline = goods.IsOffline; } if (goods.ChaoshiExtendsInfo != null) { req.ChaoshiExtendsInfo = goods.ChaoshiExtendsInfo; } if (goods.SkuHdLength != null) { req.SkuHdLength = goods.SkuHdLength; } if (goods.SkuHdHeight != null) { req.SkuHdHeight = goods.SkuHdHeight; } if (goods.SkuHdLampQuantity != null) { req.SkuHdLampQuantity = goods.SkuHdLampQuantity; } if (goods.Qualification != null) { req.Qualification = goods.Qualification; } if (goods.O2oBindService != null) { req.O2oBindService = goods.O2oBindService; } if (goods.Ignorewarning != null) { req.Ignorewarning = goods.Ignorewarning; } if (goods.EmptyFields != null) { req.EmptyFields = goods.EmptyFields; } if (goods.LocalityLifeExpirydate != null) { req.LocalityLifeExpirydate = goods.LocalityLifeExpirydate; } if (goods.LocalityLifeNetworkId != null) { req.LocalityLifeNetworkId = goods.LocalityLifeNetworkId; } if (goods.LocalityLifeMerchant != null) { req.LocalityLifeMerchant = goods.LocalityLifeMerchant; } if (goods.LocalityLifeVerification != null) { req.LocalityLifeVerification = goods.LocalityLifeVerification; } if (goods.LocalityLifeRefundRatio != null) { req.LocalityLifeRefundRatio = goods.LocalityLifeRefundRatio; } if (goods.LocalityLifeChooseLogis != null) { req.LocalityLifeChooseLogis = goods.LocalityLifeChooseLogis; } if (goods.LocalityLifeOnsaleAutoRefundRatio != null) { req.LocalityLifeOnsaleAutoRefundRatio = goods.LocalityLifeOnsaleAutoRefundRatio; } if (goods.LocalityLifeRefundmafee != null) { req.LocalityLifeRefundmafee = goods.LocalityLifeRefundmafee; } if (goods.ScenicTicketPayWay != null) { req.ScenicTicketPayWay = goods.ScenicTicketPayWay; } if (goods.ScenicTicketBookCost != null) { req.ScenicTicketBookCost = goods.ScenicTicketBookCost; } if (goods.PaimaiInfoMode != null) { req.PaimaiInfoMode = goods.PaimaiInfoMode; } if (goods.PaimaiInfoDeposit != null) { req.PaimaiInfoDeposit = goods.PaimaiInfoDeposit; } if (goods.PaimaiInfoInterval != null) { req.PaimaiInfoInterval = goods.PaimaiInfoInterval; } if (goods.PaimaiInfoReserve != null) { req.PaimaiInfoReserve = goods.PaimaiInfoReserve; } if (goods.PaimaiInfoValidHour != null) { req.PaimaiInfoValidHour = goods.PaimaiInfoValidHour; } if (goods.PaimaiInfoValidMinute != null) { req.PaimaiInfoValidMinute = goods.PaimaiInfoValidMinute; } if (goods.GlobalStockType != null) { req.GlobalStockType = goods.GlobalStockType; } if (goods.GlobalStockCountry != null) { req.GlobalStockCountry = goods.GlobalStockCountry; } #endregion ItemUpdateResponse response = client.Execute(req, sessionKey); if (!response.IsError) { return(true); } else { ErrorMsg = response.SubErrMsg; return(false); } }
/// <summary> /// /// </summary> /// <param name="outer_id"></param> /// <param name="mall_item_id"></param> /// <returns></returns> public bool MappingProduct(string outer_id, string mall_item_id) { ItemUpdateRequest req=new ItemUpdateRequest(); req.NumIid = long.Parse(mall_item_id); req.OuterId = outer_id; ItemUpdateResponse response = client.Execute(req, this.Access_Token.Access_Token1); if (response.IsError) { throw new KMJXCException(response.SubErrMsg); } return true; }
public IActionResult Atualizar([FromBody] ItemUpdateRequest req) { if (!ModelState.IsValid) { return(Response <ItemUpdateRequest>(req)); } if (!ValidarPreenchimentoFaixaValor(req.TipoItem, req.ValorFaixaId, out IActionResult result)) { return(result); } // Validando quanidade de imagens if (!ValidaQuantidadeImagens(req.Id, req.ImgExcluir, req.Imagens, out string criticas)) { return(BadRequest(new { sucess = false, mensagem = criticas })); } var dto = new ItemDto() { Id = req.Id, Titulo = req.Titulo, Descricao = req.Descricao, TipoItem = new TipoItemDto() { Descricao = (req.TipoItem.Equals(1) ? "Necessidade" : "Doação") }, Categoria = new CategoriaDto() { Id = req.CategoriaId.Value }, Usuario = new UsuarioDto() { Id = _appUser.Id }, Campanha = (req.CampanhaId.HasValue ? new CampanhaDto() { Id = req.CampanhaId.Value } : null), Anonimo = req.Anonimo }; if (req.TipoItem.Equals(1)) { dto.ValorFaixa = new ValorFaixaDto() { Id = req.ValorFaixaId.Value } } ; else { dto.ValorFaixa = null; } _appService.Atualizar(dto, out int statusCode, out string mensagem); var respExclusao = ExcluirImagens(req.ImgExcluir); IEnumerable <object> respImage = CarregarImagens(dto.Id, req.Imagens); return(StatusCode(statusCode, new { sucesso = statusCode.Equals(StatusCodes.Status200OK), mensagem, imagens = respImage, imgExclusao = respExclusao })); }
/// <summary> /// taobao.item.update /// 更新商品信息 /// </summary> /// <param name="item">参考DataContract.ProductItem</param> /// <returns></returns> public static Item UpdateItem(ProductItem item) { ITopClient client = TopClientService.GetTopClient(); ItemUpdateRequest req = new ItemUpdateRequest(); req.NumIid = item.NumIid; req.Cid = item.Cid; req.Props = item.Props; req.Num = item.Num; req.Price = item.Price; req.Title = item.Title; req.Desc = item.Desc; req.LocationState = item.LocationState; req.LocationCity = item.LocationCity; req.PostFee = item.PostFee; req.ExpressFee = item.ExpressFee; req.EmsFee = item.EmsFee; req.ListTime = item.ListTime; req.Increment = item.Increment; FileItem fItem = new FileItem(item.ImgFilePath); req.Image = fItem; req.StuffStatus = item.StuffStatus; req.AuctionPoint = item.AuctionPoint; req.PropertyAlias = item.PropertyAlias; req.InputPids = item.InputPids; req.SkuQuantities = item.SkuQuantities; req.SkuPrices = item.SkuPrices; req.SkuProperties = item.SkuProperties; req.SellerCids = item.SellerCids; req.PostageId = item.PostageId; req.OuterId = item.OuterId; req.ProductId = item.ProductId; req.PicPath = item.PicPath; req.AutoFill = item.AutoFill; req.SkuOuterIds = item.SkuOuterIds; req.IsTaobao = item.IsTaobao; req.IsEx = item.IsEx; req.Is3D = item.Is3D; req.IsReplaceSku = item.IsReplaceSku; req.InputStr = item.InputStr; req.Lang = item.Lang; req.HasDiscount = item.HasDiscount; req.HasShowcase = item.HasShowcase; req.ApproveStatus = item.ApproveStatus; req.FreightPayer = item.FreightPayer; req.ValidThru = item.ValidThru; req.HasInvoice = item.HasInvoice; req.HasWarranty = item.HasWarranty; req.AfterSaleId = item.AfterSaleId; req.SellPromise = item.SellPromise; req.CodPostageId = item.CodPostageId; req.IsLightningConsignment = item.IsLightningConsignment; req.Weight = item.Weight; req.IsXinpin = item.IsXinpin; req.SubStock = item.SubStock; req.FoodSecurityPrdLicenseNo = item.FoodSecurityPrdLicenseNo; req.FoodSecurityDesignCode = item.FoodSecurityDesignCode; req.FoodSecurityFactory = item.FoodSecurityFactory; req.FoodSecurityFactorySite = item.FoodSecurityFactorySite; req.FoodSecurityContact = item.FoodSecurityContact; req.FoodSecurityMix = item.FoodSecurityMix; req.FoodSecurityPlanStorage = item.FoodSecurityPlanStorage; req.FoodSecurityPeriod = item.FoodSecurityPeriod; req.FoodSecurityFoodAdditive = item.FoodSecurityFoodAdditive; req.FoodSecuritySupplier = item.FoodSecuritySupplier; req.FoodSecurityProductDateStart = item.FoodSecurityProductDateStart; req.FoodSecurityProductDateEnd = item.FoodSecurityProductDateEnd; req.FoodSecurityStockDateStart = item.FoodSecurityStockDateStart; req.FoodSecurityStockDateEnd = item.FoodSecurityStockDateEnd; req.SkuSpecIds = item.SkuSpecIds; req.ItemSize = item.ItemSize; req.ItemWeight = item.ItemWeight; req.ChangeProp = item.ChangeProp; req.SellPoint = item.SellPoint; req.DescModules = item.DescModules; req.FoodSecurityHealthProductNo = item.FoodSecurityHealthProductNo; req.EmptyFields = item.EmptyFields; req.LocalityLifeExpirydate = item.LocalityLifeExpirydate; req.LocalityLifeNetworkId = item.LocalityLifeNetworkId; req.LocalityLifeMerchant = item.LocalityLifeMerchant; req.LocalityLifeVerification = item.LocalityLifeVerification; req.LocalityLifeRefundRatio = item.LocalityLifeRefundRatio; req.LocalityLifeChooseLogis = item.LocalityLifeChooseLogis; req.LocalityLifeOnsaleAutoRefundRatio = item.LocalityLifeOnsaleAutoRefundRatio; req.LocalityLifeRefundmafee = item.LocalityLifeRefundmafee; req.ScenicTicketPayWay = item.ScenicTicketPayWay; req.ScenicTicketBookCost = item.ScenicTicketBookCost; req.PaimaiInfoMode = item.PaimaiInfoMode; req.PaimaiInfoDeposit = item.PaimaiInfoDeposit; req.PaimaiInfoInterval = item.PaimaiInfoInterval; req.PaimaiInfoReserve = item.PaimaiInfoReserve; req.PaimaiInfoValidHour = item.PaimaiInfoValidHour; req.PaimaiInfoValidMinute = item.PaimaiInfoValidMinute; req.GlobalStockType = item.GlobalStockType; req.GlobalStockCountry = item.GlobalStockCountry; ItemUpdateResponse response = client.Execute(req, SessionKey); return response.Item; }
public void UpdateGoodsSkuInfo( IRequest reqSource, IEnumerable <string> lstSearch, //要为款号 double discountRatio = 0.68, int stock = 3, string originalTitle = "xx", string newTitle = "xx", bool isModifyPrice = true) { foreach (var search in lstSearch) { if (search.IsEmptyString()) { continue; } List <Item> lstItem = GetOnSaleGoods(search); if (lstItem != null && lstItem.Count > 0) { #region 更新SKU信息 foreach (var item in lstItem) { Thread.Sleep(100); //获取产品原价 var oPrice = item.Title.GetNumberInt(); var req = new ItemUpdateRequest(); req.NumIid = item.NumIid; req.Title = item.Title.Replace(originalTitle, newTitle); req.LocationState = SysConst.LocationState; req.LocationCity = SysConst.LocationCity; if (isModifyPrice) { req.Price = (oPrice * discountRatio).ToType <int>().ToString(); } var skus = GetSkusByNumId(item.NumIid.ToString()).ToArray(); var lastSku = skus[skus.Count() - 1]; for (int i = 0; i < skus.Count() - 1; i++) { Thread.Sleep(100); var skuReq = new ItemSkuUpdateRequest() { NumIid = item.NumIid, Properties = skus[i].Properties, Quantity = stock, OuterId = item.OuterId }; if (isModifyPrice) { skuReq.Price = req.Price; } UpdateSku(skuReq); Thread.Sleep(100); } UpdateGoodsBase(req, item.NumIid, item.OuterId, req.Title); var skuLastReq = new ItemSkuUpdateRequest() { NumIid = item.NumIid, Properties = lastSku.Properties, Quantity = stock, OuterId = item.OuterId }; if (isModifyPrice) { skuLastReq.Price = req.Price; } UpdateSku(skuLastReq); } #endregion } else { PublishGoodsMain( reqSource, new RequestModel { GoodsSn = search, Referer = reqSource.GetGoodsUrl(search) }); } } }
private void Rename(long itemid,string newName) { tbClient = new DefaultTopClient(Config.ServerURL, Config.Appkey, Config.Secret); ItemUpdateRequest itemUpdateReq = new ItemUpdateRequest(); itemUpdateReq.NumIid = itemid; itemUpdateReq.Title = newName; ItemUpdateResponse itemUpdateResp = tbClient.Execute(itemUpdateReq,base.sessionkey); if (itemUpdateResp.IsError) { Alert(this, itemUpdateResp.ErrMsg); //错误日志 //itemUpdateResp.Body } }
public void UpdateGoodsSkuInfo( IRequest reqSource, IEnumerable<string> lstSearch, //要为款号 double discountRatio = 0.68, int stock = 3, string originalTitle = "xx", string newTitle = "xx", bool isModifyPrice = true) { foreach (var search in lstSearch) { if (search.IsEmptyString()) continue; List<Item> lstItem = GetOnSaleGoods(search); if (lstItem != null && lstItem.Count > 0) { #region 更新SKU信息 foreach (var item in lstItem) { Thread.Sleep(100); //获取产品原价 var oPrice = item.Title.GetNumberInt(); var req = new ItemUpdateRequest(); req.NumIid = item.NumIid; req.Title = item.Title.Replace(originalTitle, newTitle); req.LocationState = SysConst.LocationState; req.LocationCity = SysConst.LocationCity; if (isModifyPrice) { req.Price = (oPrice * discountRatio).ToType<int>().ToString(); } var skus = GetSkusByNumId(item.NumIid.ToString()).ToArray(); var lastSku = skus[skus.Count() - 1]; for (int i = 0; i < skus.Count() - 1; i++) { Thread.Sleep(100); var skuReq = new ItemSkuUpdateRequest() { NumIid = item.NumIid, Properties = skus[i].Properties, Quantity = stock, OuterId = item.OuterId }; if (isModifyPrice) { skuReq.Price = req.Price; } UpdateSku(skuReq); Thread.Sleep(100); } UpdateGoodsBase(req, item.NumIid, item.OuterId, req.Title); var skuLastReq = new ItemSkuUpdateRequest() { NumIid = item.NumIid, Properties = lastSku.Properties, Quantity = stock, OuterId = item.OuterId }; if (isModifyPrice) { skuLastReq.Price = req.Price; } UpdateSku(skuLastReq); } #endregion } else { PublishGoodsMain( reqSource, new RequestModel { GoodsSn = search, Referer = reqSource.GetGoodsUrl(search) }); } } }