417 lines
18 KiB
C#
417 lines
18 KiB
C#
using AllBase;
|
|
using AllBase.Model.Result.PDDResult;
|
|
using NaiBa.Util;
|
|
using NaiBa.Util.Extension;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using TemuKJD.BaseForms;
|
|
using TemuKJD.BLL;
|
|
using TemuKJD.Extension;
|
|
using TemuKJD.ToolForms;
|
|
|
|
namespace TemuKJD.WXForms.TalkForms
|
|
{
|
|
public partial class OtherBuyerOrderListForm : BaseForms.BaseGeneralForm
|
|
{
|
|
public static OtherBuyerOrderListForm Instance { get; set; } = null;
|
|
ConcurrentList<PddBuyerOrderLiteInfo> lstOtherBuyerOrderInfoLite { get; set; } = new ConcurrentList<PddBuyerOrderLiteInfo>();
|
|
bool isInitOrder = false;
|
|
|
|
public OtherBuyerOrderListForm()
|
|
{
|
|
InitializeComponent();
|
|
Instance = this;
|
|
}
|
|
|
|
private void OtherBuyerOrderListForm_Load(object sender, EventArgs e)
|
|
{
|
|
lstOtherBuyerOrderInfoLite = NaiBa.Util.Helper.ConfigHelper.LoadConfig<ConcurrentList<PddBuyerOrderLiteInfo>>("other_buyer_order_list");
|
|
if (lstOtherBuyerOrderInfoLite == null)
|
|
lstOtherBuyerOrderInfoLite = new ConcurrentList<PddBuyerOrderLiteInfo>();
|
|
lstOtherBuyerOrderInfoLite.RemoveAll(o => o.order_time < BaseClass.DateTimeToTimestampSeconds(DateTime.Now.AddMonths(-1)));
|
|
|
|
foreach (var buyer in lstOtherBuyerOrderInfoLite.Select(o => o.buyerName).Where(o => !o.IsNullOrEmpty()).Distinct().ToList())
|
|
{
|
|
cmbBuyerName.Items.Add(buyer);
|
|
}
|
|
ShowExistOrder();
|
|
}
|
|
|
|
void ShowExistOrder()
|
|
{
|
|
isInitOrder = true;
|
|
//Task.Run(() => {
|
|
int index = 0;
|
|
foreach (var order in lstOtherBuyerOrderInfoLite)
|
|
{
|
|
if (index % 100 == 0)
|
|
Thread.Sleep(1);
|
|
index++;
|
|
Invoke(new Action(() =>
|
|
{
|
|
ShowOrder(order);
|
|
}));
|
|
}
|
|
isInitOrder = false;
|
|
//});
|
|
}
|
|
|
|
void ShowOrder(PddBuyerOrderLiteInfo order)
|
|
{
|
|
if (order == null)
|
|
return;
|
|
|
|
var row = dgvBuyerOrder.Rows.Cast<DataGridViewRow>().FirstOrDefault(p => p.Cells.GetCellValueFromColumnName("colOOtherOrderSn").ParseToString() == order.order_sn);
|
|
if (row == null)
|
|
{
|
|
var rowIndex = this.dgvBuyerOrder.Rows.Add(
|
|
false,
|
|
order.buyerId,
|
|
order.buyerName,
|
|
order.order_sn,
|
|
order.order_time == null ? "" : BaseClass.StampToDateTime(order.order_time.ParseToInt()).ToString("yy-MM-dd HH:ss"),
|
|
"", // 图片路径,
|
|
DataGridViewExtension.defaultBitmap, // 订单图片
|
|
order.order_Goods == null ? "" : string.Join("\r\n", order.order_Goods.Select(g => g.goods_name + " x" + g.goods_number)), // 商品信息
|
|
order.order_amount * 0.01,
|
|
order.order_status_prompt,
|
|
order.outExpressCompanyName,
|
|
order.tracking_number,
|
|
order.sendStatus,
|
|
"编辑",
|
|
"发送",
|
|
"退货"
|
|
);
|
|
row = dgvBuyerOrder.Rows[rowIndex];
|
|
row.Height = 40;
|
|
|
|
}
|
|
else
|
|
{
|
|
//row.Cells["colOSelect"].Value = selectIds.Contains(buyer.buyer_id);
|
|
row.Cells["colOBuyerId"].Value = order.buyerId;
|
|
row.Cells["colOBuyerName"].Value = order.buyerName;
|
|
row.Cells["colOOtherOrderSn"].Value = order.order_sn;
|
|
row.Cells["colOOrderTime"].Value = order.order_time == null ? "" : BaseClass.StampToDateTime(order.order_time.ParseToInt()).ToString("yy-MM-dd HH:ss");
|
|
//row.Cells["colOImgUrl"].Value = "";
|
|
// 商品信息
|
|
row.Cells["colOGoodsInfo"].Value = order.order_Goods == null ? "" : string.Join("\r\n", order.order_Goods.Select(g => g.goods_name + " x" + g.goods_number));
|
|
row.Cells["colOOrderAmount"].Value = order.order_amount * 0.01;
|
|
row.Cells["colOStatus"].Value = order.order_status_prompt;
|
|
row.Cells["colOExpressName"].Value = order.outExpressCompanyName;
|
|
row.Cells["colOExpressId"].Value = order.tracking_number;
|
|
row.Cells["colOMsg"].Value = order.sendStatus;
|
|
}
|
|
//
|
|
if (order.outExpressCompanyName == "物流名称获取失败")
|
|
row.Cells["colOExpressName"].Style.ForeColor = Color.Orange;
|
|
else
|
|
row.Cells["colOExpressName"].Style.ForeColor = Control.DefaultForeColor;
|
|
|
|
if (order.order_status_prompt.Contains("交易成功"))
|
|
{
|
|
row.Cells["colOMsg"].Value = "[完]" + row.Cells["colOMsg"].Value.ParseToString();
|
|
row.Cells["colOMsg"].Style.ForeColor = Color.Green;
|
|
}
|
|
else if (order.order_status_prompt.Contains("退款成功") || order.order_status_prompt.Contains("交易已取消"))
|
|
{
|
|
row.Cells["colOMsg"].Value = "[已退]" + row.Cells["colOMsg"].Value.ParseToString();
|
|
row.Cells["colOMsg"].Style.ForeColor = Color.Gray;
|
|
}
|
|
else if (order.after_sales != null)
|
|
{
|
|
if (order.order_sn == "260417-009038743070257")
|
|
{
|
|
//after_sales_id 20093344800098 after_sales_status 12 after_sales_type 2
|
|
}
|
|
if (order.order_sn == "260427-536315174430257")
|
|
{
|
|
|
|
}
|
|
if (order.after_sales.after_sales_status == 12 && order.after_sales.after_sales_type == 2)
|
|
{
|
|
row.Cells["colOMsg"].Value = "[退货失败]" + row.Cells["colOMsg"].Value.ParseToString();
|
|
row.Cells["colOMsg"].Style.ForeColor = Color.SlateBlue;
|
|
}
|
|
else
|
|
{
|
|
row.Cells["colOMsg"].Value = "[退货中]" + row.Cells["colOMsg"].Value.ParseToString();
|
|
row.Cells["colOMsg"].Style.ForeColor = Color.DeepSkyBlue;
|
|
}
|
|
}
|
|
else if (!string.IsNullOrEmpty(order.wxRefundStatus))
|
|
{
|
|
row.Cells["colOMsg"].Value = "[" + order.wxRefundStatus + "]" + row.Cells["colOMsg"].Value.ParseToString();
|
|
row.Cells["colOMsg"].Style.ForeColor = Color.Red;
|
|
}
|
|
else
|
|
{
|
|
row.Cells["colOMsg"].Style.ForeColor = Control.DefaultForeColor;
|
|
}
|
|
}
|
|
|
|
private void btnSendOrder_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
PddBuyerOrderLiteInfo order = new PddBuyerOrderLiteInfo();
|
|
order.buyerName = cmbBuyerName.Text.Trim();
|
|
order.order_amount = (txtOrderAmount.Text.Trim().ParseToDecimal() * 100).ParseToInt();
|
|
order.order_sn = txtBuyerOrderSn.Text.Trim();
|
|
order.outExpressCompanyMsg = "其他快递";
|
|
order.tracking_number = txtExpressSn.Text.Trim();
|
|
order.order_time = BaseClass.DateTimeToTimestampSeconds(DateTime.Now);
|
|
order.order_status_prompt = "";
|
|
|
|
if (order.buyerName.IsNullOrEmpty() || order.order_amount == 0 || order.order_sn.IsNullOrEmpty() /*|| order.tracking_number.IsNullOrEmpty()*/)
|
|
{
|
|
BaseMsgForm.ShowError("请完整填写拍单信息");
|
|
return;
|
|
}
|
|
|
|
var orderExist = lstOtherBuyerOrderInfoLite.FirstOrDefault(o => o.order_sn == order.order_sn);
|
|
if (orderExist == null)
|
|
lstOtherBuyerOrderInfoLite.Add(order);
|
|
else
|
|
{
|
|
if (!orderExist.tracking_number.IsNullOrEmpty() || order.tracking_number.IsNullOrEmpty())
|
|
{
|
|
if (BaseMsgForm.ShowConfirm("已存在买手订单,是否覆盖并重复发送?").DialogResult != DialogResult.OK)
|
|
return;
|
|
}
|
|
orderExist.order_amount = order.order_amount;
|
|
orderExist.buyerName = order.buyerName;
|
|
orderExist.outExpressCompanyMsg = order.outExpressCompanyMsg;
|
|
orderExist.tracking_number = order.tracking_number;
|
|
}
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("other_buyer_order_list", lstOtherBuyerOrderInfoLite);
|
|
|
|
ShowOrder(order);
|
|
SendOrderE57(order, true);
|
|
}
|
|
|
|
ConcurrentList<PddBuyerOrderLiteInfo> tempWaitOrderLst = new ConcurrentList<PddBuyerOrderLiteInfo>();
|
|
/// <summary>
|
|
/// 调用e57接口更新web端订单数据信息
|
|
/// </summary>
|
|
/// <param name="order"></param>
|
|
/// <param name="resetSendStatus">手动强制重置状态,一定重新发送</param>
|
|
public void SendOrderE57(PddBuyerOrderLiteInfo order, bool resetSendStatus = false)
|
|
{
|
|
if (tempWaitOrderLst.Any(o => o.order_sn == order.order_sn))
|
|
return;
|
|
tempWaitOrderLst.Add(order);
|
|
Task.Run(() =>
|
|
{
|
|
var orderSn = order.order_sn;
|
|
Thread.Sleep(5000);
|
|
tempWaitOrderLst.RemoveAll(o => o.order_sn == orderSn);
|
|
});
|
|
|
|
if (order == null)
|
|
return;
|
|
if (resetSendStatus)
|
|
order.sendStatus = "";
|
|
var row = dgvBuyerOrder.Rows.Cast<DataGridViewRow>().FirstOrDefault(p => p.Cells.GetCellValueFromColumnName("colOPddOrderSn").ParseToString() == order.order_sn);
|
|
Invoke(new Action(() =>
|
|
{
|
|
if (row != null)
|
|
row.Cells["colOMsg"].Value = "";
|
|
}));
|
|
Thread.Sleep(100);
|
|
|
|
if (order.sendStatus.Contains("外采订单已发货") || order.sendStatus.Contains("微信发货成功") ||
|
|
order.sendStatus.Contains("已发送待发货订单") || order.sendStatus.Contains("接收成功") ||
|
|
order.sendStatus.Contains("已发送售后订单"))
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
ShowOrder(order);
|
|
}));
|
|
return;
|
|
}
|
|
|
|
JObject obj = new JObject();
|
|
obj["platform"] = "WEISHOP";
|
|
obj["outAmount"] = order.order_amount;
|
|
obj["outAccount"] = order.buyerName;
|
|
obj["outOrderNo"] = order.order_sn;
|
|
if (!order.outExpressCompanyCode.IsNullOrEmpty() && !order.tracking_number.IsNullOrEmpty())
|
|
{
|
|
obj["outExpressCompany"] = order.outExpressCompanyCode;
|
|
obj["outExpressNo"] = order.tracking_number;
|
|
}
|
|
var dataStr = JsonHelper.SerializeObject(obj);
|
|
string url = "https://po.e57.cn/prod-api/api/oms-api/external_procurement/bind";
|
|
//成功 "<ResultVo><code>0</code><msg>SUCCESS</msg><data/><totalRecords/></ResultVo>"
|
|
//失败 已存在 <ResultVo><code>1505</code><msg>调用微信接口更新物流信息失败: 非法参数, 同运单号拦截 rid: 69d8ab9c-22baa3b1-67de0d95</msg><data/><totalRecords/></ResultVo>
|
|
var exportRst = WXHttpResponseBLL.e57PostResponse(url, dataStr, "");
|
|
if (exportRst == null)
|
|
{
|
|
|
|
}
|
|
for (int i = 0; i < 3 && exportRst.Contains("操作超时") && resetSendStatus == false; i++)
|
|
{
|
|
Thread.Sleep(210000);
|
|
WXHttpResponseBLL.e57PostResponse(url, dataStr, "");
|
|
}
|
|
if (exportRst.Contains("操作超时"))
|
|
{
|
|
order.sendStatus = "发送失败 操作超时";
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("other_buyer_order_list", lstOtherBuyerOrderInfoLite);
|
|
Invoke(new Action(() =>
|
|
{
|
|
ShowOrder(order);
|
|
}));
|
|
return;
|
|
}
|
|
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
|
|
string msg = "";
|
|
string data = "";
|
|
string code = "";
|
|
try
|
|
{
|
|
xmlDoc.LoadXml(exportRst); //<ResultVo><code>1505</code><msg>不支持的平台类型: WEISHOP</msg><data/><totalRecords/></ResultVo>
|
|
code = xmlDoc["AjaxResult"]["code"].InnerText;
|
|
msg = xmlDoc["AjaxResult"]["msg"].InnerText;
|
|
//data = xmlDoc["AjaxResult"]["data"].InnerText;
|
|
|
|
// <AjaxResult><msg>更新微信外采订单信息成功, orderNo:260430-306551232030257</msg><code>1</code></AjaxResult>
|
|
}
|
|
catch
|
|
{
|
|
msg = exportRst.ParseToString();
|
|
}
|
|
if (code == "0" || code == "1") //if (msg == "SUCCESS") // || msg == "SUCCESS"
|
|
{
|
|
var sendStatusTmp = string.IsNullOrEmpty(data) ? msg : data;
|
|
order.sendStatus = sendStatusTmp;
|
|
|
|
if (code == "0" && !order.sendStatus.Contains("微信发货成功"))
|
|
order.sendStatus = ("微信发货成功 " + sendStatusTmp).Trim();
|
|
if (code == "1" && !order.sendStatus.Contains("接收成功"))
|
|
order.sendStatus = ("接收成功 " + sendStatusTmp).Trim();
|
|
|
|
// 处理特殊情况 如未发货或退货订单
|
|
//if (order.sendStatus == "处理完成" || order.sendStatus == "快递公司和快递单号必须同时提供或同时为空")
|
|
// order.sendStatus = "已发送完成";
|
|
if (order.order_status_prompt.Contains("待发货")) // 更新微信外采订单状态成功
|
|
order.sendStatus = "已发送待发货订单";
|
|
if (order.after_sales != null)
|
|
order.sendStatus = "已发送售后订单 " + sendStatusTmp;
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("other_buyer_order_list", lstOtherBuyerOrderInfoLite);
|
|
}
|
|
else
|
|
{
|
|
order.sendStatus = "发送失败 " + (string.IsNullOrEmpty(msg) ? data : msg);
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("other_buyer_order_list", lstOtherBuyerOrderInfoLite);
|
|
}
|
|
Invoke(new Action(() =>
|
|
{
|
|
ShowOrder(order);
|
|
}));
|
|
//Thread.Sleep(500);
|
|
}
|
|
|
|
private void OtherBuyerOrderListForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
Hide();
|
|
|
|
e.Cancel = true;
|
|
return;
|
|
}
|
|
|
|
private void dgvPddBuyerOrder_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
|
return;
|
|
string headerText = dgvBuyerOrder.Columns[e.ColumnIndex].HeaderText;
|
|
var orderSn = dgvBuyerOrder.Rows[e.RowIndex].Cells["colOOtherOrderSn"].Value.ParseToString();
|
|
var order = lstOtherBuyerOrderInfoLite.FirstOrDefault(p => p.order_sn == orderSn);
|
|
var row = dgvBuyerOrder.Rows[e.RowIndex];
|
|
|
|
switch (headerText)
|
|
{
|
|
case "编辑":
|
|
cmbBuyerName.Text = row.Cells["colOBuyerName"].Value.ParseToString();
|
|
txtOrderAmount.Text = row.Cells["colOOrderAmount"].Value.ParseToString();
|
|
txtBuyerOrderSn.Text = row.Cells["colOOtherOrderSn"].Value.ParseToString();
|
|
txtExpressSn.Text = row.Cells["colOExpressId"].Value.ParseToString();
|
|
break;
|
|
case "图片":
|
|
ShowImgForm imgFrom = new ShowImgForm(dgvBuyerOrder.Rows[e.RowIndex].Cells["colImgUrl"].Value.ParseToString().Replace("?imageView2/2/w/90/h/90", ""));
|
|
imgFrom.ShowDialog();
|
|
break;
|
|
case "":
|
|
case "全选":
|
|
dgvBuyerOrder.Rows[e.RowIndex].Cells["colCheck"].Value = !(bool)dgvBuyerOrder.Rows[e.RowIndex].Cells["colCheck"].Value;
|
|
break;
|
|
case "发送":
|
|
if (tempWaitOrderLst.Any(o => o.order_sn == order.order_sn))
|
|
return;
|
|
Task.Run(() =>
|
|
{
|
|
if (1 == 1)
|
|
SendOrderE57(order, true);
|
|
});
|
|
break;
|
|
case "退货":
|
|
//pictureBox1.Visible = true;
|
|
//Task.Run(() =>
|
|
//{
|
|
// MakeWxToPddAfterSale(order);
|
|
// Invoke(new Action(() => { pictureBox1.Visible = false; }));
|
|
//});
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void btnClear_Click(object sender, EventArgs e)
|
|
{
|
|
cmbBuyerName.Text = "";
|
|
txtBuyerOrderSn.Text = "";
|
|
txtExpressSn.Text = "";
|
|
txtOrderAmount.Text = "";
|
|
}
|
|
|
|
private void btnFilterOrder_Click(object sender, EventArgs e)
|
|
{
|
|
foreach(DataGridViewRow row in dgvBuyerOrder.Rows)
|
|
{
|
|
if (row.Cells["colOBuyerName"].Value.ParseToString().Contains(txtFilter.Text.Trim()))
|
|
{
|
|
row.Visible = true;
|
|
continue;
|
|
}
|
|
if (row.Cells["colOOtherOrderSn"].Value.ParseToString().Contains(txtFilter.Text.Trim()))
|
|
{
|
|
row.Visible = true;
|
|
continue;
|
|
}
|
|
if (row.Cells["colOExpressId"].Value.ParseToString().Contains(txtFilter.Text.Trim()))
|
|
{
|
|
row.Visible = true;
|
|
continue;
|
|
}
|
|
row.Visible = false;
|
|
}
|
|
}
|
|
|
|
private void btnRestore_Click(object sender, EventArgs e)
|
|
{
|
|
txtFilter.Text = "";
|
|
btnFilterOrder_Click(null, null);
|
|
}
|
|
}
|
|
}
|