Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
familyMart_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
guanghui.cui
familyMart_takeaway
Commits
5184cd29
Commit
5184cd29
authored
Mar 24, 2018
by
guanghui.cui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pos主动推送订单状态处理
parent
2cd195a1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
109 additions
and
16 deletions
+109
-16
base/BaseDefine.h
+9
-0
base/CommonStruct.h
+2
-0
src/JsonModule.cpp
+85
-16
src/JsonModule.h
+12
-0
src/main.cpp
+1
-0
No files found.
base/BaseDefine.h
View file @
5184cd29
...
...
@@ -63,6 +63,8 @@
//POS操作类型
#define OPERATION_POS_CONFIRM 1011 //确认接单
#define OPERATION_POS_CANCEL 1012 //拒绝接单
#define OPERATION_POS_REFUND_AGREE 1013 //同意退款
#define OPERATION_POS_REFUND_DISAGREE 1014 //拒绝退款
/***********************************
ODS相关预定义变量
...
...
@@ -98,4 +100,10 @@
#define ODS_PUSH_TYPE_COMMON 1017 //通用预警
#define ODS_PUSH_TYPE_COMMON_BACK 1018 //通用预警返回
//POS主动推送请求类型
#define ODS_POSPUSH_CONFIRM 1 //确认接单
#define ODS_POSPUSH_CANCEL 2 //拒绝接单
#define ODS_POSPUSH_REFUND_AGREE 5 //同意退款
#define ODS_POSPUSH_REFUND_DISAGREE 6 //拒绝退款
#endif
\ No newline at end of file
base/CommonStruct.h
View file @
5184cd29
...
...
@@ -192,6 +192,8 @@ struct stockWarnObj
struct
orderOperationObj
{
int
fm_cmd
=
0
;
//请求类型 •1011 确认接单 •1012 拒绝接单
std
::
string
store_id
;
//门店号
std
::
string
channel
;
//渠道
std
::
string
order_id
;
//订单编号
std
::
string
comment
;
//操作原因描述
};
...
...
src/JsonModule.cpp
View file @
5184cd29
...
...
@@ -705,13 +705,45 @@ bool JsonModule::getOdsResponseData(int status_code, const std::string &msg, std
bool
JsonModule
::
convertDataPos2Ods
(
const
std
::
string
&
data
,
std
::
string
&
result
)
{
if
(
data
.
empty
()){
LOG
(
INFO
)
<<
"convertDataPos2Ods empty input"
;
return
false
;
}
rapidjson
::
Document
document
;
document
.
Parse
(
data
.
c_str
());
if
(
document
.
HasParseError
())
{
LOG
(
INFO
)
<<
"convertDataPos2Ods posResponse JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
return
false
;
}
if
(
!
document
.
HasMember
(
"fm_cmd"
)
)
{
LOG
(
INFO
)
<<
"Don't have needed parames."
;
return
false
;
}
int
fm_cmd
=
document
[
"fm_cmd"
].
GetInt
();
LOG
(
INFO
)
<<
"fm_cmd:"
<<
fm_cmd
;
bool
rlt
=
false
;
if
(
fm_cmd
==
OPERATION_POS_CONFIRM
||
fm_cmd
==
OPERATION_POS_CANCEL
||
fm_cmd
==
OPERATION_POS_REFUND_AGREE
||
fm_cmd
==
OPERATION_POS_REFUND_DISAGREE
){
orderOperationObj
obj
;
if
(
_getPOSOperationObj
(
data
.
data
(),
obj
)){
result
=
_convertPosOperationToOdsJson
(
obj
);
return
true
;
rlt
=
true
;
}
}
else
if
(
fm_cmd
==
REQUEST_TYPE_GOODS_CHANGE
){
return
false
;
}
else
if
(
fm_cmd
==
REQUEST_TYPE_POS_PRIORITY
){
}
return
rlt
;
}
bool
JsonModule
::
convertDataOds2Pos
(
const
std
::
string
&
data
,
std
::
string
&
result
)
...
...
@@ -1313,14 +1345,16 @@ bool JsonModule::_getPOSOperationObj(IN const char* data,OUT orderOperationObj &
}
else
{
if
(
document
.
HasMember
(
"fm_cmd"
))
{
rapidjson
::
Value
&
fm_cmd
=
document
[
"fm_cmd"
];
int
reqType
=
fm_cmd
.
GetInt
();
if
(
reqType
==
OPERATION_POS_CONFIRM
||
reqType
==
OPERATION_POS_CANCEL
){
operation_obj
.
fm_cmd
=
reqType
;
operation_obj
.
fm_cmd
=
fm_cmd
.
GetInt
();
rapidjson
::
Value
&
order_id
=
document
[
"order_id"
];
operation_obj
.
order_id
=
order_id
.
GetString
();
operation_obj
.
store_id
=
_store_id
;
if
(
document
.
HasMember
(
"channel"
)){
rapidjson
::
Value
&
channel
=
document
[
"channel"
];
operation_obj
.
channel
=
channel
.
GetString
();
}
if
(
document
.
HasMember
(
"comment"
)){
rapidjson
::
Value
&
comment
=
document
[
"comment"
];
...
...
@@ -1329,8 +1363,6 @@ bool JsonModule::_getPOSOperationObj(IN const char* data,OUT orderOperationObj &
return
true
;
}
}
}
return
false
;
}
...
...
@@ -1341,20 +1373,20 @@ std::string JsonModule::_convertPosOperationToOdsJson(orderOperationObj &operati
writer
.
StartObject
();
writer
.
Key
(
"channel"
);
writer
.
String
(
""
);
writer
.
String
(
operation_obj
.
channel
.
c_str
()
);
writer
.
Key
(
"s
toreId
"
);
writer
.
String
(
""
);
writer
.
Key
(
"s
hopCode
"
);
writer
.
String
(
operation_obj
.
store_id
.
c_str
()
);
writer
.
Key
(
"order
_i
d"
);
writer
.
Key
(
"order
I
d"
);
writer
.
String
(
operation_obj
.
order_id
.
c_str
());
if
(
operation_obj
.
fm_cmd
==
OPERATION_POS_CONFIRM
){
writer
.
Key
(
"code"
);
writer
.
Int
(
0
);
int
reqType
=
_getODSStatusByPOSReq
(
operation_obj
.
fm_cmd
);
writer
.
Int
(
reqType
);
writer
.
Key
(
"reason"
);
writer
.
String
(
operation_obj
.
comment
.
c_str
());
}
writer
.
EndObject
();
...
...
@@ -1675,3 +1707,39 @@ bool JsonModule::_getCommonWarnResponseJson(IN const std::string& posResponse, I
return
true
;
}
void
JsonModule
::
setInitData
(
IN
const
char
*
data
)
{
rapidjson
::
Document
document
;
// 定义一个Document对象
document
.
Parse
(
data
);
// 解析,Parse()无返回值,也不会抛异常
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
{
LOG
(
ERROR
)
<<
"setInitData JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
return
;
}
_store_id
=
document
[
"store_id"
].
GetString
();
}
int
JsonModule
::
_getODSStatusByPOSReq
(
int
fm_cmd
)
{
int
rlt
=
0
;
switch
(
fm_cmd
)
{
case
OPERATION_POS_CONFIRM
:
rlt
=
ODS_POSPUSH_CONFIRM
;
break
;
case
OPERATION_POS_CANCEL
:
rlt
=
ODS_POSPUSH_CANCEL
;
break
;
case
OPERATION_POS_REFUND_AGREE
:
rlt
=
ODS_POSPUSH_REFUND_AGREE
;
break
;
case
OPERATION_POS_REFUND_DISAGREE
:
rlt
=
ODS_POSPUSH_REFUND_DISAGREE
;
break
;
default
:
break
;
}
return
rlt
;
}
\ No newline at end of file
src/JsonModule.h
View file @
5184cd29
...
...
@@ -75,10 +75,21 @@ public:
* */
int
getPushType
(
IN
const
char
*
data
);
/* 功能:缓存初始化信息,其它接口需要门店信息字段时可以直接拿取
* 参数:[1]初始化json
* 返回:...
* */
void
setInitData
(
IN
const
char
*
data
);
private
:
std
::
string
_store_id
;
//门店号
private
:
std
::
string
_getDeliveryTypeString
(
int
type
);
//订单状态转换(转换为POS对应的状态)
int
_getPOSOrderStatus
(
int
status
);
//POS请求类型转换为ODS需要类型
int
_getODSStatusByPOSReq
(
int
fm_cmd
);
void
_getStatusObj
(
IN
orderObj
&
order_obj
,
OUT
orderStatusObj
&
status_obj
);
void
_getRefundObj
(
IN
orderObj
&
order_obj
,
OUT
refundObj
&
refund_obj
);
...
...
@@ -101,6 +112,7 @@ private:
bool
_getOrderResponseJson
(
IN
const
std
::
string
&
posResponse
,
IN
const
std
::
string
&
orderData
,
OUT
std
::
string
&
result
);
bool
_getStockWarnResponseJson
(
IN
const
std
::
string
&
posResponse
,
IN
const
std
::
string
&
orderData
,
IN
const
std
::
string
&
odsData
,
OUT
std
::
string
&
result
);
bool
_getCommonWarnResponseJson
(
IN
const
std
::
string
&
posResponse
,
IN
const
std
::
string
&
orderData
,
IN
const
std
::
string
&
odsData
,
OUT
std
::
string
&
result
);
};
#endif
src/main.cpp
View file @
5184cd29
...
...
@@ -91,6 +91,7 @@ void* listen_pos_func(void* arg)
sleep
(
1
);
}
}
jsonTool
.
setInitData
(
posRequestData
.
data
());
//把初始化数据暂存起来
}
else
{
jsonTool
.
getPosResponseData
(
101
,
"invalid initdata!"
,
responseData
);
...
...
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