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

84 lines
3.1 KiB

using BBWY.Client.Helpers;
using GalaSoft.MvvmLight.Messaging;
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 WSHelper wsHelper;
private ConcurrentDictionary<string, string> dongdongBuyerDictionary;
public void InitDongDong()
{
dongdongBuyerDictionary = new ConcurrentDictionary<string, string>();
wsHelper.ServerReceiveCallback = OnDongDongSendMessage;
wsHelper.Start();
}
private void OnDongDongSendMessage(string msg)
{
Console.WriteLine($"OnDongDongSendMessage 接收到消息 {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; //已经解密过
var response = orderService.DecodeConsignee(order.Id, phone);
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;
App.Current.Dispatcher.BeginInvoke((Action)delegate
{
Messenger.Default.Send(string.Empty, "ActiveMainWindow");
});
;
//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)
{
}
}
}
}