步步为盈
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.

66 lines
2.3 KiB

using BBWY.Client.Helpers;
2 years ago
using Newtonsoft.Json.Linq;
using System;
2 years ago
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;
2 years ago
private ConcurrentDictionary<string, string> dongdongBuyerDictionary;
public void InitDongDong()
{
2 years ago
dongdongBuyerDictionary = new ConcurrentDictionary<string, string>();
pipeHelper.ServerReceiveCallback = OnDongDongSendMessage;
pipeHelper.CreateServer("bbwyPipeServer");
}
private void OnDongDongSendMessage(string msg)
{
2 years ago
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)
{
}
}
}
}