Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fmp_vip
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
xiaojing.zhang
fmp_vip
Commits
3799713d
Commit
3799713d
authored
Nov 24, 2017
by
gujin.wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
将支付结果写入sqlite数据库
parent
609da0c9
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
113 additions
and
12 deletions
+113
-12
fmp_vip_server.cpp
+3
-2
fmp_vip_settings.cpp
+5
-0
fmp_vip_settings.h
+1
-0
fmvipdispatcher.cpp
+87
-0
task/taskothers.cpp
+1
-0
task/taskpay.cpp
+16
-10
No files found.
fmp_vip_server.cpp
View file @
3799713d
...
@@ -37,8 +37,9 @@ void FMPVipServer::Write(const QByteArray &data)
...
@@ -37,8 +37,9 @@ void FMPVipServer::Write(const QByteArray &data)
return
;
return
;
}
}
QString
ip
=
FMPVipSettings
::
instance
()
->
getMonitorServer
();
QTcpSocket
client
;
QTcpSocket
client
;
client
.
connectToHost
(
"127.0.0.1"
,
23771
);
client
.
connectToHost
(
ip
,
23771
);
if
(
!
client
.
waitForConnected
())
if
(
!
client
.
waitForConnected
())
{
{
FMP_ERROR
()
<<
"Connect monitor failed. "
<<
client
.
errorString
();
FMP_ERROR
()
<<
"Connect monitor failed. "
<<
client
.
errorString
();
...
@@ -75,7 +76,7 @@ void FMPVipServer::Write(const QByteArray &data)
...
@@ -75,7 +76,7 @@ void FMPVipServer::Write(const QByteArray &data)
}
}
void
FMPVipServer
::
onNewConnection
()
void
FMPVipServer
::
onNewConnection
()
{
{
socket
=
nextPendingConnection
();
socket
=
nextPendingConnection
();
connect
(
socket
,
&
QTcpSocket
::
disconnected
,
this
,
&
FMPVipServer
::
onDisconnected
);
connect
(
socket
,
&
QTcpSocket
::
disconnected
,
this
,
&
FMPVipServer
::
onDisconnected
);
...
...
fmp_vip_settings.cpp
View file @
3799713d
...
@@ -27,6 +27,11 @@ bool FMPVipSettings::getIsNeedSocketHeader()
...
@@ -27,6 +27,11 @@ bool FMPVipSettings::getIsNeedSocketHeader()
return
_GetValue
(
FMP_INIKEY_NEEDSOCKETHEADER
,
false
).
toBool
();
return
_GetValue
(
FMP_INIKEY_NEEDSOCKETHEADER
,
false
).
toBool
();
}
}
QString
FMPVipSettings
::
getMonitorServer
()
{
return
_GetValue
(
FMP_INIKEY_MONITORSERVER
,
"127.0.0.1"
).
toString
();
}
QVariant
FMPVipSettings
::
_GetValue
(
const
QString
&
key
,
QVariant
defaultValue
)
QVariant
FMPVipSettings
::
_GetValue
(
const
QString
&
key
,
QVariant
defaultValue
)
{
{
if
(
_settings
)
{
if
(
_settings
)
{
...
...
fmp_vip_settings.h
View file @
3799713d
...
@@ -16,6 +16,7 @@ public:
...
@@ -16,6 +16,7 @@ public:
QString
getServerUrl
();
QString
getServerUrl
();
bool
getIsNeedSocketHeader
();
bool
getIsNeedSocketHeader
();
QString
getMonitorServer
();
private
:
private
:
explicit
FMPVipSettings
(
QObject
*
parent
=
0
);
explicit
FMPVipSettings
(
QObject
*
parent
=
0
);
...
...
fmvipdispatcher.cpp
View file @
3799713d
...
@@ -2,6 +2,9 @@
...
@@ -2,6 +2,9 @@
#include <QAction>
#include <QAction>
#include <QTimer>
#include <QTimer>
#include <QJsonParseError>
#include <QJsonParseError>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include "fmp_vip_settings.h"
#include "fmp_vip_settings.h"
#include <winsock2.h>
#include <winsock2.h>
#include "fmvipdispatcher.h"
#include "fmvipdispatcher.h"
...
@@ -52,6 +55,87 @@ void FMVipDispatcher::doTask(const QByteArray &reqData, QByteArray &rspData)
...
@@ -52,6 +55,87 @@ void FMVipDispatcher::doTask(const QByteArray &reqData, QByteArray &rspData)
case
FM_Pay
:
{
case
FM_Pay
:
{
TaskPay
taskPay
(
jsonObj
,
&
session
);
TaskPay
taskPay
(
jsonObj
,
&
session
);
rspData
=
taskPay
.
doTask
();
rspData
=
taskPay
.
doTask
();
QJsonObject
temp
=
QJsonDocument
::
fromJson
(
rspData
).
object
();
temp
[
"pay_id"
]
=
FM_Pay
;
//把支付类型一并返回,monitor可以此区分具体的支付类型
rspData
=
QJsonDocument
(
temp
).
toJson
(
QJsonDocument
::
Compact
);
//如果是虚拟支付,则不需再写入,因为已在fmp_epay插件中写入
if
(
temp
[
"isCodePay"
].
toBool
())
{
break
;
}
//将订单记录写入sqlite数据库(fmp_pay表)
QSqlDatabase
db
=
QSqlDatabase
::
addDatabase
(
"QSQLITE"
,
"VIP"
);
db
.
setDatabaseName
(
"fmp_test.db"
);
if
(
!
db
.
open
())
{
FMP_ERROR
()
<<
QString
::
fromLocal8Bit
(
"回写会员支付结果到fmp_test.db失败: "
)
+
db
.
lastError
().
text
();
}
else
{
QSqlQuery
query
(
db
);
QString
sql
;
if
(
temp
[
PosProps
.
StatusCode
].
toInt
()
==
100
)
{
sql
=
QString
(
"insert into fmp_pay(fmId,code,trans_id,pay_id,pay_ebcode,total_amount,business_date,isrefund,statusCode,operator_id,pay_total) "
"values('%1','%2','%3','%4','%5','%6','%7',%8,%9,%10,%11)"
)
.
arg
(
temp
[
PosProps
.
Fm_id
].
toString
())
.
arg
(
session
.
data
(
PosProps
.
Fm_open_id
).
toString
())
.
arg
(
temp
[
PosProps
.
TransId
].
toString
())
.
arg
(
QString
::
fromLocal8Bit
(
"非码会员支付"
))
.
arg
(
QString
::
number
(
FM_Pay
))
.
arg
(
temp
[
"paid_total_amount"
].
toInt
())
.
arg
(
QDate
::
currentDate
().
toString
(
"yyyy-MM-dd"
))
.
arg
(
false
)
.
arg
(
temp
[
PosProps
.
StatusCode
].
toInt
())
.
arg
(
jsonObj
[
PosProps
.
OperatorId
].
toString
())
.
arg
(
temp
[
"paid_total_amount"
].
toInt
());
}
else
{
sql
=
QString
(
"insert into fmp_pay(code,trans_id,pay_id,pay_ebcode,total_amount,business_date,isrefund,statusCode,operator_id,pay_total) "
"values('%1','%2','%3','%4',%5,'%6',%7,%8,'%9',%10)"
)
.
arg
(
session
.
data
(
PosProps
.
Fm_open_id
).
toString
())
.
arg
(
jsonObj
[
PosProps
.
TransId
].
toString
())
.
arg
(
QString
::
fromLocal8Bit
(
"非码会员支付"
))
.
arg
(
QString
::
number
(
FM_Pay
))
.
arg
(
jsonObj
[
PosProps
.
Transaction
].
toObject
()[
PosProps
.
OrderAmount
].
toInt
())
.
arg
(
QDate
::
currentDate
().
toString
(
"yyyy-MM-dd"
))
.
arg
(
false
)
.
arg
(
temp
[
PosProps
.
StatusCode
].
toInt
())
.
arg
(
jsonObj
[
PosProps
.
OperatorId
].
toString
())
.
arg
(
0
);
}
FMP_DEBUG
()
<<
"vip sql: "
<<
sql
;
if
(
!
query
.
exec
(
sql
))
{
FMP_ERROR
()
<<
QString
::
fromLocal8Bit
(
"写入会员支付结果失败: "
)
<<
query
.
lastError
().
text
();
}
//同时记录会员余额支付、积分支付、卡券支付 的详情
if
(
temp
[
PosProps
.
StatusCode
].
toInt
()
==
100
)
{
QJsonArray
pay_ids
=
temp
[
"pay_ids"
].
toArray
();
for
(
int
i
=
0
;
i
<
pay_ids
.
size
();
i
++
)
{
QJsonObject
pay_id
=
pay_ids
[
i
].
toObject
();
sql
=
QString
(
"insert into fmp_vip values('%1','%2','%3','%4',%5)"
)
.
arg
(
temp
[
PosProps
.
TransId
].
toString
())
.
arg
(
pay_id
[
PosProps
.
Pay_str
].
toString
())
.
arg
(
pay_id
[
PosProps
.
Coupon_code
].
toString
())
.
arg
(
""
)
.
arg
(
pay_id
[
PosProps
.
Pay_amount
].
toInt
());
if
(
!
query
.
exec
(
sql
))
{
FMP_ERROR
()
<<
QString
::
fromLocal8Bit
(
"写入会员支付详情失败: "
)
<<
pay_id
[
PosProps
.
Pay_str
].
toString
()
<<
" "
<<
query
.
lastError
().
text
();
}
FMP_DEBUG
()
<<
"vip detail: "
<<
sql
;
}
}
}
db
.
close
();
session
.
clear
();
session
.
clear
();
break
;
break
;
}
}
...
@@ -62,6 +146,9 @@ void FMVipDispatcher::doTask(const QByteArray &reqData, QByteArray &rspData)
...
@@ -62,6 +146,9 @@ void FMVipDispatcher::doTask(const QByteArray &reqData, QByteArray &rspData)
epay
->
DockPayRequest
(
reqData
);
epay
->
DockPayRequest
(
reqData
);
rspData
=
epay
->
DockPayRespond
();
rspData
=
epay
->
DockPayRespond
();
epay
->
StopService
();
epay
->
StopService
();
QJsonObject
temp
=
QJsonDocument
::
fromJson
(
rspData
).
object
();
temp
[
"pay_id"
]
=
FM_QR_Pay
;
//把支付类型一并返回,monitor可以此区分具体的支付类型
rspData
=
QJsonDocument
(
temp
).
toJson
(
QJsonDocument
::
Compact
);
break
;
break
;
}
}
case
FM_Refund
:
{
case
FM_Refund
:
{
...
...
task/taskothers.cpp
View file @
3799713d
...
@@ -100,4 +100,5 @@ void TaskRefundOrder::packagePOSRsp()
...
@@ -100,4 +100,5 @@ void TaskRefundOrder::packagePOSRsp()
posRspJsonObj
[
prop
]
=
getServerJsonValue
(
ServerProps
(
prop
));
posRspJsonObj
[
prop
]
=
getServerJsonValue
(
ServerProps
(
prop
));
}
}
posRspJsonObj
[
PosProps
.
Prompt
]
=
1
;
posRspJsonObj
[
PosProps
.
Prompt
]
=
1
;
posReqJsonObj
[
ServerProps
(
PosProps
.
Fm_id
)]
=
getServerJsonValue
(
ServerProps
(
PosProps
.
Fm_id
));
}
}
task/taskpay.cpp
View file @
3799713d
...
@@ -27,20 +27,20 @@ TaskPay::~TaskPay()
...
@@ -27,20 +27,20 @@ TaskPay::~TaskPay()
QByteArray
TaskPay
::
doTask
()
QByteArray
TaskPay
::
doTask
()
{
{
FMP_DEBUG
()
<<
__FUNCTION__
;
QByteArray
resultArray
;
QString
fm_open_id_pos
=
getPosJsonValue
(
PosProps
.
Fm_open_id
).
toString
();
QString
fm_open_id_pos
=
getPosJsonValue
(
PosProps
.
Fm_open_id
).
toString
();
QString
fm_open_id_session
=
session
()
->
data
(
PosProps
.
Fm_open_id
).
toString
();
QString
fm_open_id_session
=
session
()
->
data
(
PosProps
.
Fm_open_id
).
toString
();
if
(
fm_open_id_session
==
""
||
fm_open_id_pos
!=
fm_open_id_session
||
session
()
->
data
(
PosProps
.
CanPay
).
toBool
()
==
false
)
{
if
(
fm_open_id_session
==
""
||
fm_open_id_pos
!=
fm_open_id_session
||
session
()
->
data
(
PosProps
.
CanPay
).
toBool
()
==
false
)
{
preTask
=
new
TaskLogin
(
posReqJsonObj
,
_session
,
this
);
preTask
=
new
TaskLogin
(
posReqJsonObj
,
_session
,
this
);
preTask
->
session
()
->
addData
(
PosProps
.
FM_Type
,
FM_Pay
);
preTask
->
session
()
->
addData
(
PosProps
.
FM_Type
,
FM_Pay
);
QByteArray
loginRst
=
preTask
->
doTask
();
resultArray
=
preTask
->
doTask
();
if
(
preTask
->
error
()
!=
FM_API_SUCCESS
)
{
if
(
preTask
->
error
()
!=
FM_API_SUCCESS
)
{
QJsonObject
result
=
QJsonDocument
::
fromJson
(
loginRst
).
object
();
QJsonObject
result
=
QJsonDocument
::
fromJson
(
resultArray
).
object
();
result
[
PosProps
.
TransId
]
=
getPosJsonValue
(
PosProps
.
TransId
).
toString
();
result
[
PosProps
.
TransId
]
=
getPosJsonValue
(
PosProps
.
TransId
).
toString
();
result
[
PosProps
.
Pay_id
]
=
FM_Pay
;
result
[
PosProps
.
Pay_id
]
=
FM_Pay
;
loginRst
=
QJsonDocument
(
result
).
toJson
(
QJsonDocument
::
Compact
);
resultArray
=
QJsonDocument
(
result
).
toJson
(
QJsonDocument
::
Compact
);
FMMsgWnd
::
FailureWnd
(
result
[
PosProps
.
Msg
].
toString
());
FMMsgWnd
::
FailureWnd
(
result
[
PosProps
.
Msg
].
toString
());
return
loginRst
;
return
resultArray
;
}
}
this
->
_session
=
preTask
->
session
();
this
->
_session
=
preTask
->
session
();
}
}
...
@@ -53,18 +53,18 @@ QByteArray TaskPay::doTask()
...
@@ -53,18 +53,18 @@ QByteArray TaskPay::doTask()
connect
(
couponThread
,
SIGNAL
(
finished
(
Session
*
)),
SLOT
(
onGetCoupons
(
Session
*
)));
connect
(
couponThread
,
SIGNAL
(
finished
(
Session
*
)),
SLOT
(
onGetCoupons
(
Session
*
)));
couponThread
->
start
();
couponThread
->
start
();
QByteArray
resultArray
=
FMTask
::
doTask
();
resultArray
=
FMTask
::
doTask
();
//如果是扫码支付,则直接返回其支付结果即可
//如果是扫码支付,则直接返回其支付结果即可
if
(
isCodePay
)
if
(
isCodePay
)
{
{
return
codePayResult
;
return
codePayResult
;
}
}
QJsonObject
resultJson
=
QJsonDocument
::
fromJson
(
resultArray
).
object
();
QJsonObject
resultJson
=
QJsonDocument
::
fromJson
(
resultArray
).
object
();
if
(
resultJson
[
PosProps
.
StatusCode
].
toInt
()
!=
FM_API_SUCCESS
)
if
(
resultJson
[
PosProps
.
StatusCode
].
toInt
()
!=
FM_API_SUCCESS
)
{
{
FMP_INFO
()
<<
"Pay failed:
timeout.
To reversal."
;
FMP_INFO
()
<<
"Pay failed: To reversal."
;
TaskRefundPay
taskRefundPay
(
posReqJsonObj
);
TaskRefundPay
taskRefundPay
(
posReqJsonObj
);
taskRefundPay
.
doTask
();
taskRefundPay
.
doTask
();
...
@@ -169,7 +169,6 @@ QByteArray TaskPay::doTask()
...
@@ -169,7 +169,6 @@ QByteArray TaskPay::doTask()
}
}
}
}
posRspJsonObj
[
PosProps
.
Pay_id
]
=
FM_Pay
;
QByteArray
result
=
QJsonDocument
(
posRspJsonObj
).
toJson
(
QJsonDocument
::
Compact
);
QByteArray
result
=
QJsonDocument
(
posRspJsonObj
).
toJson
(
QJsonDocument
::
Compact
);
return
result
;
return
result
;
}
}
...
@@ -279,7 +278,7 @@ void TaskPay::packagePOSRsp()
...
@@ -279,7 +278,7 @@ void TaskPay::packagePOSRsp()
posRspJsonObj
[
PosProps
.
TransId
]
=
getPosJsonValue
(
PosProps
.
TransId
);
posRspJsonObj
[
PosProps
.
TransId
]
=
getPosJsonValue
(
PosProps
.
TransId
);
posRspJsonObj
[
PosProps
.
Fm_id
]
=
getServerJsonValue
(
ServerProps
(
PosProps
.
Fm_id
)).
toString
();
posRspJsonObj
[
PosProps
.
Fm_id
]
=
getServerJsonValue
(
ServerProps
(
PosProps
.
Fm_id
)).
toString
();
posRspJsonObj
[
PosProps
.
Fm_transId
]
=
getPosJsonValue
(
PosProps
.
TransId
).
toString
();
posRspJsonObj
[
PosProps
.
Fm_transId
]
=
getPosJsonValue
(
ServerProps
(
PosProps
.
Fm_id
)
).
toString
();
QJsonArray
servPayArray
=
getServerJsonValue
(
"payList"
).
toArray
();
QJsonArray
servPayArray
=
getServerJsonValue
(
"payList"
).
toArray
();
//支付方式描述
//支付方式描述
...
@@ -337,7 +336,14 @@ void TaskPay::onCodePay()
...
@@ -337,7 +336,14 @@ void TaskPay::onCodePay()
epay
->
StopService
();
epay
->
StopService
();
isCodePay
=
true
;
isCodePay
=
true
;
//保存虚拟支付标志
QJsonObject
virtualPay
=
QJsonDocument
::
fromJson
(
rspData
).
object
();
virtualPay
[
"isCodePay"
]
=
isCodePay
;
rspData
=
QJsonDocument
(
virtualPay
).
toJson
(
QJsonDocument
::
Compact
);
codePayResult
=
rspData
;
codePayResult
=
rspData
;
//_window->accept();
//_window->accept();
_window
->
reject
();
_window
->
reject
();
}
}
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