Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
takeaway
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
shuai.liu
takeaway
Commits
a4270ba2
Commit
a4270ba2
authored
Jul 10, 2018
by
刘帅
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加商品code接口34
parent
f71b3d24
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
55 additions
and
30 deletions
+55
-30
component/process.cpp
+9
-3
component/server.cpp
+4
-2
fmTakeaway/controls/flowControl.cpp
+17
-21
fmTakeaway/controls/flowControl.h
+5
-3
fmTakeaway/tools/configManage.h
+11
-1
fmTakeaway/tools/dataManage.cpp
+8
-0
fmTakeaway/tools/dataManage.h
+1
-0
No files found.
component/process.cpp
View file @
a4270ba2
...
...
@@ -56,15 +56,17 @@ QList<QVariantMap> Process::toDstFormat(QJsonDocument docSrc)
int
status
=
order
[
"status"
].
toInt
();
if
(
status
==
20
||
status
==
3
||
status
==
6
0
)
//退款
if
(
status
==
3
||
status
==
30
||
status
==
10
0
)
//退款
{
dstMap
.
insert
(
QString
(
"type"
),
QString
(
"4"
));
bodyMap
.
insert
(
QString
(
"reason"
),
QString
(
"非码外卖退订"
));
}
else
else
if
(
status
==
1
||
status
==
2
||
status
==
4
||
status
==
6
||
status
==
200
)
{
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 美团
QVariantList
itemlist
;
...
...
@@ -81,6 +83,10 @@ QList<QVariantMap> Process::toDstFormat(QJsonDocument docSrc)
QJsonDocument
doc
=
QJsonDocument
::
fromVariant
(
itemlist
);
bodyMap
.
insert
(
"itemlist"
,
doc
.
toVariant
());
}
else
{
continue
;
}
dstMap
.
insert
(
QString
(
"body"
),
QJsonDocument
::
fromVariant
(
bodyMap
).
toVariant
());
orderList
<<
dstMap
;
...
...
component/server.cpp
View file @
a4270ba2
...
...
@@ -29,13 +29,15 @@ Server::~Server()
{
m_processThread
->
quit
();
m_processThread
->
wait
();
delete
m_processThread
;
delete
m_process
;
delete
m_processThread
;
m_sendTcpThread
->
quit
();
m_sendTcpThread
->
wait
();
delete
m_sendTcpThread
;
delete
m_sendTcp
;
delete
m_sendTcpThread
;
}
void
Server
::
incomingConnection
(
int
socketDescriptor
)
...
...
fmTakeaway/controls/flowControl.cpp
View file @
a4270ba2
...
...
@@ -58,8 +58,9 @@ FlowControl::FlowControl()
socket
->
write
(
replyData
.
toUtf8
());
socket
->
waitForBytesWritten
(
1000
);
}
if
(
recvObj
.
contains
(
"reqtype"
)
&&
recvObj
[
"reqtype"
]
==
80
)
//商品库存同步
if
(
recvObj
.
contains
(
"reqtype"
)
&&
recvObj
[
"reqtype"
]
==
25
)
//商品库存同步
{
recvObj
.
insert
(
"token"
,
m_token
);
_onStockSync
(
recvObj
);
}
}
...
...
@@ -72,9 +73,13 @@ FlowControl::FlowControl()
connect
(
this
,
SIGNAL
(
recordSale
(
QJsonObject
)),
&
Sales
::
Instance
(),
SLOT
(
onRecordSale
(
QJsonObject
)));
//TODO STOCK_SYNC
QTimer
*
timer
=
new
QTimer
(
this
);
timer
->
setInterval
(
30000
);
// 拉取菜单间隔,同步库存
connect
(
timer
,
&
QTimer
::
timeout
,
this
,
&
FlowControl
::
_onGetMenu
);
if
(
ConfigManage
::
Instance
().
stockSync
())
{
QTimer
*
timer
=
new
QTimer
(
this
);
timer
->
setInterval
(
ConfigManage
::
Instance
().
stockSyncInterval
()
*
1000
);
// 拉取菜单间隔,同步库存
connect
(
timer
,
&
QTimer
::
timeout
,
this
,
&
FlowControl
::
_onGetCode
);
timer
->
start
();
}
}
void
FlowControl
::
Start
()
...
...
@@ -260,26 +265,26 @@ void FlowControl::_onProcessOrderHandle(const QString& orderId, const QString &o
//TODO STOCK_SYNC
void
FlowControl
::
_onGet
Menu
()
void
FlowControl
::
_onGet
Code
()
{
QByteArray
request
=
DataManage
::
get
MenuData
(
m_token
,
"eleme"
);
QByteArray
request
=
DataManage
::
get
CodeData
(
m_token
);
m_http
.
Post
(
request
,[
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
();
if
(
recvObj
[
"statusCode"
].
toInt
()
==
100
)
{
QTcpSocket
*
socket
=
new
QTcpSocket
();
socket
->
connectToHost
(
"127.0.0.1"
,
34956
);
if
(
!
socket
->
waitForConnected
(
3000
))
if
(
!
socket
->
waitForConnected
(
LOCAL_SOCKET_TIMEOUT
))
{
QLOG_ERROR
()
<<
"connect takeaway component failed!"
;
return
;
}
socket
->
write
(
QJsonDocument
(
recvObj
).
toJson
(
QJsonDocument
::
Compact
));
if
(
!
socket
->
waitForBytesWritten
(
3000
))
if
(
!
socket
->
waitForBytesWritten
(
LOCAL_SOCKET_TIMEOUT
))
{
QLOG_ERROR
()
<<
"write to takeaway component failed!"
;
return
;
...
...
@@ -290,13 +295,12 @@ void FlowControl::_onGetMenu()
delete
socket
;
}
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
)
{
showAlertForm
(
AlertForm
::
ERROR
,
"获取门店菜单失败[网络错误,请检查网络连接]"
,
true
);
QLOG_ERROR
()
<<
QString
(
"获取门店菜单失败: %1"
).
arg
(
error
);
QLOG_ERROR
()
<<
QString
(
"获取商品code失败: %1"
).
arg
(
error
);
}
);
}
...
...
@@ -309,15 +313,7 @@ void FlowControl::_onStockSync(QJsonObject obj)
m_http
.
Post
(
request
,[
this
](
const
QByteArray
&
data
)
{
QLOG_INFO
()
<<
QString
(
"同步库存返回数据: %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
);
}
QLOG_INFO
()
<<
QString
(
"同步库存返回数据:
\n
%1"
).
arg
(
QString
(
data
).
simplified
());
}
,[
this
](
const
QNetworkReply
::
NetworkError
&
error
)
{
...
...
fmTakeaway/controls/flowControl.h
View file @
a4270ba2
...
...
@@ -12,6 +12,8 @@
#include "alertform.h"
#include "sales.h"
const
int
LOCAL_SOCKET_TIMEOUT
=
2000
;
//本地TCP通信超时时间
class
FlowControl
:
public
QObject
{
Q_OBJECT
...
...
@@ -89,11 +91,11 @@ private slots:
void
_onProcessOrderHandle
(
const
QString
&
orderId
,
const
QString
&
operationName
,
const
QByteArray
&
appendData
,
const
std
::
function
<
void
()
>
&
onSucessful
);
/* 功能:获取
门店菜单
* 参数:
[1]请求菜单json字串
/* 功能:获取
商品编码
* 参数:
NULL
* 返回:NULL
* */
void
_onGet
Menu
();
void
_onGet
Code
();
/* 功能:库存同步
* 参数:[1]同步库存接口json字串
...
...
fmTakeaway/tools/configManage.h
View file @
a4270ba2
...
...
@@ -124,13 +124,23 @@ public:
QString
printerParameter
();
/* 功能:获取数据库路径
* 参数:NULL
i
* 参数:NULL
* 返回:数据库路径
* */
inline
QString
databasePath
(){
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
:
ConfigManage
();
...
...
fmTakeaway/tools/dataManage.cpp
View file @
a4270ba2
...
...
@@ -147,3 +147,11 @@ QByteArray DataManage::getMenuData(const QString &token, const QString &channel)
json
.
insert
(
"channel"
,
channel
);
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
();
}
fmTakeaway/tools/dataManage.h
View file @
a4270ba2
...
...
@@ -22,6 +22,7 @@ public:
static
QByteArray
pullDailyData
(
const
QString
&
token
);
static
QByteArray
getMenuData
(
const
QString
&
token
,
const
QString
&
channel
);
static
QByteArray
getCodeData
(
const
QString
&
token
);
};
#endif // DATAMANAGE_H
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