Commit 6208ee58 by 刘帅

1. 修改退款接口中的错误;

2. 门店信息从配置文件中读取,有更新时同步更新至配置文件
parent 81dd0ace
......@@ -10,6 +10,8 @@
#include <QJsonArray>
#include <QtAlgorithms>
#include <QDir>
#include <QSettings>
#include <QDate>
#ifdef WIN32
#include <direct.h>
......@@ -29,9 +31,10 @@
#include <unistd.h>
#endif
#define STORE_INFO_FILE_NAME "store_info.ini"
unsigned int QFmClient::s_reqCount = 0;
QFmClient::QFmClient(QObject *parent) : QThread(parent)
QFmClient::QFmClient(QObject *parent) : QThread(parent),store_info("1371","fm99999","1",QDate::currentDate().toString("yyyyMMdd"),"001")
{
_endflag = false;
}
......@@ -80,25 +83,34 @@ bool QFmClient::Init(QString proxy_IP, unsigned short proxy_port, unsigned short
}
/*初始化门店信息
* 启动时,如果存在门店信息文件,读取
* 启动时,如果存在门店信息文件 STORE_INFO_FILE_NAME ,读取
* 如果不存在,新建
* 每次更新门店信息时,写入
*/
bool QFmClient::InitStoreInfo()
{
QString fileName = qApp->applicationDirPath();
fileName.append(QDir::separator());
fileName.append("store_info.ini");
fileName.append(STORE_INFO_FILE_NAME);
if(QFile::exists(fileName))
{
//read store info
QSettings *configIni = new QSettings(fileName, QSettings::IniFormat);
store_info.partner_id = configIni->value("/store/partner_id").toString();
store_info.store_id = configIni->value("/store/store_id").toString();
store_info.pos_id = configIni->value("/store/pos_id").toString();
store_info.operator_id = configIni->value("/store/operator_id").toString();
store_info.business_date = configIni->value("/store/business_date").toString();
delete configIni;
}
else
{
QFile storeInfoFileName(fileName);
if(!storeInfoFileName.open(QIODevice::ReadWrite | QIODevice::Text))
qDebug()<<"open file failed!\n"<<fileName;
QSettings *configIni = new QSettings(fileName, QSettings::IniFormat);
configIni->setValue("/store/partner_id", store_info.partner_id);
configIni->setValue("/store/store_id", store_info.store_id);
configIni->setValue("/store/pos_id", store_info.pos_id);
configIni->setValue("/store/operator_id", store_info.operator_id);
configIni->setValue("/store/business_date", store_info.business_date);
delete configIni;
}
return true;
}
......@@ -479,7 +491,7 @@ bool QFmClient::ConvertRequestJsonFormat(QJsonObject &object)
bool QFmClient::ConvertResponseJsonFormat(QJsonObject &object, int nType)
{
bool bRtValue = true;
qDebug()<<"response json:\n"<<object;
qDebug()<<"proxy response json:\n"<<object;
switch(nType)
{
case SET_STORE_INFO:
......@@ -528,6 +540,17 @@ void QFmClient::SetStoreInfo(QJsonObject &object)
QString operator_id = object.value("operator_id").toString();
store_info.operator_id = operator_id;
}
QString fileName = qApp->applicationDirPath();
fileName.append(QDir::separator());
fileName.append(STORE_INFO_FILE_NAME);
QSettings *configIni = new QSettings(fileName, QSettings::IniFormat);
configIni->setValue("/store/partner_id", store_info.partner_id);
configIni->setValue("/store/store_id", store_info.store_id);
configIni->setValue("/store/pos_id", store_info.pos_id);
configIni->setValue("/store/operator_id", store_info.operator_id);
configIni->setValue("/store/business_date", store_info.business_date);
delete configIni;
}
void QFmClient::FreemudPay(QJsonObject &object)
......@@ -609,13 +632,13 @@ bool QFmClient::RefundPay(QJsonObject &object)
QJsonObject transactionObject;
QString trans_id;
QString fm_trans_id;
QJsonValue fmid;
int refund_amount = 0;
if(object.contains("trans_id"))
trans_id = object.value("trans_id").toString();
if(object.contains("fm_trans_id"))
fm_trans_id = object.value("fm_trans_id").toString();
if(object.contains("fm_order_id"))
fmid = object.value("fm_order_id");
if(object.contains("refund_amount"))
refund_amount = object.value("refund_amount").toInt();
refundObject.insert("ver", 2);
......@@ -627,7 +650,7 @@ bool QFmClient::RefundPay(QJsonObject &object)
refundObject.insert("business_date",store_info.business_date);
refundObject.insert("trans_id", trans_id.toInt());
transactionObject.insert("fmid",fm_trans_id);
transactionObject.insert("fmid",fmid);
transactionObject.insert("refund_count",refund_amount);
transactionArray.append(transactionObject);
refundObject.insert("transactions",transactionArray);
......@@ -1070,6 +1093,7 @@ int QFmClient::SendData2ZhProxyAndWaitRspData()
rlt = SendSocketData(_zhProxySock, _sendbuf, length, _codeFlag);
qDebug()<<"_zhProxySock "<<_zhProxySock<< "data:\n"<<_sendbuf;
if (rlt != length)
{
#ifdef WIN32
......@@ -1135,6 +1159,7 @@ int QFmClient::ProcessZhProxyRspDataAndSend2Pos(int nType)
size_t st = strlen(temp);
char* pResponse = new char[st + 1];
strcpy(pResponse,temp);
qDebug()<<"send to pos:\n"<<pResponse;
length = st;
rlt = SendSocketData(_acceptedSock, pResponse, length, 0);
......@@ -1171,7 +1196,7 @@ void QFmClient::run()
qDebug() << "Init QFmClient failed";
emit Error("Init QFmClient failed");
}
InitStoreInfo();
qDebug()<< "Init QFmClient success";
do
{
......@@ -1187,7 +1212,7 @@ void QFmClient::run()
}
do
{
int rlt, needBackup = 1;
int rlt;
int nResult = 0;
if (!WaitForConnectReqFromPos())
{
......@@ -1202,7 +1227,7 @@ void QFmClient::run()
QJsonObject object;
char temp_recv[MAX_BUF_LEN] = {0};
strcpy(temp_recv, _recvbuf);
//strcpy(temp_recv, _recvbuf);
nResult = ProcessPosReqData(object);
if (0 > nResult)
......@@ -1232,9 +1257,9 @@ void QFmClient::run()
memset(_sendbuf, 0, MAX_BUF_LEN);
QString temp = QString(QJsonDocument(object).toJson());
strcpy(_sendbuf, temp.toStdString().c_str());
strcpy(temp_recv, _sendbuf);
rlt = SendData2ZhProxyAndWaitRspData();
//CloseSocket(&_acceptedSock); //if test cerat fmclient.rbk file,uncomment this
if (0 == rlt)
{
rlt = ProcessZhProxyRspDataAndSend2Pos(nResult);
......@@ -1242,11 +1267,12 @@ void QFmClient::run()
CloseSocket(&_zhProxySock);
if (0 != rlt)
{
if (1 == needBackup)
if (nResult == FREEMUD_PAY)
{//is write off data, need to check roll back
//BackupPosReq(temp_recv);
BackupPosReq(temp_recv);
break;
}
}
......@@ -1296,7 +1322,7 @@ bool QFmClient::StartListenport()
s_add.sin_family=AF_INET;
s_add.sin_addr.s_addr=htonl(INADDR_ANY);
s_add.sin_port=htons(_clientPort);
qDebug()<<inet_ntoa(s_add.sin_addr)<<" : "<<_clientPort;
setsockopt(_listenSock, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse));
if(-1 == bind(_listenSock,(struct sockaddr *)(&s_add), sizeof(struct sockaddr)))
......@@ -1343,7 +1369,6 @@ void QFmClient::CheckRollBackData()
remove(filename.toStdString().c_str());
return ;
}
memset(_sendbuf, 0, MAX_BUF_LEN);
ZH_decodeBkData(_codeBuf, _sendbuf, readLen);
......@@ -1370,7 +1395,7 @@ void QFmClient::CheckRollBackData()
QString temp = QString(QJsonDocument(json).toJson());
strcpy(_sendbuf, temp.toStdString().c_str());
qDebug() << "rollback data:" << _sendbuf;
qDebug() << "rollback data:\n" << _sendbuf;
qDebug() << "\r\n";
do
......
......@@ -113,6 +113,16 @@ private:
QString pos_id; //商家POS机编号
QString operator_id; //营业员编号
QString business_date; //营业日
_STORE_INFO(QString _partner_id,
QString _store_id,
QString _pos_id,
QString _operator_id,
QString _business_date):
partner_id(_partner_id),
store_id(_store_id),
pos_id(_pos_id),
operator_id(_operator_id),
business_date(_business_date){}
}STORE_INFO;
STORE_INFO store_info;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment