Commit ed18036b by gujin.wang

初步完成大鼓米线会员支付功能

parent 3193ea90
......@@ -102,7 +102,7 @@ LIBS += -lws2_32 -luser32
CONFIG(debug, debug|release) {
#Linking library
LIBS += -lCTKCored -lCTKPluginFrameworkd
LIBS += -lCTKCored -lCTKPluginFrameworkd
#Destination path
DESTDIR = $$PWD/../debug/plugins
} else {
......
......@@ -29,9 +29,43 @@ void FMPVipServer::Listen(quint16 port)
void FMPVipServer::Write(const QByteArray &data)
{
if(!socket || socket->write(data) == -1) {
FMP_ERROR() << "Write error: " << (socket ? socket->errorString() : "connection closed.");
qDebug() << data;
QTcpSocket client;
//client.connectToHost("172.16.13.191", 23771);
client.connectToHost("127.0.0.1", 23771);
if(!client.waitForConnected())
{
FMP_ERROR() << "Connect monitor failed. " << client.errorString();
return;
}
//添加消息头
FMSOCKEHEADER header = {0, 0, 0};
header.flag = FMSOCKFLAG;
header.ver = 0x2;
header.len = data.length();
int len = sizeof(FMSOCKEHEADER) + data.length();
char* reply = new char[len];
memset(reply, 0, len);
memcpy(reply, &header, sizeof(header));
memcpy(reply + sizeof(header), data.data(), data.length());
if(client.write(reply, len) == -1)
{
FMP_ERROR() << "Write error: " << client.errorString();
return;
}
if(!client.waitForBytesWritten())
{
FMP_ERROR() << "Write failed: " << client.errorString();
}
client.disconnectFromHost();
if(client.state() == QAbstractSocket::ConnectedState)
client.waitForDisconnected();
client.close();
delete[] reply;
reply = nullptr;
}
void FMPVipServer::SetPluginContext(ctkPluginContext *ctx)
......@@ -50,15 +84,17 @@ void FMPVipServer::onNewConnection()
void FMPVipServer::onDisconnected()
{
FMP_DEBUG() << "Socket disconnected.";
socket->close();
}
void FMPVipServer::onReadyRead()
{
QByteArray recvData = socket->readAll();
socket->close();
socket->deleteLater();
socket = nullptr;
if(isNeedSocketHeader) {
FMSOCKEHEADER header = {0};
FMSOCKEHEADER header = {0, 0, 0};
memcpy(&header, recvData.data(), sizeof(FMSOCKEHEADER));
if(header.flag != FMSOCKFLAG) {
FMP_WARN() << "Incompatible protocol.";
......@@ -66,14 +102,9 @@ void FMPVipServer::onReadyRead()
}
recvData = recvData.mid(sizeof(FMSOCKEHEADER));
}
QByteArray rspData;
dispatcher->doTask(recvData, rspData);
Write(rspData);
socket->waitForBytesWritten();
socket->close();
socket->deleteLater();
socket = nullptr;
}
......@@ -2,7 +2,6 @@
#define FMP_VIP_SERVER_H
#include <QTcpServer>
#define FMSOCKFLAG 0x4d46
class FMVipDispatcher;
......@@ -23,7 +22,7 @@ public:
void Write(const QByteArray &data);
void SetPluginContext(ctkPluginContext *ctx);
//signals:
private slots:
void onNewConnection();
void onDisconnected();
......
......@@ -11,12 +11,15 @@
//#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"
//! 大鼓米线
#define APP_ID "T017"
#define KEY_CODE "838cd505-1a97-43b3-b521-3b37caa0ab1a"
#define PARTNER_ID "fcce79cf-ba55-4ff8-bde4-684ca26c0ff0"
// 请求类型的枚举值
enum FM_TYPE {
......
......@@ -106,20 +106,16 @@ bool FMTask::sendToServer(bool isShowMsg)
serverReqJsonObj[PosProps.AppId] = APP_ID;
serverReqJsonObj[PosProps.PartnerId] = PARTNER_ID;
serverReqJsonObj[PosProps.T] = QString::number(QDateTime::currentMSecsSinceEpoch());
serverReqJsonObj[ServerProps(PosProps.Fm_cmd)] = QString::number(FM_Type());
serverReqJsonObj[PosProps.Sign] = sign();
packageServerReq();
serverReqJsonObj[PosProps.Sign] = sign();
QJsonDocument json(serverReqJsonObj);
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;
net.send(url, data, rspData);
......@@ -150,7 +146,7 @@ bool FMTask::sendToServer(bool isShowMsg)
}
bool isOk = (error() == FM_API_SUCCESS);
if(!isOk && isShowMsg)
if(!isOk && isShowMsg && FM_Type() != FM_Coupon)
{
FMMsgWnd::FailureWnd(errorString(), _window);
}
......@@ -158,32 +154,54 @@ bool FMTask::sendToServer(bool isShowMsg)
return isOk;
}
QJsonValue FMTask::searchJsonValue(QJsonObject &searchJson, QString searchKey)
QJsonValue FMTask::searchJsonObject(QJsonObject &searchJson, QString searchKey)
{
QJsonValue value;
if(searchJson.contains(searchKey)) {
return searchJson[searchKey];
value = searchJson[searchKey];
} else {
foreach(QString key , searchJson.keys()) {
if(searchJson[key].isObject()) {
QJsonObject ob = searchJson[key].toObject();
QJsonValue value = searchJsonValue(ob, searchKey);
if(!value.isNull()){
return value;
}
value = searchJsonObject(ob, searchKey);
}
else if(searchJson[key].isArray())
{
QJsonArray arr = searchJson[key].toArray();
value = searchJsonArray(arr, searchKey);
}
}
}
return QJsonValue();
return value;
}
QJsonValue FMTask::searchJsonArray(QJsonArray &searchJson, QString searchKey)
{
QJsonValue value;
for(int i = 0; i < searchJson.size(); i++)
{
if(searchJson[i].isObject())
{
QJsonObject ob = searchJson[i].toObject();
value = searchJsonObject(ob, searchKey);
}
else if(searchJson[i].isArray())
{
QJsonArray arr = searchJson[i].toArray();
value = searchJsonArray(arr, searchKey);
}
}
return value;
}
QJsonValue FMTask::getServerJsonValue(const QString prop)
{
return searchJsonValue(serverRspJsonObj, ServerProps(prop));
return searchJsonObject(serverRspJsonObj, ServerProps(prop));
}
QJsonValue FMTask::getPosJsonValue(const QString prop)
{
return searchJsonValue(posReqJsonObj, prop);
return searchJsonObject(posReqJsonObj, prop);
}
QString FMTask::sign() const
......
......@@ -23,7 +23,8 @@ public:
Session* session() const {return _session;}
QJsonValue searchJsonValue(QJsonObject &searchJson, QString searchKey);
QJsonValue searchJsonObject(QJsonObject &searchJson, QString searchKey);
QJsonValue searchJsonArray(QJsonArray& searchJson, QString searchKey);
QJsonValue getServerJsonValue(const QString prop);
QJsonValue getPosJsonValue(const QString prop);
......@@ -50,7 +51,7 @@ protected:
FMTask *preTask;
private:
protected:
QString sign() const;
/**
......
......@@ -14,6 +14,15 @@ TaskFinal::TaskFinal(QJsonObject &jsonObj, Session *session, QObject *parent)
{
}
QByteArray TaskFinal::doTask()
{
serverReqJsonObj = posReqJsonObj;
sendToServer(false);
packagePOSRsp();
QJsonDocument json(posRspJsonObj);
return json.toJson(QJsonDocument::Compact);
}
void TaskFinal::packageServerReq()
{
isUseVipPay = false;
......@@ -36,33 +45,14 @@ void TaskFinal::packageServerReq()
int price = p.toObject()["price"].toInt();
product["price"] = price;
product["productId"] = p.toObject()["pid"];
product["disAmount"] = p.toObject()["dis_amount"].toInt();
products.append(product);
}
transData["productList"] = products;
int orderAmount = getPosJsonValue(PosProps.OrderAmount).toInt();
int paidAmount = getPosJsonValue(PosProps.PaidAmount).toInt();
transData["totalAmount"] = getPosJsonValue(PosProps.OrderAmount).toInt();
transData["payAmount"] = getPosJsonValue(PosProps.PaidAmount).toInt();
QJsonArray payList;
QString fmId = getPosJsonValue(PosProps.Fm_id).toString();
QByteArray orderContent = FMBackup::instance()->getOrderByFmId(fmId);
QJsonObject orderObject = QJsonDocument::fromJson(orderContent).object();
QJsonArray payArray = searchJsonValue(orderObject, "payList").toArray();
foreach (auto pay_v, payArray) {
QJsonObject pay_ob = pay_v.toObject();
if(pay_ob["typeModeFlag"].toString() == "20003") {
payList.append(pay_ob);
isUseVipPay = true;
int pay_amount = pay_ob["amount"].toInt();
orderAmount += pay_amount;
paidAmount += pay_amount;
}
}
transData[ServerProps(PosProps.OrderAmount)] = orderAmount;
transData[ServerProps(PosProps.PaidAmount)] = paidAmount;
foreach(auto p, getPosJsonValue(PosProps.Pay_ids).toArray())
{
QJsonObject pay;
......@@ -71,28 +61,14 @@ void TaskFinal::packageServerReq()
pay["code"] = p.toObject()["code"].toString();
pay[ServerProps(PosProps.TransId)] = getPosJsonValue(PosProps.TransId);
QString typeModeFlag = p.toObject()["pay_id"].toString();
if(typeModeFlag == "0101") {
//现金支付
pay["typeModeFlag"] = "20005";
} else if(typeModeFlag == "0301") {
pay["typeModeFlag"] = "10011";
} else if(typeModeFlag == "0302") {
pay["typeModeFlag"] = "10011";
} else if(typeModeFlag == "0303") {
pay["typeModeFlag"] = "10011";
} else {
pay["typeModeFlag"] = typeModeFlag;
}
pay["typeModeFlag"] = typeModeFlag;
if(typeModeFlag.compare("20001")==0 || typeModeFlag.compare("20002")==0 || typeModeFlag.compare("20003")==0) {
isUseVipPay = true;
}
payList.append(pay);
}
transData["payList"] = payList;
serverReqJsonObj["data"] = transData;
}
......@@ -117,6 +93,7 @@ bool TaskFinal::sendToServer(bool isShowMsg)
}
}
}
bool isOk = (error() == FM_API_SUCCESS);
if(!isOk)
{
......@@ -131,6 +108,8 @@ void TaskFinal::packagePOSRsp()
posRspJsonObj[PosProps.Msg] = getServerJsonValue(PosProps.Msg);
posRspJsonObj[PosProps.Fm_id] = getServerJsonValue(PosProps.Fm_id);
posRspJsonObj[PosProps.Prompt] = 1;
posRspJsonObj[PosProps.TransId] = getPosJsonValue(ServerProps(PosProps.TransId)).toString();
posRspJsonObj[PosProps.Pay_id] = "1003";
}
QString TaskFinal::backup()
......
#ifndef TASKFINAL_H
#ifndef TASKFINAL_H
#define TASKFINAL_H
#include "fmtasknownd.h"
......@@ -7,7 +7,7 @@ class TaskFinal : public FMTaskNoWnd
Q_OBJECT
public:
explicit TaskFinal(QJsonObject &jsonObj, Session *session = 0, QObject *parent = 0);
virtual QByteArray doTask();
void packageServerReq();
bool sendToServer(bool isShowMsg = true);
void packagePOSRsp();
......
#include "tasklogin.h"
#include "fmviplogin.h"
#include "fmp_home_i.h"
#include "fmp_vip_settings.h"
#include "fmnetwork.h"
#include <QJsonDocument>
#include <QSettings>
TaskLogin::TaskLogin(QJsonObject &jsonObj, Session *session, QObject *parent)
:FMTask(jsonObj, FM_Login, session, parent)
......@@ -19,7 +21,9 @@ void TaskLogin::setWindow()
_window = new FMVipLogin;
connect(qobject_cast<FMVipLogin*>(_window), &FMVipLogin::login, this, &TaskLogin::onLogin);
session()->addData("store_id", getPosJsonValue("store_id"));
QSettings settings(qApp->applicationDirPath() + "/FreemudPOS.ini", QSettings::IniFormat);
QString storeId = settings.value(FMP_INIKEY_LOGINSTOREID).toString();
session()->addData(PosProps.StoreId, storeId);
session()->addData("pos_id", getPosJsonValue("pos_id"));
session()->addData("operator_id", getPosJsonValue("operator_id"));
session()->addData("business_date", getPosJsonValue("business_date"));
......@@ -30,6 +34,7 @@ void TaskLogin::packageServerReq()
QJsonObject code;
code[ServerProps(PosProps.Member_sign)] = session()->data(PosProps.Member_sign).toString();
serverReqJsonObj["data"] = code;
serverReqJsonObj[ServerProps(PosProps.StoreId)] = session()->data("store_id").toString();
}
void TaskLogin::packagePOSRsp()
......
......@@ -10,26 +10,27 @@ void TaskCoupon::packageServerReq()
{
QJsonObject data;
data[ServerProps(PosProps.Fm_open_id)] = session()->data(PosProps.Fm_open_id).toString();
// data[ServerProps(PosProps.Fm_open_id)] = "6524402960";
// 产品列表
QJsonArray propducts;
QJsonArray products;
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["price"] = po[PosProps.Price];
spo["brand_code"] = "";
spo["category_code"] = "";
propducts.append(spo);
products.append(spo);
}
data[ServerProps(PosProps.Products)] = propducts;
data["products"] = products;
serverReqJsonObj["data"] = data;
serverReqJsonObj[ServerProps(PosProps.StoreId)] = session()->data(PosProps.StoreId).toString();
}
void TaskCoupon::packagePOSRsp()
{
int canDisAmount = session()->data(PosProps.OrderAmount).toInt() - session()->data(PosProps.PaidAmount).toInt() - session()->data(PosProps.UndisAmount).toInt();
// int canDisAmount = session()->data(PosProps.OrderAmount).toInt() - session()->data(PosProps.PaidAmount).toInt() - session()->data(PosProps.UndisAmount).toInt();
QMap<QString, QVariant> couponMap;
foreach (auto value, getServerJsonValue(PosProps.CouponList).toArray())
......@@ -41,21 +42,25 @@ void TaskCoupon::packagePOSRsp()
int type = couponOb[ServerProps(PosProps.Coupon_type)].toInt();
QString limitTime = couponOb["expiration_date"].toString();
double disAmount = qRound((1-amount)*canDisAmount/100);
if(amount<1) // 折扣券
{
Coupon c(desc, code, "discount", disAmount , 0, limitTime, false);
c.setDiscountFactor(amount*10);
QVariant v;
v.setValue(c);
couponMap[code] = v;
} else {
Coupon c(desc, code, QString::number(type), amount, 0, limitTime, false);
QVariant v;
v.setValue(c);
couponMap[code] = v;
}
// double disAmount = qRound((1-amount)*canDisAmount/100);
// if(amount<1) // 折扣券
// {
// Coupon c(desc, code, "discount", disAmount , 0, limitTime, false);
// c.setDiscountFactor(amount*10);
// QVariant v;
// v.setValue(c);
// couponMap[code] = v;
// } else {
// Coupon c(desc, code, QString::number(type), amount, 0, limitTime, false);
// QVariant v;
// v.setValue(c);
// couponMap[code] = v;
// }
Coupon c(desc, code, QString::number(type), amount, 0, limitTime, true);
QVariant v;
v.setValue(c);
couponMap[code] = v;
}
session()->addData(PosProps.CouponMap, couponMap);
}
......
......@@ -2,16 +2,20 @@
#include "tasklogin.h"
#include "fmviporder.h"
#include "fmp_logger_i.h"
#include "fmp_home_i.h"
#include "fmp_vip_settings.h"
#include "fmnetwork.h"
#include "fmbackup.h"
#include "taskfinal.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QCryptographicHash>
#include <QSettings>
TaskPay::TaskPay(QJsonObject &jsonObj, Session *session, QObject *parent)
:FMTask(jsonObj, FM_Pay, session, parent)
{
payAmount = 0; //该次支付金额
}
TaskPay::~TaskPay()
......@@ -22,7 +26,6 @@ TaskPay::~TaskPay()
QByteArray TaskPay::doTask()
{
FMP_DEBUG() << __FUNCTION__;
QString fm_open_id_pos = getPosJsonValue(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) {
......@@ -30,6 +33,10 @@ QByteArray TaskPay::doTask()
preTask->session()->addData(PosProps.FM_Type, FM_Pay);
QByteArray loginRst = preTask->doTask();
if(preTask->error() != FM_API_SUCCESS) {
QJsonObject result = QJsonDocument::fromJson(loginRst).object();
result[PosProps.TransId] = getPosJsonValue(PosProps.TransId).toString();
result[PosProps.Pay_id] = FM_Pay;
loginRst = QJsonDocument(result).toJson(QJsonDocument::Compact);
return loginRst;
}
this->_session = preTask->session();
......@@ -42,13 +49,67 @@ QByteArray TaskPay::doTask()
couponThread = new TaskCouponThread(posReqJsonObj, _session, this);
couponThread->start();
connect(couponThread, SIGNAL(finished(Session*)), SLOT(onGetCoupons(Session*)));
return FMTask::doTask();
QByteArray resultArray = FMTask::doTask();
QJsonObject resultJson = QJsonDocument::fromJson(resultArray).object();
if(resultJson[PosProps.StatusCode].toInt() != FM_API_SUCCESS)
{
resultJson[PosProps.Pay_id] = FM_Pay;
resultJson[PosProps.TransId] = getPosJsonValue(PosProps.TransId).toString();
QByteArray reply = QJsonDocument(resultJson).toJson(QJsonDocument::Compact);
return reply;
}
else
{
posRspJsonObj[PosProps.Pay_id] = FM_Pay;
//支付成功,直接调结算接口
QJsonObject data = serverReqJsonObj["data"].toObject();
data["totalAmount"] = getPosJsonValue(PosProps.OrderAmount).toInt();
serverReqJsonObj["data"] = data;
serverReqJsonObj[ServerProps(PosProps.Fm_cmd)] = FM_Final;
del_p(preTask);
preTask = new TaskFinal(serverReqJsonObj, _session, this);
preTask->doTask();
if(preTask->getServerJsonValue(PosProps.StatusCode).toInt() != FM_API_SUCCESS)
{
//结算失败,退款
QJsonObject refund;
refund["pos_ver"] = getPosJsonValue("pos_ver").toInt();
refund[PosProps.OperatorId] = getPosJsonValue(PosProps.OperatorId).toString();
refund[PosProps.PosId] = getPosJsonValue(PosProps.PosId).toString();
refund[PosProps.StoreId] = session()->data(PosProps.StoreId).toString();
refund[PosProps.BussinessDate] = getPosJsonValue(PosProps.BussinessDate).toString();
QJsonObject transactions;
transactions[PosProps.Fm_transId] = getPosJsonValue(PosProps.Fm_transId).toString();
transactions[PosProps.Fm_id] = getPosJsonValue(PosProps.Fm_id).toString();
transactions[PosProps.TransId] = getPosJsonValue(PosProps.TransId).toString();
transactions["refund_amount"] = payAmount;
refund["transactions"] = transactions;
del_p(preTask);
preTask = new TaskRefundPay(refund, this);
preTask->doTask();
if(preTask->getServerJsonValue(PosProps.StatusCode).toInt() != FM_API_SUCCESS)
{
FMP_ERROR() << QString::fromLocal8Bit("退款失败!trans_id=%1").arg(getPosJsonValue(PosProps.TransId).toString());
}
posRspJsonObj[PosProps.StatusCode] = preTask->getServerJsonValue(PosProps.StatusCode).toInt();
posRspJsonObj[PosProps.Msg] = preTask->getServerJsonValue(PosProps.Msg).toString();
}
else
{
posRspJsonObj[PosProps.StatusCode] = preTask->getServerJsonValue(PosProps.StatusCode).toInt();
posRspJsonObj[PosProps.Msg] = preTask->getServerJsonValue(PosProps.Msg).toString();
}
}
QByteArray result = QJsonDocument(posRspJsonObj).toJson(QJsonDocument::Compact);
return result;
}
void TaskPay::onGetCoupons(Session* session)
{
couponThread->exit();
_session->addData(PosProps.CouponMap, session->getCouponMap(PosProps.CouponMap));
if(_window != nullptr) {
qobject_cast<FMVipOrder*>(_window)->initCouponItems();
......@@ -69,9 +130,8 @@ void TaskPay::packageServerReq()
//! 会员新接口使用 data 打包业务数据
QJsonObject transData;
transData[ServerProps(PosProps.TransId)] = getPosJsonValue(PosProps.TransId);
transData[ServerProps(PosProps.Fm_id)] = getPosJsonValue(PosProps.Fm_id);
transData[ServerProps(PosProps.Fm_id)] = "";
transData[ServerProps(PosProps.BussinessDate)] = getPosJsonValue(PosProps.BussinessDate);
transData[ServerProps(PosProps.Fm_id)] = getPosJsonValue(PosProps.Fm_id).toString();
transData[ServerProps(PosProps.Fm_open_id)] = session()->data(PosProps.Fm_open_id).toString();
QJsonArray products;
......@@ -81,9 +141,9 @@ void TaskPay::packageServerReq()
QJsonObject obj = clientArray[i].toObject();
QJsonObject serverObj;
serverObj[ServerProps(PosProps.ConsumeNum)] = obj[PosProps.ConsumeNum];
int price = obj["price"].toInt();
serverObj["price"] = price;
serverObj["price"] = obj["price"].toInt();
serverObj["productId"] = obj["pid"];
serverObj["disAmount"] = obj["disAmount"].toInt();
products.push_back(serverObj);
}
......@@ -91,11 +151,14 @@ void TaskPay::packageServerReq()
//余额支付详情
QJsonObject balance;
int codeAmount = session()->data(PosProps.CodeAmount).toInt();
balance["amount"] = codeAmount;
balance["transId"] = getPosJsonValue("trans_id");
balance["typeModeFlag"] = 20001;
balance["thirdPayTransId"] = "";
payList.push_back(balance);
if(codeAmount != 0)
{
balance["amount"] = codeAmount;
balance["transId"] = getPosJsonValue("trans_id");
balance["typeModeFlag"] = QString::number(20001);
balance["thirdPayTransId"] = "";
payList.push_back(balance);
}
// 积分支付详情
QJsonObject score;
......@@ -103,12 +166,12 @@ void TaskPay::packageServerReq()
if(scoreAmount > 0) {
score["amount"] = scoreAmount;
score["transId"] = getPosJsonValue("trans_id");
score["typeModeFlag"] = 20002;
score["typeModeFlag"] = QString::number(20002);
score["thirdPayTransId"] = "";
payList.push_back(score);
}
#if 0
//代金券/商品券支付详情
QMap<QString, QVariant> coupons = session()->data("payCouponMap").toMap();
// 将代金券按金额从小到大排序
......@@ -121,7 +184,6 @@ void TaskPay::packageServerReq()
return (first.disAmount() < second.disAmount());
});
// 计算使用的代金券金额
int needAmount = session()->data(PosProps.NeedAmount).toInt();
int needCouponAmount = needAmount - codeAmount - scoreAmount;
int couponAmount = 0;
......@@ -147,13 +209,36 @@ void TaskPay::packageServerReq()
coupon["code"] = c.code();
payList.push_back(coupon);
}
#endif
//卡券支付详情
int couponAmount = 0;
QMap<QString, QVariant> coupons = session()->data("payCouponMap").toMap();
for(QMap<QString, QVariant>::const_iterator it = coupons.constBegin(); it != coupons.constEnd(); it++)
{
QJsonObject coupon;
coupon["amount"] = it.value().value<Coupon>().disAmount() * 100;
coupon["transId"] = getPosJsonValue(PosProps.TransId);
QString coupon_type = it.value().value<Coupon>().typeModeFlag();
if(coupon_type == "1")
{
coupon["typeModeFlag"] = "20003";
}
else
{
coupon["typeModeFlag"] = coupon_type;
}
coupon["code"] = it.value().value<Coupon>().code();
payList.push_back(coupon);
couponAmount += it.value().value<Coupon>().disAmount() * 100;
}
transData["productList"] = products;
transData["payList"] = payList;
int payAmount = codeAmount + scoreAmount + couponAmount;
transData[ServerProps(PosProps.Pay_amount)] = payAmount;
payAmount = codeAmount + scoreAmount + couponAmount;
transData["payAmount"] = payAmount;
serverReqJsonObj["data"] = transData;
serverReqJsonObj[ServerProps(PosProps.StoreId)] = session()->data(PosProps.StoreId).toString();
}
void TaskPay::packagePOSRsp()
......@@ -163,8 +248,9 @@ void TaskPay::packagePOSRsp()
posRspJsonObj[PosProps.Prompt] = 0;
posRspJsonObj[PosProps.Settlement] = 1;
posRspJsonObj[PosProps.Fm_open_id] = session()->data(PosProps.Fm_open_id).toString();
posRspJsonObj[PosProps.Fm_id] = getServerJsonValue(PosProps.Fm_id).toString();
posRspJsonObj[PosProps.Fm_transId] = getServerJsonValue(PosProps.TransId).toString();
posRspJsonObj[PosProps.TransId] = getPosJsonValue(PosProps.TransId);
posRspJsonObj[PosProps.Fm_id] = getPosJsonValue(PosProps.Fm_id).toString();
posRspJsonObj[PosProps.Fm_transId] = getPosJsonValue(PosProps.TransId).toString();
QJsonArray servPayArray = getServerJsonValue("payList").toArray();
//支付方式描述
......@@ -182,21 +268,25 @@ void TaskPay::packagePOSRsp()
{
QJsonObject pay_id;
QString payId = servPayArray[i].toObject()[ServerProps(PosProps.Pay_id)].toString();
if(payId == "20003") {
pay_id[PosProps.Pay_amount] = 0;
pay_id["merchant_discount"] = servPayArray[i].toObject()[ServerProps(PosProps.Pay_amount)].toInt();
} else {
pay_id[PosProps.Pay_amount] = servPayArray[i].toObject()[ServerProps(PosProps.Pay_amount)].toInt();
}
// if(payId == "20003") {
// pay_id[PosProps.Pay_amount] = 0;
// pay_id["merchant_discount"] = servPayArray[i].toObject()[ServerProps(PosProps.Pay_amount)].toInt();
// } else {
// pay_id[PosProps.Pay_amount] = servPayArray[i].toObject()[ServerProps(PosProps.Pay_amount)].toInt();
// }
pay_id[PosProps.Pay_amount] = servPayArray[i].toObject()[ServerProps(PosProps.Pay_amount)].toInt();
pay_id[PosProps.Pay_id] = payId;
pay_id[PosProps.Pay_str] = description[servPayArray[i].toObject()["typeModeFlag"].toString()];
pay_id[PosProps.Pay_str] = description[payId];
pay_id[PosProps.Coupon_code] = servPayArray[i].toObject()["code"].toString();
pay_ids.push_back(pay_id);
totalPaid += pay_id[PosProps.Pay_amount].toInt();
}
posRspJsonObj[PosProps.Paid_total_amount] = totalPaid;
posRspJsonObj["invoice_amount"] = getServerJsonValue("invoice_amount").toInt();
posRspJsonObj["discount_amount"] = getServerJsonValue("discount_amount").toInt();
posRspJsonObj[PosProps.Pay_ids] = pay_ids;
posRspJsonObj[PosProps.Pay_id] = "1003";
if(getServerJsonValue(PosProps.StatusCode) == FM_API_SUCCESS)
{
......
......@@ -24,6 +24,7 @@ private slots:
private:
TaskCouponThread *couponThread;
int payAmount;
};
// 加载代金券的线程类
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>786</width>
<height>624</height>
<height>626</height>
</rect>
</property>
<property name="maximumSize">
......@@ -746,6 +746,12 @@
</property>
<item>
<widget class="QLabel" name="pay_max">
<property name="minimumSize">
<size>
<width>259</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>余额最多支付 0.00 元</string>
</property>
......@@ -799,8 +805,8 @@
</property>
<property name="maximumSize">
<size>
<width>0</width>
<height>0</height>
<width>283</width>
<height>47</height>
</size>
</property>
<property name="text">
......@@ -813,10 +819,16 @@
</item>
<item>
<widget class="QLabel" name="score_label">
<property name="minimumSize">
<size>
<width>259</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>0</width>
<height>0</height>
<width>259</width>
<height>30</height>
</size>
</property>
<property name="text">
......
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