Commit 25d5b650 by Carwyn

修正: 1. 判断数据库连接是否存在Bug; 2.支付等待确认按钮后才返回; 3. 支付错误界面宽度调整

parent 215e58a6
......@@ -9,7 +9,7 @@
FMPDataBase::FMPDataBase(QString dbname, QString connectname, QObject *parent) : QObject(parent)
{
if (QSqlDatabase::contains(connectname)) {
if (!QSqlDatabase::contains(connectname)) {
_db = QSqlDatabase::addDatabase("QSQLITE", connectname);
}
else {
......
......@@ -42,6 +42,7 @@ FMPePayPrivate::FMPePayPrivate(FMPePay *parent)
{
_watcher = new QFutureWatcher<QByteArray>();
connect( _watcher, SIGNAL( finished() ), this, SLOT( witedata() ) );
connect(this, &FMPePayPrivate::confirmClicked, &_api_evt, &QEventLoop::quit);
}
FMPePayPrivate::~FMPePayPrivate()
......@@ -170,6 +171,7 @@ void FMPePayPrivate::Init()
if (trans.contains("refund_amount") && trans["refund_amount"].toInt() != 0
&& trans.contains(FMP_JKEY_FM_ORDERID) && !trans[FMP_JKEY_FM_ORDERID].toString().isEmpty()
|| trans.contains(FMP_JKEY_PAY_TRANSID) && !trans[FMP_JKEY_PAY_TRANSID].toString().isEmpty()) {
connect(this, &FMPePayPrivate::finished, this, &FMPePayPrivate::confirmClicked);
ControlRefundJson(trans);
return;
}
......@@ -240,10 +242,7 @@ void FMPePayPrivate::DockPayRequest(const QByteArray &json)
QByteArray FMPePayPrivate::DockPayRespond()
{
QByteArray json = "{\"statusCode\":106, \"msg\":\"\347\252\227\345\217\243\345\267\262\345\205\263\351\227\255\357\274\214\344\272\244\346\230\223\345\217\226\346\266\210\", \"prompt\":0}";
QEventLoop evt;
connect(this, SIGNAL(finished(QJsonObject)), &evt, SLOT(quit()));
connect(this, SIGNAL(apiError()), &evt, SLOT(quit()));
evt.exec();
_api_evt.exec();
if (!_api_abort) {
_docked_response = QJsonObject();
......@@ -277,10 +276,6 @@ QByteArray FMPePayPrivate::DockPayRespond()
json = QJsonDocument(_docked_response).toJson();
}
if (_is_api) {
Uninit();
}
return json;
}
......@@ -294,10 +289,7 @@ void FMPePayPrivate::DockRefundRequest(const QByteArray &json)
QByteArray FMPePayPrivate::DockRefundRespond()
{
QByteArray json = "{\"statusCode\":106, \"msg\":\"\347\252\227\345\217\243\345\267\262\345\205\263\351\227\255\357\274\214\344\272\244\346\230\223\345\217\226\346\266\210\", \"prompt\":0}";
QEventLoop evt;
connect(this, SIGNAL(finished(QJsonObject)), &evt, SLOT(quit()));
connect(this, SIGNAL(apiError()), &evt, SLOT(quit()));
evt.exec();
_api_evt.exec();
//!
if (!_api_abort) {
......@@ -313,20 +305,27 @@ QByteArray FMPePayPrivate::DockRefundRespond()
json = QJsonDocument(_docked_response).toJson();
}
if (_is_api) {
Uninit();
return json;
}
void FMPePayPrivate::OnFinish()
{
if (_origin_response.isEmpty()) {
_api_abort = true;
}
return json;
emit confirmClicked();
_api_evt.quit();
}
void FMPePayPrivate::ControlPayJson(QString sum, QString code)
{
Q_Q(FMPePay);
_origin_response = QJsonObject();
QtConcurrent::run( [q, sum, code, this ]()
QtConcurrent::run( [&, sum, code, this]()
{
Q_Q(FMPePay);
_origin_response = QJsonObject();
if(_reverse_flag)
{
emit error(QString::fromLocal8Bit("网络连接异常(冲正...)"));
......@@ -466,13 +465,54 @@ bool FMPePayPrivate::HttpPost(QJsonObject& outjson, QJsonObject json, QString &e
FMP_INFO() << outjson;
if(outjson[FMP_RPAY_PAY_RETURN_STATUSCODE].toInt() == 100)
int statusCode = outjson[FMP_RPAY_PAY_RETURN_STATUSCODE].toInt();
int reqType = json[FMP_EPAY_REQUESTTYPE].toInt();
if(statusCode == 100)
return true;
if(outjson.contains(FMP_RPAY_PAY_RETURN_MSG))
if (statusCode == 204 && reqType == 72) {
QJsonObject queryJson = json;
queryJson[FMP_EPAY_REQUESTTYPE] = 52;
queryJson[FMP_EPAY_VER] = 3;
FMP_INFO() << "Query: " << json[FMP_EPAY_TRANSID].toString();
QJsonObject queryOutJson;
if (!HttpPost(queryOutJson, queryJson, error, timeout)) {
QJsonObject revokeJson = json;
revokeJson[FMP_EPAY_REQUESTTYPE] = 3;
QJsonObject revokeOutJson;
HttpPost(revokeOutJson, revokeJson, error, timeout);
error = QString::fromLocal8Bit("支付失败,请重试\r\n如已扣款会自动退还");
return false;
}
else {
outjson = queryOutJson;
}
}
if(outjson.contains(FMP_RPAY_PAY_RETURN_MSG)) {
error = outjson[FMP_RPAY_PAY_RETURN_MSG].toString() + QString("[%1]").arg(outjson[FMP_RPAY_PAY_RETURN_STATUSCODE].toInt());
else
error = QString::fromLocal8Bit("未定义错误") + QString("[%1]").arg(outjson[FMP_RPAY_PAY_RETURN_STATUSCODE].toInt());
} else {
QString errorDesc;
switch(statusCode) {
case 21:
errorDesc = QString::fromLocal8Bit("参数错误");
break;
case 41:
errorDesc = QString::fromLocal8Bit("交易不存在");
break;
case 203:
errorDesc = QString::fromLocal8Bit("余额不足");
break;
case 205:
errorDesc = QString::fromLocal8Bit("支付码错误");
break;
default:
errorDesc = QString::fromLocal8Bit("未定义错误");
break;
}
error = errorDesc + QString("[%1]").arg(outjson[FMP_RPAY_PAY_RETURN_STATUSCODE].toInt());
}
return false;
}
......@@ -515,11 +555,12 @@ void FMPePayPrivate::GetMode()
void FMPePayPrivate::ControlRefundJson(const QJsonObject &trans)
{
Q_Q(FMPePay);
_origin_response = QJsonObject();
QtConcurrent::run( [q, trans, this ]()
QtConcurrent::run( [&, trans, this]()
{
Q_Q(FMPePay);
_origin_response = QJsonObject();
QStringList keylist;
QSqlQuery query;
keylist.append(SQL_KEY_EBCODE);
......@@ -617,6 +658,8 @@ void FMPePayPrivate::ControlRefundJson(const QJsonObject &trans)
if (!dock_success) {
emit apiError();
}
disconnect(this, &FMPePayPrivate::finished, this, &FMPePayPrivate::confirmClicked);
});
}
......
......@@ -59,12 +59,17 @@ private:
void SetBasicInfo(QVariantHash hash);
void clearorder();
signals:
void confirmClicked();
void apiError();
void error(QString errormsg);
void finished(QJsonObject json);
public slots:
void OnFinish();
protected slots:
void witedata();
public:
......@@ -80,7 +85,7 @@ private:
QJsonObject _docked_request;
QJsonObject _origin_response;
QJsonObject _docked_response;
QEventLoop _api_evt;
bool _is_api;
bool _api_abort;
bool _reverse_flag;
......
......@@ -92,6 +92,12 @@ FMPPayDialog::FMPPayDialog(FMPePayPrivate *control, QVariantHash basicinfo, QWid
connect(_control, &FMPePayPrivate::error, this, &FMPPayDialog::showErrorMsg);
connect(_control, &FMPePayPrivate::finished, this, &FMPPayDialog::showSuccessMsg);
connect(ui->btn_close, &QPushButton::clicked, _control, &FMPePayPrivate::OnFinish, Qt::QueuedConnection);
connect(ui->btn_success_confirm, &QPushButton::clicked, _control, &FMPePayPrivate::OnFinish, Qt::QueuedConnection);
connect(this, &FMPPayDialog::accepted, _control, &FMPePayPrivate::OnFinish, Qt::QueuedConnection);
connect(this, &FMPPayDialog::rejected, _control, &FMPePayPrivate::OnFinish, Qt::QueuedConnection);
ui->lineedit_num->setFocus();
_current_LineEdit = ui->lineedit_num;
......@@ -314,7 +320,7 @@ void FMPPayDialog::onSelectionChanged(QModelIndex idx)
void FMPPayDialog::keyPressEvent(QKeyEvent *e)
{
if (e->key() == Qt::Key_Escape) {
on_btn_close_clicked();
emit ui->btn_close->click();
}
}
......@@ -348,6 +354,10 @@ void FMPPayDialog::setPaySuccessView(QJsonObject json)
ui->lb6->show();
ui->tlb6->show();
ui->label_tip->setVisible(false);
ui->verticalLayout->removeWidget(ui->label_tip);
ui->wdg_right_bg->setMinimumHeight(450);
ui->suc2->setText(QString::fromLocal8Bit("支付成功"));
ui->tlb1->setText(QString::fromLocal8Bit("支 付 渠 道"));
ui->lb1->setText(json[FMP_RPAY_PAY_RETURN_PAYID].toString());
......@@ -365,10 +375,16 @@ void FMPPayDialog::setPaySuccessView(QJsonObject json)
_success_flag = true;
PlayAnimation(findChild<QWidget *>(_curt_btn->property("pageName").toString()), ui->wdg_success_main, RightToLeft);
ui->btn_success_confirm->setFocus();
}
void FMPPayDialog::setRefundSuccessView(QJsonObject json)
{
ui->label_tip->setVisible(false);
ui->verticalLayout->removeWidget(ui->label_tip);
ui->wdg_right_bg->setMinimumHeight(450);
ui->suc2->setText(QString::fromLocal8Bit("退款成功"));
ui->tlb1->setText(QString::fromLocal8Bit("支 付 渠 道"));
ui->lb1->setText(json[SQL_KEY_PAYID].toString());
......@@ -377,7 +393,7 @@ void FMPPayDialog::setRefundSuccessView(QJsonObject json)
ui->tlb3->setText(QString::fromLocal8Bit("支付交易号"));
ui->lb3->setText(json[SQL_KEY_PAYTRANSID].toString());
ui->tlb4->setText(QString::fromLocal8Bit("退 款 金 额"));
ui->lb4->setText(json[SQL_KEY_TOTALAMOUNT].toString());
ui->lb4->setText(QString::number(json[SQL_KEY_TOTALAMOUNT].toDouble() / 100));
ui->lb5->hide();
ui->tlb5->hide();
ui->lb6->hide();
......@@ -386,6 +402,8 @@ void FMPPayDialog::setRefundSuccessView(QJsonObject json)
_success_flag = true;
PlayAnimation(findChild<QWidget *>(_curt_btn->property("pageName").toString()), ui->wdg_success_main, RightToLeft);
ui->btn_success_confirm->setFocus();
}
void FMPPayDialog::setPayView()
......@@ -604,7 +622,7 @@ void FMPPayDialog::onBtnConfirmClicked()
{
_wait->SetContent(FMPPayWait::LOADING, QString::fromLocal8Bit("退款中..."));
QJsonObject trans;
trans["refund_amount"] = ((int)ui->lineedit_num_refund->text().toDouble() + 0.005) * 100;
trans["refund_amount"] = (int)((ui->lineedit_num_refund->text().toDouble() + 0.005) * 100);
trans["fm_id"] = ui->lineedit_code_refund->text();
_control->ControlRefundJson(trans);
}
......@@ -634,7 +652,6 @@ void FMPPayDialog::reject()
void FMPPayDialog::on_btn_close_clicked()
{
this->hide();
_control->Uninit();
}
void FMPPayDialog::onLineeditCodeGetFocus()
......@@ -699,7 +716,7 @@ void FMPPayDialog::on_pushButton_2_clicked()
_wait->SetContent(FMPPayWait::LOADING, QString::fromLocal8Bit("退款中..."));
QJsonObject trans;
trans["refund_amount"] = ((int)model->data(idx.sibling(idx.row(), 6)).toDouble() + 0.005) * 100;
trans["refund_amount"] = (int)(model->data(idx.sibling(idx.row(), 6)).toDouble() + 0.005) * 100;
trans["fm_id"] = model->data(idx.sibling(idx.row(),0)).toString();
_control->ControlRefundJson(trans);
......
......@@ -2017,6 +2017,18 @@ QPushButton:hover {
<height>460</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>628</width>
<height>460</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>628</width>
<height>460</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255);</string>
</property>
......@@ -2553,8 +2565,14 @@ font: 75 24px &quot;微软雅黑&quot;;</string>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
<width>371</width>
<height>58</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>371</width>
<height>58</height>
</size>
</property>
<property name="font">
......@@ -2840,9 +2858,9 @@ QHeaderView::section {
</item>
</layout>
</widget>
<zorder>wdg_success_main</zorder>
<zorder>wdg_refund_main</zorder>
<zorder>wdg_query_main</zorder>
<zorder>wdg_success_main</zorder>
<zorder>wdg_pay_main</zorder>
</widget>
</item>
......
......@@ -140,21 +140,14 @@ background-color: rgb(148, 148, 148, 0);
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
<number>10</number>
</property>
<property name="leftMargin">
<number>50</number>
</property>
<property name="rightMargin">
<number>10</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_logo">
<property name="minimumSize">
......@@ -181,7 +174,7 @@ background-color: rgb(148, 148, 148, 0);
<widget class="QLabel" name="label_msg">
<property name="minimumSize">
<size>
<width>161</width>
<width>0</width>
<height>0</height>
</size>
</property>
......@@ -210,27 +203,14 @@ background-color: rgb(148, 148, 148, 0);
<property name="text">
<string>支付中...</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>13</width>
<height>57</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
......
......@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 16
#define VER_BUILD 17
//! Convert version numbers to string
#define _STR(S) #S
......
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