1267 lines
70 KiB
C#
1267 lines
70 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using ESSupport.Lib;
|
||
using ESSupport.Pos;
|
||
using ConnectPoint.Common;
|
||
using System.Collections;
|
||
using Newtonsoft.Json;
|
||
using System.Data;
|
||
using Newtonsoft.Json.Linq;
|
||
|
||
namespace ConnectPoint
|
||
{
|
||
public class ThreadHelper
|
||
{
|
||
#region 方法 -> 实时交易数据统计上报
|
||
/// <summary>
|
||
/// 实时交易数据统计上报
|
||
/// </summary>
|
||
/// <param name="serviceURL">服务URL地址</param>
|
||
public static void DataCollectionUpload(string serviceURL)
|
||
{
|
||
//获取服务区编码
|
||
string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
|
||
//获取门店编码
|
||
string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
|
||
//获取收银机号
|
||
string _MachineCode = PosConfigInit.ConfigurationValues("machinecode", string.Empty);
|
||
//获取新系统标识
|
||
bool _NewSystem = PosConfigInit.ConfigurationValues("NewSystem", "0") == "1";
|
||
DataStatistics _DataStatistics = new DataStatistics
|
||
{
|
||
ServerPartCode = _ServerPartCode,
|
||
ShopCode = _ShopCode,
|
||
MachineCode = _MachineCode
|
||
};
|
||
//业态营业时间采集
|
||
_DataStatistics.BusinessTime(_NewSystem);
|
||
|
||
try
|
||
{
|
||
//十分钟实时交易数据统计
|
||
Model.DataCollectionModel _DataCollectionModel = _DataStatistics.GetDataCollection(_NewSystem);
|
||
if (_DataCollectionModel != null)
|
||
{
|
||
try
|
||
{
|
||
//记录上传
|
||
SoapWSHelper.QuerySoapWebServiceString(
|
||
serviceURL, "FeedbackUpload", new Hashtable
|
||
{
|
||
{ "feedbackType", "DataCollection" },
|
||
{ "jsonData", JsonConvert.SerializeObject(_DataCollectionModel) }
|
||
});
|
||
}
|
||
catch { }
|
||
try
|
||
{
|
||
//本地记录保存
|
||
SyBaseHelper.ExecuteSqlTran($@"INSERT INTO T_DATACOLLECTION
|
||
(DATACOLLECTION_ID,SERVERPARTCODE,SHOPCODE,MACHINECODE,
|
||
MACADDRESS,MACHINENAME,DATACOLLECTION_TYPE,
|
||
DATACOLLECTION_DATE,TOTAL_COUNT,TOTALSELL_AMOUNT,
|
||
TICKET_COUNT,TICKET_INFO)
|
||
VALUES ({_DataCollectionModel.DATACOLLECTION_ID},
|
||
'{_DataCollectionModel.SERVERPARTCODE}','{_DataCollectionModel.SHOPCODE}',
|
||
'{_DataCollectionModel.MACHINECODE}','{_DataCollectionModel.MACADDRESS}',
|
||
'{_DataCollectionModel.MACHINENAME}',2000,
|
||
DATETIME('{_DataCollectionModel.DATACOLLECTION_DATE.Value.ToString("yyyy/MM/dd HH:mm:ss")}'),
|
||
{_DataCollectionModel.TOTAL_COUNT},{_DataCollectionModel.TOTALSELL_AMOUNT},
|
||
{_DataCollectionModel.TICKET_COUNT},'{_DataCollectionModel.TICKET_INFO}')");
|
||
}
|
||
catch { }
|
||
}
|
||
}
|
||
catch { }
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 收银机状态上报
|
||
/// <summary>
|
||
/// 收银机状态上报
|
||
/// </summary>
|
||
/// <param name="serviceURL">服务URL地址</param>
|
||
public static void StateFeedbackUpload(string serviceURL)
|
||
{
|
||
try
|
||
{
|
||
//获取服务区编码
|
||
string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
|
||
//获取门店编码
|
||
string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
|
||
//获取收银机号
|
||
string _MachineCode = PosConfigInit.ConfigurationValues("machinecode", string.Empty);
|
||
//获取新系统标识
|
||
bool _NewSystem = PosConfigInit.ConfigurationValues("NewSystem", "0") == "1";
|
||
DataStatistics _DataStatistics = new DataStatistics
|
||
{
|
||
ServerPartCode = _ServerPartCode,
|
||
ShopCode = _ShopCode,
|
||
MachineCode = _MachineCode
|
||
};
|
||
//获取当日销售统计数据
|
||
PaymentInfo _PaymentInfo = _DataStatistics.GetSellStatistics(_NewSystem);
|
||
//获取本地数据版本列表
|
||
List<Model.DataVersionModel> _LocalDataVersionList = _DataStatistics.GetLocalDataVersion(_NewSystem);
|
||
Model.StateFeedbackModel _StateFeedbackModel = new Model.StateFeedbackModel
|
||
{
|
||
STATEFEEDBACK_ID = 1,
|
||
CONNECT_DATE = DateTime.Now,
|
||
SERVERPARTCODE = _ServerPartCode,
|
||
SHOPCODE = _ShopCode,
|
||
MACHINECODE = _MachineCode,
|
||
MACHINENAME = System.Net.Dns.GetHostName(),
|
||
MACHINE_MACADDRESS = PCHelper.GetMacAddressByNetworkInformation(),
|
||
CONNECT_IP = PCHelper.GetAddressIP(),
|
||
CURRENT_SELLAMOUNT = _PaymentInfo.FactAmount,
|
||
CURRENT_CASHPAY = _PaymentInfo.CashPay,
|
||
CURRENT_MOBILEPAY = _PaymentInfo.MobilePay,
|
||
CURRENT_ALIPAY = _PaymentInfo.Alipay,
|
||
CURRENT_WECHAT = _PaymentInfo.Wechat,
|
||
CURRENT_UNIONPAY = _PaymentInfo.UnionPay,
|
||
CURRENT_SELLCOUNT = _PaymentInfo.SellCount,
|
||
CURRENT_TICKETCOUNT = _PaymentInfo.TicketCount,
|
||
CURRENT_GOODSCOUNT = _DataStatistics.GetCommodityCount(),
|
||
CURRENT_PERSON = _DataStatistics.GetPersonName(_NewSystem),
|
||
SELL_CONTENT = $"{_DataStatistics.GetLastTrade(_NewSystem)}|{_DataStatistics.GetLastSellData(_NewSystem)}",
|
||
VERSION_NUM = PosConfigInit.ConfigurationValues("version", ""),
|
||
CONFIG_CONTENT = _DataStatistics.GetPosConfig(),
|
||
STATEFEEDBACK_DESC = _DataStatistics.GetSalesPromote()
|
||
};
|
||
//读取收银端软件有效期时间,空值代表未设置软件有效期
|
||
if (DateTime.TryParse(PosConfigInit.ConfigurationValues("EXPIRYDATE", ""), out DateTime date_ExpiryDate))
|
||
{
|
||
_StateFeedbackModel.EXPIRYDATE_VERSION = date_ExpiryDate;
|
||
}
|
||
|
||
foreach (Model.DataVersionModel _LocalDataVersion in _LocalDataVersionList)
|
||
{
|
||
switch (_LocalDataVersion.DataTableName.ToUpper())
|
||
{
|
||
case "COMMODITYEX"://收银机本地商品数据版本
|
||
_StateFeedbackModel.COMMODITY_VERSION = _LocalDataVersion.DataVersion;
|
||
break;
|
||
case "COMMODITYSALE"://收银机本地单品数据版本
|
||
_StateFeedbackModel.COMMODITYSALE_VERSION = _LocalDataVersion.DataVersion;
|
||
//更新本地已上传单品记录参数,用于PB系统
|
||
if (_LocalDataVersion.TransState.HasValue && _LocalDataVersion.TransState.Value != 0 && _LocalDataVersion.DataVersion.HasValue)
|
||
{
|
||
PosConfigInit.UpdateConfigUration("CommoditySale", _LocalDataVersion.DataVersion.Value.ToString());
|
||
}
|
||
break;
|
||
case "PERSONSELL"://收银机本地交班记录数据版本
|
||
_StateFeedbackModel.PERSONSELL_VERSION = _LocalDataVersion.DataVersion;
|
||
//更新本地已上传交班记录参数,用于PB系统
|
||
if (_LocalDataVersion.TransState.HasValue && _LocalDataVersion.TransState.Value != 0 && _LocalDataVersion.DataVersion.HasValue)
|
||
{
|
||
PosConfigInit.UpdateConfigUration("Personsell", _LocalDataVersion.DataVersion.Value.ToString());
|
||
}
|
||
break;
|
||
case "ENDACCOUNT"://收银机本地日结营收数据版本
|
||
_StateFeedbackModel.ENDACCOUNT_VERSION = _LocalDataVersion.DataVersion;
|
||
//更新本地已上传日结记录参数,用于PB系统
|
||
if (_LocalDataVersion.TransState.HasValue && _LocalDataVersion.TransState.Value != 0 && _LocalDataVersion.DataVersion.HasValue)
|
||
{
|
||
PosConfigInit.UpdateConfigUration("EndAccount", _LocalDataVersion.DataVersion.Value.ToString());
|
||
}
|
||
break;
|
||
case "INSPECTION"://收银机本地收银稽核数据版本
|
||
_StateFeedbackModel.INSPECTION_VERSION = _LocalDataVersion.DataVersion;
|
||
break;
|
||
case "SALESPROMOTE"://收银机本地促销活动数据版本
|
||
_StateFeedbackModel.SALESPROMOTE_VERSION = _LocalDataVersion.DataVersion;
|
||
break;
|
||
case "SHOPMESSAGE"://收银机本地门店数据版本
|
||
_StateFeedbackModel.SHOPMESSAGE_VERSION = _LocalDataVersion.DataVersion;
|
||
break;
|
||
case "SELLWORKER"://收银机本地收银工号数据版本
|
||
_StateFeedbackModel.SELLWORKER_VERSION = _LocalDataVersion.DataVersion;
|
||
break;
|
||
case "AUDITTASK"://收银机本地稽核任务数据版本
|
||
_StateFeedbackModel.AUDITTASK_VERSION = _LocalDataVersion.DataVersion;
|
||
break;
|
||
}
|
||
}
|
||
SoapWSHelper.QuerySoapWebServiceString(
|
||
serviceURL, "FeedbackUpload", new Hashtable
|
||
{
|
||
{ "feedbackType", "StateFeedback" },
|
||
{ "jsonData", JsonConvert.SerializeObject(_StateFeedbackModel) }
|
||
});
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.WriteServiceLog($"状态反馈上报失败:{ex.Message}");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 收银机器信息上报
|
||
/// <summary>
|
||
/// 收银机器信息上报
|
||
/// </summary>
|
||
/// <param name="serviceURL">服务URL地址</param>
|
||
public static void MachineInfoFeedbackUpload(string serviceURL)
|
||
{
|
||
try
|
||
{
|
||
//获取服务区编码
|
||
string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
|
||
//获取门店编码
|
||
string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
|
||
//获取收银机号
|
||
string _MachineCode = PosConfigInit.ConfigurationValues("machinecode", string.Empty);
|
||
|
||
Model.MachineInfoModel _MachineInfoModel = new Model.MachineInfoModel
|
||
{
|
||
MACHINEINFO_ID = 1,
|
||
SERVERPARTCODE = _ServerPartCode,
|
||
SHOPCODE = _ShopCode,
|
||
SERVER_IP = PosConfigInit.ConfigurationValues("server_ip", string.Empty),
|
||
MACHINECODE = _MachineCode,
|
||
MACHINENAME = System.Net.Dns.GetHostName(),
|
||
MACHINE_MACADDRESS = PCHelper.GetMacAddressByNetworkInformation(),
|
||
MACHINE_IP = PCHelper.GetAddressIP(),
|
||
ADDDATE = DateTime.Now,
|
||
FLAG = 1
|
||
};
|
||
SoapWSHelper.QuerySoapWebServiceString(
|
||
serviceURL, "FeedbackUpload", new Hashtable
|
||
{
|
||
{ "feedbackType", "MachineInfoFeedback" },
|
||
{ "jsonData", JsonConvert.SerializeObject(_MachineInfoModel) }
|
||
});
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.WriteServiceLog($"状态反馈上报失败:{ex.Message}");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 移动支付交易校验
|
||
/// <summary>
|
||
/// 移动支付交易校验
|
||
/// </summary>
|
||
/// <param name="payServiceUrl">服务接口地址</param>
|
||
/// <param name="payStartDate">校验起始时间</param>
|
||
public static void MobilePayCheck(string payServiceUrl, DateTime payStartDate)
|
||
{
|
||
//获取服务区编码
|
||
string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
|
||
//获取门店编码
|
||
string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
|
||
//获取收银机号
|
||
string _MachineCode = PosConfigInit.ConfigurationValues("machinecode", string.Empty);
|
||
|
||
try
|
||
{
|
||
DataTable _tableMobilePay = SyBaseHelper.QueryOdbc(
|
||
$@"SELECT TICKET_CODE FROM T_MOBILE_PAY
|
||
WHERE MOBILEPAY_DATE BETWEEN DATETIME('{payStartDate.ToString("yyyy/MM/dd HH:mm:ss")}') AND
|
||
DATETIME('{DateTime.Now.AddMinutes(-5).ToString("yyyy/MM/dd HH:mm:ss")}') AND
|
||
MOBILEPAY_RESULT NOT IN(1,5,9)").Tables[0];
|
||
if (_tableMobilePay.Rows.Count > 0)
|
||
{
|
||
string _strOrderCode = "";
|
||
string _strLeft = _ServerPartCode + _ShopCode + _MachineCode.PadLeft(4, '0');
|
||
List<string> _listUpdate = new List<string>();
|
||
for (int i = 0; i < _tableMobilePay.Rows.Count; i++)
|
||
{
|
||
_strOrderCode += (_strOrderCode == "" ? "" : ",") + _tableMobilePay.Rows[i]["TICKET_CODE"].ToString().Replace(_strLeft, "");
|
||
if ((i + 1) % 20 == 0 || (i + 1) == _tableMobilePay.Rows.Count)
|
||
{
|
||
try
|
||
{
|
||
string _strResult = SoapWSHelper.QuerySoapWebServiceString(
|
||
payServiceUrl, "MobilePayCheck", new Hashtable
|
||
{
|
||
{ "serverPartCode", _ServerPartCode },
|
||
{ "shopCode", _ShopCode },
|
||
{ "machineCode", _MachineCode },
|
||
{ "mobilePayOrderCode", _strOrderCode }
|
||
});
|
||
if (!string.IsNullOrWhiteSpace(_strResult))
|
||
{
|
||
DataTable _tableResult = JsonHelper.JsonToDataSet(_strResult).Tables[0];
|
||
string _strTicketCode = "";
|
||
for (int n = 0; n < _tableResult.Rows.Count; n++)
|
||
{
|
||
_strTicketCode += (_strTicketCode == "" ? "" : ",") + "'" + _tableResult.Rows[n]["TICKETCODE"].ToString() + "'";
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(_strTicketCode))
|
||
{
|
||
_listUpdate.Add(string.Format("UPDATE T_MOBILE_PAY SET MOBILEPAY_RESULT = 5, MOBILEPAY_STATE = 0" +
|
||
"WHERE TICKET_CODE IN({0}) AND MOBILEPAY_RESULT NOT IN (1,5,9)", _strTicketCode));
|
||
_listUpdate.Add(string.Format("UPDATE T_SELLDATA_PAY SET SELLDATAPAY_STATE = 8 " +
|
||
"WHERE ORDERCODE IN ({0}) AND SELLDATAPAY_STATE NOT IN (1,9)", _strTicketCode));
|
||
}
|
||
}
|
||
}
|
||
catch
|
||
{ }
|
||
_strOrderCode = "";
|
||
}
|
||
}
|
||
if (_listUpdate.Count > 0)
|
||
{
|
||
try
|
||
{
|
||
SyBaseHelper.ExecuteSqlTran(_listUpdate);
|
||
}
|
||
catch
|
||
{ }
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.WriteServiceLog("移动支付交易校验异常:" + ex.Message);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 通过移动支付通道商接口校验支付结果
|
||
/// <summary>
|
||
/// 通过移动支付通道商接口校验支付结果
|
||
/// </summary>
|
||
/// <param name="payServiceUrl">默认移动支付接口地址</param>
|
||
/// <param name="payStartDate">校验的移动支付交易起始时间</param>
|
||
public static void MobilePayQueryCheck(string payServiceUrl, DateTime payStartDate)
|
||
{
|
||
try
|
||
{
|
||
//获取服务区编码
|
||
string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
|
||
//获取门店编码
|
||
string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
|
||
//获取收银机号
|
||
string _MachineCode = PosConfigInit.ConfigurationValues("machinecode", string.Empty);
|
||
if (PosControl.PayServiceList == null)
|
||
{
|
||
PosControl.PayServiceList = new System.Collections.Concurrent.ConcurrentDictionary<PosDictionary.MobilePayOperators, string>();
|
||
GetMobilePayOperators(PosConfigInit.ConfigurationValues("server_ip", string.Empty));
|
||
}
|
||
//实例化数据操作类
|
||
DataStatistics _DataStatistics = new DataStatistics
|
||
{
|
||
ServerPartCode = _ServerPartCode,
|
||
ShopCode = _ShopCode,
|
||
MachineCode = _MachineCode
|
||
};
|
||
//获取是否直连移动支付交易参数
|
||
string _MobilePayProxy = PosConfigInit.ConfigurationValues("MobilePayProxy", "0");
|
||
//获取所有不成功的交易记录
|
||
DataTable _DataTable = SyBaseHelper.QueryOdbc(
|
||
$@"SELECT MOBILEPAY_TYPE,TICKET_CODE,
|
||
TICKET_AMOUNT,MOBILEPAY_OPERATORS
|
||
FROM T_MOBILE_PAY
|
||
WHERE TICKET_AMOUNT > 0 AND MOBILEPAY_RESULT NOT IN(1,5,9) AND
|
||
MOBILEPAY_DATE BETWEEN DATETIME('{payStartDate.ToString("yyyy/MM/dd HH:mm:ss")}') AND
|
||
DATETIME('{DateTime.Now.AddMinutes(-5).ToString("yyyy/MM/dd HH:mm:ss")}') ").Tables[0];
|
||
//循环查询交易结果
|
||
for (int i = 0; i < _DataTable.Rows.Count; i++)
|
||
{
|
||
string _Result = "";
|
||
List<string> _UpdateList = new List<string>();
|
||
try
|
||
{
|
||
string _strServiceURL = "";
|
||
Enum.TryParse(_DataTable.Rows[i]["MOBILEPAY_OPERATORS"].ToString(), out PosDictionary.MobilePayOperators mobilePayOperators);
|
||
if (PosControl.PayServiceList != null && PosControl.PayServiceList.ContainsKey(mobilePayOperators))
|
||
{
|
||
_strServiceURL = PosControl.PayServiceList[mobilePayOperators];
|
||
}
|
||
else
|
||
{
|
||
_strServiceURL = payServiceUrl;
|
||
}
|
||
//富友
|
||
if (mobilePayOperators == PosDictionary.MobilePayOperators.fuiou)
|
||
{
|
||
Hashtable hashtable = new Hashtable
|
||
{
|
||
{ "TICKETCODE", _DataTable.Rows[i]["TICKET_CODE"].ToString() },
|
||
{ "PAYTYPE", _DataTable.Rows[i]["MOBILEPAY_TYPE"].ToString() },
|
||
{ "_mchnt_cd", "" },
|
||
{ "_term_id", "" },
|
||
{ "InsertType", "1" }
|
||
};
|
||
_Result = SoapWSHelper.QuerySoapWebServiceString(_strServiceURL, "querypay", hashtable);
|
||
}
|
||
//付付/客无忧/威付通
|
||
else
|
||
{
|
||
Hashtable hashtable = new Hashtable
|
||
{
|
||
{ "TICKETCODE", _DataTable.Rows[i]["TICKET_CODE"].ToString() },
|
||
{ "OUT_TRADE_NO", "" },
|
||
{ "TICKETPRICE", ((decimal)_DataTable.Rows[i]["TICKET_AMOUNT"]).ToString("F2") },
|
||
{ "PAYTYPE", _DataTable.Rows[i]["MOBILEPAY_TYPE"].ToString() },
|
||
{ "TotalCount", 1 }
|
||
};
|
||
if (_MobilePayProxy == "1" &&
|
||
PosControl.MobilePayMerchantList != null &&
|
||
PosControl.MobilePayMerchantList.ContainsKey(mobilePayOperators))
|
||
{
|
||
switch (mobilePayOperators)
|
||
{
|
||
case PosDictionary.MobilePayOperators.kwypay:
|
||
_Result = libESPay.ESPayService.KwyPayQuery(
|
||
PosControl.MobilePayMerchantList[mobilePayOperators].Busi_id,
|
||
PosControl.MobilePayMerchantList[mobilePayOperators].Key,
|
||
_DataTable.Rows[i]["TICKET_CODE"].ToString(), "",
|
||
((decimal)_DataTable.Rows[i]["TICKET_AMOUNT"]).ToString("F2"));
|
||
_DataStatistics.InsertOrUpdateMobilePayRecord(mobilePayOperators,
|
||
PosControl.MobilePayMerchantList[mobilePayOperators].Busi_id,
|
||
PosControl.MobilePayMerchantList[mobilePayOperators].Key,
|
||
_DataTable.Rows[i]["MOBILEPAY_TYPE"].ToString(),
|
||
_DataTable.Rows[i]["TICKET_CODE"].ToString(),
|
||
((decimal)_DataTable.Rows[i]["TICKET_AMOUNT"]).ToString("F2"), _Result);
|
||
break;
|
||
case PosDictionary.MobilePayOperators.unionpay:
|
||
_Result = libESPay.ESPayService.UnionPayQuery(
|
||
PosControl.MobilePayMerchantList[mobilePayOperators].Busi_id,
|
||
PosControl.MobilePayMerchantList[mobilePayOperators].Key,
|
||
_DataTable.Rows[i]["TICKET_CODE"].ToString(), "",
|
||
((decimal)_DataTable.Rows[i]["TICKET_AMOUNT"]).ToString("F2"));
|
||
_DataStatistics.InsertOrUpdateMobilePayRecord(mobilePayOperators,
|
||
PosControl.MobilePayMerchantList[mobilePayOperators].Busi_id,
|
||
PosControl.MobilePayMerchantList[mobilePayOperators].Key,
|
||
_DataTable.Rows[i]["MOBILEPAY_TYPE"].ToString(),
|
||
_DataTable.Rows[i]["TICKET_CODE"].ToString(),
|
||
((decimal)_DataTable.Rows[i]["TICKET_AMOUNT"]).ToString("F2"), _Result);
|
||
break;
|
||
case PosDictionary.MobilePayOperators.irichpay:
|
||
_Result = libESPay.ESPayService.IRichPayQuery(
|
||
PosControl.MobilePayMerchantList[mobilePayOperators].Busi_id,
|
||
PosControl.MobilePayMerchantList[mobilePayOperators].Key,
|
||
_DataTable.Rows[i]["TICKET_CODE"].ToString(), "",
|
||
((decimal)_DataTable.Rows[i]["TICKET_AMOUNT"]).ToString("F2"));
|
||
_DataStatistics.InsertOrUpdateMobilePayRecord(mobilePayOperators,
|
||
PosControl.MobilePayMerchantList[mobilePayOperators].Busi_id,
|
||
PosControl.MobilePayMerchantList[mobilePayOperators].Key,
|
||
_DataTable.Rows[i]["MOBILEPAY_TYPE"].ToString(),
|
||
_DataTable.Rows[i]["TICKET_CODE"].ToString(),
|
||
((decimal)_DataTable.Rows[i]["TICKET_AMOUNT"]).ToString("F2"), _Result);
|
||
break;
|
||
default:
|
||
_Result = SoapWSHelper.QuerySoapWebServiceString(_strServiceURL, "querypaynew", hashtable);
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
_Result = SoapWSHelper.QuerySoapWebServiceString(_strServiceURL, "querypaynew", hashtable);
|
||
}
|
||
}
|
||
if (_Result != "")
|
||
{
|
||
JObject _JObject = JObject.Parse(_Result);
|
||
if (_JObject["result_code"].ToString() == "100")
|
||
{
|
||
_UpdateList.Add(String.Format("UPDATE T_MOBILE_PAY SET MOBILEPAY_RESULT = 5, MOBILEPAY_STATE = 0 " +
|
||
"WHERE TICKET_CODE = '{0}' AND MOBILEPAY_RESULT NOT IN (1,5,9)", _DataTable.Rows[i]["TICKET_CODE"].ToString()));
|
||
_UpdateList.Add(String.Format("UPDATE T_SELLDATA_PAY SET SELLDATAPAY_STATE = 8 " +
|
||
"WHERE ORDERCODE = '{0}' AND SELLDATAPAY_STATE NOT IN (1,9)", _DataTable.Rows[i]["TICKET_CODE"].ToString()));
|
||
SyBaseHelper.ExecuteSqlTran(_UpdateList);
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.WriteServiceLog("移动支付校验:[" + _DataTable.Rows[i]["TICKET_CODE"].ToString() + "]" + ex.Message);
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.WriteServiceLog("移动支付交易校验失败(支付通道):" + ex.Message);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取主备用通道对应的移动支付服务商,并初始化交易参数
|
||
/// </summary>
|
||
/// <param name="paySeviceIP">支付通道服务器IP地址</param>
|
||
private static void GetMobilePayOperators(string paySeviceIP)
|
||
{
|
||
try
|
||
{
|
||
string retString = "";
|
||
//获取服务区编码
|
||
string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
|
||
//获取门店编码
|
||
string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
|
||
string[] ars_ServicePort = new string[]
|
||
{
|
||
PosConfigInit.ConfigurationValues("service_port", "7080"),
|
||
PosConfigInit.ConfigurationValues("service_port2", "7080"),
|
||
PosConfigInit.ConfigurationValues("service_port3", "7080"),
|
||
PosConfigInit.ConfigurationValues("service_port4", "7080"),
|
||
PosConfigInit.ConfigurationValues("service_port5", "7080")
|
||
};
|
||
foreach (var str_ServicePort in ars_ServicePort)
|
||
{
|
||
|
||
string _strServiceURL = string.Format("http://{0}:{1}/service.asmx", paySeviceIP, str_ServicePort);
|
||
if (!PosControl.PayServiceList.Values.Contains(_strServiceURL))
|
||
{
|
||
Hashtable hashtable = new Hashtable
|
||
{
|
||
{ "serverPartCode", _ServerPartCode },
|
||
{ "shopCode", _ShopCode }
|
||
};
|
||
retString = SoapWSHelper.QuerySoapWebServiceString(_strServiceURL, "GetMerchant", hashtable);
|
||
if (retString.Trim() != "")
|
||
{
|
||
JObject _JObject = JObject.Parse(retString);
|
||
string TradeOn = _JObject["trade_no"].ToString();
|
||
string TradeNum = _JObject["trade_num"].ToString();
|
||
string ResultDesc = _JObject["result_desc"].ToString();
|
||
string ResultCode = _JObject["result_code"].ToString();
|
||
|
||
if (Enum.TryParse(ResultDesc, out PosDictionary.MobilePayOperators _MobilePayOperators))
|
||
{
|
||
PosControl.PayServiceList.AddOrUpdate(_MobilePayOperators, _strServiceURL, (operators, serviceURL) => _strServiceURL);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.WriteServiceLog("备用通道信息初始化:" + ex.Message);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 获取门店移动支付通道配置
|
||
/// <summary>
|
||
/// 获取门店移动支付通道配置
|
||
/// </summary>
|
||
/// <param name="serviceURL">接口地址</param>
|
||
/// <param name="serverPartCode">服务区编码</param>
|
||
/// <param name="businessType">业态编码</param>
|
||
public static void MobilePayConfigUpdate(string paySeviceIP)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(paySeviceIP))
|
||
{
|
||
return;
|
||
}
|
||
//获取服务区编码
|
||
string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
|
||
//获取门店编码
|
||
string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
|
||
|
||
if (string.IsNullOrWhiteSpace(_ServerPartCode) || string.IsNullOrWhiteSpace(_ShopCode))
|
||
{
|
||
return;
|
||
}
|
||
try
|
||
{
|
||
string _BusinessType = SyBaseHelper.QueryOdbc(
|
||
$@"SELECT BUSINESSTYPE FROM T_SHOPMESSAGE
|
||
WHERE SERVERPARTCODE = '{_ServerPartCode}' AND
|
||
SHOPCODE = '{_ShopCode}'").Tables[0].Rows[0]["BUSINESSTYPE"].ToString();
|
||
|
||
string[] _ServicePort = new string[]
|
||
{
|
||
PosConfigInit.ConfigurationValues("service_port", "7080"),
|
||
PosConfigInit.ConfigurationValues("service_port2", "7080"),
|
||
PosConfigInit.ConfigurationValues("DataServicePort", "7080")
|
||
};
|
||
List<string> _ServiceUrlList = new List<string>();
|
||
for (int i = 0; i < _ServicePort.Count(); i++)
|
||
{
|
||
_ServiceUrlList.Add(string.Format("http://{0}:{1}/Service.asmx", paySeviceIP, _ServicePort[i]));
|
||
}
|
||
Hashtable hashtable = new Hashtable
|
||
{
|
||
{ "serverPartCode", _ServerPartCode },
|
||
{ "businessType", _BusinessType }
|
||
};
|
||
foreach (string _strServiceUrl in _ServiceUrlList)
|
||
{
|
||
try
|
||
{
|
||
string _strResult = SoapWSHelper.QuerySoapWebServiceString(_strServiceUrl, "MobilePayConfig", hashtable);
|
||
if (!string.IsNullOrWhiteSpace(_strResult))
|
||
{
|
||
DataTable _DateTable = JsonHelper.JsonToDataTable(_strResult);
|
||
if (_DateTable != null && _DateTable.Rows.Count > 0)
|
||
{
|
||
foreach (DataRow _DataRow in _DateTable.Rows)
|
||
{
|
||
PosConfigInit.UpdateConfigUration(_DataRow["k"].ToString(), _DataRow["v"].ToString());
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.WriteServiceLog("移动支付通道配置下载异常:" + ex.Message);
|
||
}
|
||
}
|
||
}
|
||
catch { }
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 记录系统运行时间日志
|
||
/// <summary>
|
||
/// 记录系统运行时间日志
|
||
/// </summary>
|
||
/// <param name="runingTime">最后一次记录时间</param>
|
||
/// <returns></returns>
|
||
public static bool RuningLog(DateTime runingTime)
|
||
{
|
||
if (runingTime == DateTime.MinValue)
|
||
{
|
||
try
|
||
{
|
||
runingTime = (DateTime)SyBaseHelper.QueryOdbc(
|
||
@"SELECT MAX(LOGGING_DATE) AS LOGGING_DATE
|
||
FROM T_ACTIVELOGGING").Tables[0].Rows[0][0];
|
||
}
|
||
catch
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
TimeSpan _TimeSpan = DateTime.Now.Subtract(runingTime);
|
||
if ((int)_TimeSpan.TotalSeconds >= 300)
|
||
{
|
||
//获取服务区编码
|
||
string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
|
||
//获取门店编码
|
||
string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
|
||
//获取收银机号
|
||
string _MachineCode = PosConfigInit.ConfigurationValues("machinecode", string.Empty);
|
||
try
|
||
{
|
||
SyBaseHelper.ExecuteSqlTran(
|
||
$@"INSERT INTO T_ACTIVELOGGING (ACTIVELOGGING_ID,
|
||
SERVERPARTCODE, SHOPCODE,MACHINECODE,MACHINENAME,
|
||
MACADDRESS,MACHINE_IP,LOGGING_DATE,RUNNING_INTERVAL)
|
||
VALUES ( {PosReport.CreateNextSequence("T_ACTIVELOGGING", "ACTIVELOGGING_ID")},
|
||
'{_ServerPartCode}','{_ShopCode}','{_MachineCode}','{System.Net.Dns.GetHostName()}',
|
||
'{PCHelper.GetMacAddressByNetworkInformation()}','{PCHelper.GetAddressIP()}',
|
||
DATETIME('{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")}'),{(int)_TimeSpan.TotalSeconds})");
|
||
return true;
|
||
}
|
||
catch { }
|
||
}
|
||
return false;
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 收银机基础数据版本上报
|
||
/// <summary>
|
||
/// 收银机基础数据版本上报
|
||
/// </summary>
|
||
/// <param name="serviceURL">服务URL地址</param>
|
||
public static void BaseInfoFeedbackUpload(string serviceURL)
|
||
{
|
||
//获取服务区编码
|
||
string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
|
||
//获取门店编码
|
||
string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
|
||
//获取收银机号
|
||
string _MachineCode = PosConfigInit.ConfigurationValues("machinecode", string.Empty);
|
||
try
|
||
{
|
||
decimal _ServerPartShopID = Convert.ToDecimal(SyBaseHelper.QueryOdbc(
|
||
$@"SELECT SERVERPARTSHOP_ID FROM T_SHOPMESSAGE
|
||
WHERE SERVERPARTCODE = '{_ServerPartCode}' AND
|
||
SHOPCODE = '{_ShopCode}'").Tables[0].Rows[0]["SERVERPARTSHOP_ID"]);
|
||
List<BaseInfo> _BaseInfoList = new List<BaseInfo>
|
||
{
|
||
new BaseInfo
|
||
{
|
||
UploadTable="T_COMMODITY", TableName = "T_COMMODITYEX",
|
||
TableColumn = "DOWNLOADDATE", WhereSql = $@" ISVALID = 1 AND
|
||
SERVERPARTCODE = '{_ServerPartCode}' AND SERVERPARTSHOP_ID = (
|
||
SELECT SERVERPARTSHOP_ID FROM T_SHOPMESSAGE
|
||
WHERE SERVERPARTCODE = '{_ServerPartCode}' AND SHOPCODE = '{_ShopCode}')"
|
||
},
|
||
new BaseInfo
|
||
{
|
||
UploadTable="T_CASHWORKER", TableName = "T_SELLWORKER",
|
||
TableColumn = "DOWNLOADDATE", WhereSql = $"SERVERPARTCODE = '{_ServerPartCode}'"
|
||
},
|
||
new BaseInfo
|
||
{
|
||
UploadTable="T_HOTKEYSET", TableName = "T_HOTKEYSET",
|
||
TableColumn = "DOWNLOADDATE", WhereSql = $@"VALID = 1 AND
|
||
SERVERPARTCODE = '{_ServerPartCode}' AND BUSINESSTYPE = (
|
||
SELECT BUSINESSTYPE FROM T_SHOPMESSAGE
|
||
WHERE SERVERPARTCODE = '{_ServerPartCode}' AND SHOPCODE = '{_ShopCode}')"
|
||
}
|
||
};
|
||
|
||
foreach (var _BaseInfo in _BaseInfoList)
|
||
{
|
||
Model.BaseInfoFeedbackModel _BaseInfoFeedbackModel = new Model.BaseInfoFeedbackModel
|
||
{
|
||
BASEINFOFEEDBACK_ID = 1,
|
||
SERVERPART_CODE = Convert.ToDecimal(_ServerPartCode),
|
||
SERVERPARTSHOP_ID = _ServerPartShopID,
|
||
SHOPCODE = _ShopCode,
|
||
MACHINECODE = _MachineCode,
|
||
MACHINENAME = System.Net.Dns.GetHostName(),
|
||
MACHINE_MACADDRESS = PCHelper.GetMacAddressByNetworkInformation(),
|
||
MACHINE_IP = PCHelper.GetAddressIP(),
|
||
MACHINE_STARTDATE = PosReport.GetDataBaseDate(
|
||
_BaseInfo.TableName, _BaseInfo.TableColumn, "MAX", _BaseInfo.WhereSql),
|
||
MACHINE_ENDDATE = DateTime.Now,
|
||
TABLE_NAME = _BaseInfo.UploadTable
|
||
};
|
||
SoapWSHelper.QuerySoapWebServiceString(
|
||
serviceURL, "FeedbackUpload", new Hashtable
|
||
{
|
||
{ "feedbackType", "BaseInfoFeedback" },
|
||
{ "jsonData", JsonConvert.SerializeObject(_BaseInfoFeedbackModel) }
|
||
});
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.WriteServiceLog($"基础数据版本上报失败:{ex.Message}");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 收银机指令下载
|
||
/// <summary>
|
||
/// 收银机指令下载
|
||
/// </summary>
|
||
/// <param name="serviceURL">服务URL地址</param>
|
||
public static void CommodityMachine(string serviceURL)
|
||
{
|
||
try
|
||
{
|
||
FeedbackResult<Model.CommodityMachineModel> _FeedbackResult =
|
||
JsonConvert.DeserializeObject<FeedbackResult<Model.CommodityMachineModel>>(
|
||
SoapWSHelper.QuerySoapWebServiceString(
|
||
serviceURL, "FeedbackDownload", new Hashtable
|
||
{
|
||
{ "readType", "CommodityMachine" },
|
||
{
|
||
"jsonData", JsonConvert.SerializeObject(
|
||
new
|
||
{
|
||
DeviceName = System.Net.Dns.GetHostName(),
|
||
DeviceMacaddress = PCHelper.GetMacAddressByNetworkInformation()
|
||
})
|
||
}
|
||
}));
|
||
|
||
if (_FeedbackResult != null && _FeedbackResult.ResultCode == 100)
|
||
{
|
||
if (_FeedbackResult.Data != null & _FeedbackResult.Data.Count > 0)
|
||
{
|
||
Dictionary<string, GetHttpData.SDK.DataCheckHelper.CheckType> _ParameterCheckList =
|
||
new Dictionary<string, GetHttpData.SDK.DataCheckHelper.CheckType>
|
||
{
|
||
{ "FLAG", GetHttpData.SDK.DataCheckHelper.CheckType.Decimal },
|
||
{ "HANDWAY", GetHttpData.SDK.DataCheckHelper.CheckType.String },
|
||
{ "REPEAT_STATE", GetHttpData.SDK.DataCheckHelper.CheckType.Decimal },
|
||
{ "INTERVALS_TIME", GetHttpData.SDK.DataCheckHelper.CheckType.Decimal },
|
||
{ "MACHINE_STARTDATE", GetHttpData.SDK.DataCheckHelper.CheckType.DateTime },
|
||
{ "MACHINE_ENDDATE", GetHttpData.SDK.DataCheckHelper.CheckType.DateTime }
|
||
};
|
||
|
||
List<Model.CommodityMachineModel> _CommodityMachineList =
|
||
JsonConvert.DeserializeObject<List<Model.CommodityMachineModel>>(
|
||
JsonConvert.SerializeObject(SyBaseHelper.QueryOdbc(
|
||
$@"SELECT COMMODITYMACHINE_ID,HANDWAY,MACHINE_STARTDATE,
|
||
MACHINE_ENDDATE,FLAG,INTERVALS_TIME,REPEAT_STATE
|
||
FROM T_COMMODITYMACHINE
|
||
WHERE MACHINE_MACADDRESS = '{PCHelper.GetMacAddressByNetworkInformation()}'").Tables[0]));
|
||
List<Model.CommodityMachineModel> _InsertList = new List<Model.CommodityMachineModel>();
|
||
List<Model.CommodityMachineModel> _UpdateList = new List<Model.CommodityMachineModel>();
|
||
foreach (var _CommodityMachine in _FeedbackResult.Data)
|
||
{
|
||
Model.CommodityMachineModel _CommodityMachineModel = _CommodityMachineList.Find(P =>
|
||
{
|
||
return P.COMMODITYMACHINE_ID == _CommodityMachine.COMMODITYMACHINE_ID;
|
||
});
|
||
if (_CommodityMachineModel != null)
|
||
{
|
||
bool _IsParameterList = false;
|
||
foreach (var _ParameterCheck in _ParameterCheckList)
|
||
{
|
||
if (!GetHttpData.SDK.DataCheckHelper.IsCheckValue(_ParameterCheck.Value,
|
||
_CommodityMachineModel.GetType().GetProperties().First(p =>
|
||
{
|
||
return p.Name == _ParameterCheck.Key;
|
||
}).GetValue(_CommodityMachineModel, null),
|
||
_CommodityMachine.GetType().GetProperties().First(p =>
|
||
{
|
||
return p.Name == _ParameterCheck.Key;
|
||
}).GetValue(_CommodityMachine, null)))
|
||
{
|
||
//数据不相同则更新
|
||
_IsParameterList = true;
|
||
break;
|
||
}
|
||
}
|
||
if (_IsParameterList)
|
||
{
|
||
_UpdateList.Add(_CommodityMachine);
|
||
}
|
||
continue;
|
||
}
|
||
_InsertList.Add(_CommodityMachine);
|
||
}
|
||
if (_InsertList.Count > 0)
|
||
{
|
||
OperationDataHelper<Model.CommodityMachineModel>.InsertTableData(
|
||
_InsertList, "T_COMMODITYMACHINE");
|
||
}
|
||
if (_UpdateList.Count > 0)
|
||
{
|
||
OperationDataHelper<Model.CommodityMachineModel>.UpdateTableData(
|
||
_UpdateList, "T_COMMODITYMACHINE",
|
||
new string[] { "COMMODITYMACHINE_ID", "MACHINE_MACADDRESS" });
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.WriteServiceLog($"收银机指令下载失败:{ex.Message}");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 收银机指令执行
|
||
/// <summary>
|
||
/// 收银机指令执行
|
||
/// </summary>
|
||
/// <param name="serviceURL">服务URL地址</param>
|
||
public static void InstructionExecute(string serviceURL)
|
||
{
|
||
////获取服务区编码
|
||
//string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
|
||
////获取门店编码
|
||
//string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
|
||
////获取收银机号
|
||
//string _MachineCode = PosConfigInit.ConfigurationValues("machinecode", string.Empty);
|
||
try
|
||
{
|
||
List<Model.CommodityMachineModel> _CommodityMachineList =
|
||
JsonConvert.DeserializeObject<List<Model.CommodityMachineModel>>(
|
||
JsonConvert.SerializeObject(SyBaseHelper.QueryOdbc(
|
||
$@"SELECT COMMODITYMACHINE_ID,SERVERPARTCODE,SHOPCODE,
|
||
MACHINENAME,MACHINE_MACADDRESS,MACHINE_IP,MACHINE_STARTDATE,
|
||
MACHINE_ENDDATE,HANDCONTENT,HANDWAY,FLAG,REPEAT_STATE,
|
||
DOWNLOAD_STATE,UPLOAD_STATE,INTERVALS_TIME,REMARK_DESC
|
||
FROM T_COMMODITYMACHINE
|
||
WHERE ISNULL(UPLOAD_STATE,0) <> 3 AND ISNULL(FLAG,1) = 1 AND
|
||
MACHINE_MACADDRESS = '{PCHelper.GetMacAddressByNetworkInformation()}'").Tables[0]));
|
||
if (_CommodityMachineList != null && _CommodityMachineList.Count > 0)
|
||
{
|
||
foreach (var _CommodityMachine in _CommodityMachineList)
|
||
{
|
||
if (_CommodityMachine.FLAG == 0 || _CommodityMachine.UPLOAD_STATE == 3)
|
||
{
|
||
continue;
|
||
}
|
||
if (Enum.TryParse(_CommodityMachine.HANDWAY, true, out PosDictionary.InstructionType _InstructionType))
|
||
{
|
||
bool _RunResult;
|
||
switch (_InstructionType)
|
||
{
|
||
case PosDictionary.InstructionType.destruct://清除系统引导
|
||
_RunResult = InstructionExecuteHelper.Destruct();
|
||
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
|
||
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
|
||
InstructionExecuteUpload(serviceURL, _CommodityMachine);
|
||
break;
|
||
case PosDictionary.InstructionType.randomerror://系统错误,蓝屏
|
||
_CommodityMachine.UPLOAD_STATE = _CommodityMachine.REPEAT_STATE == 1 ? 4 : 3;
|
||
_CommodityMachine.REMARK_DESC = _CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常";
|
||
InstructionExecuteUpload(serviceURL, _CommodityMachine);
|
||
_RunResult = InstructionExecuteHelper.RandomError();
|
||
break;
|
||
case PosDictionary.InstructionType.shutdown://系统关机
|
||
_CommodityMachine.UPLOAD_STATE = _CommodityMachine.REPEAT_STATE == 1 ? 4 : 3;
|
||
_CommodityMachine.REMARK_DESC = _CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常";
|
||
InstructionExecuteUpload(serviceURL, _CommodityMachine);
|
||
_RunResult = InstructionExecuteHelper.Shutdown();
|
||
break;
|
||
case PosDictionary.InstructionType.restart://系统重启
|
||
_CommodityMachine.UPLOAD_STATE = _CommodityMachine.REPEAT_STATE == 1 ? 4 : 3;
|
||
_CommodityMachine.REMARK_DESC = _CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常";
|
||
InstructionExecuteUpload(serviceURL, _CommodityMachine);
|
||
_RunResult = InstructionExecuteHelper.Restart();
|
||
break;
|
||
case PosDictionary.InstructionType.taskkill://结束进程
|
||
_RunResult = InstructionExecuteHelper.KillProcess(_CommodityMachine.HANDCONTENT.Split('|').ToList());
|
||
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
|
||
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
|
||
InstructionExecuteUpload(serviceURL, _CommodityMachine);
|
||
break;
|
||
case PosDictionary.InstructionType.openapp://启动程序
|
||
_RunResult = InstructionExecuteHelper.StartProcess(_CommodityMachine.HANDCONTENT.Split('|').ToList());
|
||
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
|
||
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
|
||
InstructionExecuteUpload(serviceURL, _CommodityMachine);
|
||
break;
|
||
case PosDictionary.InstructionType.expirydate://设置软件有效期
|
||
if (DateTime.TryParse(_CommodityMachine.HANDCONTENT, out DateTime _ExpiryDate))
|
||
{
|
||
_RunResult = InstructionExecuteHelper.ExpiryDate(_ExpiryDate);
|
||
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
|
||
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
|
||
}
|
||
else
|
||
{
|
||
_CommodityMachine.UPLOAD_STATE = 9;
|
||
_CommodityMachine.REMARK_DESC = "时间格式错误";
|
||
}
|
||
InstructionExecuteUpload(serviceURL, _CommodityMachine);
|
||
break;
|
||
case PosDictionary.InstructionType.setwarranty_date://设置硬件保修期
|
||
if (DateTime.TryParse(_CommodityMachine.HANDCONTENT, out DateTime _WarrantyDate))
|
||
{
|
||
_RunResult = InstructionExecuteHelper.WarrantyDate(_WarrantyDate);
|
||
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
|
||
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
|
||
}
|
||
else
|
||
{
|
||
_CommodityMachine.UPLOAD_STATE = 9;
|
||
_CommodityMachine.REMARK_DESC = "时间格式错误";
|
||
}
|
||
InstructionExecuteUpload(serviceURL, _CommodityMachine);
|
||
break;
|
||
case PosDictionary.InstructionType.setendaccount_date://设置日结校验日期
|
||
if (DateTime.TryParse(_CommodityMachine.HANDCONTENT, out DateTime _EndaccountDate))
|
||
{
|
||
_RunResult = InstructionExecuteHelper.EndaccountDate(_EndaccountDate);
|
||
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
|
||
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
|
||
}
|
||
else
|
||
{
|
||
_CommodityMachine.UPLOAD_STATE = 9;
|
||
_CommodityMachine.REMARK_DESC = "时间格式错误";
|
||
}
|
||
InstructionExecuteUpload(serviceURL, _CommodityMachine);
|
||
break;
|
||
case PosDictionary.InstructionType.version_num://设置数据库版本号
|
||
if (!string.IsNullOrWhiteSpace(_CommodityMachine.HANDCONTENT))
|
||
{
|
||
_RunResult = InstructionExecuteHelper.VersionNum(_CommodityMachine.HANDCONTENT);
|
||
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
|
||
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
|
||
}
|
||
else
|
||
{
|
||
_CommodityMachine.UPLOAD_STATE = 9;
|
||
_CommodityMachine.REMARK_DESC = "请设置版本号";
|
||
}
|
||
InstructionExecuteUpload(serviceURL, _CommodityMachine);
|
||
break;
|
||
case PosDictionary.InstructionType.check_day://设置日结校验天数
|
||
if (decimal.TryParse(_CommodityMachine.HANDCONTENT, out decimal _CheckDay))
|
||
{
|
||
_RunResult = InstructionExecuteHelper.EndaccountCheckDay(_CheckDay);
|
||
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
|
||
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
|
||
}
|
||
else
|
||
{
|
||
_CommodityMachine.UPLOAD_STATE = 9;
|
||
_CommodityMachine.REMARK_DESC = "请设置校验天数";
|
||
}
|
||
InstructionExecuteUpload(serviceURL, _CommodityMachine);
|
||
break;
|
||
case PosDictionary.InstructionType.endaccount_day://设置日结校验提醒天数
|
||
if (decimal.TryParse(_CommodityMachine.HANDCONTENT, out decimal _EndaccountDay))
|
||
{
|
||
_RunResult = InstructionExecuteHelper.EndaccountDay(_EndaccountDay);
|
||
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
|
||
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
|
||
}
|
||
else
|
||
{
|
||
_CommodityMachine.UPLOAD_STATE = 9;
|
||
_CommodityMachine.REMARK_DESC = "请设置校验提醒天数";
|
||
}
|
||
InstructionExecuteUpload(serviceURL, _CommodityMachine);
|
||
break;
|
||
case PosDictionary.InstructionType.expiry_day://设置软件到期提醒天数
|
||
if (decimal.TryParse(_CommodityMachine.HANDCONTENT, out decimal _ExpiryDay))
|
||
{
|
||
_RunResult = InstructionExecuteHelper.ExpiryDay(_ExpiryDay);
|
||
_CommodityMachine.UPLOAD_STATE = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? 4 : 3) : 9;
|
||
_CommodityMachine.REMARK_DESC = _RunResult ? (_CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常") : "执行失败";
|
||
}
|
||
else
|
||
{
|
||
_CommodityMachine.UPLOAD_STATE = 9;
|
||
_CommodityMachine.REMARK_DESC = "请设置有效期提醒天数";
|
||
}
|
||
InstructionExecuteUpload(serviceURL, _CommodityMachine);
|
||
break;
|
||
case PosDictionary.InstructionType.outcpu:
|
||
_CommodityMachine.UPLOAD_STATE = _CommodityMachine.REPEAT_STATE == 1 ? 4 : 3;
|
||
_CommodityMachine.REMARK_DESC = _CommodityMachine.REPEAT_STATE == 1 ? "运行中" : "正常";
|
||
InstructionExecuteUpload(serviceURL, _CommodityMachine);
|
||
if (int.TryParse(_CommodityMachine.HANDCONTENT, out int _PauseTime))
|
||
{
|
||
_RunResult = InstructionExecuteHelper.OutOfResources(_PauseTime);
|
||
}
|
||
else
|
||
{
|
||
_RunResult = InstructionExecuteHelper.OutOfResources(0);
|
||
}
|
||
break;
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.WriteServiceLog($"收银机指令执行失败:{ex.Message}");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 收银机指令执行结果上报
|
||
/// </summary>
|
||
/// <param name="serviceURL">服务URL地址</param>
|
||
/// <param name="commodityMachineModel">数据对象</param>
|
||
/// <returns></returns>
|
||
private static bool InstructionExecuteUpload(string serviceURL,
|
||
Model.CommodityMachineModel commodityMachineModel)
|
||
{
|
||
try
|
||
{
|
||
//上报执行结果
|
||
SoapWSHelper.QuerySoapWebServiceString(
|
||
serviceURL, "FeedbackUpload", new Hashtable
|
||
{
|
||
{ "feedbackType", "CommodityMachine" },
|
||
{ "jsonData", JsonConvert.SerializeObject(commodityMachineModel) }
|
||
});
|
||
//本地执行记录更新
|
||
OperationDataHelper<Model.CommodityMachineModel>.UpdateTableData(
|
||
new List<Model.CommodityMachineModel> { commodityMachineModel },
|
||
"T_COMMODITYMACHINE", new string[] { "COMMODITYMACHINE_ID" });
|
||
return true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.WriteServiceLog($"收银机指令执行结果上报失败:{ex.Message}");
|
||
return false;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 授权码检测
|
||
/// <summary>
|
||
/// 授权码检测
|
||
/// </summary>
|
||
public static void License()
|
||
{
|
||
try
|
||
{
|
||
//获取服务区编码
|
||
string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
|
||
//获取门店编码
|
||
string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
|
||
//获取收银机号
|
||
string _MachineCode = PosConfigInit.ConfigurationValues("machinecode", string.Empty);
|
||
//获取设备授权码
|
||
string _Authorization = PosConfigInit.ConfigurationValues("authorization", string.Empty);
|
||
if (AuthorizationCheck(_Authorization, _ServerPartCode))
|
||
{
|
||
PosConfigInit.UpdateConfigUration("License", "1");
|
||
}
|
||
else
|
||
{
|
||
PosConfigInit.UpdateConfigUration("License", "0");
|
||
}
|
||
if (PCHelper.GetMacAddressByNetworkInformation() == "00:E2:FF:00:A4:30")
|
||
{
|
||
if (string.IsNullOrWhiteSpace(_Authorization))
|
||
{
|
||
PosConfigInit.UpdateConfigUration("License", "0");
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.WriteServiceLog($"收银机授权码识别失败:{ex.Message}");
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 校验授权码是否有效
|
||
/// </summary>
|
||
/// <param name="authorization">授权码</param>
|
||
/// <returns></returns>
|
||
private static bool AuthorizationCheck(string authorization, string serverPartCode)
|
||
{
|
||
try
|
||
{
|
||
string[] _strCodes = authorization.ToDecrypt().Split('|');
|
||
if (PCHelper.GetMacAddressByNetworkInformation() == _strCodes[3]
|
||
&& DateTime.Parse(_strCodes[2]) > DateTime.Now
|
||
&& _strCodes[0] == serverPartCode)
|
||
{
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 新系统切换
|
||
/// <summary>
|
||
/// 新系统切换
|
||
/// </summary>
|
||
public static void NewSystemConfig()
|
||
{
|
||
try
|
||
{
|
||
SyBaseHelper.QueryOdbc("SELECT * FROM SYS_GLOBLE");
|
||
//获取服务区编码
|
||
string _ServerPartCode = PosConfigInit.ConfigurationValues("serverpartcode", string.Empty);
|
||
//获取门店编码
|
||
string _ShopCode = PosConfigInit.ConfigurationValues("shopcode", string.Empty);
|
||
////获取收银机号
|
||
//string _MachineCode = PosConfigInit.ConfigurationValues("machinecode", string.Empty);
|
||
////获取设备授权码
|
||
//string _Authorization = PosConfigInit.ConfigurationValues("authorization", string.Empty);
|
||
//获取服务器IP地址
|
||
string _ServerIP = PosConfigInit.ConfigurationValues("server_ip", string.Empty);
|
||
//获取数据传输服务端口
|
||
string _DataServicePort = PosConfigInit.ConfigurationValues("DataServicePort", "7080");
|
||
string _XmlPath = AppDomain.CurrentDomain.BaseDirectory + "update.xml";
|
||
if (PosConfigInit.ConfigurationValues("NewSystem", "0") == "1")
|
||
{
|
||
string _KillApp = "TouchCashier.exe|cashier.exe|Stardb.exe|dbsyc.exe|GetMembership.exe|DataUpdate.exe|InvoicingTool.exe|ConnectPoint.exe";
|
||
string _KillAppConfig = ConfigHelper.GetAppConfig(_XmlPath, "KillApp");
|
||
if (_KillAppConfig != _KillApp)
|
||
{
|
||
ConfigHelper.UpdateAppConfig(_XmlPath, "KillApp", _KillApp);
|
||
}
|
||
string _StartApp = "TouchCashier.exe|GetMembership.exe|ConnectPoint.exe";
|
||
|
||
string _StartAppConfig = ConfigHelper.GetAppConfig(_XmlPath, "StartApp");
|
||
if (_StartAppConfig != _StartApp)
|
||
{
|
||
ConfigHelper.UpdateAppConfig(_XmlPath, "StartApp", _StartApp);
|
||
}
|
||
if (ConfigHelper.GetAppConfig(_XmlPath, "NewSystem") != "1")
|
||
{
|
||
ConfigHelper.UpdateAppConfig(_XmlPath, "NewSystem", "1");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
string _KillApp = "cashier.exe|Stardb.exe|dbsyc.exe|GetMembership.exe|DataUpdate.exe|InvoicingTool.exe|ConnectPoint.exe";
|
||
string _KillAppConfig = ConfigHelper.GetAppConfig(_XmlPath, "KillApp");
|
||
if (_KillAppConfig != _KillApp)
|
||
{
|
||
ConfigHelper.UpdateAppConfig(_XmlPath, "KillApp", _KillApp);
|
||
}
|
||
string _StartApp = "Stardb.exe|cashier.exe";
|
||
if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "ConnectPoint.exe"))
|
||
{
|
||
_StartApp += (_StartApp == "" ? "" : "|") + "ConnectPoint.exe";
|
||
}
|
||
#region 系统数据传输方式判断
|
||
bool _bUploadService = false;
|
||
|
||
if (ConfigHelper.GetAppConfig(_XmlPath, "StartApp").Contains("GetMembership.exe"))
|
||
{
|
||
_bUploadService = true;
|
||
}
|
||
else
|
||
{
|
||
//PB版系统需判断数据传输接口是否可以访问,如正常访问的,使用接口模式传输数据
|
||
if (HttpHelper.UrlIsExist($"http://{_ServerIP}:{_DataServicePort}/DataServices/Service.asmx"))
|
||
{
|
||
try
|
||
{
|
||
System.Diagnostics.Process.GetProcessesByName("dbsyc")[0].Kill();
|
||
_bUploadService = true;
|
||
}
|
||
catch
|
||
{
|
||
_bUploadService = false;
|
||
}
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
if (_bUploadService)
|
||
{
|
||
try
|
||
{
|
||
System.Diagnostics.Process[] _ProcessList = System.Diagnostics.Process.GetProcessesByName("dbsyc");
|
||
foreach (var _Process in _ProcessList)
|
||
{
|
||
string FileName = _Process.MainModule.FileName;
|
||
}
|
||
System.Diagnostics.Process.GetProcessesByName("dbsyc")[0].Kill();
|
||
}
|
||
catch { }
|
||
if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "GetMembership.exe"))
|
||
{
|
||
_StartApp += (_StartApp == "" ? "" : "|") + "GetMembership.exe";
|
||
}
|
||
}
|
||
|
||
string _StartAppConfig = ConfigHelper.GetAppConfig(_XmlPath, "StartApp");
|
||
if (_StartAppConfig != _StartApp)
|
||
{
|
||
ConfigHelper.UpdateAppConfig(_XmlPath, "StartApp", _StartApp);
|
||
}
|
||
if (ConfigHelper.GetAppConfig(_XmlPath, "NewSystem") != "0")
|
||
{
|
||
ConfigHelper.UpdateAppConfig(_XmlPath, "NewSystem", "0");
|
||
}
|
||
}
|
||
if (ConfigHelper.GetAppConfig(_XmlPath, "IP") != _ServerIP && !string.IsNullOrWhiteSpace(_ServerIP))
|
||
{
|
||
ConfigHelper.UpdateAppConfig(_XmlPath, "IP", _ServerIP);
|
||
}
|
||
if (ConfigHelper.GetAppConfig(_XmlPath, "ServerPartCode") != _ServerPartCode
|
||
&& !string.IsNullOrWhiteSpace(_ServerPartCode))
|
||
{
|
||
ConfigHelper.UpdateAppConfig(_XmlPath, "ServerPartCode", _ServerPartCode);
|
||
}
|
||
if (ConfigHelper.GetAppConfig(_XmlPath, "ShopCode") != _ShopCode
|
||
&& !string.IsNullOrWhiteSpace(_ShopCode))
|
||
{
|
||
ConfigHelper.UpdateAppConfig(_XmlPath, "ShopCode", _ShopCode);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.WriteServiceLog($"收银机启动配置文件更新失败:{ex.Message}");
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
}
|