@@ -42,6 +42,9 @@ namespace HKCardOUT | |||||
DataBus.StoreId = configer["StoreId"]; | DataBus.StoreId = configer["StoreId"]; | ||||
DataBus.COM = configer["COM"]; | DataBus.COM = configer["COM"]; | ||||
DataBus.IsTest = configer["IsTest"].AsBool(); | DataBus.IsTest = configer["IsTest"].AsBool(); | ||||
DataBus.AM = configer["AM"]; | |||||
DataBus.PM = configer["PM"]; | |||||
DataBus.AT = configer["AT"]; | |||||
DbContext.InitTable(); | DbContext.InitTable(); | ||||
RemoteService.PullShopInfo(); | RemoteService.PullShopInfo(); | ||||
base.Configure(); | base.Configure(); | ||||
@@ -30,6 +30,9 @@ namespace HKCardOUT.Helper | |||||
public static string StoreId { get; set; } | public static string StoreId { get; set; } | ||||
public static string COM { get; set; } | public static string COM { get; set; } | ||||
public static string SaasRoute { get; set; } | public static string SaasRoute { get; set; } | ||||
public static string AM { get; set; } | |||||
public static string PM { get; set; } | |||||
public static string AT { get; set; } | |||||
public static StoreInfoResponse StoreInfo { get; set; } | public static StoreInfoResponse StoreInfo { get; set; } | ||||
public static Dictionary<string, AdWindow> AdStatus { get; set; } = new Dictionary<string, AdWindow>(); | public static Dictionary<string, AdWindow> AdStatus { get; set; } = new Dictionary<string, AdWindow>(); | ||||
} | } | ||||
@@ -22,26 +22,30 @@ namespace HKCardOUT.Logic.Service | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
if (RemoteService.CheckCardStuatas(input.CardNo) != 1) return false; | |||||
//if (RemoteService.CheckCardStuatas(input.CardNo) != 1) return false; | |||||
if (!DataBus.IsTest) | if (!DataBus.IsTest) | ||||
if (!Main.GetInstance.GetIsSwipe(input.Location.AsInt())) return false; | if (!Main.GetInstance.GetIsSwipe(input.Location.AsInt())) return false; | ||||
var Old = DbContext.Context.Queryable<SaleLog>() | |||||
.Where(t => t.CardNo == input.CardNo).OrderByDescending(t => t.CreateTime).First(); | |||||
if (Old != null) | |||||
{ | |||||
var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity(); | |||||
if (entity.Id != Guid.Empty) | |||||
{ | |||||
var res = RemoteService.SyncSaleLog(input.CardNo, input.Location); | |||||
if (!DataBus.IsTest) | |||||
Main.GetInstance.Start(input.Location.AsInt()); | |||||
DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand(); | |||||
return res; | |||||
} | |||||
return false; | |||||
} | |||||
else | |||||
var Old = DbContext.Context.Queryable<SaleLog>().Where(t => t.CardNo == input.CardNo).Where(t => t.CreateTime.Day == DateTime.Now.Day).ToList(); | |||||
if (Old.Count > 3) return false; | |||||
var AM = DataBus.AM.Split(",").Select(t => t.AsInt()).ToList(); | |||||
var PM = DataBus.PM.Split(",").Select(t => t.AsInt()).ToList(); | |||||
var AT = DataBus.AT.Split(",").Select(t => t.AsInt()).ToList(); | |||||
var condition1 = (DateTime.Now.Hour >= AM[0] && DateTime.Now.Hour < AM[1]); | |||||
var condition2 = (DateTime.Now.Hour >= PM[0] && DateTime.Now.Hour < PM[1]); | |||||
var condition3 = (DateTime.Now.Hour >= AT[0] && DateTime.Now.Hour < AT[1]); | |||||
if (condition1 || condition2 || condition1) | |||||
{ | { | ||||
var AMDay = Old.Where(t => t.CreateTime.Hour >= AM[0] && t.CreateTime.Hour < AM[1]).Count(); | |||||
if (AMDay > 0) return false; | |||||
var PMDay = Old.Where(t => t.CreateTime.Hour >= PM[0] && t.CreateTime.Hour < PM[1]).Count(); | |||||
if (PMDay > 0) return false; | |||||
var ATDay = Old.Where(t => t.CreateTime.Hour >= AT[0] && t.CreateTime.Hour < AT[1]).Count(); | |||||
if (ATDay > 0) return false; | |||||
var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity(); | var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity(); | ||||
if (entity.Id != Guid.Empty) | if (entity.Id != Guid.Empty) | ||||
{ | { | ||||
@@ -51,16 +55,17 @@ namespace HKCardOUT.Logic.Service | |||||
DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand(); | DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand(); | ||||
return res; | return res; | ||||
} | } | ||||
return false; | |||||
} | |||||
else return false; | |||||
} | |||||
else return false; | |||||
} | } | ||||
catch (Exception ex) | catch (Exception ex) | ||||
{ | { | ||||
HKLog.HKLogImport.WriteError(ex); | HKLog.HKLogImport.WriteError(ex); | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
/// <summary> | /// <summary> | ||||
/// 获取当天消费前100条展示 | /// 获取当天消费前100条展示 | ||||
@@ -2,11 +2,14 @@ | |||||
using HKCardOUT.Helper; | using HKCardOUT.Helper; | ||||
using HKCardOUT.Logic.Model; | using HKCardOUT.Logic.Model; | ||||
using HKCardOUT.Logic.Service; | using HKCardOUT.Logic.Service; | ||||
using NStandard; | |||||
using SqlSugar.DistributedSystem.Snowflake; | |||||
using Stylet; | using Stylet; | ||||
using StyletIoC; | using StyletIoC; | ||||
using System; | using System; | ||||
using System.Collections.ObjectModel; | using System.Collections.ObjectModel; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Text.RegularExpressions; | |||||
using System.Threading; | using System.Threading; | ||||
using System.Windows.Documents; | using System.Windows.Documents; | ||||
using UHFHelper; | using UHFHelper; | ||||
@@ -21,7 +24,7 @@ namespace HKCardOUT.ViewModels | |||||
public delegate void ReadCardFunc(DKoutput? input); | public delegate void ReadCardFunc(DKoutput? input); | ||||
public event ReadCardFunc ReadFunc; | public event ReadCardFunc ReadFunc; | ||||
private readonly object locker = new object(); | private readonly object locker = new object(); | ||||
IContainer Container; | |||||
private IContainer Container; | |||||
public RootViewModel(IContainer Container) | public RootViewModel(IContainer Container) | ||||
{ | { | ||||
this.Container = Container; | this.Container = Container; | ||||
@@ -30,11 +33,13 @@ namespace HKCardOUT.ViewModels | |||||
protected override void OnViewLoaded() | protected override void OnViewLoaded() | ||||
{ | { | ||||
ThreadManage.GetInstance().Start(() => | |||||
System.Timers.Timer timer = new System.Timers.Timer(500); | |||||
timer.Enabled = true; | |||||
timer.Elapsed += (s, e) => | |||||
{ | { | ||||
Result = new ObservableCollection<SaleLog>(this.Container.Get<HKCore>().PullDaySaleLog()); | Result = new ObservableCollection<SaleLog>(this.Container.Get<HKCore>().PullDaySaleLog()); | ||||
Thread.Sleep(500); | |||||
}, "消费记录查询"); | |||||
}; | |||||
timer.Start(); | |||||
//广告初始化 | //广告初始化 | ||||
var Init = DataBus.StoreInfo?.Devices.Join(DataBus.StoreInfo?.Stalls, t => t.GateId, x => x.Id, (t, x) => new AdDTO | var Init = DataBus.StoreInfo?.Devices.Join(DataBus.StoreInfo?.Stalls, t => t.GateId, x => x.Id, (t, x) => new AdDTO | ||||
{ | { | ||||
@@ -102,22 +107,26 @@ namespace HKCardOUT.ViewModels | |||||
} | } | ||||
if (!UHF_RS485_Helper.GetInstance().GetSerialPortState()) | if (!UHF_RS485_Helper.GetInstance().GetSerialPortState()) | ||||
HandyControl.Controls.Growl.InfoGlobal("串口打开失败"); | HandyControl.Controls.Growl.InfoGlobal("串口打开失败"); | ||||
//读取读卡器 | |||||
ThreadManage.GetInstance().StartLong(new Action(() => | |||||
DataBus.StoreInfo.Devices.ForEach(item => | |||||
{ | { | ||||
DataBus.StoreInfo.Devices.ForEach(async item => | |||||
System.Timers.Timer timer = new System.Timers.Timer(500); | |||||
timer.Enabled = true; | |||||
timer.Elapsed += (sender, eve) => | |||||
{ | { | ||||
if (!UHF_RS485_Helper.GetInstance().GetSerialPortState()) | if (!UHF_RS485_Helper.GetInstance().GetSerialPortState()) | ||||
return; | return; | ||||
else | else | ||||
{ | { | ||||
var x = await UHF_RS485_Helper.GetInstance().ReadCard(item.Address.AsInt()); | |||||
if (x != null) | |||||
ReadFunc?.Invoke(x); | |||||
var res = UHF_RS485_Helper.GetInstance().ReadCard(item.Address.AsInt()).Result; | |||||
if (res != null) | |||||
{ | |||||
if (!res.ResData.IsMatch(new Regex("0{20}"))) | |||||
ReadFunc?.Invoke(res); | |||||
} | |||||
} | } | ||||
}); | |||||
Thread.Sleep(500); | |||||
}), "循环读取卡片内容", false); | |||||
}; | |||||
timer.Start(); | |||||
}); | |||||
} | } | ||||
#endregion | #endregion | ||||
@@ -155,18 +164,11 @@ namespace HKCardOUT.ViewModels | |||||
{ | { | ||||
lock (locker) | lock (locker) | ||||
{ | { | ||||
var key = input.Address + ":" + input.ResData; | |||||
//没有超时第一是刷 | |||||
if (Caches.RunTimeCacheGet<DKoutput>(key) == null) | |||||
Container.Get<HKCore>().DeviceSale(new SaleLog | |||||
{ | { | ||||
Caches.RunTimeCacheSet(key, input, 10, true); | |||||
Container.Get<HKCore>().DeviceSale(new SaleLog | |||||
{ | |||||
CardNo = input.ResData.Substring(1, input.ResData.Length - 1), | |||||
Location = input.Address.AsInt().ToString() | |||||
}); | |||||
} | |||||
CardNo = input.ResData.Substring(1, input.ResData.Length - 1), | |||||
Location = input.Address.AsInt().ToString() | |||||
}); | |||||
} | } | ||||
} | } | ||||
#endregion | #endregion | ||||
@@ -9,5 +9,11 @@ | |||||
"StoreId": "a19535e8-119f-4b10-a011-6288fd3ddb37", | "StoreId": "a19535e8-119f-4b10-a011-6288fd3ddb37", | ||||
"ConnectionStrings": { | "ConnectionStrings": { | ||||
"Sqlite": "HKSQL.db3" | "Sqlite": "HKSQL.db3" | ||||
} | |||||
}, | |||||
//早上 | |||||
"AM": "6,11", | |||||
//中午 | |||||
"PM": "11,14", | |||||
//下午 | |||||
"AT": "17,20" | |||||
} | } |