bxx 相关服务
This commit is contained in:
1 parent
b44fa2a6c3
commit
025c213435
50 files changed
+16075
No files matched your search
@@ -0,0 +1,320 @@
|
||||
using AllBase;
|
||||
using AllBase.Helper;
|
||||
using AllBase.Model.Result;
|
||||
using NaiBa.Util.Extension;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TemuKJD.KJDForms.BaseForms;
|
||||
using Work;
|
||||
|
||||
namespace TemuKJD.PDDForms.ShopForms
|
||||
{
|
||||
public class ShopBrowserObject
|
||||
{
|
||||
public delegate void InfoReceivedHandler(string information);
|
||||
public event InfoReceivedHandler OnInfoReceived;
|
||||
|
||||
public string getProduct(ShopLoginInfo shop, string productId)
|
||||
{
|
||||
var prodId = productId.ParseToLong();
|
||||
if (prodId <= 0)
|
||||
{
|
||||
BaseMsgForm.ShowError("商品Id不存在!");
|
||||
return "failed";
|
||||
}
|
||||
if (shop == null)
|
||||
{
|
||||
BaseMsgForm.ShowError("店铺不存在!");
|
||||
return "failed";
|
||||
}
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var shop1 = shop;
|
||||
var prodId1 = prodId;
|
||||
string success_err_msg = "";
|
||||
var html = ProductQuery(shop1, prodId1.ToString());
|
||||
|
||||
var testHtml1 = GetHtml.UrlEncodeUtf8(html);
|
||||
var testHtml2 = GetHtml.UrlDecode(testHtml1);
|
||||
testHtml1 = HttpUtility.UrlEncode(html, Encoding.UTF8);
|
||||
testHtml2 = HttpUtility.UrlDecode(testHtml1);
|
||||
if (!html.Contains("\"success\":true") || !html.Contains("\"result\""))
|
||||
{
|
||||
OnInfoReceived("商品获取失败!" + BaseRegex.GetStringJson(ref html, "errorMsg"));
|
||||
return;
|
||||
}
|
||||
|
||||
JObject obj = JObject.Parse(html);
|
||||
var result = JsonHelper.SerializeObject(obj["result"]);
|
||||
var sizeRst = "";
|
||||
TemuDetailProductInfo product = JsonHelper.DeserializeJsonToObject<TemuDetailProductInfo>(result);
|
||||
|
||||
if (product.sizeTemplateId > 0)
|
||||
{
|
||||
html = SizeSpecQuery(shop1, prodId1.ToString(), product.sizeTemplateId.ToString());
|
||||
if(!html.Contains("\"success\":true"))
|
||||
{
|
||||
success_err_msg += " 尺码表获取失败!" + BaseRegex.GetStringJson(ref html, "errorMsg");
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = JObject.Parse(html);
|
||||
sizeRst = JsonHelper.SerializeObject(obj["result"]);
|
||||
}
|
||||
}
|
||||
|
||||
var url = BaseClass.BuildObjString("product/add_product");
|
||||
var data = Work.UserLogin.GetSignaturex() +
|
||||
"&spu_id=" + product?.productId +
|
||||
"&skc_id=" + product?.productSkcList?.FirstOrDefault()?.productSkcId +
|
||||
"&cat_id=" + GetCat(product).catId +
|
||||
"&cat_name=" + HttpUtility.UrlEncode(GetCat(product).catName, Encoding.UTF8) +
|
||||
"&ext_code=" + HttpUtility.UrlEncode(product?.productSkcList?.FirstOrDefault()?.extCode, Encoding.UTF8) +
|
||||
"&product_name=" + HttpUtility.UrlEncode(product?.productName, Encoding.UTF8) +
|
||||
"&product_json=" + HttpUtility.UrlEncode(result, Encoding.UTF8) +
|
||||
"&size_json=" + HttpUtility.UrlEncode(sizeRst, Encoding.UTF8) +
|
||||
"&main_img=" + HttpUtility.UrlEncode(product?.carouselImageUrls?.FirstOrDefault(), Encoding.UTF8);
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
{
|
||||
string msg = "选品商品保存失败!请检查网络连接:" +
|
||||
BaseRegex.GetStringJson(ref html, "msg");
|
||||
OnInfoReceived(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
OnInfoReceived("选品商品保存成功!" + success_err_msg);
|
||||
}
|
||||
|
||||
|
||||
//// 创建 SaveFileDialog 的实例
|
||||
//SaveFileDialog saveFileDialog = new SaveFileDialog();
|
||||
|
||||
//// 单线程单元(STA)模式运行文件对话框,否则会报错。
|
||||
//System.Threading.Thread InvokeThread = new System.Threading.Thread(new System.Threading.ThreadStart(()=> {
|
||||
|
||||
// // 设置对话框的属性
|
||||
// saveFileDialog.Title = "保存商品";
|
||||
// saveFileDialog.Filter = "商品文件 (*.prd)|*.prd|所有文件 (*.*)|*.*"; // 过滤文件类型
|
||||
// saveFileDialog.FileName = product.productId.ParseToString(); // 默认文件名
|
||||
// saveFileDialog.DefaultExt = "txt"; // 默认文件扩展名
|
||||
|
||||
// // 显示对话框并获取结果
|
||||
// if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
// {
|
||||
// // 用户点击了“保存”按钮,此时可以获取文件的路径
|
||||
// string filePath = saveFileDialog.FileName;
|
||||
// // 在这里处理文件保存逻辑,例如写入数据到文件
|
||||
// System.IO.File.WriteAllText(filePath, result);
|
||||
|
||||
// //BaseMsgForm.ShowInfo("商品保存成功!");
|
||||
// }
|
||||
//}));
|
||||
//InvokeThread.SetApartmentState(System.Threading.ApartmentState.STA);
|
||||
//InvokeThread.Start();
|
||||
//InvokeThread.Join();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
});
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 第三方获取商品并直接提交到第三方待上传列表
|
||||
/// </summary>
|
||||
/// <param name="sProdId"></param>
|
||||
/// <param name="supplierId"></param>
|
||||
/// <returns></returns>
|
||||
public string getThirdProduct(string sProdId, long supplierId)
|
||||
{
|
||||
var prodId = sProdId.ParseToLong();
|
||||
if (prodId <= 0)
|
||||
{
|
||||
BaseMsgForm.ShowError("商品Id不存在!");
|
||||
return "failed";
|
||||
}
|
||||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == supplierId.ToString());
|
||||
if (supplierId <= 0 || shop == null)
|
||||
{
|
||||
BaseMsgForm.ShowError("店铺不存在!");
|
||||
return "failed";
|
||||
}
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var sourceShop = shop;
|
||||
var sourceProdId = prodId;
|
||||
string success_err_msg = "";
|
||||
string errorMsg = "";
|
||||
var html = ProductQuery(sourceShop, sourceProdId.ToString());
|
||||
if (!html.Contains("\"success\":true") || !html.Contains("\"result\""))
|
||||
{
|
||||
OnInfoReceived("商品获取失败!" + BaseRegex.GetStringJson(ref html, "errorMsg"));
|
||||
return;
|
||||
}
|
||||
|
||||
JObject obj = JObject.Parse(html);
|
||||
var result = JsonHelper.SerializeObject(obj["result"]);
|
||||
var sizeRst = "";
|
||||
TemuDetailProductInfo product = JsonHelper.DeserializeJsonToObject<TemuDetailProductInfo>(result);
|
||||
|
||||
if (product.sizeTemplateId > 0)
|
||||
{
|
||||
html = SizeSpecQuery(sourceShop, sourceProdId.ToString(), product.sizeTemplateId.ToString());
|
||||
if (!html.Contains("\"success\":true"))
|
||||
{
|
||||
success_err_msg += " 尺码表获取失败!" + BaseRegex.GetStringJson(ref html, "errorMsg");
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = JObject.Parse(html);
|
||||
sizeRst = JsonHelper.SerializeObject(obj["result"]);
|
||||
}
|
||||
}
|
||||
|
||||
List<ShopLoginInfo> shopLst = new List<ShopLoginInfo>();
|
||||
PDDShopListForm.Instance.Invoke(new Action(() =>
|
||||
{
|
||||
//todo:
|
||||
//ProductThirdSelectAddShopForm shopForm = new ProductThirdSelectAddShopForm();
|
||||
//shopForm.ShowDialog();
|
||||
//shopLst.AddRange(shopForm.lstSelectShop);
|
||||
}));
|
||||
|
||||
var url = BaseClass.BuildObjString("product_third/add_product");
|
||||
var data = UserLogin.GetSignaturex() +
|
||||
"&spu_id=" + product?.productId +
|
||||
"&skc_id=" + product?.productSkcList?.FirstOrDefault()?.productSkcId +
|
||||
"&cat_id=" + GetCat(product).catId +
|
||||
"&cat_name=" + HttpUtility.UrlEncode(GetCat(product).catName, Encoding.UTF8) +
|
||||
"&ext_code=" + HttpUtility.UrlEncode(product?.productSkcList?.FirstOrDefault()?.extCode, Encoding.UTF8) +
|
||||
"&product_name=" + HttpUtility.UrlEncode(product?.productName, Encoding.UTF8) +
|
||||
"&product_json=" + HttpUtility.UrlEncode(result, Encoding.UTF8) +
|
||||
"&size_json=" + HttpUtility.UrlEncode(sizeRst, Encoding.UTF8) +
|
||||
"&main_img=" + HttpUtility.UrlEncode(product?.carouselImageUrls?.FirstOrDefault(), Encoding.UTF8);
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
{
|
||||
errorMsg = "选品商品保存失败!请检查网络连接:" +
|
||||
BaseRegex.GetStringJson(ref html, "msg").Replace("'", "\\'").Replace("\"", "\\\"");
|
||||
}
|
||||
var id = BaseRegex.GetLongJson(ref html, "id");
|
||||
if (id == 0)
|
||||
goto end;
|
||||
|
||||
foreach (var addProdShop in shopLst)
|
||||
{
|
||||
url = BaseClass.BuildObjString("product_third/add_user_select_product");
|
||||
data = UserLogin.GetSignaturex() +
|
||||
"&out_product_id=" + id +
|
||||
"&shop_id=" + addProdShop.ShopId +
|
||||
"&shop_account=" + addProdShop.ShopAccount +
|
||||
"&main_user_name=" + addProdShop.UserName +
|
||||
"&sub_user_name=" + addProdShop.SubUserName +
|
||||
"&add_product_remaining=" + addProdShop.AddProductRemaining +
|
||||
"&status=待上传";
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
{
|
||||
errorMsg += product?.productId + " " + BaseRegex.GetStringJson(ref html, "msg") + "; ";
|
||||
}
|
||||
else
|
||||
{
|
||||
addProdShop.AddProductRemaining = addProdShop.AddProductRemaining - 1;
|
||||
}
|
||||
}
|
||||
end:;
|
||||
if (!string.IsNullOrEmpty(errorMsg))
|
||||
{
|
||||
OnInfoReceived(errorMsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
OnInfoReceived("库存上传保存成功!" + success_err_msg);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnInfoReceived("发生错误:" + ex.Message);
|
||||
}
|
||||
});
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
TemuCat GetCat(TemuDetailProductInfo product)
|
||||
{
|
||||
if (product == null)
|
||||
return new TemuCat();
|
||||
|
||||
var cat = product.categories.cat10;
|
||||
if (string.IsNullOrWhiteSpace(cat.catName))
|
||||
cat = product.categories.cat9;
|
||||
if (string.IsNullOrWhiteSpace(cat.catName))
|
||||
cat = product.categories.cat8;
|
||||
if (string.IsNullOrWhiteSpace(cat.catName))
|
||||
cat = product.categories.cat7;
|
||||
if (string.IsNullOrWhiteSpace(cat.catName))
|
||||
cat = product.categories.cat6;
|
||||
if (string.IsNullOrWhiteSpace(cat.catName))
|
||||
cat = product.categories.cat5;
|
||||
if (string.IsNullOrWhiteSpace(cat.catName))
|
||||
cat = product.categories.cat4;
|
||||
if (string.IsNullOrWhiteSpace(cat.catName))
|
||||
cat = product.categories.cat3;
|
||||
if (string.IsNullOrWhiteSpace(cat.catName))
|
||||
cat = product.categories.cat2;
|
||||
if (string.IsNullOrWhiteSpace(cat.catName))
|
||||
cat = product.categories.cat1;
|
||||
|
||||
return cat;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private string ProductQuery(ShopLoginInfo shop, string prodId)
|
||||
{
|
||||
//string url = "https://seller.kuajingmaihuo.com/bg-visage-mms/product/query";
|
||||
//string body = @"{""productId"":" + prodId + @",""productEditTaskUid"":""""}";
|
||||
//string refere = "https://seller.kuajingmaihuo.com/goods/product-create/product-edit?from=productList&productId=" + prodId;
|
||||
//return KJDHttpResponse.PostResponse(shop, url, body, refere);
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private string SizeSpecQuery(ShopLoginInfo shop, string prodId, string sizeSpecId)
|
||||
{
|
||||
//string url = "https://seller.kuajingmaihuo.com/bg-anniston-mms/sizespec/query";
|
||||
//string body = @"{""businessId"":" + sizeSpecId + @",""reusable"":false}";
|
||||
//string refere = "https://seller.kuajingmaihuo.com/goods/product-create/product-edit?from=productList&productId=" + prodId;
|
||||
//return KJDHttpResponse.PostResponse(shop, url, body, refere);
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user