Commit 4df412ec by NitefullWind

1.实现没有用会员支付的订单,遇到网络错误或超时时,返回POS成功,备份并重发请求。

parent 8f5aa9cb
......@@ -36,7 +36,7 @@ bool FMBackup::connect()
if(!QFile::exists(dbname)) {
isOk = createTable(dbname);
} else {
_db = QSqlDatabase::addDatabase("QSQLITE");
_db = QSqlDatabase::addDatabase("QSQLITE", "fmvipbackupdb");
_db.setDatabaseName(dbname);
isOk =_db.open();
}
......@@ -51,7 +51,7 @@ bool FMBackup::connect()
bool FMBackup::createTable(const QString &dbname)
{
_db = QSqlDatabase::addDatabase("QSQLITE");
_db = QSqlDatabase::addDatabase("QSQLITE", "fmvipbackupdb");
_db.setDatabaseName(dbname);
_db.open();
QSqlQuery query(_db);
......
......@@ -6,6 +6,7 @@
#include <QSqlRecord>
#include <QNetworkReply>
#include <QDebug>
#include "global.h"
ReSend::ReSend()
{
......@@ -31,7 +32,7 @@ void ReSend::trySend()
net.send(url, data, rspData);
// 如果发送失败则不再继续发送
if(net.error != 1) {
if(net.error != FM_API_SUCCESS) {
break;
} else{
FMBackup::instance()->removeReqData(id);
......@@ -42,9 +43,13 @@ void ReSend::trySend()
void ReSend::run()
{
int waitTime = 0;
while(true)
{
trySend();
QThread::sleep(5);
if(++waitTime > 30) {
trySend();
waitTime = 0;
}
QThread::sleep(1);
}
}
......@@ -44,7 +44,7 @@ int FMNetwork::send(const QString &url, const QByteArray &reqData, QByteArray &r
QTimer timer;
timer.setSingleShot(true);
connect(&timer, SIGNAL(timeout()),&loop,SLOT(quit()));
timer.start(1000 * 60 * 60);
timer.start(1000 * 60);
loop.exec();
if(timer.isActive())
......@@ -56,10 +56,12 @@ int FMNetwork::send(const QString &url, const QByteArray &reqData, QByteArray &r
int err = reply->error();
rspData = reply->readAll();
error = FM_API_NETWORERROR;
errorMsg = QString::fromLocal8Bit("NetworkError(%1):%2").arg(err).arg(QString(rspData));
errorMsg = QString::fromLocal8Bit("NetworkError(%1):%2").arg(err).arg(QString(reply->errorString()));
FMP_ERROR() << errorMsg;
}
}else{
error = FM_API_TIMEOUT;
FMP_ERROR() << "Request timeout.";
}
return error;
}
......
......@@ -11,6 +11,8 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
#DEFINES += TEST
SOURCES += \
fmp_vip.cpp \
fmp_vip_p.cpp \
......
......@@ -16,6 +16,7 @@ TaskFinal::TaskFinal(QJsonObject &jsonObj, Session *session, QObject *parent)
void TaskFinal::packageServerReq()
{
isUseVipPay = false;
QJsonObject transData;
std::vector<QString> p;
p.push_back(PosProps.BussinessDate);
......@@ -63,6 +64,10 @@ void TaskFinal::packageServerReq()
} else {
pay["typeModeFlag"] = typeModeFlag;
}
if(typeModeFlag.compare("20001")==0 || typeModeFlag.compare("20002")==0 || typeModeFlag.compare("20003")==0) {
isUseVipPay = true;
}
payList.append(pay);
}
......@@ -76,22 +81,20 @@ bool TaskFinal::sendToServer(bool isShowMsg)
FMTask::sendToServer(false);
// 备份
// if(error() == FM_API_NETWORERROR) {
// if(searchJsonValue(serverReqJsonObj,ServerProps(PosProps.CodeAmount)).toInt() == 0 &&
// searchJsonValue(serverReqJsonObj,ServerProps(PosProps.ScoreAmount)).toInt() == 0 &&
// searchJsonValue(serverReqJsonObj,ServerProps(PosProps.Coupons)).toArray().isEmpty()) {
// QString fm_id = backup();
// if(!fm_id.isEmpty()){
// setError(FM_API_SUCCESS);
// serverRspJsonObj[ServerProps(PosProps.StatusCode)] = FM_API_SUCCESS;
// serverRspJsonObj[ServerProps(PosProps.Msg)] = QString::fromLocal8Bit("结算成功");
// serverRspJsonObj[ServerProps(PosProps.Fm_id)] = fm_id;
// serverRspJsonObj[ServerProps(PosProps.Prompt)] = 1;
// serverRspJsonObj[ServerProps(PosProps.Print1)] = "";
// serverRspJsonObj[ServerProps(PosProps.Print2)] = "";
// }
// }
// }
if(error() == FM_API_NETWORERROR || error() == FM_API_TIMEOUT) {
if(!isUseVipPay) {
QString fm_id = backup();
if(!fm_id.isEmpty()){
setError(FM_API_SUCCESS);
serverRspJsonObj[ServerProps(PosProps.StatusCode)] = FM_API_SUCCESS;
serverRspJsonObj[ServerProps(PosProps.Msg)] = QString::fromLocal8Bit("结算成功");
serverRspJsonObj[ServerProps(PosProps.Fm_id)] = fm_id;
serverRspJsonObj[ServerProps(PosProps.Prompt)] = 1;
serverRspJsonObj[ServerProps(PosProps.Print1)] = "";
serverRspJsonObj[ServerProps(PosProps.Print2)] = "";
}
}
}
bool isOk = (error() == FM_API_SUCCESS);
if(!isOk)
{
......@@ -104,6 +107,7 @@ void TaskFinal::packagePOSRsp()
{
posRspJsonObj[PosProps.StatusCode] = getServerJsonValue(PosProps.StatusCode);
posRspJsonObj[PosProps.Msg] = getServerJsonValue(PosProps.Msg);
posRspJsonObj[PosProps.Fm_id] = getServerJsonValue(PosProps.Fm_id);
posRspJsonObj[PosProps.Prompt] = 1;
}
......@@ -113,11 +117,11 @@ QString TaskFinal::backup()
QString uuid = QString("E%1%2%3%4")
.arg(getPosJsonValue(PosProps.StoreId).toString())
.arg(getPosJsonValue(PosProps.PosId).toString().toInt(), 2, 10, QChar('0'))
.arg(QDateTime::currentDateTime().toString("yyMMdd"))
.arg(QDateTime::currentDateTime().toString("yyMMddhhmmsszzz"))
.arg(newId, 5, 10, QChar('0'));
QJsonDocument json(serverReqJsonObj);
bool isOk = FMBackup::instance()->updateReqData(newId, this->url, json.toJson(QJsonDocument::Compact));
if(isOk && uuid.length()==20) {
if(isOk) {
return uuid;
}
return "";
......
......@@ -14,6 +14,7 @@ public:
private:
QString backup();
bool isUseVipPay;
};
#endif // TASKFINAL_H
......@@ -75,7 +75,9 @@ void TaskLogin::onLogin()
QString name = getServerJsonValue(PosProps.Name).toString();
bool canPay = (getServerJsonValue(PosProps.CanPay).toInt() == 1);
#ifdef TEST
canPay = true;
#endif
if(!canPay) {
if(getPosJsonValue(PosProps.Fm_cmd).toInt() != FM_Pay) {
FMMsgWnd::LoginSuccess(account, name, birthday, _window);
......
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