Commit 4df412ec by NitefullWind

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

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