Commit 3977e516 by unknown

1.使用QMutex和QWaitCondition控制进程阻塞。2.修复充值金额总为0的bug

parent bc4c83aa
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.0.2, 2016-09-07T11:12:17. --> <!-- Written by QtCreator 4.0.2, 2016-09-07T16:39:03. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
...@@ -292,7 +292,7 @@ ...@@ -292,7 +292,7 @@
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">FMVip.pro</value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">FMVip.pro</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default"></value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default">C:/Users/zzf/Documents/Qt/FMVip/build-FMVip-Desktop_Qt_5_7_0_MinGW_32bit-Debug</value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value> <value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value> <value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
......
...@@ -59,8 +59,6 @@ INT FMVipDispatcher::_ParseRequest(LPSTR data) ...@@ -59,8 +59,6 @@ INT FMVipDispatcher::_ParseRequest(LPSTR data)
FMVipForward::instance()->resetSessionData(_posReqObj); FMVipForward::instance()->resetSessionData(_posReqObj);
isLastOne = true; isLastOne = true;
canBeContinue = false;
isServerResponsed = false; // 重置服务器是否已返回信息的标志
// 唤起客户端界面 // 唤起客户端界面
emit requested(_posReqObj); emit requested(_posReqObj);
...@@ -73,18 +71,21 @@ BOOL FMVipDispatcher::_GetResponse(LPSTR &rsp, UINT &len) ...@@ -73,18 +71,21 @@ BOOL FMVipDispatcher::_GetResponse(LPSTR &rsp, UINT &len)
{ {
qDebug() << __FUNCTION__; qDebug() << __FUNCTION__;
// QTime dieTime = QTime::currentTime().addMSecs(1000*5);
// 服务器还未返回则一直阻塞 // 服务器还未返回则一直阻塞
while(isServerResponsed == false && canBeContinue == false) mutex.lock();
QCoreApplication::processEvents(QEventLoop::AllEvents, 100); serverIsBusy.wait(&mutex);
rsp = _serverRspData.data(); rsp = _serverRspData.data();
len = _serverRspData.length(); len = _serverRspData.length();
mutex.unlock();
return isServerResponsed; return 1;
} }
void FMVipDispatcher::onRequest(const QJsonObject &jsonObj) void FMVipDispatcher::onRequest(const QJsonObject &jsonObj)
{ {
_windowReturn = 1;
QString type = jsonObj["fm_cmd"].toString(); QString type = jsonObj["fm_cmd"].toString();
if (type == Type_Login) { if (type == Type_Login) {
...@@ -96,7 +97,6 @@ void FMVipDispatcher::onRequest(const QJsonObject &jsonObj) ...@@ -96,7 +97,6 @@ void FMVipDispatcher::onRequest(const QJsonObject &jsonObj)
#ifdef _DEBUG #ifdef _DEBUG
else if (type == "-1") { else if (type == "-1") {
qDebug() << "Quit"; qDebug() << "Quit";
canBeContinue = true;
jsonObj["reqType"] = -1; jsonObj["reqType"] = -1;
QJsonDocument d = QJsonDocument(jsonObj); QJsonDocument d = QJsonDocument(jsonObj);
_serverRspData = d.toJson(); _serverRspData = d.toJson();
...@@ -104,6 +104,7 @@ void FMVipDispatcher::onRequest(const QJsonObject &jsonObj) ...@@ -104,6 +104,7 @@ void FMVipDispatcher::onRequest(const QJsonObject &jsonObj)
} }
#endif #endif
else { else {
requestSuccess = true;
// 支付、充值、结算先检查登陆状态。 // 支付、充值、结算先检查登陆状态。
QJsonObject copyJsonObj(jsonObj); QJsonObject copyJsonObj(jsonObj);
if (!isLogined()) { if (!isLogined()) {
...@@ -111,20 +112,18 @@ void FMVipDispatcher::onRequest(const QJsonObject &jsonObj) ...@@ -111,20 +112,18 @@ void FMVipDispatcher::onRequest(const QJsonObject &jsonObj)
isLastOne = false; isLastOne = false;
login(); login();
} }
if (canBeContinue || _windowReturn == -1) { if (requestSuccess == false || _windowReturn == -1) {
_serverRspData.clear(); _serverRspData.clear();
canBeContinue = true; serverIsBusy.wakeAll();
return; return;
} }
_posReqObj = copyJsonObj; _posReqObj = copyJsonObj;
isLastOne = true; isLastOne = true;
if (type == Type_Pay) { if (type == Type_Pay) {
pay(); pay();
canBeContinue = true;
} }
else if (type == Type_Fund) { else if (type == Type_Fund) {
fund(); fund();
canBeContinue = true;
} }
else if (type == Type_Final) { else if (type == Type_Final) {
final(); final();
...@@ -146,6 +145,10 @@ void FMVipDispatcher::onFinished() ...@@ -146,6 +145,10 @@ void FMVipDispatcher::onFinished()
{ {
qDebug() << __FUNCTION__; qDebug() << __FUNCTION__;
if(_windowReturn == -1){
serverIsBusy.wakeAll();
}
_vindow = 0; _vindow = 0;
} }
...@@ -159,7 +162,7 @@ void FMVipDispatcher::onServerResponsed(const QJsonObject &rspObj) ...@@ -159,7 +162,7 @@ void FMVipDispatcher::onServerResponsed(const QJsonObject &rspObj)
QJsonDocument rspDoc(rspObj); QJsonDocument rspDoc(rspObj);
QByteArray rspData = rspDoc.toJson(); QByteArray rspData = rspDoc.toJson();
_serverRspData = rspData; _serverRspData = rspData;
isServerResponsed = true; // 重置服务器是否已返回信息的标志 serverIsBusy.wakeAll();
} }
int status = rspObj["statusCode"].toInt(); int status = rspObj["statusCode"].toInt();
...@@ -172,10 +175,6 @@ void FMVipDispatcher::onServerResponsed(const QJsonObject &rspObj) ...@@ -172,10 +175,6 @@ void FMVipDispatcher::onServerResponsed(const QJsonObject &rspObj)
msgBox.setAttribute(Qt::WA_QuitOnClose, false); msgBox.setAttribute(Qt::WA_QuitOnClose, false);
msgBox.exec(); msgBox.exec();
} }
else {
// 可以继续下一步操作
canBeContinue = false;
}
} }
else { else {
QString msg = rspObj["msg"].toString(); QString msg = rspObj["msg"].toString();
...@@ -186,7 +185,7 @@ void FMVipDispatcher::onServerResponsed(const QJsonObject &rspObj) ...@@ -186,7 +185,7 @@ void FMVipDispatcher::onServerResponsed(const QJsonObject &rspObj)
msgBox.setAttribute(Qt::WA_QuitOnClose, false); msgBox.setAttribute(Qt::WA_QuitOnClose, false);
msgBox.exec(); msgBox.exec();
canBeContinue = true; requestSuccess = false;
_vindow = 0; _vindow = 0;
} }
} }
...@@ -194,13 +193,11 @@ void FMVipDispatcher::onServerResponsed(const QJsonObject &rspObj) ...@@ -194,13 +193,11 @@ void FMVipDispatcher::onServerResponsed(const QJsonObject &rspObj)
// 向服务器发送请求 // 向服务器发送请求
void FMVipDispatcher::onDoPost() void FMVipDispatcher::onDoPost()
{ {
isServerResponsed = false;
FMVipForward::instance()->parseRequest(_posReqObj); FMVipForward::instance()->parseRequest(_posReqObj);
} }
void FMVipDispatcher::login() void FMVipDispatcher::login()
{ {
if (!_vindow) { if (!_vindow) {
FMVipLogin *login = new FMVipLogin; FMVipLogin *login = new FMVipLogin;
connect(login, SIGNAL(destroyed(QObject*)), SLOT(onFinished())); connect(login, SIGNAL(destroyed(QObject*)), SLOT(onFinished()));
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include <QJsonObject> #include <QJsonObject>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include "fmapirelay.h" #include "fmapirelay.h"
#include <QMutex>
#include <QWaitCondition>
//#include <QNetworkAccessManager> //#include <QNetworkAccessManager>
//#include <QNetworkReply> //#include <QNetworkReply>
...@@ -60,13 +62,15 @@ private slots: ...@@ -60,13 +62,15 @@ private slots:
private: private:
FMVipWnd *_vindow; FMVipWnd *_vindow;
QJsonObject _posReqObj; QJsonObject _posReqObj;
BOOL isServerResponsed;
BOOL canBeContinue;
QByteArray _serverRspData; QByteArray _serverRspData;
BOOL isLastOne; BOOL isLastOne;
int _windowReturn; int _windowReturn;
QSystemTrayIcon *_sysIcon; QSystemTrayIcon *_sysIcon;
QMutex mutex;
QWaitCondition serverIsBusy;
BOOL requestSuccess;
}; };
#endif // FMVIPDISPATCHER_H #endif // FMVIPDISPATCHER_H
...@@ -147,8 +147,8 @@ void FMVipForward::fund(const QJsonObject &job, QJsonObject &fmjob) ...@@ -147,8 +147,8 @@ void FMVipForward::fund(const QJsonObject &job, QJsonObject &fmjob)
QJsonObject transObj; QJsonObject transObj;
transObj["account"] = sessionData("fm_open_id"); transObj["account"] = sessionData("fm_open_id");
transObj["amount"] = sessionData("fundAmount"); transObj["amount"] = sessionData("fundAmount");
transObj["cashAmout"] = sessionData("fundAmount"); transObj["cashAmount"] = sessionData("fundAmount");
transObj["thirdAmout"] = 0; transObj["thirdAmount"] = 0;
transObj["thirdPayType"] = 0; transObj["thirdPayType"] = 0;
transObj["thirdPayTransId"] = ""; transObj["thirdPayTransId"] = "";
...@@ -325,10 +325,8 @@ QString FMVipForward::sign(const QJsonObject &reqJob) const ...@@ -325,10 +325,8 @@ QString FMVipForward::sign(const QJsonObject &reqJob) const
void FMVipForward::resetSessionData(const QJsonObject &jsonObj) void FMVipForward::resetSessionData(const QJsonObject &jsonObj)
{ {
// _sessionDataMap.clear();
foreach (QString sessionData, _sessionDataList) foreach (QString sessionData, _sessionDataList)
{ {
qDebug() << sessionData;
addSessionData(sessionData, jsonObj[sessionData].toString()); addSessionData(sessionData, jsonObj[sessionData].toString());
} }
} }
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include "fmvipforward.h" #include "fmvipforward.h"
#include <QMovie> #include <QMovie>
#include <QPixmap>
#include <QBitmap>
FMVipLogin::FMVipLogin(QDialog *parent) : FMVipLogin::FMVipLogin(QDialog *parent) :
FMVipWnd(parent), FMVipWnd(parent),
...@@ -20,6 +22,11 @@ FMVipLogin::FMVipLogin(QDialog *parent) : ...@@ -20,6 +22,11 @@ FMVipLogin::FMVipLogin(QDialog *parent) :
ui->operator_label->setText(operator_id); ui->operator_label->setText(operator_id);
ui->bd_label->setText(business_date); ui->bd_label->setText(business_date);
QLabel topLevelLabel;
QPixmap pixmap(":/img_logo.png");
topLevelLabel.setPixmap(pixmap);
topLevelLabel.setMask(pixmap.mask());
} }
FMVipLogin::~FMVipLogin() FMVipLogin::~FMVipLogin()
......
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