Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fmp_epay
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhenfei.zhang
fmp_epay
Commits
c988b99a
Commit
c988b99a
authored
Aug 25, 2017
by
gujin.wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.给数据库添加一个字段,存放该订单的支付总额。2.添加对只使用卡券情况的处理逻辑 3.在支付失败的情况下,对已核销的卡券进行冲正,并从核销表中删除该券的核销记录。
parent
868048a7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
124 additions
and
18 deletions
+124
-18
fmp_epay_p.cpp
+23
-3
fmp_epay_p.h
+3
-2
fmp_epayview_dialog.cpp
+88
-12
fmp_epayview_dialog.h
+10
-1
No files found.
fmp_epay_p.cpp
View file @
c988b99a
...
...
@@ -70,6 +70,7 @@ FMPePayPrivate::FMPePayPrivate(FMPePay *parent)
"statusCode integer,"
"operator_id varchar(40),"
"addtime TIMESTAMP default (datetime('now', 'localtime')),"
"pay_total integer,"
"PRIMARY KEY (trans_id)"
")"
;
FMP_INFO
()
<<
" creat table sql:"
<<
sql
;
...
...
@@ -420,6 +421,8 @@ void FMPePayPrivate::ControlPayJson(QString sum, QString code)
outjson
.
insert
(
SQL_KEY_TRANSID
,
_docked_request
[
SQL_KEY_TRANSID
].
toString
());
_origin_response
=
outjson
;
_origin_response
[
"pay_total"
]
=
_payDialog
->
_pay_total
+
_origin_response
[
"total_amount"
].
toInt
();
FMP_INFO
()
<<
"result json : "
<<
outjson
;
writeOrderToSqlite
();
// if (_is_api) {
...
...
@@ -729,8 +732,9 @@ bool FMPePayPrivate::GetPayJson(const QString& sum, const QString& code)
transaction
.
insert
(
FMP_EPAY_TRANSTRACTION_CODE
,
code
);
if
(
_is_api
)
{
QJsonObject
origin_trans
=
_origin_request
[
"transactions"
].
toObject
();
transaction
[
FMP_EPAY_TRANSTRACTION_AMOUNT
]
=
origin_trans
[
"order_amount"
];
//QJsonObject origin_trans = _origin_request["transactions"].toObject();
//transaction[FMP_EPAY_TRANSTRACTION_AMOUNT] = origin_trans["order_amount"];
transaction
[
FMP_EPAY_TRANSTRACTION_AMOUNT
]
=
(
int
)(
sum
.
toDouble
()
*
100
);
QJsonArray
pos_products
=
_origin_request
[
"products"
].
toArray
();
QJsonArray
products
;
int
i
=
1
;
...
...
@@ -850,6 +854,12 @@ void FMPePayPrivate::ClosePayWindow(int type)
writeOrderToSqlite
();
}
void
FMPePayPrivate
::
writeOrderToSqlite
(
const
QJsonObject
&
response
)
{
_origin_response
=
response
;
writeOrderToSqlite
();
}
void
FMPePayPrivate
::
writeOrderToSqlite
()
{
Q_Q
(
FMPePay
);
...
...
@@ -899,7 +909,10 @@ void FMPePayPrivate::writeOrderToSqlite()
else
_db
->
update
(
q
->
_table
,
_dbWrite
.
toVariantHash
(),
QString
(
"trans_id = '%1'"
).
arg
(
_dbWrite
[
SQL_KEY_TRANSID
].
toString
()));
}
else
{
else
{
//支付失败,将pay_total置为order_amount
_dbWrite
[
"pay_total"
]
=
0
;
if
(
!
_db
->
isRecordExist
(
q
->
_table
,
_pos_trans_id
)){
QJsonObject
origin_trans
=
_origin_request
[
"transactions"
].
toObject
();
_dbWrite
[
"total_amount"
]
=
origin_trans
[
"order_amount"
];
...
...
@@ -911,6 +924,13 @@ void FMPePayPrivate::writeOrderToSqlite()
else
{
_db
->
update
(
q
->
_table
,
_dbWrite
.
toVariantHash
(),
QString
(
"trans_id = '%1'"
).
arg
(
_dbWrite
[
FMP_EPAY_TRANSID
].
toString
()));
}
//并重置pay_total变量
//并对已核销的卡券进行冲正
_payDialog
->
_pay_total
=
0
;
if
(
_dbWrite
[
FMP_RPAY_PAY_RETURN_STATUSCODE
].
toInt
()
!=
ERROR_ORDER_STATUS
){
_payDialog
->
Reverse
();
}
}
FMP_INFO
()
<<
"writeOrderToSqlite json : "
<<
_dbWrite
;
...
...
fmp_epay_p.h
View file @
c988b99a
...
...
@@ -61,6 +61,8 @@ public:
QByteArray
DockRefundRespond
();
void
writeOrderToSqlite
();
void
writeOrderToSqlite
(
const
QJsonObject
&
response
);
void
updateSqlite
(
const
QJsonObject
&
json
);
...
...
@@ -113,6 +115,7 @@ public:
FMPNetworkInterface
*
_network
;
bool
_is_api
;
CQueryThread
*
_queryThread
;
QString
_pos_trans_id
;
private
:
bool
_reverse_flag
;
...
...
@@ -127,8 +130,6 @@ private:
QJsonObject
_docked_request
;
QJsonObject
_origin_response
;
QJsonObject
_docked_response
;
QString
_pos_trans_id
;
};
#endif // FMP_EPAY_P_H
fmp_epayview_dialog.cpp
View file @
c988b99a
...
...
@@ -26,9 +26,11 @@
#include <QSqlRecord>
#include <QTableWidget>
#include <QSqlQuery>
#include <QMessageBox>
FMPPayDialog
::
FMPPayDialog
(
FMPePayPrivate
*
control
,
QVariantHash
basicinfo
,
QWidget
*
parent
)
:
_control
(
control
),
_pay_total
(
0
),
QDialog
(
parent
),
ui
(
new
Ui
::
FMPPayDialog
)
{
...
...
@@ -195,7 +197,7 @@ FMPPayDialog::FMPPayDialog(FMPePayPrivate *control, QVariantHash basicinfo, QWid
_products_info
=
basicinfo
[
"products"
].
toJsonArray
();
ui
->
tableView_hasPay
->
setToolTip
(
QString
::
fromLocal8Bit
(
"双击查看支付详情"
));
connect
(
ui
->
tableView_hasPay
,
&
QTableView
::
doubleClicked
,
this
,
&
FMPPayDialog
::
ShowPayDetail
);
_should_pay
=
basicinfo
[
"amount"
].
toInt
();
setShowFunc
();
}
...
...
@@ -854,20 +856,47 @@ void FMPPayDialog::PlayAnimation(QWidget *target0, QWidget *target1, Movemode mo
//确定按钮
void
FMPPayDialog
::
onBtnConfirmClicked
()
{
if
(
ui
->
lineedit_num
->
text
().
toDouble
()
<=
0.0
)
{
_api_force_close
=
true
;
_control
->
ClosePayWindow
(
DIALOG_FORCE_CLOSE
);
this
->
close
();
_control
->
Uninit
();
return
;
}
if
(
_wait
==
NULL
)
{
_wait
=
new
FMPPayWait
(
this
);
_wait
->
setModal
(
true
);
}
if
(
ui
->
lineedit_num
->
text
().
toDouble
()
<=
0.0
&&
_pay_total
>
0
&&
ui
->
lineedit_code
->
text
().
isEmpty
())
{
QJsonObject
fakeResponse
;
fakeResponse
[
"statusCode"
]
=
100
;
fakeResponse
[
"pay_acount"
]
=
""
;
fakeResponse
[
"pay_ebcode"
]
=
""
;
fakeResponse
[
"pay_id"
]
=
QString
::
fromLocal8Bit
(
"非码卡券支付"
);
fakeResponse
[
"pay_transId"
]
=
""
;
fakeResponse
[
"fmId"
]
=
""
;
fakeResponse
[
"total_amount"
]
=
_should_pay
;
fakeResponse
[
"alipay_amount"
]
=
0
;
fakeResponse
[
"mcoupon_amount"
]
=
0
;
fakeResponse
[
"invoice_amount"
]
=
_pay_total
;
fakeResponse
[
"pay_total"
]
=
_pay_total
;
fakeResponse
[
"isrefund"
]
=
false
;
QJsonObject
ext
;
QString
desc
=
QString
::
fromLocal8Bit
(
"
\r\n
卡券支付明细
\r\n
"
);
desc
.
append
(
"----------------------------------------
\r\n
"
);
foreach
(
QString
item
,
couponDes
)
{
desc
.
append
(
item
);
desc
.
append
(
"
\r\n
"
);
}
desc
.
append
(
QString
::
fromLocal8Bit
(
"商户交易号:"
).
append
(
_control
->
_pos_trans_id
).
append
(
"
\r\n
"
));
desc
.
append
(
"----------------------------------------"
);
ext
[
"print"
]
=
desc
;
fakeResponse
[
"ext"
]
=
ext
;
qDebug
()
<<
fakeResponse
;
_control
->
writeOrderToSqlite
(
fakeResponse
);
_control
->
finished
(
fakeResponse
);
// _api_force_close=true;
// _control->ClosePayWindow(DIALOG_FORCE_CLOSE);
// this->close();
// _control->Uninit();
return
;
}
if
((
ui
->
lineedit_num
->
text
()
==
""
&&
ui
->
lineedit_num_refund
->
text
()
==
""
)
||
(
ui
->
lineedit_num
->
text
().
toDouble
()
<
0.01
&&
ui
->
lineedit_num_refund
->
text
().
toDouble
()
<
0.01
)
||
...
...
@@ -890,7 +919,6 @@ void FMPPayDialog::onBtnConfirmClicked()
{
_wait
->
SetContent
(
FMPPayWait
::
LOADING
,
QString
::
fromLocal8Bit
(
"支付中..."
));
_control
->
ControlPayJson
(
ui
->
lineedit_num
->
text
(),
ui
->
lineedit_code
->
text
());
}
else
{
...
...
@@ -1096,7 +1124,7 @@ void FMPPayDialog::setShowFunc()
}
else
{
ui
->
btn_pay
->
setVisible
(
false
);
ui
->
btn_check
->
setVisible
(
fals
e
);
ui
->
btn_check
->
setVisible
(
tru
e
);
ui
->
btn_refund
->
setVisible
(
false
);
ui
->
btn_waitPay
->
setVisible
(
true
);
ui
->
btn_errorOrder
->
setVisible
(
true
);
...
...
@@ -1121,6 +1149,26 @@ void FMPPayDialog::redeem()
double
needPay
=
ui
->
lineedit_num
->
text
().
toDouble
();
FMPRedeemInterface
*
redeem
=
FMP
::
GetService
<
FMPRedeemInterface
>
();
redeem
->
StartService
();
// QJsonObject request;
// request["business_date"] = "20170825";
// request["clientReqCount"] = 2;
// request["operator_id"] = "001";
// request["partnerId"] = 1371;
// request["reqtype"] = 71;
// request["station_id"] = "01";
// request["store_id"] = "fm99999";
// request["trans_id"] = "1503649216";
// QJsonArray transactions;
// QJsonObject transaction;
// transaction["code"] = "779335294";
// transaction["ebcode"] = "0000000252";
// transactions.append(transaction);
// request["transactions"] = transactions;
// request["ver"] = 2;
// redeem->Reverse(request);
// return;
QJsonObject
result
=
redeem
->
Redeem
(
needPay
,
_products_info
);
FMP_DEBUG
()
<<
"redeem result: "
<<
result
;
needPay
-=
result
[
"discount"
].
toInt
()
/
100.0
;
...
...
@@ -1128,6 +1176,15 @@ void FMPPayDialog::redeem()
if
(
result
[
"statusCode"
].
toInt
()
==
100
)
{
//增加该笔订单的总支付额
_pay_total
+=
result
[
"discount"
].
toInt
();
//记录该张券的支付描述
couponDes
.
append
(
QString
::
fromLocal8Bit
(
"%1:%2元"
).
arg
(
result
[
"couponType"
].
toString
()).
arg
(
result
[
"discount"
].
toInt
()
/
100.0
));
//保存该卡券的核销参数,以便后续冲正
reverses
.
push_back
(
redeem
->
GetRedeemJson
());
//记录核销详情
QJsonObject
redeemInfo
;
redeemInfo
[
"pay_id"
]
=
result
[
"couponType"
].
toString
();
...
...
@@ -1171,3 +1228,22 @@ void FMPPayDialog::ShowPayDetail(const QModelIndex &index)
}
detailDlg
.
exec
();
}
void
FMPPayDialog
::
Reverse
()
{
FMPRedeemInterface
*
redeem
=
FMP
::
GetService
<
FMPRedeemInterface
>
();
redeem
->
StartService
();
foreach
(
QJsonObject
obj
,
reverses
)
{
QJsonObject
result
=
redeem
->
Reverse
(
obj
);
if
(
result
[
"statusCode"
].
toInt
()
==
100
)
{
//如果冲正成功,则从数据库中删除该券的核销记录
QString
coupon
=
obj
[
"transactions"
].
toArray
()[
0
].
toObject
()[
"code"
].
toString
();
FMPDataBase
*
database
=
_control
->
GetDB
();
if
(
!
database
->
dlt
(
DEFAULT_REDEEM_TABLE
,
"code="
+
coupon
))
{
FMP_ERROR
()
<<
"delete from redeem_table failed. code="
<<
coupon
;
}
}
}
}
fmp_epayview_dialog.h
View file @
c988b99a
...
...
@@ -8,6 +8,7 @@
#include <QModelIndex>
#include <QDateTime>
#include <QTimer>
#include <QVector>
#include <QDialog>
#include <QLineEdit>
...
...
@@ -109,6 +110,8 @@ public:
void
setShowFunc
();
void
Reverse
();
private
:
void
setCheckView
();
...
...
@@ -132,7 +135,11 @@ private:
void
setWaitPayView
();
void
setDoneView
();
void
setDailyBillView
();
public
:
int
_pay_total
;
//一笔订单的支付总额,包括 扫码支付额、卡券支付额......
QStringList
couponDes
;
private
:
Ui
::
FMPPayDialog
*
ui
;
...
...
@@ -153,6 +160,8 @@ private:
bool
_api_force_close
;
QPoint
_mMovePosition
;
QJsonArray
_products_info
;
QVector
<
QJsonObject
>
reverses
;
//存放卡券冲正的请求数据
int
_should_pay
;
//支付请求的应付金额,即amount
};
#endif // DIALOG_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment