Commit 6b70992e by NitefullWind

1. 与服务端支付接口修改。

parent fa96ae04
......@@ -2,3 +2,6 @@ build*
FMVipTest/
*.user*
*.autosave
CardReader/
EntityCard/
fmvip_card_reader/
\ No newline at end of file
......@@ -13,6 +13,8 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = FMVip_LXJ
TEMPLATE = app
DEFINES += FMTEST
SOURCES += main.cpp\
task/fmtask.cpp \
task/taskfactory.cpp \
......
......@@ -26,7 +26,7 @@ FMNetwork::~FMNetwork()
QByteArray FMNetwork::send(const QString *url, const QByteArray *data)
{
qDebug() << "Send Url: " << *url;
qDebug() << "Send Data: " << *data;
qDebug() << "Send Data: " << (*data).data();
_req->setUrl(*url);
......
......@@ -58,7 +58,7 @@ BOOL FMVipDispatcher::Transfer(LPSTR data, LPSTR &rsp, UINT &rsp_len)
void FMVipDispatcher::onDoTask()
{
qDebug() << "===============";
qDebug() << "Recv POS reqData: " << QString::fromUtf8(reqData);
qDebug() << "Recv POS reqData: " << reqData.data();
fmTask = TaskFactory::Task(reqData);
......@@ -115,7 +115,7 @@ void FMVipDispatcher::onDoTask()
}
}
}
qDebug() << "Send to pos: " << QString::fromUtf8(rspData);
qDebug() << "Send to pos: " << rspData.data();
qDebug() << "===============";
condition.wakeAll();
......
......@@ -124,6 +124,7 @@ struct{
const QString Transaction = "transactions";
const QString OrderAmount = "order_amount";
const QString PaidAmount = "paid_amount";
const QString NeedAmount = "need_amount";
const QString StandardAmount = "standard_amount";
const QString UndisAmount = "undis_amount";
const QString Fm_id = "fm_id";
......
......@@ -48,11 +48,13 @@ void TaskLogin::onLogin()
closeWindow();
}
}
#ifndef FMTEST
// 认证成功但限制用支付码
else if((session()->data(PosProps.FM_Type).toInt() == FM_Pay) &&
(getServerJsonValue(PosProps.CanPay).toInt() != 1)) {
FMMsgWnd::FailureWnd(ErrorNeedPayCode);
}
#endif
// 认证成功
else {
QString fm_unique_id = getServerJsonValue(PosProps.Fm_unique_id).toString();
......
......@@ -56,6 +56,17 @@ void TaskCoupon::packagePOSRsp()
v.setValue(c);
couponMap[code] = v;
}
#ifdef FMTEST
for(double i=1.99; i<=2.01; i=i+0.01) {
QString code = QString::number(i);
Coupon c(QString::fromUtf8("测试券%1").arg(i), code, i, 0, true);
QVariant v;
v.setValue(c);
couponMap[code] = v;
}
#endif
session()->addData(PosProps.CouponMap, couponMap);
}
......
......@@ -58,16 +58,61 @@ void TaskPay::packageServerReq()
{
QJsonObject transObj;
transObj[ServerProps(PosProps.Fm_open_id)] = session()->data(PosProps.Fm_open_id).toString();
transObj[ServerProps(PosProps.CodeAmount)] = session()->data(PosProps.CodeAmount).toInt();
transObj[ServerProps(PosProps.IsUseScore)] = session()->data(ServerProps(PosProps.IsUseScore)).toInt();
QJsonArray couponArr;
for (auto code : session()->data(PosProps.CouponMap).toMap().keys())
int codeAmount = session()->data(PosProps.CodeAmount).toInt();
QJsonArray payList;
QJsonObject paymentCodeObj;
paymentCodeObj[ServerProps(PosProps.Pay_id)] = "20001";
paymentCodeObj[ServerProps(PosProps.Amount)] = codeAmount;
payList.append(paymentCodeObj);
//! NOTE 老乡鸡暂时没有积分支付 2017-09-25 15:45
int scoreAmount = session()->data(PosProps.ScoreAmount).toInt();
if(scoreAmount > 0) {
QJsonObject paymentScoreObj;
paymentScoreObj[ServerProps(PosProps.Pay_id)] = "20002";
paymentScoreObj[ServerProps(PosProps.Amount)] = scoreAmount;
payList.append(paymentScoreObj);
}
//代金券/商品券支付详情
QMap<QString, QVariant> coupons = session()->data(PosProps.CouponMap).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)
{
couponArr.append(code);
if(needCouponAmount <= 0) {
break;
}
QJsonObject coupon;
double couponDisAmount = c.disAmount() * 100;
if(couponDisAmount <= needCouponAmount) {
couponDisAmount = couponDisAmount;
needCouponAmount -= couponDisAmount;
} else {
couponDisAmount = MAX(0, needCouponAmount);
needCouponAmount = 0;
}
couponAmount += couponDisAmount;
coupon[ServerProps(PosProps.Amount)] = couponDisAmount;
coupon[ServerProps(PosProps.Pay_id)] = "20003";
coupon[ServerProps(PosProps.Coupon_code)] = c.code();
payList.push_back(coupon);
}
transObj[ServerProps(PosProps.Coupons)] = couponArr;
transObj[ServerProps(PosProps.Pay_ids)] = payList;
serverReqJsonObj[ServerProps(PosProps.Transaction)] = transObj;
serverReqJsonObj[ServerProps(PosProps.TransId)] = getPosJsonValue(PosProps.TransId);
}
......
......@@ -41,6 +41,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);
double standard_amount = session->data(PosProps.StandardAmount).toInt() / 100.0;
......
......@@ -91,7 +91,8 @@ private:
QString getPayAmountStr(QString amountStr)
{
double payAmount = MIN(_needPay, (amountStr.toDouble() + _couponAmount + _useScore)) * 100;
// double payAmount = MIN(_needPay, (amountStr.toDouble() + _couponAmount + _useScore)) * 100;
double payAmount = MIN(_needPay, (amountStr.toDouble())) * 100;
return QString::number(payAmount);
}
......
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