Commit a4270ba2 by 刘帅

添加商品code接口34

parent f71b3d24
...@@ -56,15 +56,17 @@ QList<QVariantMap> Process::toDstFormat(QJsonDocument docSrc) ...@@ -56,15 +56,17 @@ QList<QVariantMap> Process::toDstFormat(QJsonDocument docSrc)
int status = order["status"].toInt(); int status = order["status"].toInt();
if(status == 20 || status == 3 || status == 60) //退款 if(status == 3 || status == 30 || status == 100) //退款
{ {
dstMap.insert(QString("type"), QString("4")); dstMap.insert(QString("type"), QString("4"));
bodyMap.insert(QString("reason"), QString("非码外卖退订")); bodyMap.insert(QString("reason"), QString("非码外卖退订"));
} }
else else if(status == 1 || status == 2 || status == 4 || status == 6 || status == 200)
{ {
dstMap.insert(QString("type"), QString("3")); dstMap.insert(QString("type"), QString("3"));
bodyMap.insert("amount", order["user_fee"].toInt() - order["send_fee"].toInt()); //“用户实付金额”-“配送费” bodyMap.insert("amount", order["product_fee"].toInt()); //明细金额
bodyMap.insert("pay", order["user_fee"].toInt() - order["send_fee"].toInt()); //用户实付金额-配送费
bodyMap.insert("source", order["channel"].toString() == "eleme" ? 1: 2); //-- 1饿了么 2 美团 bodyMap.insert("source", order["channel"].toString() == "eleme" ? 1: 2); //-- 1饿了么 2 美团
QVariantList itemlist; QVariantList itemlist;
...@@ -81,6 +83,10 @@ QList<QVariantMap> Process::toDstFormat(QJsonDocument docSrc) ...@@ -81,6 +83,10 @@ QList<QVariantMap> Process::toDstFormat(QJsonDocument docSrc)
QJsonDocument doc = QJsonDocument::fromVariant(itemlist); QJsonDocument doc = QJsonDocument::fromVariant(itemlist);
bodyMap.insert("itemlist", doc.toVariant()); bodyMap.insert("itemlist", doc.toVariant());
} }
else
{
continue;
}
dstMap.insert(QString("body"), QJsonDocument::fromVariant(bodyMap).toVariant()); dstMap.insert(QString("body"), QJsonDocument::fromVariant(bodyMap).toVariant());
orderList << dstMap; orderList << dstMap;
......
...@@ -29,13 +29,15 @@ Server::~Server() ...@@ -29,13 +29,15 @@ Server::~Server()
{ {
m_processThread->quit(); m_processThread->quit();
m_processThread->wait(); m_processThread->wait();
delete m_processThread;
delete m_process; delete m_process;
delete m_processThread;
m_sendTcpThread->quit(); m_sendTcpThread->quit();
m_sendTcpThread->wait(); m_sendTcpThread->wait();
delete m_sendTcpThread;
delete m_sendTcp; delete m_sendTcp;
delete m_sendTcpThread;
} }
void Server::incomingConnection(int socketDescriptor) void Server::incomingConnection(int socketDescriptor)
......
...@@ -58,8 +58,9 @@ FlowControl::FlowControl() ...@@ -58,8 +58,9 @@ FlowControl::FlowControl()
socket->write(replyData.toUtf8()); socket->write(replyData.toUtf8());
socket->waitForBytesWritten(1000); socket->waitForBytesWritten(1000);
} }
if(recvObj.contains("reqtype") && recvObj["reqtype"] == 80) //商品库存同步 if(recvObj.contains("reqtype") && recvObj["reqtype"] == 25) //商品库存同步
{ {
recvObj.insert("token", m_token);
_onStockSync(recvObj); _onStockSync(recvObj);
} }
} }
...@@ -72,9 +73,13 @@ FlowControl::FlowControl() ...@@ -72,9 +73,13 @@ FlowControl::FlowControl()
connect(this, SIGNAL(recordSale(QJsonObject)), &Sales::Instance(), SLOT(onRecordSale(QJsonObject))); connect(this, SIGNAL(recordSale(QJsonObject)), &Sales::Instance(), SLOT(onRecordSale(QJsonObject)));
//TODO STOCK_SYNC //TODO STOCK_SYNC
QTimer* timer = new QTimer(this); if(ConfigManage::Instance().stockSync())
timer->setInterval(30000); // 拉取菜单间隔,同步库存 {
connect(timer, &QTimer::timeout, this, &FlowControl::_onGetMenu); QTimer* timer = new QTimer(this);
timer->setInterval(ConfigManage::Instance().stockSyncInterval() * 1000); // 拉取菜单间隔,同步库存
connect(timer, &QTimer::timeout, this, &FlowControl::_onGetCode);
timer->start();
}
} }
void FlowControl::Start() void FlowControl::Start()
...@@ -260,26 +265,26 @@ void FlowControl::_onProcessOrderHandle(const QString& orderId, const QString &o ...@@ -260,26 +265,26 @@ void FlowControl::_onProcessOrderHandle(const QString& orderId, const QString &o
//TODO STOCK_SYNC //TODO STOCK_SYNC
void FlowControl::_onGetMenu() void FlowControl::_onGetCode()
{ {
QByteArray request = DataManage::getMenuData(m_token,"eleme"); QByteArray request = DataManage::getCodeData(m_token);
m_http.Post(request m_http.Post(request
,[this](const QByteArray &data) ,[this](const QByteArray &data)
{ {
QLOG_INFO() << QString("获取门店菜单返回数据: %1").arg(QString(data).simplified()); QLOG_INFO() << QString("获取商品code返回数据: %1").arg(QString(data).simplified());
QJsonObject recvObj = QJsonDocument::fromJson(data).object(); QJsonObject recvObj = QJsonDocument::fromJson(data).object();
if(recvObj["statusCode"].toInt() == 100) if(recvObj["statusCode"].toInt() == 100)
{ {
QTcpSocket *socket = new QTcpSocket(); QTcpSocket *socket = new QTcpSocket();
socket->connectToHost("127.0.0.1", 34956); socket->connectToHost("127.0.0.1", 34956);
if(! socket->waitForConnected(3000)) if(! socket->waitForConnected(LOCAL_SOCKET_TIMEOUT))
{ {
QLOG_ERROR() << "connect takeaway component failed!"; QLOG_ERROR() << "connect takeaway component failed!";
return; return;
} }
socket->write(QJsonDocument(recvObj).toJson(QJsonDocument::Compact)); socket->write(QJsonDocument(recvObj).toJson(QJsonDocument::Compact));
if(! socket->waitForBytesWritten(3000)) if(! socket->waitForBytesWritten(LOCAL_SOCKET_TIMEOUT))
{ {
QLOG_ERROR() << "write to takeaway component failed!"; QLOG_ERROR() << "write to takeaway component failed!";
return; return;
...@@ -290,13 +295,12 @@ void FlowControl::_onGetMenu() ...@@ -290,13 +295,12 @@ void FlowControl::_onGetMenu()
delete socket; delete socket;
}else }else
{ {
showAlertForm(AlertForm::ERROR, QString("获取门店菜单失败[%1]").arg(recvObj["msg"].toString()), true); QLOG_ERROR() << QString("商品code接口返回错误: %1").arg(recvObj["msg"].toString());
} }
} }
,[this](const QNetworkReply::NetworkError &error) ,[this](const QNetworkReply::NetworkError &error)
{ {
showAlertForm(AlertForm::ERROR, "获取门店菜单失败[网络错误,请检查网络连接]", true); QLOG_ERROR() << QString("获取商品code失败: %1").arg(error);
QLOG_ERROR() << QString("获取门店菜单失败: %1").arg(error);
} }
); );
} }
...@@ -309,15 +313,7 @@ void FlowControl::_onStockSync(QJsonObject obj) ...@@ -309,15 +313,7 @@ void FlowControl::_onStockSync(QJsonObject obj)
m_http.Post(request m_http.Post(request
,[this](const QByteArray &data) ,[this](const QByteArray &data)
{ {
QLOG_INFO() << QString("同步库存返回数据: %1").arg(QString(data).simplified()); QLOG_INFO() << QString("同步库存返回数据:\n %1").arg(QString(data).simplified());
QJsonObject recvObj = QJsonDocument::fromJson(data).object();
if(recvObj["statusCode"].toInt() == 100)
{
QLOG_ERROR() << QString("同步库存成功");
}else
{
showAlertForm(AlertForm::ERROR, QString("同步库存失败[%1]").arg(recvObj["msg"].toString()), true);
}
} }
,[this](const QNetworkReply::NetworkError &error) ,[this](const QNetworkReply::NetworkError &error)
{ {
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include "alertform.h" #include "alertform.h"
#include "sales.h" #include "sales.h"
const int LOCAL_SOCKET_TIMEOUT = 2000; //本地TCP通信超时时间
class FlowControl : public QObject class FlowControl : public QObject
{ {
Q_OBJECT Q_OBJECT
...@@ -89,11 +91,11 @@ private slots: ...@@ -89,11 +91,11 @@ private slots:
void _onProcessOrderHandle(const QString &orderId, const QString& operationName, void _onProcessOrderHandle(const QString &orderId, const QString& operationName,
const QByteArray& appendData, const std::function< void() > &onSucessful); const QByteArray& appendData, const std::function< void() > &onSucessful);
/* 功能:获取门店菜单 /* 功能:获取商品编码
* 参数:[1]请求菜单json字串 * 参数:NULL
* 返回:NULL * 返回:NULL
* */ * */
void _onGetMenu(); void _onGetCode();
/* 功能:库存同步 /* 功能:库存同步
* 参数:[1]同步库存接口json字串 * 参数:[1]同步库存接口json字串
......
...@@ -124,13 +124,23 @@ public: ...@@ -124,13 +124,23 @@ public:
QString printerParameter(); QString printerParameter();
/* 功能:获取数据库路径 /* 功能:获取数据库路径
* 参数:NULLi * 参数:NULL
* 返回:数据库路径 * 返回:数据库路径
* */ * */
inline QString databasePath(){ inline QString databasePath(){
return m_userIni->value("database/path").toString(); return m_userIni->value("database/path").toString();
} }
// 库存同步时间间隔,单位秒
inline int stockSyncInterval(){
return m_userIni->value("stock/intervalSync", 30).toInt();
}
// 是否进行库存同步
inline bool stockSync(){
return m_userIni->value("stock/enable", false).toBool();
}
private: private:
ConfigManage(); ConfigManage();
......
...@@ -147,3 +147,11 @@ QByteArray DataManage::getMenuData(const QString &token, const QString &channel) ...@@ -147,3 +147,11 @@ QByteArray DataManage::getMenuData(const QString &token, const QString &channel)
json.insert("channel", channel); json.insert("channel", channel);
return QJsonDocument(json).toJson().simplified(); return QJsonDocument(json).toJson().simplified();
} }
QByteArray DataManage::getCodeData(const QString &token)
{
QJsonObject json;
json.insert("reqtype", 34);
json.insert("token", token);
return QJsonDocument(json).toJson().simplified();
}
...@@ -22,6 +22,7 @@ public: ...@@ -22,6 +22,7 @@ public:
static QByteArray pullDailyData(const QString& token); static QByteArray pullDailyData(const QString& token);
static QByteArray getMenuData(const QString& token, const QString& channel); static QByteArray getMenuData(const QString& token, const QString& channel);
static QByteArray getCodeData(const QString& token);
}; };
#endif // DATAMANAGE_H #endif // DATAMANAGE_H
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