using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using SuperMap.RealEstate.ServiceModel; using SuperMap.RealEstate.FrameWork.Business; using SuperMap.RealEstate.Coop.Merchant.Business; using SuperMap.RealEstate.HighWay.SellData.Business; using HWSB = SuperMap.RealEstate.HighWay.Storage.Business; using HCC = HZQR.Common.Common; using HZQR.Common.Models; using HZQR.Common; namespace ServerPartTransmission.Method { /// /// 银行到账相关方法 /// public class BankAccountHelper { /// /// 移动支付到账金额对比 /// /// 事务管理器 /// 到账日期 /// 服务区编码 /// 门店编码 /// 机器编码 public static void BankAccountCompare(Transaction transaction, string AccountDate, string ServerpartCode, string ShopCode, string MachineCode) { string SQLString, LogContent; HWSB.SERVERPARTSHOP _SERVERPARTSHOP = new HWSB.SERVERPARTSHOP(transaction); _SERVERPARTSHOP.AddSearchParameter("SERVERPART_CODE", ServerpartCode); _SERVERPARTSHOP.AddSearchParameter("SHOPCODE", ShopCode); if (_SERVERPARTSHOP.Search()) { //查询通道返回交易金额 DataTable dtBusinessShopCode = new BUSINESSSHOPCODE(transaction).FillDataTable( "WHERE SERVERPART_CODE = '" + ServerpartCode + "' AND SERVERPARTSHOP_CODE = '" + ShopCode + "'"); if (dtBusinessShopCode.Select("PAYMENT_CHANNEL in (1010,1012)").Length == 0) { List TradeStatisticsDataList = MobilePayHelper.GetTradeStatistics( transaction, AccountDate, AccountDate, dtBusinessShopCode); decimal TotalBankAccountAmount = TradeStatisticsDataList.Sum(o => o.amount); //查询自然日结账报表数据 SQLString = string.Format(@"SELECT * FROM HIGHWAY_SELLDATA.T_ENDACCOUNT_DAILY WHERE SERVERPARTCODE = '{0}' AND SHOPCODE = '{1}' AND MACHINECODE = '{2}' AND ENDACCOUNT_STARTDATE = TO_DATE('{3}','YYYY/MM/DD')", ServerpartCode, ShopCode, MachineCode, AccountDate); DataTable dtEndaccountDaily = new ENDACCOUNT(transaction).ExecuteDataTable(SQLString); //获取账期唯一标识 string UniqueCode = ServerpartCode + "|" + ShopCode + "|" + AccountDate + "|" + MachineCode; if (dtEndaccountDaily.Rows.Count == 0) { if (TotalBankAccountAmount != 0) { LogContent = _SERVERPARTSHOP.SERVERPART_NAME + _SERVERPARTSHOP.SHOPNAME + "【" + AccountDate + "】" + MachineCode + ":无自然日结账数据,通道返回金额:" + TotalBankAccountAmount; BusinessLogModel businessLogModel = new BusinessLogModel(); businessLogModel.BUSINESSLOG_TYPE = 1; businessLogModel.BUSINESS_ID = 0; businessLogModel.TABLE_NAME = "T_ENDACCOUNT_DAILY"; businessLogModel.OWNER_NAME = "HIGHWAY_SELLDATA"; businessLogModel.BUSINESSLOG_CONTENT = LogContent; businessLogModel.DATA_CONSISTENCY = 0; businessLogModel.CHECK_STATE = 0; businessLogModel.UNIQUECODE = UniqueCode; businessLogModel.CHECK_COUNT = 0; businessLogModel.SERVERPARTCODE = ServerpartCode; businessLogModel.SHOPCODE = ShopCode; businessLogModel.MACHINECODE = MachineCode; businessLogModel.BUSINESSTYPE = _SERVERPARTSHOP.SHOPTRADE.TryParseToInt(); businessLogModel.CHANNEL_AMOUNT = (double)TotalBankAccountAmount; SQLString = string.Format(@"SELECT * FROM HIGHWAY_SELLDATA.T_ENDACCOUNT_DAILY WHERE SERVERPARTCODE = '{0}' AND SHOPCODE = '{1}' AND MACHINECODE = '{2}' AND ENDACCOUNT_DATE >= TO_DATE('{3}','YYYY/MM/DD') AND ENDACCOUNT_DATE < TO_DATE('{3}','YYYY/MM/DD') + 1", ServerpartCode, ShopCode, MachineCode, AccountDate); DataTable dtEndaccount = new ENDACCOUNT(transaction).ExecuteDataTable(SQLString); if (dtEndaccount.Rows.Count > 0) { businessLogModel.ENDACCOUNT_ID = dtEndaccount.Rows[0]["ENDACCOUNT_ID"].TryParseToInt(); } HCC.BusinessHelper.RecordBusinessLog(transaction, businessLogModel); } } else { DataRow drEndaccountDaily = dtEndaccountDaily.Rows[0]; //查询已记录的日志内容 DataTable dtBusinessLog = new User(transaction).ExecuteDataTable( "SELECT * FROM PLATFORM_FRAMEWORK.T_BUSINESSLOG WHERE BUSINESSLOG_TYPE = 1 AND UNIQUECODE = '" + UniqueCode + "'"); LogContent = _SERVERPARTSHOP.SERVERPART_NAME + _SERVERPARTSHOP.SHOPNAME + "【" + AccountDate + "】" + MachineCode + ":收银机自然日金额:" + (drEndaccountDaily["TICKETBILL"].TryParseToDecimal() + drEndaccountDaily["OTHERPAY"].TryParseToDecimal()) + ",通道返回金额:" + TotalBankAccountAmount; //如果移动支付金额不相等,则标记数据异常 if (drEndaccountDaily["TICKETBILL"].TryParseToDecimal() + drEndaccountDaily["OTHERPAY"].TryParseToDecimal() != TotalBankAccountAmount) { if (dtBusinessLog.Rows.Count == 0) { BusinessLogModel businessLogModel = new BusinessLogModel(); businessLogModel.BUSINESSLOG_TYPE = 1; businessLogModel.BUSINESS_ID = drEndaccountDaily["ENDACCOUNT_ID"].TryParseToInt(); businessLogModel.TABLE_NAME = "T_ENDACCOUNT_DAILY"; businessLogModel.OWNER_NAME = "HIGHWAY_SELLDATA"; businessLogModel.BUSINESSLOG_CONTENT = LogContent; businessLogModel.DATA_CONSISTENCY = 0; businessLogModel.CHECK_STATE = 0; businessLogModel.UNIQUECODE = UniqueCode; businessLogModel.CHECK_COUNT = 0; businessLogModel.SERVERPARTCODE = ServerpartCode; businessLogModel.SHOPCODE = ShopCode; businessLogModel.MACHINECODE = MachineCode; businessLogModel.BUSINESSTYPE = _SERVERPARTSHOP.SHOPTRADE.TryParseToInt(); businessLogModel.DAILY_AMOUNT = (double)(drEndaccountDaily["TICKETBILL"].TryParseToDecimal() + drEndaccountDaily["OTHERPAY"].TryParseToDecimal()); businessLogModel.CHANNEL_AMOUNT = (double)TotalBankAccountAmount; SQLString = string.Format(@"SELECT * FROM HIGHWAY_SELLDATA.T_ENDACCOUNT_DAILY WHERE SERVERPARTCODE = '{0}' AND SHOPCODE = '{1}' AND MACHINECODE = '{2}' AND ENDACCOUNT_DATE >= TO_DATE('{3}','YYYY/MM/DD') AND ENDACCOUNT_DATE < TO_DATE('{3}','YYYY/MM/DD') + 1", ServerpartCode, ShopCode, MachineCode, AccountDate); DataTable dtEndaccount = new ENDACCOUNT(transaction).ExecuteDataTable(SQLString); if (dtEndaccount.Rows.Count > 0) { businessLogModel.ENDACCOUNT_ID = dtEndaccount.Rows[0]["ENDACCOUNT_ID"].TryParseToInt(); } businessLogModel.STATISTICS_DATE = DateTime.Parse(AccountDate).ToString("yyyyMMdd").TryParseToLong(); HCC.BusinessHelper.RecordBusinessLog(transaction, businessLogModel); } else { foreach (DataRow drBusinessLog in dtBusinessLog.Rows) { if (drBusinessLog["CHECK_STATE"].ToString() == "0") { HCC.BusinessHelper.UpdateBusinessLogCheckState(transaction, drBusinessLog["BUSINESSLOG_ID"].TryParseToInt(), LogContent, 0, 0); } } } } else if (dtBusinessLog.Rows.Count > 0) { foreach (DataRow drBusinessLog in dtBusinessLog.Rows) { HCC.BusinessHelper.UpdateBusinessLogCheckState(transaction, drBusinessLog["BUSINESSLOG_ID"].TryParseToInt(), LogContent, 1, 1); } } } } } } } }