You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.3 KiB
65 lines
2.3 KiB
using BBWY.Client.Helpers;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace BBWY.Client.ViewModels
|
|
{
|
|
public partial class OrderListViewModel
|
|
{
|
|
private PipeHelper pipeHelper;
|
|
private ConcurrentDictionary<string, string> dongdongBuyerDictionary;
|
|
|
|
public void InitDongDong()
|
|
{
|
|
dongdongBuyerDictionary = new ConcurrentDictionary<string, string>();
|
|
pipeHelper.ServerReceiveCallback = OnDongDongSendMessage;
|
|
pipeHelper.CreateServer("bbwyPipeServer");
|
|
}
|
|
|
|
private void OnDongDongSendMessage(string msg)
|
|
{
|
|
if (string.IsNullOrEmpty(msg))
|
|
return;
|
|
try
|
|
{
|
|
var j = JObject.Parse(msg);
|
|
var buyerAccount = j.Value<string>("user");
|
|
var phone = j.Value<string>("phone");
|
|
if (!string.IsNullOrEmpty(buyerAccount) && !string.IsNullOrEmpty(phone))
|
|
{
|
|
var key = $"{buyerAccount}_{phone}";
|
|
if (!dongdongBuyerDictionary.TryAdd(key, phone))
|
|
return;
|
|
}
|
|
|
|
var order = OrderList.FirstOrDefault(o => !string.IsNullOrEmpty(o.BuyerAccount) && o.BuyerAccount == buyerAccount);
|
|
if (order != null && order.Consignee != null && order.Consignee.IsDecode)
|
|
return; //已经解密过
|
|
|
|
Task.Factory.StartNew(() => orderService.DecodeConsignee(order.Id, phone)).ContinueWith(t =>
|
|
{
|
|
var response = t.Result;
|
|
IsLoading = false;
|
|
if (!response.Success)
|
|
{
|
|
App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "解密失败"));
|
|
return;
|
|
}
|
|
order.Consignee.ContactName = response.Data.ContactName;
|
|
order.Consignee.Address = response.Data.Address;
|
|
order.Consignee.Mobile = response.Data.Mobile;
|
|
order.Consignee.IsDecode = true;
|
|
});
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|