|
- using HandyControl.Controls;
- using HKCardOUT.Helper;
- using HKCardOUT.Logic.Model;
- using HKControl;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using XExten.Advance.LinqFramework;
-
- namespace HKCardOUT.Logic.Service
- {
- public class HKCore
- {
- /// <summary>
- /// 刷卡消费
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public bool DeviceSale(SaleLog input)
- {
- try
- {
- //if (RemoteService.CheckCardStuatas(input.CardNo) != 1) return false;
- if (!DataBus.IsTest)
- if (!Main.GetInstance.GetIsSwipe(input.Location.AsInt())) return false;
- 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();
- 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;
- }
- else return false;
-
- }
- else return false;
- }
- catch (Exception ex)
- {
- HKLog.HKLogImport.WriteError(ex);
- return false;
- }
-
- }
- /// <summary>
- /// 获取当天消费前100条展示
- /// </summary>
- /// <returns></returns>
- public List<SaleLog> PullDaySaleLog()
- {
- var Begin = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
- var End = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));
- return DbContext.Context.Queryable<SaleLog>()
- .Where(t => t.CreateTime >= Begin)
- .Where(t => t.CreateTime < End)
- .OrderByDescending(t => t.CreateTime).ToPageList(0, 100);
- }
- }
- }
|