diff --git a/pos/.vs/POSV2020/v16/.suo b/pos/.vs/POSV2020/v16/.suo index 51a81d1..9001e29 100644 Binary files a/pos/.vs/POSV2020/v16/.suo and b/pos/.vs/POSV2020/v16/.suo differ diff --git a/pos/POSV.Core/Constant.cs b/pos/POSV.Core/Constant.cs index a347b53..a92a45b 100644 --- a/pos/POSV.Core/Constant.cs +++ b/pos/POSV.Core/Constant.cs @@ -267,8 +267,16 @@ namespace POSV /// 支付失败后需要重新生成订单号触发 /// public static string ORDER_PAYMENT_ERROR_GENERATENO = "orderpayerror:generateticketno"; - + + /// + /// 分账上传进度 + /// public static string SPLITPAY_UPLOAD_PROGRESS = "splitpay:uploadprogress"; + + /// + /// 分账完成 + /// + public static string SPLITPAY_UPLOAD_FINISHED = "splitpay:uploadfinish"; #endregion /// diff --git a/pos/POSV.Core/Job/ServiceCenterUploadJob.cs b/pos/POSV.Core/Job/ServiceCenterUploadJob.cs index 2a99672..991ea95 100644 --- a/pos/POSV.Core/Job/ServiceCenterUploadJob.cs +++ b/pos/POSV.Core/Job/ServiceCenterUploadJob.cs @@ -63,13 +63,13 @@ namespace POSV.Job } foreach (var order in waitUpload) { - logger.Info("订单同步到服务中心成功,isHaveCenterTicket=true"); + logger.Info($"订单[{order.TradeNo}]同步到服务中心成功,isHaveCenterTicket=true"); UploadSCNewOrder.UploadNewOrder2SC4KDS(order.TradeNo); } } } - catch(Exception ex) + catch (Exception ex) { logger.Error(ex, "销售订单上传服务中心异常"); } diff --git a/pos/POSV.Core/ShoppingCart/OrderUtils.cs b/pos/POSV.Core/ShoppingCart/OrderUtils.cs index 455c0e3..64896de 100644 --- a/pos/POSV.Core/ShoppingCart/OrderUtils.cs +++ b/pos/POSV.Core/ShoppingCart/OrderUtils.cs @@ -668,7 +668,7 @@ namespace POSV.ShoppingCart /// public void OrderObjectCheck(OrderObject orderObject) { - logger.Info(JsonUtils.Serialize(orderObject)); + //logger.Info(JsonUtils.Serialize(orderObject)); int itemGroupCount = orderObject.Items.GroupBy(x => x.Id).ToList().Count;//订单明细数量 int itemCount = orderObject.Items.Count();//订单明细数量 if (itemGroupCount != itemCount) diff --git a/pos/POSV.Core/Utils/HttpClientUtils.cs b/pos/POSV.Core/Utils/HttpClientUtils.cs index 59e703a..7188321 100644 --- a/pos/POSV.Core/Utils/HttpClientUtils.cs +++ b/pos/POSV.Core/Utils/HttpClientUtils.cs @@ -111,7 +111,8 @@ namespace POSV.Utils try { - logger.Info("请求参数:{0}", JsonUtils.Serialize(parameters)); + //20240203 subin 注释掉 + //logger.Info("请求参数:{0}", JsonUtils.Serialize(parameters)); var stringParams = new Func, string>((dic) => { diff --git a/pos/POSV.Core/Utils/MessageCenterUtils.cs b/pos/POSV.Core/Utils/MessageCenterUtils.cs index 839a370..b4ef344 100644 --- a/pos/POSV.Core/Utils/MessageCenterUtils.cs +++ b/pos/POSV.Core/Utils/MessageCenterUtils.cs @@ -77,7 +77,7 @@ namespace POSV.Utils } catch (Exception ex) { - logger.Error(ex , "初始化消息中心异常"); + logger.Error(ex, "初始化消息中心异常"); } } @@ -85,7 +85,7 @@ namespace POSV.Utils /// 检测消息中心是否正常。1)没有配置消息中心;2)启用了消息中心是否连接; /// /// - public Tuple IsAvailable() + public Tuple IsAvailable() { bool enabled = false; bool connected = false; @@ -95,7 +95,7 @@ namespace POSV.Utils Stopwatch watch = Stopwatch.StartNew(); //是否启用消息中心 - bool enabledMessageCenter = Global.Instance.GlobalConfigBoolValue(ConfigConstant.DEVICE_SERVICECENTER_ENABLE , false); + bool enabledMessageCenter = Global.Instance.GlobalConfigBoolValue(ConfigConstant.DEVICE_SERVICECENTER_ENABLE, false); if (enabledMessageCenter) { enabled = true; @@ -110,8 +110,8 @@ namespace POSV.Utils logger.Info("开始检测服务中心是否通畅耗时"); //获取配置的参数 - string host = Global.Instance.GlobalConfigStringValue(ConfigConstant.DEVICE_SERVICECENTER_IP , string.Empty); - int port = Global.Instance.GlobalConfigIntValue(ConfigConstant.DEVICE_SERVICECENTER_PORT , 0); + string host = Global.Instance.GlobalConfigStringValue(ConfigConstant.DEVICE_SERVICECENTER_IP, string.Empty); + int port = Global.Instance.GlobalConfigIntValue(ConfigConstant.DEVICE_SERVICECENTER_PORT, 0); //IP和端口配置错误 if (string.IsNullOrEmpty(host) || port == 0) @@ -121,8 +121,8 @@ namespace POSV.Utils else { //检测IP和端口是否通畅 - var url = string.Format("{0}{1}" , this._baseUrl , "/amok"); - HttpResult hr = this._httpManager.Get(url , null, 2000); + var url = string.Format("{0}{1}", this._baseUrl, "/amok"); + HttpResult hr = this._httpManager.Get(url, null, 2000); connected = (hr.Code == 200); } @@ -131,17 +131,17 @@ namespace POSV.Utils { connected = false; } - logger.Info("检测服务中心是否通畅耗时<{0}>", watch.ElapsedMilliseconds); + logger.Info("检测服务中心是否通畅[{0}]耗时<{1}>", connected, watch.ElapsedMilliseconds); } catch (Exception ex) { - logger.Error(ex , "连接消息中心失败"); + logger.Error(ex, "连接消息中心失败"); enabled = false; connected = false; } - return new Tuple(enabled , connected); + return new Tuple(enabled, connected); } @@ -153,7 +153,7 @@ namespace POSV.Utils get { //是否启用共享沽清 - var enableSaleClear = Global.Instance.GlobalConfigBoolValue(ConfigConstant.DEVICE_SALECLEAR_ENABLE , false); + var enableSaleClear = Global.Instance.GlobalConfigBoolValue(ConfigConstant.DEVICE_SALECLEAR_ENABLE, false); //1)启用消息中心;2)消息中心连接正常;3)参数配置中设置了共享沽清 return Global.Instance.MessageCenterOnline.Item1 && Global.Instance.MessageCenterOnline.Item2 && enableSaleClear; @@ -166,7 +166,7 @@ namespace POSV.Utils /// /// /// - public Tuple GetGlobalTicketNo(int length = 4) + public Tuple GetGlobalTicketNo(int length = 4) { lock (Global.Instance.CacheLock) { @@ -174,31 +174,31 @@ namespace POSV.Utils { if (!string.IsNullOrEmpty(this._baseUrl)) { - var url = string.Format("{0}{1}{2}" , this._baseUrl , "/trade/" , length); + var url = string.Format("{0}{1}{2}", this._baseUrl, "/trade/", length); - HttpResult hr = this._httpManager.Get(url , null); + HttpResult hr = this._httpManager.Get(url, null); if (hr.Code == 200) { - return new Tuple(true , string.Format("获取到全局票号成功<{0}>" , hr.Text) , hr.Text); + return new Tuple(true, string.Format("获取到全局票号成功<{0}>", hr.Text), hr.Text); } else { - return new Tuple(false , string.Format("获取到全局票号失败<{0}>" , hr.Text) , hr.Text); + return new Tuple(false, string.Format("获取到全局票号失败<{0}>", hr.Text), hr.Text); } } else { - return new Tuple(false , this._message , string.Empty); + return new Tuple(false, this._message, string.Empty); } } catch (Exception ex) { - logger.Error(ex , "获取全局票号异常"); + logger.Error(ex, "获取全局票号异常"); - return new Tuple(false , "获取全局票号失败" , string.Empty); + return new Tuple(false, "获取全局票号失败", string.Empty); } - } + } } /// @@ -207,37 +207,37 @@ namespace POSV.Utils /// /// /// - public Tuple GetGlobalOrderNo(int length = 2,int initialValue = 0) + public Tuple GetGlobalOrderNo(int length = 2, int initialValue = 0) { - lock(Global.Instance.CacheLock) + lock (Global.Instance.CacheLock) { try { if (!string.IsNullOrEmpty(this._baseUrl)) { - var url = string.Format("{0}{1}{2}/{3}" , this._baseUrl , "/order/" , length , initialValue); + var url = string.Format("{0}{1}{2}/{3}", this._baseUrl, "/order/", length, initialValue); - HttpResult hr = this._httpManager.Get(url , null); + HttpResult hr = this._httpManager.Get(url, null); if (hr.Code == 200) { - return new Tuple(true , string.Format("获取到全局序号成功<{0}>" , hr.Text) , hr.Text); + return new Tuple(true, string.Format("获取到全局序号成功<{0}>", hr.Text), hr.Text); } else { - return new Tuple(false , string.Format("获取到全局序号失败<{0}>" , hr.Text) , hr.Text); + return new Tuple(false, string.Format("获取到全局序号失败<{0}>", hr.Text), hr.Text); } } else { - return new Tuple(false , this._message , string.Empty); + return new Tuple(false, this._message, string.Empty); } } catch (Exception ex) { - logger.Error(ex , "获取全局序号异常"); + logger.Error(ex, "获取全局序号异常"); - return new Tuple(false , "获取全局序号失败" , string.Empty); + return new Tuple(false, "获取全局序号失败", string.Empty); } } } @@ -247,13 +247,13 @@ namespace POSV.Utils /// /// /// - public Tuple> GetGlobalAvailableSaleClear() + public Tuple> GetGlobalAvailableSaleClear() { try { - var url = string.Format("{0}{1}" , this._baseUrl , "/sale/clear"); + var url = string.Format("{0}{1}", this._baseUrl, "/sale/clear"); - HttpResult hr = this._httpManager.PostJson(url ,"{}", null); + HttpResult hr = this._httpManager.PostJson(url, "{}", null); if (hr.Code == 200) { logger.Info(hr.Text); @@ -264,36 +264,36 @@ namespace POSV.Utils if (obj.Status == 1) { - return new Tuple>(true , obj.Message , obj.Data); + return new Tuple>(true, obj.Message, obj.Data); } else { - return new Tuple>(false , obj.Message , new List()); + return new Tuple>(false, obj.Message, new List()); } } else { - return new Tuple>(false , "获取沽清数据错误" , new List()); + return new Tuple>(false, "获取沽清数据错误", new List()); } } catch (Exception ex) { - logger.Error(ex , "获取沽清数据异常"); + logger.Error(ex, "获取沽清数据异常"); - return new Tuple>(false , "获取沽清数据异常" , new List()); + return new Tuple>(false, "获取沽清数据异常", new List()); } } - public Tuple> GetSaleClearList(string dateTimer = null) + public Tuple> GetSaleClearList(string dateTimer = null) { try { if (!string.IsNullOrEmpty(this._baseUrl)) { - var url = string.Format("{0}{1}" , this._baseUrl , "/sale/clear/list"); + var url = string.Format("{0}{1}", this._baseUrl, "/sale/clear/list"); //构建POST的JSON参数,date为空标识今日沽清 - var body = new Dictionary(); + var body = new Dictionary(); body["date"] = string.Empty; //指定日期的沽清 @@ -302,7 +302,7 @@ namespace POSV.Utils body["date"] = dateTimer; } - HttpResult hr = this._httpManager.PostJson(url , JsonUtils.Serialize(body) , null); + HttpResult hr = this._httpManager.PostJson(url, JsonUtils.Serialize(body), null); if (hr.Code == 200) { var obj = JsonUtils.Deserialize>>(hr.Text); @@ -311,33 +311,33 @@ namespace POSV.Utils { var data = obj.Data as List; - return new Tuple>(true , obj.Message , data); + return new Tuple>(true, obj.Message, data); } else { - return new Tuple>(false , obj.Message , new List()); + return new Tuple>(false, obj.Message, new List()); } } else { - return new Tuple>(false , "获取沽清列表数据错误" , new List()); + return new Tuple>(false, "获取沽清列表数据错误", new List()); } } else { - return new Tuple>(false , this._message , new List()); + return new Tuple>(false, this._message, new List()); } } catch (Exception ex) { - logger.Error(ex , "获取沽清列表数据异常"); + logger.Error(ex, "获取沽清列表数据异常"); - return new Tuple>(false , "获取沽清列表数据异常" , new List()); + return new Tuple>(false, "获取沽清列表数据异常", new List()); } } - public Tuple ChangeSaleClear(SaleClear saleClear) + public Tuple ChangeSaleClear(SaleClear saleClear) { lock (Global.Instance.CacheLock) { @@ -345,12 +345,12 @@ namespace POSV.Utils { if (!string.IsNullOrEmpty(this._baseUrl)) { - var url = string.Format("{0}{1}" , this._baseUrl , "/sale/clear/change"); - + var url = string.Format("{0}{1}", this._baseUrl, "/sale/clear/change"); + //将沽清对象序列化,传递到http var body = JsonUtils.Serialize(saleClear); - HttpResult hr = this._httpManager.PostJson(url , body , null); + HttpResult hr = this._httpManager.PostJson(url, body, null); if (hr.Code == 200) { logger.Info("变更沽清信息,服务中心的应答"); @@ -360,24 +360,24 @@ namespace POSV.Utils SaleClearUtils.Instance.SaveOrUpdateNoChanged(obj.Data); - - return new Tuple(true , "获取沽清列表数据错误"); + + return new Tuple(true, "获取沽清列表数据错误"); } else { - return new Tuple(false , "获取沽清列表数据错误"); + return new Tuple(false, "获取沽清列表数据错误"); } } else { - return new Tuple(false , this._message); + return new Tuple(false, this._message); } } catch (Exception ex) { - logger.Error(ex , "获取沽清列表数据异常"); + logger.Error(ex, "获取沽清列表数据异常"); - return new Tuple(false , "获取沽清列表数据异常"); + return new Tuple(false, "获取沽清列表数据异常"); } } } diff --git a/pos/POSV.Core/Utils/SplitPayUtils.cs b/pos/POSV.Core/Utils/SplitPayUtils.cs index 72fc747..4b98465 100644 --- a/pos/POSV.Core/Utils/SplitPayUtils.cs +++ b/pos/POSV.Core/Utils/SplitPayUtils.cs @@ -42,14 +42,12 @@ namespace POSV.Utils public bool SaveSplitPayInfo(OrderObject orderObject) { Stopwatch sw = new Stopwatch(); - - sw.Start(); - - logger.Info($"开始保存订单<{orderObject.TradeNo}>的分账信息"); - var isExist = false; try { + sw.Start(); + logger.Info($"开始保存订单<{orderObject.TradeNo}>的分账信息"); + var _pid = IdWorkerUtils.Instance.NextId(); using (var db = Global.Instance.OpenDataBase) { @@ -230,7 +228,7 @@ namespace POSV.Utils RefundQuantity = item.MiddleRefundQuantity, Pid = _pid }; - + if (i == 0) { ssp.fee = string.IsNullOrEmpty(pay.Ext2) ? 0 : Convert.ToDecimal(pay.Ext2); @@ -308,7 +306,7 @@ namespace POSV.Utils RefundQuantity = item.RefundQuantity, Pid = _pid }; - + if (i == 0) { ssp.fee = string.IsNullOrEmpty(pay.Ext2) ? 0 : Convert.ToDecimal(pay.Ext2); @@ -398,8 +396,8 @@ namespace POSV.Utils #endregion } } - } + logger.Info($"完成保存订单<{orderObject.TradeNo}>的分账信息"); } catch (Exception ex) { @@ -410,7 +408,7 @@ namespace POSV.Utils { sw.Stop(); - logger.Info($"保存订单<{orderObject.TradeNo}的分账信息时长<{sw.ElapsedMilliseconds}>"); + logger.Info($"保存订单<{orderObject.TradeNo}>的分账信息时长<{sw.ElapsedMilliseconds}>"); } @@ -649,7 +647,8 @@ namespace POSV.Utils } trans.Complete(); - logger.Info($"退款成功后,更新本地分账信息:成功,json:" + JsonUtils.Serialize(updateData)); + //logger.Info($"退款成功后,更新本地分账信息:成功,json:" + JsonUtils.Serialize(updateData)); + logger.Info($"退款成功后,更新本地分账信息:成功"); } } } @@ -675,11 +674,13 @@ namespace POSV.Utils var result = api.UpdateSplitPay(entity); if (result.Item1) { - logger.Info($"退款成功后,更新服务端原分账信息:成功,json:" + JsonUtils.Serialize(entity)); + //logger.Info($"退款成功后,更新服务端原分账信息:成功,json:" + JsonUtils.Serialize(entity)); + logger.Info($"退款成功后,更新服务端原分账信息:成功。"); } else { - logger.Info($"退款成功后,更新服务端原分账信息:失败,json:" + JsonUtils.Serialize(entity)); + //logger.Info($"退款成功后,更新服务端原分账信息:失败,json:" + JsonUtils.Serialize(entity)); + logger.Info($"退款成功后,更新服务端原分账信息:失败。"); } Thread.Sleep(100); @@ -706,7 +707,7 @@ namespace POSV.Utils logger.Info($"开始日订单[{date.ToString("yyyy-MM-dd")}]的分账信息存储处理..."); var proValue = 0; - var proMaxValue = 20; + var proMaxValue = 400; Stopwatch sw = new Stopwatch(); sw.Start(); @@ -718,90 +719,104 @@ namespace POSV.Utils var pays = new List(); //支付方式分摊明细 var itemPays = new List(); + var index = 0; try { - using (var db = Global.Instance.OpenDataBase) + while (index < 2) { - //var delSql = "delete from pos_split_store_pay where syncStatus = 1 and uploadStatus = 1;"; - //db.Execute(delSql); + using (var db = Global.Instance.OpenDataBase) + { + //var delSql = "delete from pos_split_store_pay where syncStatus = 1 and uploadStatus = 1;"; + //db.Execute(delSql); - count = db.Query($"where isSplited = 0 and finishDate between '{sDate}' and '{eDate}';").Count(); - //主单数据 - //lists = db.Query("where syncStatus = 0 and uploadErrors < 3000 order by uploadErrors limit @0;", 1).ToList(); + count = db.Query($"where isSplited = 0 and finishDate between '{sDate}' and '{eDate}';").Count(); + //主单数据 + //lists = db.Query("where syncStatus = 0 and uploadErrors < 3000 order by uploadErrors limit @0;", 1).ToList(); + var tmpPress = proMaxValue / 2 / count == 0 ? 1 : proMaxValue / 2 / count; - var pageCount = count % pageSize != 0 ? (count / pageSize) + 1 : count / pageSize; + var pageCount = count % pageSize != 0 ? (count / pageSize) + 1 : count / pageSize; - logger.Info($"日订单[{date.ToString("yyyy-MM-dd")}]<{count}>条,页尺寸<{pageSize}>,共<{pageCount}>页"); - var sqlList = new ConcurrentQueue(); - for (int i = 0; i < pageCount; i++) - { - logger.Info($"日订单[{date.ToString("yyyy-MM-dd")}],分账第<{i + 1}>页订单数据"); - lists = db.Query($"where isSplited = 0 and finishDate between '{sDate}' and '{eDate}' limit ({i * pageSize}), {pageSize};").ToList(); + logger.Info($"日订单[{date.ToString("yyyy-MM-dd")}]<{count}>条,页尺寸<{pageSize}>,共<{pageCount}>页"); + var sqlList = new ConcurrentQueue(); + for (int i = 0; i < pageCount; i++) + { + logger.Info($"日订单[{date.ToString("yyyy-MM-dd")}],分账[index:{index + 1}]第<{i + 1}>页订单数据"); + lists = db.Query($"where isSplited = 0 and finishDate between '{sDate}' and '{eDate}' limit ({i * pageSize}), {pageSize};").ToList(); - var ids = string.Join("','", lists.ConvertAll(x => x.Id).ToArray()); - var nos = string.Join("','", lists.ConvertAll(x => x.TradeNo).ToArray()); - logger.Info($"日订单[{date.ToString("yyyy-MM-dd")}],分账第<{i + 1}>页订单数据:{nos}"); - var condition = " where orderId in ('" + ids + "');"; + var ids = string.Join("','", lists.ConvertAll(x => x.Id).ToArray()); + var nos = string.Join("','", lists.ConvertAll(x => x.TradeNo).ToArray()); + logger.Info($"日订单[{date.ToString("yyyy-MM-dd")}],分账[index:{index + 1}]第<{i + 1}>页订单数据:{nos}"); + var condition = " where orderId in ('" + ids + "');"; - //单据明细 - items = db.Query(condition).ToList(); + //单据明细 + items = db.Query(condition).ToList(); - //支付明细 - pays = db.Query(condition).ToList(); + //支付明细 + pays = db.Query(condition).ToList(); - itemPays = db.Query(condition).ToList(); + itemPays = db.Query(condition).ToList(); - foreach (var orderObject in lists) - { - orderObject.Items = items.FindAll(x => x.OrderId == orderObject.Id); + foreach (var orderObject in lists) + { + orderObject.Items = items.FindAll(x => x.OrderId == orderObject.Id); - //将支付方式附加到主单 - orderObject.Pays = pays.FindAll(x => x.OrderId == orderObject.Id); + //将支付方式附加到主单 + orderObject.Pays = pays.FindAll(x => x.OrderId == orderObject.Id); - foreach (var item in orderObject.Items) - { - item.ItemPayList = itemPays.FindAll(x => x.OrderId == orderObject.Id & x.ItemId == item.Id); + foreach (var item in orderObject.Items) + { + item.ItemPayList = itemPays.FindAll(x => x.OrderId == orderObject.Id & x.ItemId == item.Id); + } } - } - if (lists.Count > 0) - { - foreach (var orderObject in lists) + if (lists.Count > 0) { - logger.Info($"日订单[{date.ToString("yyyy-MM-dd")}]<{orderObject.TradeNo}>分账信息处理..."); - var isExist = SaveSplitPayInfo(orderObject); - if (!isExist) + var p = 0; + foreach (var orderObject in lists) { - var sql = $"update pos_order set isSplited=1 where id={orderObject.Id};"; - logger.Info($"日订单[{date.ToString("yyyy-MM-dd")}]<{orderObject.TradeNo}>更改分账状态isSplited==>1"); - sqlList.Enqueue(sql); - } - else - { - logger.Info($"日订单[{date.ToString("yyyy-MM-dd")}]<{orderObject.TradeNo}>的分账信息存储异常"); + logger.Info($"日订单[{date.ToString("yyyy-MM-dd")}]<{orderObject.TradeNo}>分账信息处理..."); + var isExist = SaveSplitPayInfo(orderObject); + if (!isExist) + { + var sql = $"update pos_order set isSplited=1 where id={orderObject.Id};"; + logger.Info($"日订单[{date.ToString("yyyy-MM-dd")}]<{orderObject.TradeNo}>更改分账状态isSplited==>1"); + sqlList.Enqueue(sql); + } + else + { + logger.Info($"日订单[{date.ToString("yyyy-MM-dd")}]<{orderObject.TradeNo}>的分账信息存储异常"); + } + Thread.Sleep(100); + //if (proValue < proMaxValue / (2 - index)) + // proValue = (proMaxValue / (2 - index) * index) + tmpPress * ((p + 1) + pageSize * i); + proValue++; + MsgEvent.Send(Constant.SPLITPAY_UPLOAD_PROGRESS, proValue); + p++; } - Thread.Sleep(100); } - } - else - { - logger.Info($"日订单[{date.ToString("yyyy-MM-dd")}],第<{i + 1}>页订单数据无可分账数据"); - } + else + { + logger.Info($"日订单[{date.ToString("yyyy-MM-dd")}],[index:{index + 1}]第<{i + 1}>页订单数据无可分账数据"); + //proValue = pageSize * (i + 1); + //if (proValue < proMaxValue / (2 - index)) + //{ + // MsgEvent.Send(Constant.SPLITPAY_UPLOAD_PROGRESS, proValue); + //} + //else + //{ + // MsgEvent.Send(Constant.SPLITPAY_UPLOAD_PROGRESS, proMaxValue / (2 - index)); + //} + proValue = count * (index + 1); + MsgEvent.Send(Constant.SPLITPAY_UPLOAD_PROGRESS, proValue); + } - if (i > proMaxValue) - { - proValue = 20; - } - else - { - proValue = i; } - MsgEvent.Send(Constant.SPLITPAY_UPLOAD_PROGRESS, proValue); - } - SqliteUtils.ExecuteTransaction(sqlList); + SqliteUtils.ExecuteTransaction(sqlList); + index++; + } } } catch (Exception ex) @@ -814,32 +829,37 @@ namespace POSV.Utils sw.Stop(); logger.Info("日订单<{0}>的分账信息存储结束<{1}>", count, sw.ElapsedMilliseconds); - MsgEvent.Send(Constant.SPLITPAY_UPLOAD_PROGRESS, proMaxValue); + MsgEvent.Send(Constant.SPLITPAY_UPLOAD_PROGRESS, count * 2); } return isException; } } - public Tuple SplitData2Server(DateTime date) + public Tuple SplitData2Server(DateTime date, int proIndexValue = 0) { Tuple result = null; var sDate = date.ToString("yyyy-MM-dd 00:00:00"); var eDate = date.AddDays(1).ToString("yyyy-MM-dd 00:00:00"); logger.Info($"开始日订单[{date.ToString("yyyy-MM-dd")}]的分账信息上传..."); - var pageSize = 10; + var pageSize = 1500; Stopwatch sw = new Stopwatch(); sw.Start(); int index = 0; - MsgEvent.Send(Constant.SPLITPAY_UPLOAD_PROGRESS, 25); + //proIndexValue = 401; + var proValue = proIndexValue; + MsgEvent.Send(Constant.SPLITPAY_UPLOAD_PROGRESS, proValue); - var proValue = 24; + var proMaxValue = 990; var flg = false; + var tmpPress = 0; lock (Global.Instance.SyncLock) { + while (index < 3) { + tmpPress = proIndexValue + (proMaxValue - proIndexValue) / (3 - index); var icount = 0; var count = 0; var total = 0; @@ -853,19 +873,7 @@ namespace POSV.Utils if (count > 0) { var pageCount = count % pageSize != 0 ? count / pageSize + 1 : count / pageSize; - var spp = 1; - if (pageCount > 0 && pageCount == proValue) - { - spp = 1; - } - else if (pageCount > 0 && pageCount <= 6) - { - spp = 4; - } - else if (pageCount > 7 && pageCount <= 12) - { - spp = 2; - } + //tmpPress = tmpPress / count == 0 ? 1 : tmpPress / count; for (int i = 0; i < pageCount; i++) { @@ -874,14 +882,13 @@ namespace POSV.Utils var pSplitLst = db.Query(condition).ToList(); var list = new ConcurrentQueue(); - int j = 0; foreach (var item in pSplitLst) { StringBuilder strBil = new StringBuilder(); strBil.Append("select ord.ticketId as ordTicketId,ord.tableNo,ord.people,ord.workerNo,oi.price as unitPrice,oi.productId as goodid,ssp.* from pos_split_store_pay ssp "); strBil.Append("left join pos_order_item oi on oi.id=ssp.orderItemId and oi.productId=ssp.productId "); strBil.Append("left join pos_order ord on ord.id=ssp.orderId "); - strBil.Append("where ssp.pid={0};"); + strBil.Append("where ssp.pid='{0}';"); string sql = string.Format(strBil.ToString(), item.Id); var lists = db.Query(sql); var succLst = new List(); @@ -951,13 +958,15 @@ namespace POSV.Utils list.Enqueue(strPSql); logger.Info($"分账信息第<{index + 1}>次上传,日订单[{date.ToString("yyyy-MM-dd")}]<{item.BusNo}>明细的分账信息上传操作失败"); } - - j++; Thread.Sleep(100); } + //if (proValue < tmpPress) + // proValue++; + //MsgEvent.Send(Constant.SPLITPAY_UPLOAD_PROGRESS, proValue); + proValue++; + MsgEvent.Send(Constant.SPLITPAY_UPLOAD_PROGRESS, proValue); } - proValue += spp; - MsgEvent.Send(Constant.SPLITPAY_UPLOAD_PROGRESS, proValue); + SqliteUtils.ExecuteTransaction(list); } } @@ -972,17 +981,21 @@ namespace POSV.Utils { flg = false; logger.Error(ex, $"分账信息第<{index + 1}>次上传,日订单[{date.ToString("yyyy-MM-dd")}]的分账信息上传错误"); + + //MsgEvent.Send(Constant.SPLITPAY_UPLOAD_PROGRESS, proMaxValue / 3 * index); } finally { sw.Stop(); logger.Info($"分账信息第<{index + 1}>次上传,日订单<{count}>条,应上传明细<{total}>条,实传<{icount}>条,时长<{sw.ElapsedMilliseconds}>"); - var pressValue = count == 0 ? proValue * (index + 1) : proValue; - MsgEvent.Send(Constant.SPLITPAY_UPLOAD_PROGRESS, pressValue); + //var pressValue = count == 0 ? proValue * (index + 1) : proValue; + //MsgEvent.Send(Constant.SPLITPAY_UPLOAD_PROGRESS, tmpPress); + proValue = proIndexValue + count * (index + 1); + MsgEvent.Send(Constant.SPLITPAY_UPLOAD_PROGRESS, proValue); index++; } } - MsgEvent.Send(Constant.SPLITPAY_UPLOAD_PROGRESS, 100); + //MsgEvent.Send(Constant.SPLITPAY_UPLOAD_PROGRESS, 1000); if (!flg) { diff --git a/pos/POSV.Core/Utils/WSSE.cs b/pos/POSV.Core/Utils/WSSE.cs index 542c441..d94ef88 100644 --- a/pos/POSV.Core/Utils/WSSE.cs +++ b/pos/POSV.Core/Utils/WSSE.cs @@ -54,7 +54,7 @@ namespace POSV.Utils var ip = Global.Instance.GlobalConfigStringValue(ConfigConstant.DEVICE_SERVICECENTER_IP); var port = Global.Instance.GlobalConfigStringValue(ConfigConstant.DEVICE_SERVICECENTER_PORT); var enableKds = Global.Instance.GlobalConfigBoolValue(ConfigConstant.DEVICE_KITCHEN_DISPLAY_ENABLE, false); - if(enable && !string.IsNullOrEmpty(ip) && !string.IsNullOrEmpty(port)) + if (enable && !string.IsNullOrEmpty(ip) && !string.IsNullOrEmpty(port)) { if (enableKds) { @@ -96,16 +96,16 @@ namespace POSV.Utils } catch (Exception ex) { - logger.Debug(ex , "InitWebSocket"); + logger.Debug(ex, "InitWebSocket"); } - + } - public void Query(string name , object content , Action executor) + public void Query(string name, object content, Action executor) { if (this._websocket != null) { - this._websocket.Query(name , content , executor); + this._websocket.Query(name, content, executor); } } @@ -119,26 +119,26 @@ namespace POSV.Utils //} - public void On(string name , Action executor) + public void On(string name, Action executor) { logger.Info("收到消息" + name); if (this._websocket != null) { - this._websocket.On(name , executor); + this._websocket.On(name, executor); } } - private void WebSocketClosed(object sender , EventArgs e) + private void WebSocketClosed(object sender, EventArgs e) { this._connected = false; } - private void WebSocketError(object sender , SuperSocket.ClientEngine.ErrorEventArgs e) + private void WebSocketError(object sender, SuperSocket.ClientEngine.ErrorEventArgs e) { this._connected = false; } - private void WebSocketOpened(object sender , EventArgs e) + private void WebSocketOpened(object sender, EventArgs e) { this._connected = true; } @@ -149,7 +149,7 @@ namespace POSV.Utils public void RestartConnect() { //停止自动重连任务 - if(_reconnectTimer != null) + if (_reconnectTimer != null) { _reconnectTimer.Close(); } @@ -169,24 +169,34 @@ namespace POSV.Utils InitWebSocket(); - if(this._websocket != null) + if (this._websocket != null) { this._websocket.Open(); } } - private void ReconnectTimerCallback(object sender , System.Timers.ElapsedEventArgs e) + private void ReconnectTimerCallback(object sender, System.Timers.ElapsedEventArgs e) { - //already open or openning - if (this._websocket.State == WebSocketState.Connecting || this._websocket.State == WebSocketState.Open) + try { - return; + //already open or openning + if (this._websocket.State == WebSocketState.Connecting || this._websocket.State == WebSocketState.Open) + { + return; + } + + + logger.Info("尝试连接服务中心……"); + + StartConnect(); + } + catch (Exception ex) + { + logger.Error(ex, "连接服务中心错误"); } - logger.Info("尝试连接服务中心……"); - StartConnect(); } - + } } diff --git a/pos/POSV.DefaultTemplate/DefaultTemplate.cs b/pos/POSV.DefaultTemplate/DefaultTemplate.cs index 0a06223..47c002a 100644 --- a/pos/POSV.DefaultTemplate/DefaultTemplate.cs +++ b/pos/POSV.DefaultTemplate/DefaultTemplate.cs @@ -8856,6 +8856,10 @@ namespace POSV if (!string.IsNullOrEmpty(outTradeNo)) { this._orderObject.TradeNo = outTradeNo; + foreach (var item in this._orderObject.Items) + { + item.TradeNo = this._orderObject.TradeNo; + } } else { @@ -8867,6 +8871,10 @@ namespace POSV if (ticket.Item1) { this._orderObject.TradeNo = ticket.Item3; + foreach (var item in this._orderObject.Items) + { + item.TradeNo = this._orderObject.TradeNo; + } } //重新判断是否获取到单号 @@ -8896,6 +8904,10 @@ namespace POSV if (DialogResult.Yes == dialog.ShowDialog()) { this._orderObject.TradeNo = OrderUtils.Instance.GenerateTicketNo(); + foreach (var item in this._orderObject.Items) + { + item.TradeNo = this._orderObject.TradeNo; + } } else { @@ -8908,6 +8920,10 @@ namespace POSV if (isLocalTicketNo) { this._orderObject.TradeNo = OrderUtils.Instance.GenerateTicketNo(); + foreach (var item in this._orderObject.Items) + { + item.TradeNo = this._orderObject.TradeNo; + } } else { diff --git a/pos/POSV.Proxy/MqttClient/MqttClientUtils.cs b/pos/POSV.Proxy/MqttClient/MqttClientUtils.cs index 0bd9d10..7cd14b1 100644 --- a/pos/POSV.Proxy/MqttClient/MqttClientUtils.cs +++ b/pos/POSV.Proxy/MqttClient/MqttClientUtils.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading.Tasks; using uPLibrary.Networking.M2Mqtt; using uPLibrary.Networking.M2Mqtt.Messages; @@ -59,7 +60,8 @@ namespace POSV.Proxy.Mqtt //2022-12-13 11:06 zhangy Edit 更换IP地址为域名 - this.mqttClient = new MqttClient("mqtt.ffcygl.com", 18830, false, null, null, MqttSslProtocols.None); + //this.mqttClient = new MqttClient("mqtt.ffcygl.com", 18830, false, null, null, MqttSslProtocols.None); + this.mqttClient = new MqttClient("csmqtt.ffcygl.com", 18830, false, null, null, MqttSslProtocols.None); //this.mqttClient = new MqttClient("127.0.0.1", 1883, false, null, null, MqttSslProtocols.None); @@ -154,25 +156,30 @@ namespace POSV.Proxy.Mqtt /// void OnMqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e) { - + string message = Encoding.UTF8.GetString(e.Message); string topic = e.Topic; - logger.Info("服务端推送<{0}>消息:{1}",topic, message); + logger.Info("服务端推送<{0}>消息:{1}", topic, message); if (topic.StartsWith("program")) { logger.Info("收到巨为小程序订单"); JuWeiAppOrderProxy.sendJwWeixinMessage(message); - OnMessageReceived?.Invoke(sender, new MessageEventArgs(0, message)); + + //Task.Factory.StartNew(() => + //{ + // JuWeiAppOrderProxy.sendJwWeixinMessage(message); + // OnMessageReceived?.Invoke(sender, new MessageEventArgs(0, message)); + //}); } if (topic.StartsWith("waimai")) { //开启商家版美团外卖和餐道外卖 - var enableShopMeiTuan = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CONFIG_CASHIER_ENABLESHOPMEITUAN,false); + var enableShopMeiTuan = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CONFIG_CASHIER_ENABLESHOPMEITUAN, false); if (enableShopMeiTuan) { logger.Info("收到美团商家外卖订单"); @@ -182,25 +189,25 @@ namespace POSV.Proxy.Mqtt { logger.Info("收到外卖订单"); OtherWaiMaiApi.sendWaiMaiMessage(message); - } - + } + OnMessageReceived?.Invoke(sender, new MessageEventArgs(0, message)); } if (topic.StartsWith("weixin")) { logger.Info("微信小程序订单"); - OtherWaiMaiApi.sendWeixinMessage(message); + OtherWaiMaiApi.sendWeixinMessage(message); OnMessageReceived?.Invoke(sender, new MessageEventArgs(1, message)); } if (topic.StartsWith("qimai")) { logger.Info("收到企迈第三方订单"); - OtherWaiMaiApi.sendQiMaiMessage(message); + OtherWaiMaiApi.sendQiMaiMessage(message); OnMessageReceived?.Invoke(sender, new MessageEventArgs(1, message)); } - + this._action?.Invoke(e); } @@ -230,7 +237,7 @@ namespace POSV.Proxy.Mqtt //运维参数 string tenant = string.Format("{0}/{1}/{2}", "devops", "cy2", Global.Instance.Worker.TenantId); string shop = string.Format("{0}/{1}/{2}/{3}", "devops", "cy2", Global.Instance.Worker.TenantId, Global.Instance.Worker.StoreInfo.No); - string pos = string.Format("{0}/{1}/{2}/{3}/{4}", "devops", "cy2", Global.Instance.Worker.TenantId, Global.Instance.Worker.StoreInfo.No,Global.Instance.Authc.PosNo); + string pos = string.Format("{0}/{1}/{2}/{3}/{4}", "devops", "cy2", Global.Instance.Worker.TenantId, Global.Instance.Worker.StoreInfo.No, Global.Instance.Authc.PosNo); //业务参数 string waimai = string.Format("{0}/{1}/{2}/{3}", "waimai", "cy2", Global.Instance.Worker.TenantId, Global.Instance.Worker.StoreInfo.Id); @@ -239,7 +246,7 @@ namespace POSV.Proxy.Mqtt string program = string.Format("{0}/{1}/{2}/{3}", "program", "cy2", Global.Instance.Worker.TenantId, Global.Instance.Worker.StoreInfo.Id); - string[] topics = { waimai, weixin, qimai, program , tenant ,shop , pos}; + string[] topics = { waimai, weixin, qimai, program, tenant, shop, pos }; byte[] levels = { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE }; diff --git a/pos/POSV.Proxy/ThirdPartyOrder/JuWeiAppOrderProxy.cs b/pos/POSV.Proxy/ThirdPartyOrder/JuWeiAppOrderProxy.cs index ab20715..21a1d57 100644 --- a/pos/POSV.Proxy/ThirdPartyOrder/JuWeiAppOrderProxy.cs +++ b/pos/POSV.Proxy/ThirdPartyOrder/JuWeiAppOrderProxy.cs @@ -25,6 +25,10 @@ namespace POSV.Proxy.ThirdPartyOrder public JuWeiAppOrderProxy() { + if (LOGGET == null) + { + LOGGET = NLog.LogManager.GetLogger(GetType().FullName); + } } #region API @@ -213,7 +217,7 @@ namespace POSV.Proxy.ThirdPartyOrder LOGGET.Info("小程序点餐_门店信息请求:" + JsonUtils.Serialize(parameters)); string response = HttpClientUtils.PostAsync(api, api.Url, parameters); - LOGGET.Info("小程序点餐_门店信息接收:" + response); + //LOGGET.Info("小程序点餐_门店信息接收:" + response); //获取成功 if (Constant.IsSuccessful(response)) { @@ -268,9 +272,9 @@ namespace POSV.Proxy.ThirdPartyOrder var ignoreParameters = new List(); parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignoreParameters)); - LOGGET.Info("小程序点餐_门店开停业_请求:" + _isopen + JsonUtils.Serialize(parameters)); + //LOGGET.Info("小程序点餐_门店开停业_请求:" + _isopen + JsonUtils.Serialize(parameters)); string response = HttpClientUtils.PostAsync(api, api.Url, parameters); - LOGGET.Info("小程序点餐_门店开停业_接收:" + _isopen + response); + //LOGGET.Info("小程序点餐_门店开停业_接收:" + _isopen + response); //获取成功 if (Constant.IsSuccessful(response)) { @@ -319,7 +323,7 @@ namespace POSV.Proxy.ThirdPartyOrder parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignoreParameters)); LOGGET.Info("小程序点餐_门店开业_请求:" + JsonUtils.Serialize(parameters)); string response = HttpClientUtils.PostAsync(api, api.Url, parameters); - LOGGET.Info("小程序点餐_门店开业_接收:" + response); + //LOGGET.Info("小程序点餐_门店开业_接收:" + response); //获取成功 if (Constant.IsSuccessful(response)) { @@ -421,7 +425,7 @@ namespace POSV.Proxy.ThirdPartyOrder LOGGET.Info("小程序点餐_配送信息请求:" + JsonUtils.Serialize(parameters)); string response = HttpClientUtils.PostAsync(api, api.Url, parameters); - LOGGET.Info("小程序点餐_配送信息接收:" + response); + //LOGGET.Info("小程序点餐_配送信息接收:" + response); //获取成功 if (Constant.IsSuccessful(response)) { @@ -471,7 +475,7 @@ namespace POSV.Proxy.ThirdPartyOrder parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignoreParameters)); LOGGET.Info("小程序点餐_请求内容:" + JsonUtils.Serialize(parameters)); string response = HttpClientUtils.PostAsync(api, api.Url, parameters); - LOGGET.Info("小程序点餐_订单内容:" + response); + //LOGGET.Info("小程序点餐_订单内容:" + response); //获取成功 if (Constant.IsSuccessful(response)) { @@ -542,7 +546,7 @@ namespace POSV.Proxy.ThirdPartyOrder parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignoreParameters)); LOGGET.Info("小程序点餐_订单" + orderOperationType + "_请求:" + JsonUtils.Serialize(parameters)); string response = HttpClientUtils.PostAsync(api, api.Url, parameters); - LOGGET.Info("小程序点餐_订单" + orderOperationType + "_接收:" + response); + //LOGGET.Info("小程序点餐_订单" + orderOperationType + "_接收:" + response); //获取成功 if (Constant.IsSuccessful(response)) { @@ -605,7 +609,7 @@ namespace POSV.Proxy.ThirdPartyOrder LOGGET.Info("小程序点餐_订单列表 是否待处理" + _isHandle + "请求:" + JsonUtils.Serialize(parameters)); string response = HttpClientUtils.PostAsync(api, api.Url, parameters); - LOGGET.Info("小程序点餐_订单列表 是否待处理" + _isHandle + "接收:" + response); + //LOGGET.Info("小程序点餐_订单列表 是否待处理" + _isHandle + "接收:" + response); //获取成功 if (Constant.IsSuccessful(response)) @@ -704,6 +708,16 @@ namespace POSV.Proxy.ThirdPartyOrder try { var _data = this.Program_Order_Query_Bybusno(Global.Instance.Authc.StoreId, busNo); + + if (_data != null && _data.Item1 == false) + { + if (_data.Item2.Equals("小程序点餐_订单详情,请检测网络连接")) + { + LOGGET.Info($"第二次小程序订单查询<{busNo}>"); + _data = this.Program_Order_Query_Bybusno(Global.Instance.Authc.StoreId, busNo); + } + } + if (_data != null && _data.Item1) { return new Tuple(_data.Item1, _data.Item2, _data.Item3.Data); @@ -760,6 +774,15 @@ namespace POSV.Proxy.ThirdPartyOrder var _data = this.Program_Order_Confirm(orderOperationType, Global.Instance.Authc.StoreId, busNo); LOGGET.Info("订单状态结果:<{0},{1}>", (_data != null && _data.Item1), _data.Item3 != null && _data.Item3.Data != null); + if (_data != null && _data.Item1 == false) + { + if (_data.Item2.Equals("小程序点餐_订单接单,请检测网络连接")) + { + LOGGET.Info("第二次修改订单状态:<{0},{1}>", busNo, orderOperationType.ToString()); + _data = this.Program_Order_Confirm(orderOperationType, Global.Instance.Authc.StoreId, busNo); + } + } + if (_data != null && _data.Item1) { return new Tuple(_data.Item1, _data.Item2, _data.Item3.Data); @@ -1049,7 +1072,8 @@ namespace POSV.Proxy.ThirdPartyOrder } else { - LOGGET.Error("订单保存或者补单操作失败,原因:本地单号<" + orderObject.TradeNo + ">重复!,订单内容:" + JsonUtils.Serialize(orderObject)); + //LOGGET.Error("订单保存或者补单操作失败,原因:本地单号<" + orderObject.TradeNo + ">重复!,订单内容:" + JsonUtils.Serialize(orderObject)); + LOGGET.Error("订单保存或者补单操作失败,原因:本地单号<" + orderObject.TradeNo + ">重复!"); return new Tuple(false, "订单保存失败", "已成功补入 0 单"); } @@ -1688,8 +1712,13 @@ namespace POSV.Proxy.ThirdPartyOrder /// public static void sendJwWeixinMessage(string message) { + if (LOGGET == null) + { + LOGGET = NLog.LogManager.GetLogger("JuWeiAppOrderProxy"); + } try { + LOGGET.Info("巨为微信小程序接单开始"); //微信小程序订单是否开启自动接单 bool openConfirm = Global.Instance.GlobalConfigBoolValue(ConfigConstant.WEIXIN_CONFIRM_PARAMETER, false); @@ -1733,9 +1762,16 @@ namespace POSV.Proxy.ThirdPartyOrder //自动接单处理 if (orderIds.Length > 0) { + LOGGET.Info("巨为小程序订单Length>0"); + } + //20240129 subin 改为只处理服务端返回为一条订单的小程序订单 + if (orderIds.Length == 1) + { + LOGGET.Info($"巨为小程序订单Length={orderIds.Length}"); var _len = orderIds.Length; foreach (var item in orderIds) { + LOGGET.Info($"巨为小程序订单进入自动接单<{item}>开始"); if (string.IsNullOrEmpty(item)) { LOGGET.Info("订单编号为空,忽略"); @@ -1743,11 +1779,20 @@ namespace POSV.Proxy.ThirdPartyOrder } // 播放声音 - SoundUtils.PlaySound("weixin"); - LOGGET.Info("巨为小程序订单播放声音,通知自动接单"); + #region 播放声音 + //SoundUtils.PlaySound("weixin"); + //LOGGET.Info($"巨为小程序订单<{item}>播放声音,通知自动接单"); + //20240129 subin 改为异步播放 + Task.Factory.StartNew(() => + { + SoundUtils.PlaySound("weixin"); + LOGGET.Info($"巨为小程序订单<{item}>播放声音,通知自动接单"); + }); + #endregion //请求接口查询订单 + LOGGET.Info($"巨为小程序请求接口查询订单<{item}>"); var _order = _juWeiAppOrderProxy.GetOrder(item); if (_order == null) @@ -1821,19 +1866,24 @@ namespace POSV.Proxy.ThirdPartyOrder var _orderdata = getOrderLocalJuWeiOrder(_order.Item3); if (_orderdata != null) { - LOGGET.Info("巨为小程序自动接单,开始保存数据...."); var _intder = _juWeiAppOrderProxy.InsertOrder(_orderdata); if (_intder.Item1) { - LOGGET.Info("巨为小程序自动接单,数据保存成功,开始打印小票...."); - + #region 打印小票 + LOGGET.Info($"巨为小程序自动接单<{item}>,数据保存成功,开始打印小票...."); + //JuWeiAppOrderProxy.PrintOrder(_orderdata); - JuWeiAppOrderProxy.PrintOrder(_orderdata); + //20240129 subin 改为异步打印 + Task.Factory.StartNew(() => + { + JuWeiAppOrderProxy.PrintOrder(_orderdata); + }); + #endregion #region subin 20230916 订单保存成功后处理分账明细 - LOGGET.Info("巨为小程序自动接单,数据保存成功,开始保存分账明细...."); + //LOGGET.Info("巨为小程序自动接单,数据保存成功,开始保存分账明细...."); //JuWeiAppOrderProxy.DoSplitOrder(_orderdata); //Task.Factory.StartNew(() => //{ @@ -1858,6 +1908,7 @@ namespace POSV.Proxy.ThirdPartyOrder Thread.Sleep(100); + LOGGET.Info($"巨为小程序订单进入自动接单<{item}>结束"); } } } @@ -1872,7 +1923,7 @@ namespace POSV.Proxy.ThirdPartyOrder LOGGET.Error(ex, "巨为小程序自动接单发生异常"); } - + LOGGET.Info("巨为微信小程序接单结束"); } public static Tuple DoRefund(string tradeNo) @@ -2221,7 +2272,7 @@ namespace POSV.Proxy.ThirdPartyOrder if (splitStorePayLst.Count() > 0) { db.InsertBatch(splitStorePayLst); - LOGGET.Info($"保存订单的分账信息:{JsonUtils.Serialize(splitStorePayLst)}"); + //LOGGET.Info($"保存订单的分账信息:{JsonUtils.Serialize(splitStorePayLst)}"); LOGGET.Info("有需要上传的营业分账数据,isHaveUpLoadSplitPay = true"); Global.isHaveUpLoadSplitPay = true; } diff --git a/pos/POSV.Template/Bill/AllinPayControl.cs b/pos/POSV.Template/Bill/AllinPayControl.cs index ffb1d2a..23b5fa7 100644 --- a/pos/POSV.Template/Bill/AllinPayControl.cs +++ b/pos/POSV.Template/Bill/AllinPayControl.cs @@ -372,17 +372,29 @@ namespace POSV.Bill if (ticket.Item1) { this._orderObject.TradeNo = ticket.Item3; + LOGGER.Info($"订单支付失败,重新生成订单号,原单号:[{Global.Instance.BusinessPlanLog.StoreNo}_{oldTradeNo}]==>新单号:[{Global.Instance.BusinessPlanLog.StoreNo}_{_orderObject.TradeNo}]......开始"); + + foreach (var item in this._orderObject.Items) + { + item.TradeNo = this._orderObject.TradeNo; + LOGGER.Info($"订单支付失败,原订单[{oldTradeNo}]商品<{item.ShortName}:{item.Id}>,重置订单号:{_orderObject.TradeNo}"); + } + using (var db = Global.Instance.OpenDataBase) { //订单保存成功更新核销状态 - LOGGER.Info($"订单支付失败,重新生成订单号,原单号:[{Global.Instance.BusinessPlanLog.StoreNo}_{oldTradeNo}]==>新单号:[{Global.Instance.BusinessPlanLog.StoreNo}_{_orderObject.TradeNo}]......开始"); + string sql = "update pos_saoma_pay_ticket set orderNo ='{0}' where orderNo = '{1}'"; sql = string.Format(sql, string.Format("{0}_{1}", Global.Instance.BusinessPlanLog.StoreNo, _orderObject.TradeNo), string.Format("{0}_{1}", Global.Instance.BusinessPlanLog.StoreNo, oldTradeNo)); db.Execute(sql, null); - LOGGER.Info($"订单支付失败,重新生成订单号,原单号:[{Global.Instance.BusinessPlanLog.StoreNo}_{oldTradeNo}]==>新单号:[{Global.Instance.BusinessPlanLog.StoreNo}_{_orderObject.TradeNo}]......更新成功"); + + LOGGER.Info($"订单支付失败,重新生成订单号,原单号:[{Global.Instance.BusinessPlanLog.StoreNo}_{oldTradeNo}]==>新单号:[{Global.Instance.BusinessPlanLog.StoreNo}_{_orderObject.TradeNo}]......pos_saoma_pay_ticket更新成功"); + //发送支付失败,重新生成订单号事件 MsgEvent.Send(Constant.ORDER_PAYMENT_ERROR_GENERATENO, _orderObject.TradeNo); } + + LOGGER.Info($"订单支付失败,重新生成订单号,原单号:[{Global.Instance.BusinessPlanLog.StoreNo}_{oldTradeNo}]==>新单号:[{Global.Instance.BusinessPlanLog.StoreNo}_{_orderObject.TradeNo}]......更新成功"); } else { diff --git a/pos/POSV.Template/Shift/ShiftForm.cs b/pos/POSV.Template/Shift/ShiftForm.cs index a635854..fc40776 100644 --- a/pos/POSV.Template/Shift/ShiftForm.cs +++ b/pos/POSV.Template/Shift/ShiftForm.cs @@ -25,6 +25,7 @@ namespace POSV.Shift public partial class ShiftForm : BusinessForm { HandOverTicket handOverTicket = null; + bool splitPayFinished = false; public ShiftForm() { InitializeComponent(); @@ -40,7 +41,10 @@ namespace POSV.Shift #region subin 20231025 分账由实时改为交班时分账 MsgEvent.RemoveListener(Constant.SPLITPAY_UPLOAD_PROGRESS, MessageEventNotify); - MsgEvent.Receive(Constant.SPLITPAY_UPLOAD_PROGRESS, MessageEventNotify); + MsgEvent.Receive(Constant.SPLITPAY_UPLOAD_PROGRESS, MessageEventNotify); + + MsgEvent.RemoveListener(Constant.SPLITPAY_UPLOAD_FINISHED, SplitPayFinishEventNotify); + MsgEvent.Receive(Constant.SPLITPAY_UPLOAD_FINISHED, SplitPayFinishEventNotify); #endregion if (this.DesignMode) return; @@ -1155,16 +1159,12 @@ namespace POSV.Shift private void ButtonOk_Click(object sender, EventArgs e) { + #region 原始代码 var button = sender as ButtonX; try { button.Enabled = false; - //#region subin 20231025 分账由实时改为交班时分账 - //splitFrm = new SplitPayUploadForm(0, 100); - //this.Invoke(new EventJisuan(SplitHandle), sender, e); - //#endregion - if (Global.Instance.GlobalConfigBoolValue(ConfigConstant.CONFIG_CASHIER_ISVERIFICATIONORDER)) { int _count = 0; @@ -1189,6 +1189,8 @@ namespace POSV.Shift } } + var shiftDateTime = DateTime.Now; + if (handOverTicket != null) { decimal handsMoney = 0.00M; @@ -1260,45 +1262,90 @@ namespace POSV.Shift #region subin 20231025 分账由实时改为交班时分账 - splitFrm = new SplitPayUploadForm(0, 100); + splitFrm = new SplitPayUploadForm(0, 1000); this.Invoke(new EventJisuan(SplitHandle), sender, e); #endregion - //刷新界面??? - - //交班打印 - this.ShowToastNotify(this, "开始打印"); - //构建收银小票模版参数 - handOverTicket.PrintType = ""; - handOverTicket.handMoney = handsMoney;//手工金额 - handOverTicket.diffMoney = difMoney;//差异金额 - bool ShiftPrint = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CONFIG_CASHIER_SHIFPRINT, false); - - LOGGER.Info("-------------------构建小票参数------------------------------"); - LOGGER.Info(JsonUtils.Serialize(this.handOverTicket)); - var vars = ShiftHelper.BuilderTicketVariable(handOverTicket, ShiftPrint, false); - LOGGER.Info("-------------------------------------------------"); - //交班开钱箱 - bool openCashbox = false; - if (Global.Instance.GlobalConfigBoolValue(ConfigConstant.CONFIG_CASHIER_ISSHIFTOPENCASH)) + ////刷新界面??? + + ////交班打印 + //this.ShowToastNotify(this, "开始打印"); + ////构建收银小票模版参数 + //handOverTicket.PrintType = ""; + //handOverTicket.handMoney = handsMoney;//手工金额 + //handOverTicket.diffMoney = difMoney;//差异金额 + //bool ShiftPrint = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CONFIG_CASHIER_SHIFPRINT, false); + + //LOGGER.Info("-------------------构建小票参数------------------------------"); + //LOGGER.Info(JsonUtils.Serialize(this.handOverTicket)); + //var vars = ShiftHelper.BuilderTicketVariable(handOverTicket, ShiftPrint, false); + //LOGGER.Info("-------------------------------------------------"); + ////交班开钱箱 + //bool openCashbox = false; + //if (Global.Instance.GlobalConfigBoolValue(ConfigConstant.CONFIG_CASHIER_ISSHIFTOPENCASH)) + //{ + // openCashbox = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CONFIG_CASHIER_ISSHIFTOPENCASH); + //} + //Tuple result = ShiftHelper.PrinterTicket("交班汇总", vars, true, openCashbox); + //this.ShowToastNotify(this, string.Format("{0}", result.Item2)); + ////是否交班 + //Global.isHandOver = false; + //StoreBusinessUtils.SaveOperationLog("103", "班次:" + handOverTicket.ShiftNo); + ////关闭当前秤 + //MsgEvent.Send(Constant.CURRENTSTEELYARD_STATUS_CHANGE, "close"); + ////两秒退出系统 + //System.Threading.Thread.Sleep(2000); + //OnCloseTouchClick(sender, e); + ////交班后重启收银程序 + //Global.Instance.Restart = true; + //Application.ExitThread(); + while (splitPayFinished || DateTime.Now.Minute > shiftDateTime.AddMinutes(20).Minute) { - openCashbox = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CONFIG_CASHIER_ISSHIFTOPENCASH); + if (splitPayFinished) + { + LOGGER.Info("交接班分账,splitPayFinished=true"); + } + else if (DateTime.Now.Minute > shiftDateTime.AddMinutes(20).Minute) + { + LOGGER.Info("交接班分账,超出规定分账时长<20>分钟"); + } + splitPayFinished = false; + shiftDateTime = shiftDateTime.AddMinutes(100); + //刷新界面??? + + //交班打印 + this.ShowToastNotify(this, "开始打印"); + //构建收银小票模版参数 + handOverTicket.PrintType = ""; + handOverTicket.handMoney = handsMoney;//手工金额 + handOverTicket.diffMoney = difMoney;//差异金额 + bool ShiftPrint = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CONFIG_CASHIER_SHIFPRINT, false); + + LOGGER.Info("-------------------构建小票参数------------------------------"); + LOGGER.Info(JsonUtils.Serialize(this.handOverTicket)); + var vars = ShiftHelper.BuilderTicketVariable(handOverTicket, ShiftPrint, false); + LOGGER.Info("-------------------------------------------------"); + //交班开钱箱 + bool openCashbox = false; + if (Global.Instance.GlobalConfigBoolValue(ConfigConstant.CONFIG_CASHIER_ISSHIFTOPENCASH)) + { + openCashbox = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CONFIG_CASHIER_ISSHIFTOPENCASH); + } + Tuple result = ShiftHelper.PrinterTicket("交班汇总", vars, true, openCashbox); + this.ShowToastNotify(this, string.Format("{0}", result.Item2)); + //是否交班 + Global.isHandOver = false; + StoreBusinessUtils.SaveOperationLog("103", "班次:" + handOverTicket.ShiftNo); + //关闭当前秤 + MsgEvent.Send(Constant.CURRENTSTEELYARD_STATUS_CHANGE, "close"); + //两秒退出系统 + System.Threading.Thread.Sleep(2000); + OnCloseTouchClick(sender, e); + //交班后重启收银程序 + Global.Instance.Restart = true; + Application.ExitThread(); } - Tuple result = ShiftHelper.PrinterTicket("交班汇总", vars, true, openCashbox); - this.ShowToastNotify(this, string.Format("{0}", result.Item2)); - //是否交班 - Global.isHandOver = false; - StoreBusinessUtils.SaveOperationLog("103", "班次:" + handOverTicket.ShiftNo); - //关闭当前秤 - MsgEvent.Send(Constant.CURRENTSTEELYARD_STATUS_CHANGE, "close"); - //两秒退出系统 - System.Threading.Thread.Sleep(2000); - OnCloseTouchClick(sender, e); - //交班后重启收银程序 - Global.Instance.Restart = true; - Application.ExitThread(); - } } catch (Exception ex) @@ -1309,7 +1356,7 @@ namespace POSV.Shift { button.Enabled = true; } - + #endregion } private void OnControlBoxKeyboardClick(object sender, EventArgs e) @@ -1350,166 +1397,54 @@ namespace POSV.Shift private void SplitHandle(object sender, EventArgs e) { + var sDate = DateTime.Now.ToString("yyyy-MM-dd 00:00:00"); + var eDate = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:00:00"); + var count = 0; + using (var db = Global.Instance.OpenDataBase) + { + count = db.Query($"where isSplited = 0 and finishDate between '{sDate}' and '{eDate}';").Count(); + } + + splitFrm.ProgressBar1.Maximum = count * 2 * 3; splitFrm.Show(this); splitFrm.setPos(0);//设置进度条位置0% //需要加载进度的内容 var isException = SplitPayUtils.Instance.Order2Split(DateTime.Now); if (isException) - { + { LOGGER.Info($"↓↓↓日订单[{DateTime.Now.ToString("yyyy-MM-dd")}]转分账数据失败↓↓↓"); - DialogForm dialog = new DialogForm("提示信息", $"日订单[{DateTime.Now.ToString("yyyy-MM-dd")}]数据处理失败"); - dialog.Show(); + //DialogForm dialog = new DialogForm("提示信息", $"日订单[{DateTime.Now.ToString("yyyy-MM-dd")}]数据处理失败"); + //dialog.Show(); } - splitFrm.setPos(20);//设置进度条位置0% + //splitFrm.setPos(200);//设置进度条位置0% + splitFrm.setPos(count * 2);//设置进度条位置0% #region 上传分账记录 - var result1 = SplitPayUtils.Instance.SplitData2Server(DateTime.Now); + var result1 = SplitPayUtils.Instance.SplitData2Server(DateTime.Now, count * 2); if (result1.Item1) { LOGGER.Info($"↓↓↓日订单[{DateTime.Now.ToString("yyyy-MM-dd")}]分账数据上传完成完成↓↓↓"); } else - { + { LOGGER.Info($"↓↓↓日订单[{DateTime.Now.ToString("yyyy-MM-dd")}]分账数据上传完成失败↓↓↓"); - DialogForm dialog = new DialogForm("提示信息", $"日订单[{DateTime.Now.ToString("yyyy-MM-dd")}]数据上传失败"); - dialog.Show(); + //DialogForm dialog = new DialogForm("提示信息", $"日订单[{DateTime.Now.ToString("yyyy-MM-dd")}]数据上传失败"); + //dialog.Show(); } - splitFrm.setPos(100);//设置进度条位置0% + //splitFrm.setPos(1000);//设置进度条位置0% + splitFrm.setPos(count * 2 + count * 3);//设置进度条位置0% Thread.Sleep(100); splitFrm.Close(); + + MsgEvent.Send(Constant.SPLITPAY_UPLOAD_FINISHED, true); #endregion + } - //#region 交接班 - //if (Global.Instance.GlobalConfigBoolValue(ConfigConstant.CONFIG_CASHIER_ISVERIFICATIONORDER)) - //{ - // int _count = 0; - // //核销提示 - // using (var db = Global.Instance.OpenDataBase) - // { - // using (var transaction = db.GetTransaction()) - // { - // string querySql = "select * from pos_saoma_pay_ticket where payStatus ='{0}'"; - // querySql = string.Format(querySql, 0); - // _count = db.Query(querySql).Count(); - // } - // } - // if (_count > 0) - // { - // DialogForm dialog = new DialogForm("操作提醒", "您有未核销订单,是否继续交班?", MessageBoxIcon.Warning, MessageBoxButtons.OKCancel); - // if (DialogResult.OK != dialog.ShowDialog()) - // { - // return; - // } - - // } - //} - - //if (handOverTicket != null) - //{ - // decimal handsMoney = 0.00M; - // decimal difMoney = 0.00M; - - // string shiftNo = OrderUtils.Instance.GenerateShiftNo(); - // handOverTicket.Id = IdWorkerUtils.Instance.NextId(); - // handOverTicket.No = shiftNo; - // handOverTicket.Memo = memoTextBox.Text; - - // handOverTicket.ShiftNo = Global.Instance.BusinessPlanLog.No; - - // if (handOverTicket.Detail != null) - // { - // foreach (HandOverDetail handOverDetail in handOverTicket.Detail) - // { - // handOverDetail.Id = IdWorkerUtils.Instance.NextId(); - // handOverDetail.TenantId = handOverTicket.TenantId; - // handOverDetail.BusNo = handOverTicket.No; - // handOverDetail.PosNo = Global.Instance.Authc.PosNo; - // handOverDetail.DeviceIp = DeviceUtils.Instance.IPAddress; - // handOverDetail.DeviceMac = DeviceUtils.Instance.MacAddress; - // handOverDetail.DeviceName = DeviceUtils.Instance.ComputerName; - // handOverDetail.HandsMoney = handOverDetail.SumMoney; - // if ("01".Equals(handOverDetail.PayModeNo)) - // { - // handsMoney = handOverDetail.SumMoney + handOverTicket.Inmoney - handOverTicket.Outmoney; - // //人民币金额计算方式 - // handOverDetail.HandsMoney = handsMoney; - // difMoney = 0.00M; - // } - - // handOverDetail.StoreId = handOverTicket.StoreId; - // handOverDetail.TicketId = handOverTicket.Id; - // } - // } - - // if (handOverTicket.Pay != null) - // { - // foreach (HandOverPay handOverPay in handOverTicket.Pay) - // { - // handOverPay.Id = IdWorkerUtils.Instance.NextId(); - // handOverPay.TenantId = handOverTicket.TenantId; - // handOverPay.BusNo = handOverTicket.No; - // handOverPay.PosNo = Global.Instance.Authc.PosNo; - // handOverPay.DeviceIp = DeviceUtils.Instance.IPAddress; - // handOverPay.DeviceMac = DeviceUtils.Instance.MacAddress; - // handOverPay.DeviceName = DeviceUtils.Instance.ComputerName; - // handOverPay.StoreId = handOverTicket.StoreId; - // handOverPay.TicketId = handOverTicket.Id; - // } - // } - // saveHandOver(handOverTicket); - - - // var uploadObject = new UploadHandoverObject(); - // uploadObject.Id = IdWorkerUtils.Instance.NextId(); - // uploadObject.TenantId = this.handOverTicket.TenantId; - // uploadObject.TradeNo = this.handOverTicket.No; - // uploadObject.SyncStatus = 0; - // uploadObject.HandOverTicket = this.handOverTicket; - // uploadObject.PrintStatus = HandOverPrintStatus.WAIT; - // uploadObject.UploadErrors = 0; - // uploadObject.PrintTimes = 0; - // saveHandOverObject(uploadObject); - // //有要上传的数据 - // LOGGER.Info("有需要上传的交班数据,isHaveUpLoadShift=true"); - // Global.isHaveUpLoadShift = true; - - // //刷新界面??? - - // //交班打印 - // this.ShowToastNotify(this, "开始打印"); - // //构建收银小票模版参数 - // handOverTicket.PrintType = ""; - // handOverTicket.handMoney = handsMoney;//手工金额 - // handOverTicket.diffMoney = difMoney;//差异金额 - // bool ShiftPrint = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CONFIG_CASHIER_SHIFPRINT, false); - - // LOGGER.Info("-------------------构建小票参数------------------------------"); - // LOGGER.Info(JsonUtils.Serialize(this.handOverTicket)); - // var vars = ShiftHelper.BuilderTicketVariable(handOverTicket, ShiftPrint, false); - // LOGGER.Info("-------------------------------------------------"); - // //交班开钱箱 - // bool openCashbox = false; - // if (Global.Instance.GlobalConfigBoolValue(ConfigConstant.CONFIG_CASHIER_ISSHIFTOPENCASH)) - // { - // openCashbox = Global.Instance.GlobalConfigBoolValue(ConfigConstant.CONFIG_CASHIER_ISSHIFTOPENCASH); - // } - // Tuple result = ShiftHelper.PrinterTicket("交班汇总", vars, true, openCashbox); - // this.ShowToastNotify(this, string.Format("{0}", result.Item2)); - // //是否交班 - // Global.isHandOver = false; - // StoreBusinessUtils.SaveOperationLog("103", "班次:" + handOverTicket.ShiftNo); - // //关闭当前秤 - // MsgEvent.Send(Constant.CURRENTSTEELYARD_STATUS_CHANGE, "close"); - // //两秒退出系统 - // System.Threading.Thread.Sleep(2000); - // OnCloseTouchClick(sender, e); - // //交班后重启收银程序 - // Global.Instance.Restart = true; - // Application.ExitThread(); - - //} - //#endregion + protected virtual void SplitPayFinishEventNotify(object sender, MsgEventArgs args) + { + splitPayFinished = true; + LOGGER.Info("交接班分账完成"); } #endregion } diff --git a/pos/POSV.Template/Shift/SplitPayUploadForm.Designer.cs b/pos/POSV.Template/Shift/SplitPayUploadForm.Designer.cs index 2601939..36d9ff2 100644 --- a/pos/POSV.Template/Shift/SplitPayUploadForm.Designer.cs +++ b/pos/POSV.Template/Shift/SplitPayUploadForm.Designer.cs @@ -38,6 +38,7 @@ namespace POSV.Shift this.ProgressBar1.Dock = System.Windows.Forms.DockStyle.Top; this.ProgressBar1.Location = new System.Drawing.Point(0, 0); this.ProgressBar1.Margin = new System.Windows.Forms.Padding(6); + this.ProgressBar1.Maximum = 1000; this.ProgressBar1.Name = "ProgressBar1"; this.ProgressBar1.Size = new System.Drawing.Size(534, 42); this.ProgressBar1.TabIndex = 1; @@ -60,7 +61,7 @@ namespace POSV.Shift // // SplitPayUploadForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); + this.AutoScaleDimensions = new System.Drawing.SizeF(14F, 31F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(534, 69); this.Controls.Add(this.labelX1);