Commit 599b7612 by unknown

调试版。修复流程错误

parent 34f723e0
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.0.2, 2016-09-02T19:37:11. -->
<!-- Written by QtCreator 4.0.2, 2016-09-04T23:10:28. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......@@ -62,7 +62,7 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.7.0 MinGW 32bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.7.0 MinGW 32bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.57.win32_mingw53_kit</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">1</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
......@@ -292,7 +292,7 @@
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">FMVip.pro</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.default">C:/Users/zzf/Documents/Qt/FMVip/build-FMVip-Desktop_Qt_5_7_0_MinGW_32bit-Release</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="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
......
......@@ -6,17 +6,20 @@
#include "fmvipforward.h"
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
#include <QApplication>
#include <QMessageBox>
FMVipDispatcher::FMVipDispatcher(QObject *parent)
: QObject(parent),
FMApiRelay(),
_vindow(0)
_vindow(0),
isLastOne(true),
_windowReturn(0)
{
connect(this, SIGNAL(requested(QJsonObject)), SLOT(onRequest(QJsonObject)));
connect(this, SIGNAL(responded(QByteArray)), SLOT(onResponse(QByteArray)));
connect(FMVipForward::instance(), SIGNAL(serverResponsed(QByteArray)), SLOT(onServerResponsed(QByteArray)));
connect(FMVipForward::instance(), SIGNAL(serverResponsed(QJsonObject)), SLOT(onServerResponsed(QJsonObject)));
}
INT FMVipDispatcher::_ParseRequest(LPSTR data)
......@@ -31,11 +34,15 @@ INT FMVipDispatcher::_ParseRequest(LPSTR data)
_posReqObj = json.object();
FMVipForward::instance()->resetSessionData(_posReqObj);
isLastOne = true;
canBeContinue = false;
isServerResponsed = false; // 重置服务器是否已返回信息的标志
// 唤起客户端界面
emit requested(_posReqObj);
isWindowClosed = false;
isServerResponsed = false; // 重置服务器是否已返回信息的标志
return FM_API_SUCCESS;
}
......@@ -46,7 +53,7 @@ BOOL FMVipDispatcher::_GetResponse(LPSTR &rsp, UINT &len)
// QTime dieTime = QTime::currentTime().addMSecs(1000*5);
// 服务器还未返回则一直阻塞
while(isServerResponsed == false && isWindowClosed == false)
while(isServerResponsed == false && canBeContinue == false)
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
rsp = _serverRspData.data();
len = _serverRspData.length();
......@@ -59,27 +66,51 @@ void FMVipDispatcher::onRequest(const QJsonObject &jsonObj)
QString type = jsonObj["fm_cmd"].toString();
if (type == Type_Login) {
FMVipForward::instance()->resetSessionData(jsonObj);
login();
}
else if (type == Type_Pay) {
pay();
}
else if (type == Type_Coupon) {
coupon();
}
else if (type == Type_Fund) {
fund();
}
else if (type == Type_Final) {
final();
}
#ifdef _DEBUG
else if (type == "") {
qDebug() << "Quit";
// qDebug() << "Quit";
// _serverRspData.clear();
// canBeContinue = true;
// _serverRspData = "{\"reqType\":-1}";
qApp->quit();
}
#endif
else {
// 支付、充值、结算先检查登陆状态。
QJsonObject copyJsonObj(jsonObj);
if (!isLogined()) {
_posReqObj["fm_cmd"] = Type_Login;
isLastOne = false;
login();
}
if (canBeContinue || _windowReturn == -1) {
_serverRspData.clear();
canBeContinue = true;
return;
}
_posReqObj = copyJsonObj;
isLastOne = true;
if (type == Type_Pay) {
pay();
canBeContinue = true;
}
else if (type == Type_Fund) {
fund();
canBeContinue = true;
}
else if (type == Type_Final) {
final();
}
FMVipForward::instance()->clearSessionData();
}
if(_windowReturn == -1) {
_serverRspData.clear();
}
}
void FMVipDispatcher::onResponse(const QByteArray &rsp)
......@@ -88,44 +119,71 @@ void FMVipDispatcher::onResponse(const QByteArray &rsp)
Q_UNUSED(rsp)
}
void FMVipDispatcher::onWindowClosed()
{
_serverRspData.clear();
isWindowClosed = true;
}
void FMVipDispatcher::onFinished()
{
qDebug() << __FUNCTION__;
isWindowClosed = true;
_vindow = 0;
}
void FMVipDispatcher::onServerResponsed(const QByteArray &rsp)
void FMVipDispatcher::onServerResponsed(const QJsonObject &rspObj)
{
qDebug() << __FUNCTION__;
_serverRspData = rsp;
isServerResponsed = true; // 重置服务器是否已返回信息的标志
if(_vindow != 0) {
_vindow->deleteLater();
}
if( isLastOne ) {
QJsonDocument rspDoc(rspObj);
QByteArray rspData = rspDoc.toJson();
_serverRspData = rspData;
isServerResponsed = true; // 重置服务器是否已返回信息的标志
}
int status = rspObj["statusCode"].toInt();
if(status == 100) {
if(isLastOne) {
QMessageBox msgBox;
msgBox.setWindowTitle("提示");
msgBox.setText("操作成功");
msgBox.setAttribute(Qt::WA_QuitOnClose, false);
msgBox.exec();
}
else {
// 可以继续下一步操作
canBeContinue = false;
}
}
else {
QString msg = rspObj["msg"].toString();
QMessageBox msgBox;
msgBox.setWindowTitle("错误");
msgBox.setText(msg);
msgBox.setAttribute(Qt::WA_QuitOnClose, false);
msgBox.exec();
canBeContinue = true;
_vindow = 0;
}
}
// 向服务器发送请求
void FMVipDispatcher::onDoPost()
{
isServerResponsed = false;
FMVipForward::instance()->parseRequest(_posReqObj);
}
void FMVipDispatcher::login()
{
if (!_vindow) {
FMVipLogin *login = new FMVipLogin;
connect(login, SIGNAL(destroyed(QObject*)), SLOT(onFinished()));
connect(login, SIGNAL(doPost()), SLOT(onDoPost()));
_vindow = login;
login->exec();
_windowReturn = login->exec();
}
}
......@@ -147,21 +205,21 @@ void FMVipDispatcher::pay()
if(canPay != 1) {
onDoPost();
return;
}
if (!_vindow) {
else if (!_vindow) {
FMVipOrder *order = new FMVipOrder;
connect(order, SIGNAL(destroyed(QObject*)), SLOT(onFinished()));
connect(order, SIGNAL(doPost()), SLOT(onDoPost()));
_vindow = order;
order->exec();
_windowReturn = order->exec();
}
}
void FMVipDispatcher::fund()
{
// _posReqObj["fm_cmd"] = Type_Fund;
FMVipForward::instance()->addSessionData("charge_amount", QString::number(_posReqObj["charge_amount"].toInt()));
if (!_vindow) {
......@@ -169,7 +227,7 @@ void FMVipDispatcher::fund()
connect(fund, SIGNAL(destroyed(QObject*)), SLOT(onFinished()));
connect(fund, SIGNAL(doPost()), SLOT(onDoPost()));
_vindow = fund;
fund->exec();
_windowReturn = fund->exec();
}
}
......@@ -177,3 +235,9 @@ void FMVipDispatcher::final()
{
onDoPost();
}
BOOL FMVipDispatcher::isLogined()
{
QString account = FMVipForward::instance()->sessionData("fm_open_id");
return account != "";
}
......@@ -30,11 +30,13 @@ class FMVipDispatcher : public QObject, public FMApiRelay
public:
explicit FMVipDispatcher(QObject *parent = 0);
private:
void login();
void pay();
void coupon();
void fund();
void final();
BOOL isLogined();
protected:
virtual INT _ParseRequest(LPSTR data);
......@@ -49,16 +51,17 @@ private slots:
void onResponse(const QByteArray &rsp);
void onFinished();
void onServerResponsed(const QByteArray &rsp);
void onServerResponsed(const QJsonObject &rspObj);
void onDoPost();
void onWindowClosed();
private:
FMVipWnd *_vindow;
QJsonObject _posReqObj;
BOOL isServerResponsed;
BOOL isWindowClosed;
BOOL canBeContinue;
QByteArray _serverRspData;
BOOL isLastOne;
int _windowReturn;
};
#endif // FMVIPDISPATCHER_H
......@@ -125,10 +125,7 @@ void FMVipForward::onServerFinished(QNetworkReply *reply)
default:
break;
}
QJsonDocument posDoc(posObj);
QByteArray posData = posDoc.toJson();
emit serverResponsed(posData);
emit serverResponsed(posObj);
}
......@@ -159,7 +156,6 @@ void FMVipForward::coupon(const QJsonObject &job, QJsonObject &fmjob)
{
Q_UNUSED(job);
fmjob["reqType"] = FM_VIP_COUPON;
fmjob["account"] = sessionData("fm_open_id");
}
void FMVipForward::pay(const QJsonObject &job, QJsonObject &fmjob)
{
......@@ -167,6 +163,7 @@ void FMVipForward::pay(const QJsonObject &job, QJsonObject &fmjob)
fmjob["reqType"] = FM_VIP_PAY;
QJsonObject transObj;
// transObj["account"] = job["fm_open_id"];
transObj["account"] = sessionData("fm_open_id");
transObj["codeAmount"] = sessionDataInt("codeAmount");
transObj["isUseScore"] = sessionDataInt("isUseScore");
......@@ -176,21 +173,40 @@ void FMVipForward::pay(const QJsonObject &job, QJsonObject &fmjob)
void FMVipForward::final(const QJsonObject &job, QJsonObject &fmjob)
{
fmjob["reqType"] = FM_VIP_FINAL;
fmjob["memberTransId"] = sessionData("fm_id");
// fmjob["memberTransId"] = sessionData("fm_id");
QJsonObject transObj;
QJsonObject posTransObj = job["transactions"].toObject();
// transObj["account"] = job["fm_open_id"];
transObj["account"] = sessionData("fm_open_id");
transObj["amount"] = posTransObj["order_amount"];
transObj["payAmount"] = posTransObj["paid_amount"];
transObj["cashAmount"] = 1;
transObj["codeAmount"] = 1;
transObj["scoreAmount"] = 1;
transObj["thirdAmount"] = 1;
transObj["thirdPayType"] = 2;
transObj["thirdPayTransId"] = "";
int amount = posTransObj["order_amount"].toInt();
int paidAmount = posTransObj["paid_amount"].toInt();
QJsonArray pay_ids = job["pay_ids"].toArray();
QJsonArray couponArray;
int codeAmount=0, scoreAmount=0, cashAmount=0, thirdAmount=0;
for (QJsonValue pay_v : pay_ids)
{
QJsonObject pay_ob = pay_v.toObject();
if(pay_ob["pay_id"] == "001") {
codeAmount = pay_ob["paid_total_amount"].toInt();
}
if(pay_ob["pay_id"] == "003") {
scoreAmount = pay_ob["paid_total_amount"].toInt();
couponArray = pay_ob["coupons"].toArray();
}
}
cashAmount = paidAmount - codeAmount - thirdAmount;
transObj["amount"] = amount;
transObj["payAmount"] = paidAmount;
transObj["codeAmount"] = codeAmount;
transObj["scoreAmount"] = scoreAmount;
transObj["cashAmount"] = cashAmount;
transObj["thirdAmount"] = thirdAmount;
transObj["thirdPayType"] = 0;
transObj["thirdPayTransId"] = "";
transObj["coupons"] = couponArray;
QJsonArray posProdArray = posTransObj["products"].toArray();
......@@ -231,6 +247,7 @@ void FMVipForward::funded(const QJsonObject &serverJob, QJsonObject &posJob)
void FMVipForward::couponed(const QJsonObject &serverJob, QJsonObject &posJob)
{
posJob["pid"] = serverJob["productCode"];
posJob["fm_open_id"] = serverJob["account"];
}
void FMVipForward::payed(const QJsonObject &serverJob, QJsonObject &posJob)
......@@ -306,7 +323,7 @@ QString FMVipForward::sign(const QJsonObject &reqJob) const
void FMVipForward::resetSessionData(const QJsonObject &jsonObj)
{
_sessionDataMap.clear();
// _sessionDataMap.clear();
for (QString sessionData : _sessionDataList)
{
addSessionData(sessionData, jsonObj[sessionData].toString());
......
......@@ -74,7 +74,7 @@ private:
QMap<QString, QString> _sessionDataMap;
QStringList _sessionDataList;
signals:
void serverResponsed(const QByteArray& rspData);
void serverResponsed(const QJsonObject& rspData);
private slots:
void onServerFinished(QNetworkReply *reply);
};
......
......@@ -5,19 +5,9 @@
FMVipFund::FMVipFund(QDialog *parent) :
FMVipWnd(parent),
ui(new Ui::FMVipFund),
_digit_group(new QButtonGroup(this))
ui(new Ui::FMVipFund)
{
ui->setupUi(this);
_digit_group->addButton(ui->half);
_digit_group->addButton(ui->one);
_digit_group->addButton(ui->two);
_digit_group->addButton(ui->five);
_digit_group->addButton(ui->ten);
_digit_group->addButton(ui->twenty);
connect(_digit_group, SIGNAL(buttonClicked(QAbstractButton*)), SLOT(onDigitChecked(QAbstractButton*)));
QString operator_id = FMVipForward::instance()->sessionData("operator_id");
QString business_date = FMVipForward::instance()->sessionData("business_date");
QString fm_id = FMVipForward::instance()->sessionData("fm_open_id");
......@@ -49,13 +39,6 @@ void FMVipFund::show()
FMVipWnd::show();
}
void FMVipFund::onDigitChecked(QAbstractButton *btn)
{
QString digit = btn->text();
digit = digit.replace("¥", "");
ui->amount_edit->setText(digit);
}
void FMVipFund::on_fund_btn_clicked()
{
qDebug() << __FUNCTION__;
......
......@@ -21,12 +21,10 @@ public:
public slots:
void show();
void onDigitChecked(QAbstractButton *btn);
void on_fund_btn_clicked();
private:
Ui::FMVipFund *ui;
QButtonGroup *_digit_group;
};
#endif // FMVIPFUND_H
......@@ -41,6 +41,7 @@ bool FMVipWnd::setProfile(const QByteArray &d)
void FMVipWnd::on_close_btn_clicked()
{
close();
setResult(-1); // 关闭时返回-1
deleteLater();
}
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>968</width>
<height>768</height>
<width>964</width>
<height>565</height>
</rect>
</property>
<property name="maximumSize">
......@@ -344,163 +344,7 @@ QPushButton#fund_btn:hover {
<property name="spacing">
<number>14</number>
</property>
<item row="5" column="0">
<widget class="QPushButton" name="two">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>282</width>
<height>110</height>
</size>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>¥200</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="half">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>282</width>
<height>110</height>
</size>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>¥50</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QPushButton" name="ten">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>282</width>
<height>110</height>
</size>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>¥1000</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QPushButton" name="five">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>282</width>
<height>110</height>
</size>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>¥500</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="one">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>282</width>
<height>110</height>
</size>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>¥100</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>true</bool>
</property>
</widget>
</item>
<item row="7" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="8" column="1">
<item row="4" column="1">
<widget class="QPushButton" name="fund_btn">
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
......@@ -510,38 +354,7 @@ QPushButton#fund_btn:hover {
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QPushButton" name="twenty">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>282</width>
<height>110</height>
</size>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>¥2000</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>true</bool>
</property>
</widget>
</item>
<item row="8" column="0">
<item row="4" column="0">
<widget class="QWidget" name="input" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
......@@ -572,7 +385,7 @@ QPushButton#fund_btn:hover {
<string>50</string>
</property>
<property name="readOnly">
<bool>false</bool>
<bool>true</bool>
</property>
</widget>
</item>
......
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