Commit 3ef5b009 by 刘帅

1. 合并,是否有TCP header进行配置

2. 部分退款,打印出退款商品和数量
parent d924bdf0
...@@ -41,7 +41,67 @@ FlowControl::FlowControl() ...@@ -41,7 +41,67 @@ FlowControl::FlowControl()
connect(socket, &QTcpSocket::readyRead, [socket, this]() connect(socket, &QTcpSocket::readyRead, [socket, this]()
{ {
QString recvData; QString recvData;
recvData = QString::fromUtf8(socket->readAll()).simplified(); if(ConfigManage::Instance().tcpHeader())
{
QByteArray byteArray;
int rcvedLength = 0;
int rcvFlag = 0; //firstly, to rcv header
int needLength = sizeof(FMSOCKEHEADER);
int rlt = 0;
FMSOCKEHEADER headx;
char * pcRcvBufer = (char *)(&headx);
while(0 < needLength)
{
socket->waitForReadyRead(1000);
int length = socket->read( pcRcvBufer + rcvedLength, needLength);
qDebug() << "need " << needLength;
if (0 < length)
{
needLength -= length;
rcvedLength += length;
if (0 == needLength)
{
if (0 == rcvFlag)
{ //header rcved complete
rcvFlag = 1; //to rcv payload
//need to check payloadLength is valid or not
needLength = headx.len;
if(needLength > 81920 || needLength < 1)
{
QLOG_ERROR() << "TCP data invalid length:" << needLength;
break;
}
byteArray.resize(headx.len);
pcRcvBufer = byteArray.data();
rcvedLength = 0;
continue;
}
else
{ //payload rcved complete
rlt = rcvedLength;
break;
}
}
}
else if(length == 0)
{
byteArray += '\0';
break;
}
else
{
}
}
recvData = QString(byteArray);
}
else
{
recvData = QString::fromUtf8(socket->readAll()).simplified();
}
QLOG_INFO() << QString("收到数据: %1").arg(recvData); QLOG_INFO() << QString("收到数据: %1").arg(recvData);
QJsonObject recvObj; QJsonObject recvObj;
QJsonParseError jsonError; QJsonParseError jsonError;
...@@ -446,10 +506,10 @@ void FlowControl::requestPartialRefundDetail(QString order_id) ...@@ -446,10 +506,10 @@ void FlowControl::requestPartialRefundDetail(QString order_id)
{ {
QByteArray appendData = DataManage::getRefundDetail(m_token, order_id); QByteArray appendData = DataManage::getRefundDetail(m_token, order_id);
m_http.Post(appendData m_http.Post(appendData
,[this](const QByteArray &data) ,[this, order_id](const QByteArray &data)
{ {
QLOG_INFO() << QString("退款详情: %1").arg(QString(data).simplified()); QLOG_INFO() << QString("退款详情: %1").arg(QString(data).simplified());
emit partialRefundDetail(data); emit partialRefundDetail(order_id, data);
} }
,[this](const QNetworkReply::NetworkError &error) ,[this](const QNetworkReply::NetworkError &error)
{ {
......
...@@ -69,6 +69,8 @@ private: ...@@ -69,6 +69,8 @@ private:
// 用于和服务端通信的本地数据 // 用于和服务端通信的本地数据
QString m_token; QString m_token;
QString m_timestamp; QString m_timestamp;
public:
// 用于存储订单信息<订单ID, 订单对象> // 用于存储订单信息<订单ID, 订单对象>
QMap<QString, OrderObject*> m_ordersMap; QMap<QString, OrderObject*> m_ordersMap;
...@@ -167,7 +169,7 @@ signals: ...@@ -167,7 +169,7 @@ signals:
* 参数:[1]获取退款详情接口返回 * 参数:[1]获取退款详情接口返回
* 返回:NULL * 返回:NULL
* */ * */
void partialRefundDetail(QByteArray detail); void partialRefundDetail(QString order_id, QByteArray detail);
}; };
#endif // FLOWCONTROL_H #endif // FLOWCONTROL_H
...@@ -211,7 +211,7 @@ void DetailForm::on_detail_btnReprint_clicked() ...@@ -211,7 +211,7 @@ void DetailForm::on_detail_btnReprint_clicked()
* 参数:[1]获取退款详情接口返回 * 参数:[1]获取退款详情接口返回
* 返回:NULL * 返回:NULL
* */ * */
void DetailForm::partialRefundDetail(QByteArray detail) void DetailForm::partialRefundDetail(QString order_id, QByteArray detail)
{ {
QJsonParseError json_error; QJsonParseError json_error;
QJsonDocument doc = QJsonDocument::fromJson(detail, &json_error); QJsonDocument doc = QJsonDocument::fromJson(detail, &json_error);
...@@ -227,6 +227,22 @@ void DetailForm::partialRefundDetail(QByteArray detail) ...@@ -227,6 +227,22 @@ void DetailForm::partialRefundDetail(QByteArray detail)
QVariantMap detailMap = doc.toVariant().toMap(); QVariantMap detailMap = doc.toVariant().toMap();
QVariantMap infoMap = detailMap["refund_info"].toMap(); QVariantMap infoMap = detailMap["refund_info"].toMap();
QStringList list;
QMap<QString, int> productDetail;
foreach (QVariant variant, infoMap["refund_items"].toList())
{
QVariantMap product = variant.toMap();
list << product["name"].toString();
productDetail[product["name"].toString()] = product["product_amount"].toInt();
}
OrderObject *orderObj = FlowControl::Instance().m_ordersMap.value(order_id);
foreach(DishObject* item, orderObj->products)
{
if(list.contains(item->name))
item->name = item->name + QString("( 退x%1 )").arg(productDetail[item->name]);
}
QTreeWidgetItem* partialProducts = new QTreeWidgetItem( QStringList()<< QString("退款商品")); QTreeWidgetItem* partialProducts = new QTreeWidgetItem( QStringList()<< QString("退款商品"));
ui->detail_tree->addTopLevelItem( partialProducts ); ui->detail_tree->addTopLevelItem( partialProducts );
......
...@@ -36,7 +36,7 @@ public slots: ...@@ -36,7 +36,7 @@ public slots:
* 参数:[1]获取退款详情接口返回 * 参数:[1]获取退款详情接口返回
* 返回:NULL * 返回:NULL
* */ * */
void partialRefundDetail(QByteArray detail); void partialRefundDetail(QString order_id, QByteArray detail);
private: private:
Ui::DetailForm *ui; Ui::DetailForm *ui;
......
...@@ -95,6 +95,7 @@ MainWindow::MainWindow(QWidget *parent) : ...@@ -95,6 +95,7 @@ MainWindow::MainWindow(QWidget *parent) :
this->ui->main_btnSPGL->setEnabled(true); this->ui->main_btnSPGL->setEnabled(true);
}); });
FlowControl::Instance()._onGetMenu(); FlowControl::Instance()._onGetMenu();
on_main_btnHide_clicked();
}); });
connect(&FlowControl::Instance(), &FlowControl::showDailyForm, [this](QList<DailyInfo> infos) connect(&FlowControl::Instance(), &FlowControl::showDailyForm, [this](QList<DailyInfo> infos)
...@@ -188,7 +189,6 @@ MainWindow::MainWindow(QWidget *parent) : ...@@ -188,7 +189,6 @@ MainWindow::MainWindow(QWidget *parent) :
ui->main_btnDCL->click(); ui->main_btnDCL->click();
connect(m_detailForm, &DetailForm::requestDetail,&FlowControl::Instance(), &FlowControl::requestPartialRefundDetail); connect(m_detailForm, &DetailForm::requestDetail,&FlowControl::Instance(), &FlowControl::requestPartialRefundDetail);
connect(&FlowControl::Instance(), &FlowControl::partialRefundDetail, m_detailForm, &DetailForm::partialRefundDetail); connect(&FlowControl::Instance(), &FlowControl::partialRefundDetail, m_detailForm, &DetailForm::partialRefundDetail);
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
......
...@@ -34,12 +34,16 @@ PrintDocument PrintDocument::ParseToDocument(const QByteArray &content, bool res ...@@ -34,12 +34,16 @@ PrintDocument PrintDocument::ParseToDocument(const QByteArray &content, bool res
int indexForword=0,indexBack=0; int indexForword=0,indexBack=0;
while(indexBack!=(content.length()-1)&&indexBack!=-1&&indexForword!=-1) while(indexBack!=(content.length()-1)&&indexBack!=-1&&indexForword!=-1)
{ {
indexForword = content.indexOf('<',0); indexForword = content.indexOf('<',indexBack);
indexBack = content.indexOf('>',0); indexBack = content.indexOf('>',indexForword);
if(indexBack!=-1&&indexForword!=-1) if(indexBack!=-1&&indexForword!=-1)
{ {
QString printLine = content.mid(indexForword+1,indexBack-indexForword-2); QString printLine = content.mid(indexForword+1,indexBack-indexForword-1);
LineNode *node = new LineNode(printLine,&doc); LineNode *node = new LineNode(printLine,&doc);
if(!node->nodeName.compare("product"))
{
doc._productNodeIndexList.append(doc._nodeList.size());
}
doc._nodeList.append(node); doc._nodeList.append(node);
} }
else else
......
...@@ -73,6 +73,12 @@ public: ...@@ -73,6 +73,12 @@ public:
return m_clientIni->value("net/tcpListenPort").toInt(); return m_clientIni->value("net/tcpListenPort").toInt();
} }
// TCP 通信是否添加包头
inline bool tcpHeader()
{
return m_clientIni->value("net/tcpHeader").toBool();
}
/* 功能:获取非码服务器地址 /* 功能:获取非码服务器地址
* 参数:NULL * 参数:NULL
* 返回:服务器地址 * 返回:服务器地址
......
TEMPLATE = subdirs TEMPLATE = subdirs
SUBDIRS += \ SUBDIRS += \
component
SUBDIRS += \
fmTakeaway fmTakeaway
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