/// <summary> /// 处理添加一个商品 /// </summary> /// <param name="p"></param> /// <returns></returns> private Lebi_Product DoOneProduct(Lebi_Product pro) { Lebi_Pro_Type t = new Lebi_Pro_Type(); string ids = pro.taobaoid_type; if (ids != "") { ids = "'0" + ids.Replace(",", "','") + "0'"; List <Lebi_Pro_Type> models = B_Lebi_Pro_Type.GetList("taobaoid in (lbsql{" + ids + "})", ""); t = models.FirstOrDefault(); } if (t == null) { t = new Lebi_Pro_Type(); } string p131ids = pro.ProPerty131; string p132ids = pro.ProPerty132; if (p131ids != "") { p131ids = "'" + p131ids.Replace(",", "','") + "'"; List <Lebi_ProPerty> p131s = B_Lebi_ProPerty.GetList("taobaoid in (" + p131ids + ")", ""); p131ids = ""; foreach (Lebi_ProPerty p in p131s) { if (p131ids == "") { p131ids = p.id.ToString(); } else { p131ids += "," + p.id.ToString(); } } } if (p132ids != "") { p132ids = "'" + p132ids.Replace(",", "','") + "'"; List <Lebi_ProPerty> p132s = B_Lebi_ProPerty.GetList("taobaoid in (" + p132ids + ")", ""); p132ids = ""; foreach (Lebi_ProPerty p in p132s) { if (p132ids == "") { p132ids = p.id.ToString(); } else { p132ids += "," + p.id.ToString(); } } } pro.ProPerty131 = p131ids; pro.ProPerty132 = p132ids; pro.Pro_Type_id = t.id; B_Lebi_Product.Add(pro); pro.id = B_Lebi_Product.GetMaxId(); return(pro); }
/// <summary> /// 导入淘宝商品数据 /// </summary> public void taobao_product_in() { if (!Power("supplier_product_datainout", "导入导出")) { AjaxNoPower(); return; } int tb_typeid = RequestTool.RequestInt("tb_typeid", 0); string tb_file = RequestTool.RequestString("tb_file"); string tb_folder = RequestTool.RequestString("tb_folder"); string fileName = HttpContext.Current.Server.MapPath(@"~/" + WebPath + tb_file); int tb_split = RequestTool.RequestInt("tb_split", 0); string tbin_lang = RequestTool.RequestString("tbin_lang"); int i = 0; if (File.Exists(fileName)) { DataTable dt = new DataTable(); char flag = '\t'; if (tb_split == 2) { flag = ','; } using (FileStream fs = new FileStream(fileName, FileMode.Open)) { using (StreamReader reader = new StreamReader(fs, Encoding.Default)) { string text = string.Empty; while (!reader.EndOfStream) { text = reader.ReadLine(); if (i == 1) { string[] arr = text.Split(flag); foreach (string col in arr) { dt.Columns.Add(col); } } else if (i > 1) { string[] arr = text.Split(flag); DataRow r = dt.NewRow(); int j = 0; foreach (string col in arr) { if (j >= dt.Columns.Count) { break; } try { r[j] = col.Replace("\"", ""); } catch { r[j] = ""; } j++; } dt.Rows.Add(r); } i++; } } } //====================================== if (!dt.Columns.Contains("outer_id")) { Response.Write("{\"msg\":\"请检查是否包含outer_id字段\"}"); return; } string number = ""; int count = 0; for (int m = 0; m < dt.Rows.Count; m++) { try { if (dt.Columns.Contains("outer_id")) { number = dt.Rows[m]["outer_id"].ToString(); } bool addflag = false; Lebi_Product pro = B_Lebi_Product.GetModel("Supplier_id =" + CurrentSupplier.id + " and Number=lbsql{'" + number + "'}"); if (pro == null) { pro = new Lebi_Product(); addflag = true; pro.Number = dt.Rows[m]["outer_id"].ToString(); pro.Type_id_ProductStatus = 101; pro.Type_id_ProductType = 320; pro.Supplier_id = CurrentSupplier.id; pro.IsSupplierTransport = CurrentSupplierGroup.IsSubmit; } pro.Pro_Type_id = tb_typeid; if (dt.Columns.Contains("title")) { pro.Name = Language.GetString(dt.Rows[m]["title"].ToString(), pro.Name, tbin_lang); } if (dt.Columns.Contains("description")) { pro.Description = Language.GetString(dt.Rows[m]["description"].ToString(), pro.Description, tbin_lang); } if (dt.Columns.Contains("wireless_desc")) { pro.MobileDescription = Language.GetString(dt.Rows[m]["wireless_desc"].ToString(), pro.MobileDescription, tbin_lang); } if (dt.Columns.Contains("price")) { if (dt.Columns.Contains("price")) { string p = dt.Rows[m]["price"].ToString(); pro.Price = Convert.ToDecimal(p); } pro.Price_Market = pro.Price; pro.Price_Cost = pro.Price; } if (dt.Columns.Contains("num")) { int Count_Stock = 0; int.TryParse(Convert.ToString(dt.Rows[m]["num"]), out Count_Stock); pro.Count_Stock = Count_Stock; } if (dt.Columns.Contains("item_weight")) { int Weight = 0; int.TryParse(Convert.ToString(dt.Rows[m]["item_weight"]), out Weight); pro.Weight = Weight; } if (dt.Columns.Contains("VolumeL")) { int VolumeL = 0; int.TryParse(Convert.ToString(dt.Rows[m]["VolumeL"]), out VolumeL); pro.VolumeL = VolumeL; } if (dt.Columns.Contains("VolumeW")) { int VolumeW = 0; int.TryParse(Convert.ToString(dt.Rows[m]["VolumeW"]), out VolumeW); pro.VolumeW = VolumeW; } if (dt.Columns.Contains("VolumeH")) { int VolumeH = 0; int.TryParse(Convert.ToString(dt.Rows[m]["VolumeH"]), out VolumeH); pro.VolumeH = VolumeH; } if (dt.Columns.Contains("PackageRate")) { int PackageRate = 1; int.TryParse(Convert.ToString(dt.Rows[m]["PackageRate"]), out PackageRate); pro.PackageRate = PackageRate; } if (addflag) { B_Lebi_Product.Add(pro); pro.id = B_Lebi_Product.GetMaxId(); } else { B_Lebi_Product.Update(pro); } if (dt.Columns.Contains("picture")) { try { string img = dt.Rows[m]["picture"].ToString(); string images = ""; if (tb_folder == "") { //1f6edf58105f3abb1ef9665129eb6c52 //1f6edf58105f3abb1ef9665129eb6c52:1:0:|http://img01.taobaocdn.com/bao/uploaded/i1/T1Oys1FgNeXXXXXXXX_!!0-item_pic.jpg; //5327022ebfe958090d3abff999c8c800:1:1:|http://img02.taobaocdn.com/bao/uploaded/i2/24197542/T2wnCFXtNXXXXXXXXX_!!24197542.jpg; //b7972e16753d746d77f2f769002268d5:1:2:|http://img01.taobaocdn.com/bao/uploaded/i1/24197542/T2n6BuXvhXXXXXXXXX_!!24197542.jpg; //06e5fd8cdb3babd4664b7b736258290a:1:3:|http://img03.taobaocdn.com/bao/uploaded/i3/24197542/T2yX1BXwhXXXXXXXXX_!!24197542.jpg; //d1a5c9c441a994310db75a83005628b7:1:4:|http://img03.taobaocdn.com/bao/uploaded/i3/24197542/T2I4XAXpJaXXXXXXXX_!!24197542.jpg; //处理图片 string[,] arr = RegexTool.GetRegArray(img, @"\|(.*?);"); for (int ai = 0; ai < arr.GetUpperBound(0); ai++) { string v = RegexTool.GetRegValue(arr[ai, 1], @"\|(.*?);"); if (v == null || v == "") { continue; } LBimage lbimg = ImageHelper.DownLoadImage(v, pro); if (ai == 0) { pro.ImageBig = lbimg.big; pro.ImageMedium = lbimg.medium; pro.ImageOriginal = lbimg.original; pro.ImageSmall = lbimg.small; } else { images += "@" + lbimg.original; } } } else { //上传文件夹导入图片的方式 img = ";" + img; string[,] arr = RegexTool.GetRegArray(img, @";(.*?):"); string ServerPath = System.Web.HttpContext.Current.Server.MapPath("~/"); for (int ai = 0; ai < arr.GetUpperBound(0); ai++) { string v = RegexTool.GetRegValue(arr[ai, 1], @";(.*?):"); if (v == null || v == "") { continue; } v = ServerPath + tb_folder + "/" + v + ".tbi"; v = v.Replace("//", "/"); LBimage lbimg = ImageHelper.CreateTaobaoImage(v, pro); if (ai == 0) { pro.ImageBig = lbimg.big; pro.ImageMedium = lbimg.medium; pro.ImageOriginal = lbimg.original; pro.ImageSmall = lbimg.small; } else { images += "@" + lbimg.original; } } } pro.Images = images; B_Lebi_Product.Update(pro); } catch { } } count++; } catch { continue; } } Log.Add("导入淘宝商品", "Product", ""); Response.Write("{\"msg\":\"OK\",\"count\":\"" + count + "\"}"); } else { Response.Write("{\"msg\":\"" + Tag("数据文件错误") + "\"}"); return; } }