优化了微店商品上传 优化pdd买手读单
This commit is contained in:
1 parent
6c4f16b897
commit
f360688c43
62 files changed
+5620
-1432
No files matched your search
@@ -2861,7 +2861,7 @@ namespace TemuKJD.PDDForms.ProductForms.ActivityForms
|
||||
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||||
foreach (var shop in GlobalConfig.ShopLoginList)
|
||||
{
|
||||
if (isForceRefresh || (shop.AuthAddTime <= DateTime.Now.AddDays(-1) && shop.AuthExpiresTime <= DateTime.Now))
|
||||
if (isForceRefresh || (shop.AuthUpdateTime <= DateTime.Now.AddDays(-1) && shop.AuthExpiresTime <= DateTime.Now))
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
@@ -2876,26 +2876,26 @@ namespace TemuKJD.PDDForms.ProductForms.ActivityForms
|
||||
}));
|
||||
}
|
||||
}
|
||||
List<List<AuthInfo>> NewApiInfolsts = JsonHelper.DeserializeJsonToList<List<AuthInfo>>(JsonHelper.SerializeObject(GlobalConfig.ShopLoginList.Select(s => s.ApiAuthInfoList).ToList()));
|
||||
foreach (var newLst in NewApiInfolsts)
|
||||
{
|
||||
if (newLst.FirstOrDefault()!= null)
|
||||
{
|
||||
var oldApiAuths = PddApiHelper.LstAuthInfos.FirstOrDefault(oldLst => oldLst.FirstOrDefault()?.ShopId == newLst.FirstOrDefault().ShopId);
|
||||
if (oldApiAuths != null)
|
||||
{
|
||||
oldApiAuths.Clear();
|
||||
oldApiAuths.AddRange(newLst);
|
||||
}
|
||||
else
|
||||
{
|
||||
PddApiHelper.LstAuthInfos.Add(newLst);
|
||||
}
|
||||
}
|
||||
}
|
||||
//List<List<AuthInfo>> NewApiInfolsts = JsonHelper.DeserializeJsonToList<List<AuthInfo>>(JsonHelper.SerializeObject(GlobalConfig.ShopLoginList.Select(s => s.ApiAuthInfoList).ToList()));
|
||||
//foreach (var newLst in NewApiInfolsts)
|
||||
//{
|
||||
// if (newLst.FirstOrDefault()!= null)
|
||||
// {
|
||||
// var oldApiAuths = PddApiHelper.LstAuthInfos.FirstOrDefault(oldLst => oldLst.FirstOrDefault()?.ShopId == newLst.FirstOrDefault().ShopId);
|
||||
// if (oldApiAuths != null)
|
||||
// {
|
||||
// oldApiAuths.Clear();
|
||||
// oldApiAuths.AddRange(newLst);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// PddApiHelper.LstAuthInfos.Add(newLst);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
PddApiHelper.LstAuthInfos = PddApiHelper.LstAuthInfos.Where(a => a.OrderBy(o => o.AddTime).LastOrDefault().AddTime > DateTime.Now.AddDays(-30)).ToList();
|
||||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("pdd_shop_api_auth_info_lists", PddApiHelper.LstAuthInfos);
|
||||
//PddApiHelper.LstAuthInfos = PddApiHelper.LstAuthInfos.Where(a => a.OrderBy(o => o.UpdateTime).LastOrDefault().UpdateTime > DateTime.Now.AddDays(-30)).ToList();
|
||||
//NaiBa.Util.Helper.ConfigHelper.SaveConfig("pdd_shop_api_auth_info_lists", PddApiHelper.LstAuthInfos);
|
||||
Invoke(new Action(() => { pbShopLoading.Visible = false; }));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
|
||||
namespace TemuKJD.PDDForms.ProductForms
|
||||
{
|
||||
partial class ExprotProductForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.statusBar = new TemuKJD.UserControls.StatusBarUserControl();
|
||||
this.btnExportWxApp = new DevComponents.DotNetBar.PanelEx();
|
||||
this.panel1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel1.BackColor = System.Drawing.Color.White;
|
||||
this.panel1.Controls.Add(this.statusBar);
|
||||
this.panel1.Controls.Add(this.btnExportWxApp);
|
||||
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.panel1.Location = new System.Drawing.Point(0, 0);
|
||||
this.panel1.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(800, 450);
|
||||
this.panel1.TabIndex = 432;
|
||||
//
|
||||
// statusBar
|
||||
//
|
||||
this.statusBar.BackColor = System.Drawing.Color.White;
|
||||
this.statusBar.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.statusBar.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.statusBar.Location = new System.Drawing.Point(0, 427);
|
||||
this.statusBar.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.statusBar.Name = "statusBar";
|
||||
this.statusBar.Size = new System.Drawing.Size(800, 23);
|
||||
this.statusBar.TabIndex = 435;
|
||||
//
|
||||
// btnExportWxApp
|
||||
//
|
||||
this.btnExportWxApp.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
|
||||
this.btnExportWxApp.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
this.btnExportWxApp.DisabledBackColor = System.Drawing.Color.Empty;
|
||||
this.btnExportWxApp.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.btnExportWxApp.Location = new System.Drawing.Point(32, 26);
|
||||
this.btnExportWxApp.Name = "btnExportWxApp";
|
||||
this.btnExportWxApp.Size = new System.Drawing.Size(167, 23);
|
||||
this.btnExportWxApp.Style.Alignment = System.Drawing.StringAlignment.Center;
|
||||
this.btnExportWxApp.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
|
||||
this.btnExportWxApp.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
|
||||
this.btnExportWxApp.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder;
|
||||
this.btnExportWxApp.Style.BorderDashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
|
||||
this.btnExportWxApp.Style.BorderSide = DevComponents.DotNetBar.eBorderSide.None;
|
||||
this.btnExportWxApp.Style.ForeColor.Color = System.Drawing.Color.White;
|
||||
this.btnExportWxApp.Style.GradientAngle = 90;
|
||||
this.btnExportWxApp.StyleMouseOver.Alignment = System.Drawing.StringAlignment.Center;
|
||||
this.btnExportWxApp.StyleMouseOver.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255)))));
|
||||
this.btnExportWxApp.StyleMouseOver.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255)))));
|
||||
this.btnExportWxApp.TabIndex = 431;
|
||||
this.btnExportWxApp.Text = "微信App商品";
|
||||
this.btnExportWxApp.Click += new System.EventHandler(this.btnExportWxApp_Click);
|
||||
//
|
||||
// ExprotProductForm
|
||||
//
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.panel1);
|
||||
this.Name = "ExprotProductForm";
|
||||
this.Text = "ExprotProductForm";
|
||||
this.panel1.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DevComponents.DotNetBar.PanelEx btnExportWxApp;
|
||||
private System.Windows.Forms.Panel panel1;
|
||||
private UserControls.StatusBarUserControl statusBar;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,486 @@
|
||||
using AllBase;
|
||||
using AllBase.Model.Result.WXResult;
|
||||
using NaiBa.Util.Extension;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TemuKJD.BaseForms;
|
||||
using Work;
|
||||
|
||||
namespace TemuKJD.PDDForms.ProductForms
|
||||
{
|
||||
public partial class ExprotProductForm : BaseForms.BaseForm
|
||||
{
|
||||
public ExprotProductForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void btnExportWxApp_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||||
openFileDialog.Multiselect = true;
|
||||
// 设置过滤条件,只显示文本文件
|
||||
openFileDialog.Filter = "文本文件 (*.txt)|*.txt|All files (*.*)|*.*";
|
||||
// 显示对话框并获取结果
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
var filePathLst = openFileDialog.FileNames.ToList();
|
||||
//pbLoading.Visible = true;
|
||||
this.statusBar.pgbTaskProgress.Maximum = filePathLst.Count;
|
||||
this.statusBar.UpdateProgressBar(0);
|
||||
Task.Run(() =>
|
||||
{
|
||||
int successNum = 0;
|
||||
int failedNum = 0;
|
||||
foreach (var path in filePathLst)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.statusBar.lblTaskStatus.Text = "正在导入 " + (successNum + failedNum) + "/" + filePathLst.Count + " 成功:" + successNum + " 失败:" + failedNum;
|
||||
}));
|
||||
//string content = "";
|
||||
string rst = "";
|
||||
try
|
||||
{
|
||||
rst = getProd(path);
|
||||
if (!rst.Contains("成功"))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
rst = ex.Message;
|
||||
}
|
||||
if (string.IsNullOrEmpty(rst) || rst.Contains("入库成功"))
|
||||
successNum++;
|
||||
else
|
||||
failedNum++;
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.statusBar.UpdateProgressBar(this.statusBar.pgbTaskProgress.Value + 1);
|
||||
this.statusBar.lblTaskStatus.Text = "正在导入 " + (successNum + failedNum) + "/" + filePathLst.Count + " 成功:" + successNum + " 失败:" + failedNum;
|
||||
}));
|
||||
}
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
//pbLoading.Visible = false;
|
||||
this.statusBar.lblTaskStatus.Text = "导入完成" + (successNum + failedNum) + "/" + filePathLst.Count + " 成功:" + successNum + " 失败:" + failedNum;
|
||||
BaseMsgForm.ShowInfo("导入完成!");
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
string getProd(string filePath)
|
||||
{
|
||||
string prodStr = "";
|
||||
//prodStr = Encoding.UTF8.GetString(this.FileUpload1.FileBytes);
|
||||
//prodStr = TextBox2.Text.Trim();
|
||||
//prodStr = FileBase.ReadAllText(filePath, Encoding.UTF8);
|
||||
|
||||
using (StreamReader sr = new StreamReader(filePath))
|
||||
{
|
||||
prodStr = sr.ReadToEnd();
|
||||
|
||||
}
|
||||
|
||||
var reducePer = filePath.Replace(".txt", "").Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault().ParseToInt();
|
||||
if (reducePer > 0)
|
||||
prodStr = "{\"reducePre\":" + reducePer + "}" + prodStr;
|
||||
var realPricePer = 1m - reducePer * 0.01m;
|
||||
if (realPricePer < 0.1m)
|
||||
realPricePer = 0.1m;
|
||||
|
||||
WXClientProductInfoLite wxClientProd = new WXClientProductInfoLite();
|
||||
|
||||
var str_lst = BaseRegex.GetJsonObjStrJson(ref prodStr, "product_key");
|
||||
try
|
||||
{
|
||||
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
|
||||
wxClientProd.product_key = JsonHelper.DeserializeJsonToObject<wx_client_prod_key>(regex_str);
|
||||
if (wxClientProd.product_key == null)
|
||||
return "解析失败product_key";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "解析失败product_key";
|
||||
}
|
||||
|
||||
//商品详情格式
|
||||
wxClientProd.info = new wx_client_prod_info();
|
||||
|
||||
//主标题
|
||||
wxClientProd.info.title = BaseRegex.GetStringJson(ref prodStr, "title");
|
||||
if (wxClientProd.info.title.IsNullOrEmpty())
|
||||
return "解析失败title";
|
||||
|
||||
//副标题
|
||||
wxClientProd.info.sub_title = BaseRegex.GetStringJson(ref prodStr, "sub_title");
|
||||
|
||||
str_lst = BaseRegex.GetJsonArrStrJson(ref prodStr, "head_img");
|
||||
try
|
||||
{
|
||||
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
|
||||
wxClientProd.info.head_img = JsonHelper.DeserializeJsonToListNullable<string>(regex_str);
|
||||
if (wxClientProd.info.head_img == null)
|
||||
return "解析失败sub_title";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "解析失败sub_title";
|
||||
}
|
||||
|
||||
var nodeCatId = BaseRegex.GetStringJson(ref prodStr, "nodeCatId");
|
||||
|
||||
str_lst = BaseRegex.GetJsonArrStrJson(ref prodStr, "category");
|
||||
try
|
||||
{
|
||||
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
|
||||
wxClientProd.info.category = JsonHelper.DeserializeJsonToListNullable<wx_client_category>(regex_str);
|
||||
if (wxClientProd.info.category != null && !str_lst.IsNullOrEmpty() && !wxClientProd.info.category.Any(c => c.catIdStr == nodeCatId))
|
||||
{
|
||||
wxClientProd.info.category.Add(new wx_client_category() { catId = nodeCatId, cat_id = nodeCatId });
|
||||
}
|
||||
//if (wxClientProd.info.category == null)
|
||||
// return "解析失败";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "解析失败category";
|
||||
}
|
||||
|
||||
str_lst = BaseRegex.GetJsonObjStrJson(ref prodStr, "detail");
|
||||
try
|
||||
{
|
||||
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
|
||||
wxClientProd.info.detail = JsonHelper.DeserializeJsonToObjectNullable<wx_client_prod_detail>(regex_str);
|
||||
if (wxClientProd.info.detail == null)
|
||||
{
|
||||
wxClientProd.info.detail = new wx_client_prod_detail();
|
||||
wxClientProd.info.detail.detail_img.Add(wxClientProd.info.head_img.FirstOrDefault());
|
||||
}
|
||||
|
||||
//if (wxClientProd.info.detail == null)
|
||||
// return "解析失败";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "解析失败detail";
|
||||
}
|
||||
|
||||
str_lst = BaseRegex.GetJsonArrStrJson(ref prodStr, "param");
|
||||
try
|
||||
{
|
||||
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
|
||||
wxClientProd.info.param = JsonHelper.DeserializeJsonToListNullable<wx_client_param>(regex_str);
|
||||
if (wxClientProd.info.param == null)
|
||||
wxClientProd.info.param = new List<wx_client_param>();
|
||||
//if (wxClientProd.info.param == null)
|
||||
// return "解析失败";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "解析失败param";
|
||||
}
|
||||
|
||||
//品牌id
|
||||
wxClientProd.info.brand_id = BaseRegex.GetStringJson(ref prodStr, "brand_id");
|
||||
//if (wxClientProd.info.brand_id.IsNullOrEmpty())
|
||||
// return "解析失败";
|
||||
|
||||
str_lst = BaseRegex.GetJsonObjStrJson(ref prodStr, "sku_id_list");
|
||||
try
|
||||
{
|
||||
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
|
||||
wxClientProd.info.sku_id_list = JsonHelper.DeserializeJsonToObjectNullable<wx_client_sku_id_list>(regex_str);
|
||||
//if (wxClientProd.info.sku_id_list == null)
|
||||
// return "解析失败";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "解析失败sku_id_list";
|
||||
}
|
||||
|
||||
str_lst = BaseRegex.GetJsonObjStrJson(ref prodStr, "sku_list");
|
||||
try
|
||||
{
|
||||
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
|
||||
wxClientProd.info.sku_list = JsonHelper.DeserializeJsonToObjectNullable<wx_sku>(regex_str);
|
||||
//if (wxClientProd.info.sku_list == null)
|
||||
// return "解析失败";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "解析失败sku_id_list";
|
||||
}
|
||||
|
||||
if (wxClientProd.info.sku_list == null)
|
||||
{
|
||||
str_lst = BaseRegex.GetJsonArrStrJson(ref prodStr, "sku_info");
|
||||
try
|
||||
{
|
||||
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
|
||||
var sku_infos = JsonHelper.DeserializeJsonToListNullable<wx_client_sku_info>(regex_str);
|
||||
if (sku_infos != null)
|
||||
{
|
||||
wxClientProd.info.sku_list = new wx_sku();
|
||||
wxClientProd.info.sku_list.sku_info = sku_infos;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "解析失败sku_info";
|
||||
}
|
||||
}
|
||||
|
||||
// 佣金商品 根据折扣价格和佣金比例减去佣金
|
||||
if (wxClientProd.info.sku_list != null)
|
||||
{
|
||||
foreach (var sku in wxClientProd.info.sku_list.sku_info)
|
||||
{
|
||||
sku.price = (sku.price - (sku.price - sku.discounted_price) * (1m - realPricePer)).ParseToInt();
|
||||
}
|
||||
}
|
||||
|
||||
str_lst = BaseRegex.GetJsonArrStrJson(ref prodStr, "product_sale_attrs");
|
||||
try
|
||||
{
|
||||
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
|
||||
wxClientProd.info.product_sale_attrs = JsonHelper.DeserializeJsonToListNullable<wx_client_product_sale_attr>(regex_str);
|
||||
//if (wxClientProd.info.product_sale_attrs == null)
|
||||
// return "解析失败";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "解析失败product_sale_attrs";
|
||||
}
|
||||
|
||||
|
||||
//总销量
|
||||
wxClientProd.info.total_sold_num = BaseRegex.GetStringJson(ref prodStr, "total_sold_num");
|
||||
//if (wxClientProd.info.total_sold_num.IsNullOrEmpty())
|
||||
// return "解析失败";
|
||||
|
||||
str_lst = BaseRegex.GetJsonObjStrJson(ref prodStr, "service_desc");
|
||||
try
|
||||
{
|
||||
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
|
||||
wxClientProd.info.service_desc = JsonHelper.DeserializeJsonToObjectNullable<wx_client_service_desc>(regex_str);
|
||||
//if (wxClientProd.info.service_desc == null)
|
||||
// return "解析失败";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "解析失败service_desc";
|
||||
}
|
||||
|
||||
str_lst = BaseRegex.GetJsonObjStrJson(ref prodStr, "express_info");
|
||||
try
|
||||
{
|
||||
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
|
||||
wxClientProd.info.express_info = JsonHelper.DeserializeJsonToObjectNullable<wx_client_express_info>(regex_str);
|
||||
//if (wxClientProd.info.express_info == null)
|
||||
// return;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "解析失败express_info";
|
||||
}
|
||||
|
||||
str_lst = BaseRegex.GetJsonArrStrJson(ref prodStr, "headVideoInfo");
|
||||
try
|
||||
{
|
||||
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
|
||||
wxClientProd.info.headVideoInfo = JsonHelper.DeserializeJsonToListNullable<wx_client_head_video_info>(regex_str);
|
||||
//if (wxClientProd.info.headVideoInfo == null)
|
||||
// return "解析失败";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "解析失败headVideoInfo";
|
||||
}
|
||||
|
||||
str_lst = BaseRegex.GetJsonObjStrJson(ref prodStr, "afterSaleInfo");
|
||||
try
|
||||
{
|
||||
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
|
||||
wxClientProd.info.afterSaleInfo = JsonHelper.DeserializeJsonToObjectNullable<object>(regex_str);
|
||||
//if (wxClientProd.info.afterSaleInfo == null)
|
||||
// return "解析失败";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "解析失败afterSaleInfo";
|
||||
}
|
||||
|
||||
str_lst = BaseRegex.GetJsonArrStrJson(ref prodStr, "deliveryExpressFee");
|
||||
try
|
||||
{
|
||||
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
|
||||
wxClientProd.info.deliveryExpressFee = JsonHelper.DeserializeJsonToListNullable<object>(regex_str);
|
||||
//if (wxClientProd.info.deliveryExpressFee == null)
|
||||
// return "解析失败";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "解析失败deliveryExpressFee";
|
||||
}
|
||||
|
||||
str_lst = BaseRegex.GetJsonArrStrJson(ref prodStr, "templateInfo");
|
||||
try
|
||||
{
|
||||
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
|
||||
wxClientProd.info.templateInfo = JsonHelper.DeserializeJsonToListNullable<object>(regex_str);
|
||||
//if (wxClientProd.info.templateInfo == null)
|
||||
// return "解析失败";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "解析失败templateInfo";
|
||||
}
|
||||
|
||||
wxClientProd.info.spuCode = BaseRegex.GetStringJson(ref prodStr, "spuCode");
|
||||
|
||||
str_lst = BaseRegex.GetJsonArrStrJson(ref prodStr, "productSkus");
|
||||
try
|
||||
{
|
||||
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
|
||||
wxClientProd.productSkus = JsonHelper.DeserializeJsonToList<WXProductSkuInfoLite>(regex_str);
|
||||
if (wxClientProd.productSkus == null)
|
||||
return "解析失败productSkus";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "解析失败productSkus";
|
||||
}
|
||||
|
||||
// 佣金商品 根据价格给售卖价格赋值,如果价格丢失,直接在售卖价上计算
|
||||
foreach (var sku in wxClientProd.productSkus)
|
||||
{
|
||||
var wxDisSku = wxClientProd.info.sku_list?.sku_info?.FirstOrDefault(s => s.sku_id == sku.skuKey.skuId);
|
||||
if (wxDisSku != null)
|
||||
sku.productSkuInfo.salePrice = wxDisSku.price;
|
||||
else
|
||||
sku.productSkuInfo.salePrice = (sku.productSkuInfo.salePrice - sku.productSkuInfo.salePrice * realPricePer).ParseToInt();
|
||||
}
|
||||
|
||||
if (wxClientProd.productSkus.Min(s => s.productSkuInfo.salePrice * 0.01m) == 0)
|
||||
{
|
||||
return "解析失败Sku价格为0";
|
||||
}
|
||||
|
||||
return SaveWxProd(wxClientProd.product_key.product_id, wxClientProd, prodStr);
|
||||
}
|
||||
|
||||
string SaveWxProd(string prodId, WXClientProductInfoLite wxClientProdInfoLite, string baseStr)
|
||||
{
|
||||
bool isExist = false;
|
||||
var existUrl = BaseClass.BuildPDDObjString("product/get_product_spu_id_list");
|
||||
string existData = UserLogin.GetSignaturex() + "&search_spu_ids=" + prodId;
|
||||
//if (!string.IsNullOrEmpty(prod.dbProduct.real_spu_id))
|
||||
// existData = UserLogin.GetSignaturex() + "&search_spu_ids=" + prod.spuId + "," + prod.dbProduct.real_spu_id;
|
||||
string html = GetHtml.PostUtf8(existUrl, existData);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(existUrl, existData);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
{
|
||||
return "采集入库失败,产品数据库连接失败";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (html.Contains("\"data\":[") && !html.Contains("\"data\":[]"))
|
||||
isExist = true;
|
||||
}
|
||||
|
||||
var url = BaseClass.BuildPDDObjString("product/add_product");
|
||||
if (isExist)
|
||||
url = BaseClass.BuildPDDObjString("product/mdy_product");
|
||||
|
||||
var skus = wxClientProdInfoLite.productSkus;
|
||||
|
||||
var product_json = "{\"wxxdData\":" + JsonHelper.SerializeObject(wxClientProdInfoLite) + ",\"baseData\":" + JsonHelper.SerializeObject(baseStr) + "}";
|
||||
var data = UserLogin.GetSignaturex() +
|
||||
"&from_shop_id=" + wxClientProdInfoLite.product_key.appid +
|
||||
"&from_shop_name=" + wxClientProdInfoLite.product_key.appid +
|
||||
"&spu_id=" + prodId +
|
||||
"&skc_id=" + prodId +
|
||||
"&price_text=" + skus.Min(s => s.productSkuInfo.salePrice * 0.01m) + " - " + skus.Max(s => s.productSkuInfo.salePrice * 0.01m) +
|
||||
"&ext_code=" + wxClientProdInfoLite.info.spuCode +
|
||||
"&product_name=" + HttpUtility.UrlEncode(wxClientProdInfoLite.info.title, Encoding.UTF8) +
|
||||
"&product_json=" + HttpUtility.UrlEncode(product_json, Encoding.UTF8) + // product_json /*HttpUtility.UrlEncode(JsonUtils.SerializeObject(wxClientProdInfoLite), Encoding.UTF8)*/
|
||||
"&sale_count=" + wxClientProdInfoLite.info.total_sold_num +
|
||||
"&sale_count_text=" + wxClientProdInfoLite.info.total_sold_num +
|
||||
"&main_img=" + HttpUtility.UrlEncode(wxClientProdInfoLite.info.head_img.FirstOrDefault(), Encoding.UTF8) +
|
||||
"&wx_safe_status=" + HttpUtility.UrlEncode("安全商品", Encoding.UTF8) +
|
||||
"&product_get_type=" + HttpUtility.UrlEncode("微信小店", Encoding.UTF8);
|
||||
|
||||
if (wxClientProdInfoLite.info.category.Count > 0)
|
||||
{
|
||||
data += "&wx_cat_1=" + wxClientProdInfoLite.info.category[0].catIdStr;
|
||||
data += "&main_cat_id=" + wxClientProdInfoLite.info.category[0].catIdStr;
|
||||
data += "&main_cat_name=" + wxClientProdInfoLite.info.category[0].name;
|
||||
|
||||
data += "&wx_cat_leaf=" + wxClientProdInfoLite.info.category.LastOrDefault()?.catIdStr;
|
||||
data += "&cat_id=" + wxClientProdInfoLite.info.category.LastOrDefault()?.catIdStr;
|
||||
data += "&cat_name=" + HttpUtility.UrlEncode((wxClientProdInfoLite.info.category.LastOrDefault()?.name).ParseToString(), Encoding.UTF8);
|
||||
}
|
||||
if (wxClientProdInfoLite.info.category.Count > 1)
|
||||
{
|
||||
data += "&wx_cat_2=" + wxClientProdInfoLite.info.category[1].catIdStr;
|
||||
}
|
||||
if (wxClientProdInfoLite.info.category.Count > 2)
|
||||
{
|
||||
data += "&wx_cat_3=" + wxClientProdInfoLite.info.category[2].catIdStr;
|
||||
}
|
||||
|
||||
if (wxClientProdInfoLite.info.category.FirstOrDefault().name == "图书")
|
||||
{
|
||||
data += "&special_prod_type=" + HttpUtility.UrlEncode("书籍", 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"))
|
||||
{
|
||||
string msg = "商品入库失败!请检查网络连接:" + BaseRegex.GetStringJson(ref html, "msg");
|
||||
//Invoke(new Action(() =>
|
||||
//{
|
||||
// row.Cells["colMsg"].Value = msg;
|
||||
//}));
|
||||
return msg;
|
||||
}
|
||||
else
|
||||
{
|
||||
//prod.getProductMsg = "商品入库成功!";
|
||||
//Invoke(new Action(() =>
|
||||
//{
|
||||
// row.Cells["colMsg"].Value = prod.getProductMsg;
|
||||
//}));
|
||||
if (!isExist)
|
||||
{
|
||||
url = BaseClass.BuildPDDObjString("product/mdy_product");
|
||||
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");
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
return "微信商品采集入库成功!";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -43,8 +43,8 @@ namespace TemuKJD.PDDForms.ProductForms
|
||||
|
||||
if (info.updateDay == DateTime.Now.ToString("yyMMdd"))
|
||||
{
|
||||
// 今日同步过,跳过
|
||||
continue;
|
||||
// 今日同步过,跳过,暂时关闭改为每次打开立即读取
|
||||
//continue;
|
||||
}
|
||||
|
||||
info.failReason = "";
|
||||
@@ -148,8 +148,8 @@ namespace TemuKJD.PDDForms.ProductForms
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
// 休眠一小时
|
||||
Thread.Sleep(1000 * 60 * 60);
|
||||
// 休眠两个小时
|
||||
Thread.Sleep(1000 * 60 * 60 * 2);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user