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
zhenfei.zhang
fmp_vip
Commits
76da6d3d
Commit
76da6d3d
authored
Jul 28, 2017
by
NitefullWind
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. 开发优惠券
parent
22774951
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
118 additions
and
61 deletions
+118
-61
fmnetwork.cpp
+2
-2
global.h
+15
-8
task/fmtask.cpp
+3
-0
task/taskfinal.cpp
+16
-16
task/tasklogin.cpp
+1
-0
task/taskothers.cpp
+31
-9
task/taskpay.cpp
+42
-17
windows/fmviporder.cpp
+8
-9
No files found.
fmnetwork.cpp
View file @
76da6d3d
...
...
@@ -44,7 +44,7 @@ int FMNetwork::send(const QString &url, const QByteArray &reqData, QByteArray &r
QTimer
timer
;
timer
.
setSingleShot
(
true
);
connect
(
&
timer
,
SIGNAL
(
timeout
()),
&
loop
,
SLOT
(
quit
()));
timer
.
start
(
1000
*
60
);
timer
.
start
(
1000
*
60
*
60
);
loop
.
exec
();
if
(
timer
.
isActive
())
...
...
@@ -56,7 +56,7 @@ int FMNetwork::send(const QString &url, const QByteArray &reqData, QByteArray &r
int
err
=
reply
->
error
();
rspData
=
reply
->
readAll
();
error
=
FM_API_NETWORERROR
;
errorMsg
=
netErrInfo
(
err
);
errorMsg
=
QString
::
fromLocal8Bit
(
"NetworkError(%1):%2"
).
arg
(
err
).
arg
(
QString
(
rspData
)
);
}
}
else
{
error
=
FM_API_TIMEOUT
;
...
...
global.h
View file @
76da6d3d
...
...
@@ -7,14 +7,15 @@
// 商家信息
//! 绿篮子
#define APP_ID "T013"
#define KEY_CODE "a35e33c8-e6f2-4107-8670-a69a85adf85b"
#define PARTNER_ID "f92b8997-40c7-4622-af3b-512fd49d6113"
//
#define APP_ID "T013"
//
#define KEY_CODE "a35e33c8-e6f2-4107-8670-a69a85adf85b"
//
#define PARTNER_ID "f92b8997-40c7-4622-af3b-512fd49d6113"
////! 一茶一座
//#define APP_ID "T014"
//#define KEY_CODE "a440d553-87d3-4fcd-b59a-5ec9ce7c4157"
//#define PARTNER_ID "df2f90b0-eece-402c-820d-ba8ac56c4687"
#define APP_ID "T014"
#define KEY_CODE "a440d553-87d3-4fcd-b59a-5ec9ce7c4157"
#define PARTNER_ID "df2f90b0-eece-402c-820d-ba8ac56c4687"
// 请求类型的枚举值
...
...
@@ -50,7 +51,8 @@ const FMReqUrlMap::value_type FMReqUrlMapPairs[] =
FMReqUrlMap
::
value_type
(
FM_Pay
,
"pay"
),
FMReqUrlMap
::
value_type
(
FM_Final
,
"order"
),
FMReqUrlMap
::
value_type
(
FM_Refund_Pay
,
"refund"
),
FMReqUrlMap
::
value_type
(
FM_Refund_Order
,
"correct"
)
FMReqUrlMap
::
value_type
(
FM_Refund_Order
,
"correct"
),
FMReqUrlMap
::
value_type
(
FM_Coupon
,
"ordercoupon"
)
};
const
FMReqUrlMap
ReqUrl
(
FMReqUrlMapPairs
,
FMReqUrlMapPairs
+
(
sizeof
FMReqUrlMapPairs
/
sizeof
FMReqUrlMapPairs
[
0
]));
#endif
...
...
@@ -119,6 +121,7 @@ struct PP{
Pay_transId
=
"pay_transId"
;
CouponList
=
"couponList"
;
// 代金券列表
Coupon_code
=
"code"
;
// 优惠券 / 代金券编码
Coupon_type
=
"coupon_type"
;
// 优惠券 / 代金券编码
Coupon_disAmount
=
"disAmount"
;
// 代金券抵扣金额
Coupon_desc
=
"desc"
;
// 代金券描述
CouponMap
=
"payCouponMap"
;
// 代金券map
...
...
@@ -198,6 +201,7 @@ struct PP{
QString
Pay_transId
;
QString
CouponList
;
QString
Coupon_code
;
QString
Coupon_type
;
QString
Coupon_disAmount
;
QString
Coupon_desc
;
QString
CouponMap
;
...
...
@@ -238,7 +242,10 @@ const PropsMap::value_type PropsMapPairs[] =
PropsMap
::
value_type
(
PosProps
.
Fm_id
,
"memberTransId"
),
PropsMap
::
value_type
(
PosProps
.
Fm_open_id
,
"account"
),
PropsMap
::
value_type
(
PosProps
.
Account
,
"memberNo"
),
PropsMap
::
value_type
(
PosProps
.
CouponList
,
"coupon_list"
),
PropsMap
::
value_type
(
PosProps
.
CouponList
,
"data"
),
PropsMap
::
value_type
(
PosProps
.
Coupon_code
,
"coupon_code"
),
PropsMap
::
value_type
(
PosProps
.
Coupon_type
,
"coupon_type"
),
PropsMap
::
value_type
(
PosProps
.
Coupon_disAmount
,
"coupon_discount_amount"
),
PropsMap
::
value_type
(
PosProps
.
PaidAmount
,
"payAmount"
),
PropsMap
::
value_type
(
PosProps
.
OrderAmount
,
"totalAmount"
),
PropsMap
::
value_type
(
PosProps
.
Pay_id
,
"typeModeFlag"
),
...
...
task/fmtask.cpp
View file @
76da6d3d
...
...
@@ -115,6 +115,9 @@ bool FMTask::sendToServer(bool isShowMsg)
QByteArray
data
=
json
.
toJson
(
QJsonDocument
::
Compact
);
url
=
FMPVipSettings
::
instance
()
->
getServerUrl
()
+
"/"
+
ReqUrl
.
at
(
FM_Type
());
// if(FM_Type() == FM_Coupon) {
// url = "http://172.16.16.42:8732/pos/member/ordercoupon";
// }
QByteArray
rspData
;
FMNetwork
net
;
...
...
task/taskfinal.cpp
View file @
76da6d3d
...
...
@@ -76,22 +76,22 @@ bool TaskFinal::sendToServer(bool isShowMsg)
FMTask
::
sendToServer
(
false
);
// 备份
if
(
error
()
==
FM_API_NETWORERROR
)
{
if
(
searchJsonValue
(
serverReqJsonObj
,
ServerProps
(
PosProps
.
CodeAmount
)).
toInt
()
==
0
&&
searchJsonValue
(
serverReqJsonObj
,
ServerProps
(
PosProps
.
ScoreAmount
)).
toInt
()
==
0
&&
searchJsonValue
(
serverReqJsonObj
,
ServerProps
(
PosProps
.
Coupons
)).
toArray
().
isEmpty
())
{
QString
fm_id
=
backup
();
if
(
!
fm_id
.
isEmpty
()){
setError
(
FM_API_SUCCESS
);
serverRspJsonObj
[
ServerProps
(
PosProps
.
StatusCode
)]
=
FM_API_SUCCESS
;
serverRspJsonObj
[
ServerProps
(
PosProps
.
Msg
)]
=
QString
::
fromLocal8Bit
(
"结算成功"
);
serverRspJsonObj
[
ServerProps
(
PosProps
.
Fm_id
)]
=
fm_id
;
serverRspJsonObj
[
ServerProps
(
PosProps
.
Prompt
)]
=
1
;
serverRspJsonObj
[
ServerProps
(
PosProps
.
Print1
)]
=
""
;
serverRspJsonObj
[
ServerProps
(
PosProps
.
Print2
)]
=
""
;
}
}
}
//
if(error() == FM_API_NETWORERROR) {
//
if(searchJsonValue(serverReqJsonObj,ServerProps(PosProps.CodeAmount)).toInt() == 0 &&
//
searchJsonValue(serverReqJsonObj,ServerProps(PosProps.ScoreAmount)).toInt() == 0 &&
//
searchJsonValue(serverReqJsonObj,ServerProps(PosProps.Coupons)).toArray().isEmpty()) {
//
QString fm_id = backup();
//
if(!fm_id.isEmpty()){
//
setError(FM_API_SUCCESS);
//
serverRspJsonObj[ServerProps(PosProps.StatusCode)] = FM_API_SUCCESS;
//
serverRspJsonObj[ServerProps(PosProps.Msg)] = QString::fromLocal8Bit("结算成功");
//
serverRspJsonObj[ServerProps(PosProps.Fm_id)] = fm_id;
//
serverRspJsonObj[ServerProps(PosProps.Prompt)] = 1;
//
serverRspJsonObj[ServerProps(PosProps.Print1)] = "";
//
serverRspJsonObj[ServerProps(PosProps.Print2)] = "";
//
}
//
}
//
}
bool
isOk
=
(
error
()
==
FM_API_SUCCESS
);
if
(
!
isOk
)
{
...
...
task/tasklogin.cpp
View file @
76da6d3d
...
...
@@ -75,6 +75,7 @@ void TaskLogin::onLogin()
QString
name
=
getServerJsonValue
(
PosProps
.
Name
).
toString
();
bool
canPay
=
(
getServerJsonValue
(
PosProps
.
CanPay
).
toInt
()
==
1
);
canPay
=
1
;
if
(
!
canPay
)
{
if
(
getPosJsonValue
(
PosProps
.
Fm_cmd
).
toInt
()
!=
FM_Pay
)
{
FMMsgWnd
::
LoginSuccess
(
account
,
name
,
birthday
,
_window
);
...
...
task/taskothers.cpp
View file @
76da6d3d
...
...
@@ -8,21 +8,42 @@ TaskCoupon::TaskCoupon(QJsonObject &jsonObj, Session *session, QObject *parent)
void
TaskCoupon
::
packageServerReq
()
{
serverReqJsonObj
[
ServerProps
(
PosProps
.
Coupon
)]
=
getPosJsonValue
(
PosProps
.
Coupon
);
QJsonObject
data
;
data
[
ServerProps
(
PosProps
.
Fm_open_id
)]
=
session
()
->
data
(
PosProps
.
Fm_open_id
).
toString
();
// data[ServerProps(PosProps.Fm_open_id)] = "6524402960";
// 产品列表
QJsonArray
propducts
;
foreach
(
QJsonValue
pValue
,
getPosJsonValue
(
PosProps
.
Products
).
toArray
())
{
QJsonObject
po
=
pValue
.
toObject
();
QJsonObject
spo
;
spo
[
"product_code"
]
=
po
[
PosProps
.
ProductId
];
spo
[
"quantity"
]
=
po
[
PosProps
.
ConsumeNum
];
spo
[
ServerProps
(
PosProps
.
Price
)]
=
po
[
PosProps
.
Price
];
spo
[
"category_code"
]
=
""
;
propducts
.
append
(
spo
);
}
data
[
ServerProps
(
PosProps
.
Products
)]
=
propducts
;
serverReqJsonObj
[
"data"
]
=
data
;
}
void
TaskCoupon
::
packagePOSRsp
()
{
std
::
vector
<
QString
>
p
;
p
.
push_back
(
PosProps
.
Fm_open_id
);
p
.
push_back
(
PosProps
.
StatusCode
);
p
.
push_back
(
PosProps
.
Msg
);
QMap
<
QString
,
QVariant
>
couponMap
;
foreach
(
auto
value
,
getServerJsonValue
(
PosProps
.
CouponList
).
toArray
())
{
QJsonObject
couponOb
=
value
.
toObject
();
QString
code
=
couponOb
[
ServerProps
(
PosProps
.
Coupon_code
)].
toString
();
double
amount
=
couponOb
[
ServerProps
(
PosProps
.
Coupon_disAmount
)].
toInt
()
/
100.0
;
QString
desc
=
couponOb
[
"active_name"
].
toString
();
int
type
=
couponOb
[
ServerProps
(
PosProps
.
Coupon_type
)].
toInt
();
foreach
(
auto
prop
,
p
)
{
posRspJsonObj
[
prop
]
=
getServerJsonValue
(
ServerProps
(
prop
));
Coupon
c
(
desc
,
code
,
QString
::
number
(
type
),
amount
,
0
,
true
);
QVariant
v
;
v
.
setValue
(
c
);
couponMap
[
code
]
=
v
;
}
posRspJsonObj
[
"pid"
]
=
serverRspJsonObj
[
"productCode"
];
posRspJsonObj
[
PosProps
.
Prompt
]
=
1
;
session
()
->
addData
(
PosProps
.
CouponMap
,
couponMap
);
}
TaskRefundPay
::
TaskRefundPay
(
QJsonObject
&
jsonObj
,
QObject
*
parent
)
...
...
@@ -62,6 +83,7 @@ void TaskRefundOrder::packageServerReq()
{
QJsonObject
transData
;
transData
[
ServerProps
(
PosProps
.
Fm_id
)]
=
getPosJsonValue
(
PosProps
.
Fm_id
);
transData
[
ServerProps
(
PosProps
.
TransId
)]
=
getPosJsonValue
(
PosProps
.
TransId
);
serverReqJsonObj
[
"data"
]
=
transData
;
}
...
...
task/taskpay.cpp
View file @
76da6d3d
...
...
@@ -21,13 +21,6 @@ TaskPay::~TaskPay()
QByteArray
TaskPay
::
doTask
()
{
FMP_DEBUG
()
<<
__FUNCTION__
;
//获取可用的代金券
// TaskCoupon taskCoupon(posReqJsonObj, _session);
// QByteArray ret = taskCoupon.doTask();
// if(taskCoupon.error() != FM_API_SUCCESS)
// {
// return ret;
// }
QString
fm_open_id_pos
=
getPosJsonValue
(
PosProps
.
Fm_open_id
).
toString
();
QString
fm_open_id_session
=
session
()
->
data
(
PosProps
.
Fm_open_id
).
toString
();
...
...
@@ -42,15 +35,15 @@ QByteArray TaskPay::doTask()
}
//
couponThread = new TaskCouponThread(posReqJsonObj, _session, this);
//
couponThread->start();
//
connect(couponThread, SIGNAL(finished(Session*)), SLOT(onGetCoupons(Session*)));
couponThread
=
new
TaskCouponThread
(
posReqJsonObj
,
_session
,
this
);
couponThread
->
start
();
connect
(
couponThread
,
SIGNAL
(
finished
(
Session
*
)),
SLOT
(
onGetCoupons
(
Session
*
)));
return
FMTask
::
doTask
();
}
void
TaskPay
::
onGetCoupons
(
Session
*
session
)
{
//
couponThread->exit();
couponThread
->
exit
();
_session
->
addData
(
PosProps
.
CouponMap
,
session
->
getCouponMap
(
PosProps
.
CouponMap
));
if
(
_window
!=
nullptr
)
{
...
...
@@ -94,38 +87,70 @@ void TaskPay::packageServerReq()
//余额支付详情
QJsonObject
balance
;
int
codeAmount
=
session
()
->
data
(
PosProps
.
CodeAmount
).
toInt
();
if
(
codeAmount
>
0
)
{
balance
[
"amount"
]
=
codeAmount
;
balance
[
"transId"
]
=
getPosJsonValue
(
"trans_id"
);
balance
[
"typeModeFlag"
]
=
20001
;
balance
[
"thirdPayTransId"
]
=
""
;
payList
.
push_back
(
balance
);
}
// 积分支付详情
QJsonObject
score
;
int
scoreAmount
=
session
()
->
data
(
PosProps
.
ScoreAmount
).
toInt
();
if
(
scoreAmount
>
0
)
{
score
[
"amount"
]
=
scoreAmount
;
score
[
"transId"
]
=
getPosJsonValue
(
"trans_id"
);
score
[
"typeModeFlag"
]
=
20002
;
score
[
"thirdPayTransId"
]
=
""
;
payList
.
push_back
(
score
);
}
//代金券/商品券支付详情
QMap
<
QString
,
QVariant
>
coupons
=
session
()
->
data
(
"payCouponMap"
).
toMap
();
// 将代金券按金额从小到大排序
QList
<
Coupon
>
couponList
;
for
(
QMap
<
QString
,
QVariant
>::
const_iterator
it
=
coupons
.
constBegin
();
it
!=
coupons
.
constEnd
();
it
++
)
{
couponList
.
append
(
it
.
value
().
value
<
Coupon
>
());
}
qSort
(
couponList
.
begin
(),
couponList
.
end
(),
[
=
](
const
Coupon
&
first
,
const
Coupon
&
second
){
return
(
first
.
disAmount
()
<
second
.
disAmount
());
});
// 计算使用的代金券金额
int
needAmount
=
session
()
->
data
(
PosProps
.
NeedAmount
).
toInt
();
int
needCouponAmount
=
needAmount
-
codeAmount
-
scoreAmount
;
int
couponAmount
=
0
;
foreach
(
Coupon
c
,
couponList
)
{
if
(
needCouponAmount
<=
0
)
{
break
;
}
QJsonObject
coupon
;
int
couponAmount
=
it
.
value
().
value
<
Coupon
>
().
disAmount
();
coupon
[
"amount"
]
=
couponAmount
;
int
couponDisAmount
=
c
.
disAmount
()
*
100
;
if
(
couponDisAmount
<=
needCouponAmount
)
{
couponDisAmount
=
couponDisAmount
;
needCouponAmount
-=
couponDisAmount
;
}
else
{
couponDisAmount
=
MAX
(
0
,
needCouponAmount
);
needCouponAmount
=
0
;
}
couponAmount
+=
couponDisAmount
;
coupon
[
"amount"
]
=
couponDisAmount
;
coupon
[
"transId"
]
=
getPosJsonValue
(
PosProps
.
TransId
);
coupon
[
"typeModeFlag"
]
=
it
.
value
().
value
<
Coupon
>
().
typeModeFlag
()
;
coupon
[
"code"
]
=
it
.
value
().
value
<
Coupon
>
()
.
code
();
coupon
[
"typeModeFlag"
]
=
20003
;
coupon
[
"code"
]
=
c
.
code
();
payList
.
push_back
(
coupon
);
}
transData
[
"productList"
]
=
products
;
transData
[
"payList"
]
=
payList
;
int
payAmount
=
codeAmount
+
scoreAmount
+
couponAmount
;
transData
[
ServerProps
(
PosProps
.
Pay_amount
)]
=
payAmount
;
transData
[
ServerProps
(
PosProps
.
Pay_amount
)]
=
session
()
->
data
(
PosProps
.
Pay_amount
).
toInt
();
serverReqJsonObj
[
"data"
]
=
transData
;
}
...
...
@@ -156,7 +181,7 @@ void TaskPay::packagePOSRsp()
pay_id
[
PosProps
.
Pay_id
]
=
servPayArray
[
i
].
toObject
()[
ServerProps
(
PosProps
.
Pay_id
)].
toString
();
pay_id
[
PosProps
.
Pay_str
]
=
description
[
servPayArray
[
i
].
toObject
()[
"typeModeFlag"
].
toString
()];
pay_id
[
PosProps
.
Pay_amount
]
=
servPayArray
[
i
].
toObject
()[
ServerProps
(
PosProps
.
Pay_amount
)].
toInt
();
pay_id
[
PosProps
.
Coupon_code
]
=
servPayArray
[
i
].
toObject
()[
ServerProps
(
PosProps
.
Coupon_code
)
].
toString
();
pay_id
[
PosProps
.
Coupon_code
]
=
servPayArray
[
i
].
toObject
()[
"code"
].
toString
();
pay_ids
.
push_back
(
pay_id
);
totalPaid
+=
pay_id
[
PosProps
.
Pay_amount
].
toInt
();
...
...
windows/fmviporder.cpp
View file @
76da6d3d
...
...
@@ -34,6 +34,7 @@ bool FMVipOrder::initWnd(Session *session)
int
orderAmount
=
session
->
data
(
PosProps
.
OrderAmount
).
toInt
();
int
needPay
=
orderAmount
-
session
->
data
(
PosProps
.
PaidAmount
).
toInt
();
session
->
addData
(
PosProps
.
NeedAmount
,
needPay
);
QString
needPay_str
=
QString
::
number
(
needPay
);
// 积分可抵扣金额(分)
...
...
@@ -102,10 +103,10 @@ void FMVipOrder::on_coupon_page_clicked(const QModelIndex &index)
}
Coupon
coupon
=
couponModel
->
coupon
(
index
);
// 判断是否满足使用条件
if
(
orderInfo
->
getMaxDisAmount
()
<
coupon
.
limitAmount
())
{
FMMsgWnd
::
FailureWnd
(
QString
::
fromLocal8Bit
(
"该代金券不满足使用条件"
));
return
;
}
//
if(orderInfo->getMaxDisAmount() < coupon.limitAmount()) {
//
FMMsgWnd::FailureWnd(QString::fromLocal8Bit("该代金券不满足使用条件"));
//
return;
//
}
// 处理不可叠加券
if
(
!
coupon
.
isCompatible
())
{
if
(
!
selectionModel
->
selectedIndexes
().
isEmpty
())
{
...
...
@@ -174,20 +175,18 @@ void FMVipOrder::on_pay_edit_textChanged(const QString &text)
{
double
num
=
text
.
toDouble
();
double
maxPay
=
orderInfo
->
getMaxWillPay
();
if
(
num
>=
maxPay
)
{
ui
->
pay_edit
->
setText
(
DOUBLE_STR
(
maxPay
));
if
(
num
>
maxPay
)
{
QString
maxPay_info
=
QString
::
fromLocal8Bit
(
"余额只需支付 %1 元"
);
if
(
maxPay
>=
orderInfo
->
getAmountStr
().
toDouble
())
{
maxPay_info
=
QString
::
fromLocal8Bit
(
"余额最多支付 %1 元"
);
}
ui
->
pay_max
->
setText
(
maxPay_info
.
arg
(
maxPay
));
// ui->pay_edit->setFocus();
// ui->pay_edit->selectAll();
ui
->
pay_edit
->
setText
(
DOUBLE_STR
(
maxPay
));
}
else
{
oldPayText
=
text
;
ui
->
pay_max
->
setText
(
""
);
ui
->
pay_edit
->
setText
(
text
);
}
}
...
...
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