Exemplo n.º 1
0
        /// <summary>
        /// 入库回传接口
        /// </summary>
        /// <param name="apptoken"></param>
        /// <param name="appkey"></param>
        /// <param name="sign"></param>
        /// <param name="timestamp"></param>
        /// <param name="data"></param>
        private void PutSKUData(string data)
        {
            WMSHelper.SaveLog("PutSKUData", data, "调用方法", "info", "in");

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(data);

            if (xmlDocument == null)
            {
                result = ReturnXML("0001", "xml文档格式错误", "0", "");
                WMSHelper.SaveLog("PutSKUData", data, "xml文档格式错误", "error", "in");
                return;
            }

            XmlNode skulist = xmlDocument.SelectSingleNode("xmldata/skulist");

            if (skulist == null)
            {
                result = ReturnXML("0001", "不包含入库信息", "0", "");
                WMSHelper.SaveLog("PutSKUData", data, "不包含入库信息", "error", "in");
                return;
            }

            try
            {
                List <SimpleSKUUpdateInfo> list = new List <SimpleSKUUpdateInfo>();
                foreach (XmlNode skuNode in skulist.SelectNodes("item"))
                {
                    SimpleSKUUpdateInfo info = new SimpleSKUUpdateInfo();
                    info.SkuId  = skuNode.SelectSingleNode("skuid").InnerText;
                    info.Amount = int.Parse(skuNode.SelectSingleNode("amount").InnerText);
                    list.Add(info);
                }

                bool flag = false;
                if (list.Count > 0)
                {
                    List <ErrorSimpleSKUUpdateInfo> errorlist;
                    flag = ProductHelper.AddSkusStock(list, out errorlist);

                    if (flag && errorlist.Count == 0)
                    {
                        result = ReturnXML("0000", "操作成功", "1", "");
                        WMSHelper.SaveLog("PutSKUData", data, "操作成功", "info", "in");
                        //商品入库状态及数量修改
                        UpdateEntrepotStatus(data, xmlDocument, list, flag);
                        return;
                    }
                    else if (flag && errorlist.Count > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (ErrorSimpleSKUUpdateInfo info in errorlist)
                        {
                            sb.Append("<resultInfo>");
                            sb.AppendFormat("<skuid>{0}</skuid>", info.SkuId);
                            sb.AppendFormat("<amount>{0}</amount>", info.Amount);
                            sb.Append("<errorcode>0001</errorcode>");
                            sb.Append("<errordescr>sku不存在</errordescr>");
                            sb.Append("</resultInfo>");
                        }
                        result = ReturnXML("0001", "部分操作成功", "2", sb.ToString());
                        WMSHelper.SaveLog("PutSKUData", data, "部分操作成功" + sb.ToString(), "info", "in");
                        return;
                    }

                    else
                    {
                        result = ReturnXML("0001", "数据库操作异常", "0", "");
                        WMSHelper.SaveLog("PutSKUData", data, "数据库操作异常", "error", "in");
                    }
                }

                else
                {
                    result = ReturnXML("0001", "不包含入库信息", "0", "");
                    WMSHelper.SaveLog("PutSKUData", data, "不包含入库信息", "error", "in");
                    return;
                }
            }

            catch (Exception ex)
            {
                result = ReturnXML("0001", ex.ToString(), "0", "");
                //ErrorLog.Write(ex.ToString());
                WMSHelper.SaveLog("PutSKUData", data, ex.ToString(), "error", "in");
                return;
            }
        }