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
d28fc2cc
Commit
d28fc2cc
authored
Feb 26, 2018
by
unknown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix 1:修复编译出错问题
parent
2a952a5e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1196 additions
and
1193 deletions
+1196
-1193
src/JsonModule.cpp
+1123
-1122
src/JsonModule.h
+73
-71
No files found.
src/JsonModule.cpp
View file @
d28fc2cc
#include "JsonModule.h"
#include "../3rdParty/rapidjson/rapidjson.h"
#include "../3rdParty/rapidjson/document.h"
#include "../3rdParty/rapidjson/reader.h"
#include "../3rdParty/rapidjson/writer.h"
#include "../3rdParty/rapidjson/stringbuffer.h"
#include "../3rdParty/easylogging/easylogging++.h"
using
namespace
rapidjson
;
// std::string GetTestJson(const int statuscode,const char* msg,const char* orderid)
// {
// rapidjson::StringBuffer buffer;
// rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
// writer.StartObject();
// writer.Key("statusCode");
// writer.Int(statuscode);
// writer.Key("msg");
// writer.String(msg);
// writer.Key("orderid");
// writer.String(orderid);
// writer.EndObject();
// return buffer.GetString();
// }
// void parseJson(const char* json)
// {
// rapidjson::Document document; // 定义一个Document对象
// document.Parse(json); // 解析,Parse()无返回值,也不会抛异常
// if (document.HasParseError()) // 通过HasParseError()来判断解析是否成功
// {
// // 可通过GetParseError()取得出错代码,
// // 注意GetParseError()返回的是一个rapidjson::ParseErrorCode类型的枚举值
// // 使用函数rapidjson::GetParseError_En()得到错误码的字符串说明,这里的En为English简写
// // 函数GetErrorOffset()返回出错发生的位置
// LOG(ERROR)<<"JSON parse error:"<<document.GetParseError()<<":"<<document.GetErrorOffset();
// }
// else
// {
// rapidjson::Value& vStatusCode = document["statusCode"];
// rapidjson::Value& vMsg = document["msg"];
// rapidjson::Value& vOrderid = document["orderid"];
// int iStatusCode = vStatusCode.GetInt();
// std::string strMsg = vMsg.GetString();
// std::string strOrderid = vOrderid.GetString();
// LOG(INFO)<<"statusCode:"<<iStatusCode;
// LOG(INFO)<<"msg:"<<strMsg.data();
// LOG(INFO)<<"orderId:"<<strOrderid.data();
// }
// }
JsonModule
::
JsonModule
()
{
}
JsonModule
::~
JsonModule
()
{
}
bool
JsonModule
::
getPushOrders
(
IN
const
char
*
json
,
OUT
orderObj
&
order
)
{
rapidjson
::
Document
document
;
// 定义一个Document对象
document
.
Parse
(
json
);
// 解析,Parse()无返回值,也不会抛异常
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
{
// 可通过GetParseError()取得出错代码,
// 注意GetParseError()返回的是一个rapidjson::ParseErrorCode类型的枚举值
// 使用函数rapidjson::GetParseError_En()得到错误码的字符串说明,这里的En为English简写
// 函数GetErrorOffset()返回出错发生的位置
LOG
(
ERROR
)
<<
"JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
return
false
;
}
else
{
rapidjson
::
Value
&
channel
=
document
[
"channel"
];
order
.
channel
=
channel
.
GetString
();
rapidjson
::
Value
&
token
=
document
[
"token"
];
token
.
GetString
();
rapidjson
::
Value
&
ver
=
document
[
"ver"
];
ver
.
GetInt
();
//配送信息
{
rapidjson
::
Value
&
delivery_obj
=
document
[
"delivery"
];
rapidjson
::
Value
&
customerAddress
=
delivery_obj
[
"customerAddress"
];
order
.
customerInfo
.
address
=
customerAddress
.
GetString
();
rapidjson
::
Value
&
customerName
=
delivery_obj
[
"customerName"
];
order
.
customerInfo
.
name
=
customerName
.
GetString
();
rapidjson
::
Value
&
customerPhone
=
delivery_obj
[
"customerPhone"
];
order
.
customerInfo
.
phone
=
customerPhone
.
GetString
();
rapidjson
::
Value
&
deliveryTime
=
delivery_obj
[
"deliveryTime"
];
order
.
delivery_time
=
deliveryTime
.
GetString
();
rapidjson
::
Value
&
name
=
delivery_obj
[
"name"
];
order
.
deliveryInfo
.
driver_name
=
name
.
GetString
();
rapidjson
::
Value
&
phone
=
delivery_obj
[
"phone"
];
order
.
deliveryInfo
.
driver_phone
=
phone
.
GetString
();
rapidjson
::
Value
&
type
=
delivery_obj
[
"type"
];
order
.
deliveryInfo
.
type
=
type
.
GetString
();
}
//发票信息
{
rapidjson
::
Value
&
invoice_obj
=
document
[
"invoice"
];
rapidjson
::
Value
&
companyName
=
invoice_obj
[
"companyName"
];
companyName
.
GetString
();
rapidjson
::
Value
&
invoiceType
=
invoice_obj
[
"invoiceType"
];
invoiceType
.
GetInt
();
rapidjson
::
Value
&
taxNum
=
invoice_obj
[
"taxNum"
];
taxNum
.
GetString
();
rapidjson
::
Value
&
title
=
invoice_obj
[
"title"
];
title
.
GetString
();
rapidjson
::
Value
&
transNum
=
invoice_obj
[
"transNum"
];
transNum
.
GetString
();
}
//订单内容
{
rapidjson
::
Value
&
orderContent_obj
=
document
[
"orderContent"
];
rapidjson
::
Value
&
createTime
=
orderContent_obj
[
"createTime"
];
order
.
create_time
=
createTime
.
GetString
();
//用户信息
rapidjson
::
Value
&
customer_array
=
orderContent_obj
[
"customer"
];
if
(
customer_array
.
IsArray
())
{
for
(
unsigned
int
i
=
0
;
i
<
customer_array
.
Size
();
i
++
){
rapidjson
::
Value
&
customer_obj
=
customer_array
[
i
];
rapidjson
::
Value
&
accountId
=
customer_obj
[
"accountId"
];
order
.
customerInfo
.
account
=
accountId
.
GetString
();
rapidjson
::
Value
&
accountType
=
customer_obj
[
"accountType"
];
order
.
customerInfo
.
account_type
=
atoi
(
accountType
.
GetString
().
data
());
rapidjson
::
Value
&
level
=
customer_obj
[
"level"
];
order
.
customerInfo
.
account_level
=
level
.
GetString
();
}
}
rapidjson
::
Value
&
deliveryFee
=
orderContent_obj
[
"deliveryFee"
];
order
.
delivery_price
=
deliveryFee
.
GetInt
();
//订单信息
{
rapidjson
::
Value
&
orders_obj
=
orderContent_obj
[
"orders"
];
rapidjson
::
Value
&
deliveryStatus
=
orders_obj
[
"deliveryStatus"
];
order
.
deliveryInfo
.
status
=
atoi
(
deliveryStatus
.
GetString
().
data
());
rapidjson
::
Value
&
deliveryStatusDesc
=
orders_obj
[
"deliveryStatusDesc"
];
order
.
deliveryInfo
.
status_desc
=
deliveryStatusDesc
.
GetString
();
rapidjson
::
Value
&
orderId
=
orders_obj
[
"orderId"
];
order
.
order_id
=
orderId
.
GetString
();
rapidjson
::
Value
&
pickupCode
=
orders_obj
[
"pickupCode"
];
order
.
pickup_code
=
pickupCode
.
GetString
();
rapidjson
::
Value
&
pickupPoint
=
orders_obj
[
"pickupPoint"
];
order
.
pickup_point
=
pickupPoint
.
GetString
();
rapidjson
::
Value
&
remark
=
orders_obj
[
"remark"
];
remark
.
GetString
();
rapidjson
::
Value
&
status
=
orders_obj
[
"status"
];
order
.
status
=
atoi
(
status
.
GetString
().
data
());
rapidjson
::
Value
&
statusDesc
=
orders_obj
[
"statusDesc"
];
order
.
status_desc
=
statusDesc
.
GetString
();
//订单商品
{
rapidjson
::
Value
&
products_array
=
orders_obj
[
"products"
];
if
(
products_array
.
IsArray
())
{
for
(
unsigned
int
i
=
0
;
i
<
products_array
.
Size
();
i
++
){
rapidjson
::
Value
&
product_obj
=
products_array
[
i
];
productAttr
structProduct
;
rapidjson
::
Value
&
attributes
=
product_obj
[
"attributes"
];
structProduct
.
pro
.
attributes
=
attributes
.
GetString
();
rapidjson
::
Value
&
catgId
=
product_obj
[
"catgId"
];
structProduct
.
pro
.
combo_id
=
catgId
.
GetString
();
rapidjson
::
Value
&
groupIndex
=
product_obj
[
"groupIndex"
];
structProduct
.
pro
.
bom_id
=
groupIndex
.
GetString
();
rapidjson
::
Value
&
name
=
product_obj
[
"name"
];
structProduct
.
pro
.
name
=
name
.
GetString
();
rapidjson
::
Value
&
price
=
product_obj
[
"price"
];
structProduct
.
pro
.
price
=
price
.
GetInt
();
rapidjson
::
Value
&
productType
=
product_obj
[
"productType"
];
productType
.
GetString
();
rapidjson
::
Value
&
qty
=
product_obj
[
"qty"
];
structProduct
.
pro
.
qty
=
qty
.
GetInt
();
rapidjson
::
Value
&
sku
=
product_obj
[
"sku"
];
structProduct
.
pro
.
sku
=
sku
.
GetString
();
rapidjson
::
Value
&
source
=
product_obj
[
"source"
];
structProduct
.
pro
.
source
=
source
.
GetString
();
//子商品信息
{
rapidjson
::
Value
&
specs_array
=
product_obj
[
"specs"
];
if
(
specs_array
.
IsArray
())
{
for
(
unsigned
int
i
=
0
;
i
<
specs_array
.
Size
();
i
++
){
rapidjson
::
Value
&
specs_obj
=
specs_array
[
i
];
productSpec
structProductSpec
;
rapidjson
::
Value
&
name
=
specs_obj
[
"name"
];
structProductSpec
.
name
=
name
.
GetString
();
rapidjson
::
Value
&
price
=
specs_obj
[
"price"
];
structProductSpec
.
price
=
price
.
GetInt
();
rapidjson
::
Value
&
qty
=
specs_obj
[
"qty"
];
structProductSpec
.
qty
=
qty
.
GetInt
();
rapidjson
::
Value
&
sku
=
specs_obj
[
"sku"
];
structProductSpec
.
sku
=
sku
.
GetString
();
structProduct
.
vecSpec
.
push_back
(
structProductSpec
);
}
}
}
order
.
vecProducts
.
push_back
(
structProduct
);
}
}
}
}
//支付信息
{
//TODO
//sumary未映射字段值
rapidjson
::
Value
&
payInfos_array
=
orderContent_obj
[
"payInfos"
];
if
(
payInfos_array
.
IsArray
())
{
for
(
unsigned
int
i
=
0
;
i
<
payInfos_array
.
Size
();
i
++
){
rapidjson
::
Value
&
payInfos_obj
=
payInfos_array
[
i
];
paymentDetail
detail
;
rapidjson
::
Value
&
amount
=
payInfos_obj
[
"amount"
];
detail
.
amount
=
amount
.
GetInt
();
rapidjson
::
Value
&
payType
=
payInfos_obj
[
"payType"
];
detail
.
type
=
atoi
(
payType
.
GetString
().
data
());
rapidjson
::
Value
&
transNum
=
payInfos_obj
[
"transNum"
];
detail
.
trans_id
=
transNum
.
GetString
();
order
.
payInfo
.
vecDetail
.
push_back
(
detail
);
}
}
}
rapidjson
::
Value
&
payType
=
orderContent_obj
[
"payType"
];
payType
.
GetString
();
//积分信息
{
rapidjson
::
Value
&
points_obj
=
orderContent_obj
[
"points"
];
rapidjson
::
Value
&
totalPoint
=
points_obj
[
"totalPoint"
];
char
temp
[
20
]
=
{
0
};
int
iPoint
=
totalPoint
.
GetInt
();
itoa
(
iPoint
,
temp
,
10
);
order
.
bonusInfo
.
summary
=
temp
;
//积分信息详情
{
rapidjson
::
Value
&
pointDetails_array
=
points_obj
[
"pointDetails"
];
if
(
pointDetails_array
.
IsArray
())
{
for
(
unsigned
int
i
=
0
;
i
<
pointDetails_array
.
Size
();
i
++
){
rapidjson
::
Value
&
pointDetails_obj
=
pointDetails_array
[
i
];
bonusDetail
detail
;
rapidjson
::
Value
&
bomId
=
pointDetails_obj
[
"bomId"
];
bomId
.
GetString
();
rapidjson
::
Value
&
comboId
=
pointDetails_obj
[
"comboId"
];
comboId
.
GetString
();
rapidjson
::
Value
&
desc
=
pointDetails_obj
[
"desc"
];
detail
.
desc
=
desc
.
GetString
();
rapidjson
::
Value
&
groupId
=
pointDetails_obj
[
"groupId"
];
groupId
.
GetString
();
rapidjson
::
Value
&
point
=
pointDetails_obj
[
"point"
];
detail
.
point
=
point
.
GetInt
();
rapidjson
::
Value
&
sku
=
pointDetails_obj
[
"sku"
];
detail
.
sku
=
sku
.
GetString
();
rapidjson
::
Value
&
type
=
pointDetails_obj
[
"type"
];
detail
.
type
=
atoi
(
type
.
GetString
().
data
());
order
.
bonusInfo
.
vecDetail
.
push_back
(
detail
);
}
}
}
}
//优惠信息
{
rapidjson
::
Value
&
promotions_obj
=
orderContent_obj
[
"promotions"
];
rapidjson
::
Value
&
totalDiscount
=
promotions_obj
[
"totalDiscount"
];
totalDiscount
.
GetInt
();
rapidjson
::
Value
&
totalOriginalPrice
=
promotions_obj
[
"totalOriginalPrice"
];
totalOriginalPrice
.
GetInt
();
rapidjson
::
Value
&
totalPrmotionPrice
=
promotions_obj
[
"totalPrmotionPrice"
];
totalPrmotionPrice
.
GetInt
();
//优惠信息详情
{
rapidjson
::
Value
&
promtionDetails_array
=
promotions_obj
[
"promtionDetails"
];
if
(
promtionDetails_array
.
IsArray
())
{
for
(
unsigned
int
i
=
0
;
i
<
promtionDetails_array
.
Size
();
i
++
){
rapidjson
::
Value
&
promtionDetails_obj
=
promtionDetails_array
[
i
];
rapidjson
::
Value
&
bomId
=
promtionDetails_obj
[
"bomId"
];
bomId
.
GetString
();
rapidjson
::
Value
&
comboId
=
promtionDetails_obj
[
"comboId"
];
comboId
.
GetString
();
rapidjson
::
Value
&
desc
=
promtionDetails_obj
[
"desc"
];
desc
.
GetString
();
rapidjson
::
Value
&
discount
=
promtionDetails_obj
[
"discount"
];
discount
.
GetInt
();
rapidjson
::
Value
&
groupId
=
promtionDetails_obj
[
"groupId"
];
groupId
.
GetString
();
rapidjson
::
Value
&
originalPrice
=
promtionDetails_obj
[
"originalPrice"
];
originalPrice
.
GetInt
();
rapidjson
::
Value
&
pcode
=
promtionDetails_obj
[
"pcode"
];
pcode
.
GetString
();
rapidjson
::
Value
&
prmotionPrice
=
promtionDetails_obj
[
"prmotionPrice"
];
prmotionPrice
.
GetInt
();
rapidjson
::
Value
&
sku
=
promtionDetails_obj
[
"sku"
];
sku
.
GetString
();
rapidjson
::
Value
&
type
=
promtionDetails_obj
[
"type"
];
type
.
GetString
();
}
}
}
}
rapidjson
::
Value
&
sessionId
=
orderContent_obj
[
"sessionId"
];
sessionId
.
GetString
();
rapidjson
::
Value
&
totalAmount
=
orderContent_obj
[
"totalAmount"
];
order
.
total_price
=
totalAmount
.
GetInt
();
rapidjson
::
Value
&
totalDiscount
=
orderContent_obj
[
"totalDiscount"
];
order
.
reduced_price
=
totalDiscount
.
GetInt
();
}
//第三方商户信息
{
rapidjson
::
Value
&
sellerInfo_obj
=
document
[
"sellerInfo"
];
rapidjson
::
Value
&
sellerId
=
sellerInfo_obj
[
"sellerId"
];
sellerId
.
GetString
();
rapidjson
::
Value
&
sellerName
=
sellerInfo_obj
[
"sellerName"
];
sellerName
.
GetString
();
}
//门店信息
{
rapidjson
::
Value
&
shopInfo_obj
=
document
[
"shopInfo"
];
rapidjson
::
Value
&
barCounter
=
shopInfo_obj
[
"barCounter"
];
barCounter
.
GetString
();
rapidjson
::
Value
&
vOperator
=
shopInfo_obj
[
"operator"
];
vOperator
.
GetString
();
rapidjson
::
Value
&
posId
=
shopInfo_obj
[
"posId"
];
order
.
storeInfo
.
pos_id
=
posId
.
GetString
();
rapidjson
::
Value
&
storeId
=
shopInfo_obj
[
"storeId"
];
order
.
storeInfo
.
store_id
=
storeId
.
GetString
();
//自助机信息
rapidjson
::
Value
&
selfHelpMac_obj
=
shopInfo_obj
[
"selfHelpMac"
];
rapidjson
::
Value
&
id
=
selfHelpMac_obj
[
"id"
];
order
.
storeInfo
.
vem_id
=
id
.
GetString
();
rapidjson
::
Value
&
shelf
=
selfHelpMac_obj
[
"shelf"
];
order
.
storeInfo
.
vem_shelf
=
shelf
.
GetString
();
}
}
return
true
;
}
bool
JsonModule
::
isInitData
(
const
std
::
string
&
data
)
{
rapidjson
::
Document
document
;
// 定义一个Document对象
document
.
Parse
(
data
.
c_str
());
// 解析,Parse()无返回值,也不会抛异常
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
{
LOG
(
ERROR
)
<<
"JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
return
false
;
}
return
document
[
"fm_cmd"
].
GetInt
()
==
1000
;
}
bool
JsonModule
::
checkInitData
(
const
std
::
string
&
data
,
int
&
posListenPort
)
{
rapidjson
::
Document
document
;
// 定义一个Document对象
document
.
Parse
(
data
.
c_str
());
// 解析,Parse()无返回值,也不会抛异常
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
{
LOG
(
ERROR
)
<<
"JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
return
false
;
}
if
(
!
document
.
HasMember
(
"store_id"
)
||
!
document
.
HasMember
(
"pos_id"
)
||
!
document
.
HasMember
(
"operator_id"
)
||
!
document
.
HasMember
(
"is_master"
)
||
document
[
"listen_port"
].
GetInt
()
<
0
)
{
return
false
;
}
posListenPort
=
document
[
"listen_port"
].
GetInt
();
return
true
;
}
bool
JsonModule
::
getPosResponseData
(
int
status
,
const
std
::
string
&
msg
,
std
::
string
&
result
)
{
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartObject
();
writer
.
Key
(
"status_code"
);
writer
.
Int
(
status
);
writer
.
Key
(
"msg"
);
writer
.
String
(
msg
.
c_str
());
writer
.
EndObject
();
result
=
buffer
.
GetString
();
return
true
;
}
bool
JsonModule
::
getPosResponseData
(
const
std
::
string
&
odsResponse
,
std
::
string
&
result
)
{
result
=
"{
\"
status_code
\"
:100,
\"
msg
\"
:
\"\"
}"
;
return
true
;
}
bool
JsonModule
::
getOdsResponseData
(
int
status_code
,
const
std
::
string
&
msg
,
std
::
string
&
result
)
{
/*
{
"type" : 2,
"order_id" : "xxxxx",
"status" : 1,
"status_code" : 100,
"msg" : "接收订单成功"
}
*/
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartObject
();
writer
.
Key
(
"type"
);
writer
.
Int
(
2
);
writer
.
Key
(
"order_id"
);
writer
.
String
(
""
);
writer
.
Key
(
"status"
);
writer
.
Int
(
0
);
writer
.
Key
(
"status_code"
);
writer
.
Int
(
status_code
);
writer
.
Key
(
"msg"
);
writer
.
String
(
msg
.
c_str
());
writer
.
EndObject
();
result
=
buffer
.
GetString
();
return
true
;
}
bool
JsonModule
::
getOdsResponseData
(
const
std
::
string
&
posResponse
,
const
std
::
string
&
orderData
,
std
::
string
&
result
)
{
int
status_code
;
std
::
string
msg
;
std
::
string
order_id
;
int
status
;
if
(
posResponse
.
empty
()
||
orderData
.
empty
()
)
return
false
;
rapidjson
::
Document
document
,
document1
;
document
.
Parse
(
posResponse
.
c_str
());
document1
.
Parse
(
orderData
.
c_str
());
if
(
document
.
HasParseError
()
||
document1
.
HasParseError
())
{
return
false
;
}
if
(
!
document
.
HasMember
(
"status_code"
)
||
!
document1
.
HasMember
(
"order_id"
)
||
!
document1
.
HasMember
(
"status"
)
)
{
return
false
;
}
status_code
=
document
[
"status_code"
].
GetInt
();
msg
=
document
[
"msg"
].
GetString
();
order_id
=
document1
[
"order_id"
].
GetString
();
status
=
document1
[
"status"
].
GetInt
();
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartObject
();
writer
.
Key
(
"type"
);
writer
.
Int
(
2
);
writer
.
Key
(
"order_id"
);
writer
.
String
(
order_id
.
c_str
());
writer
.
Key
(
"status"
);
writer
.
Int
(
status
);
writer
.
Key
(
"status_code"
);
writer
.
Int
(
status_code
);
writer
.
Key
(
"msg"
);
writer
.
String
(
msg
.
c_str
());
writer
.
EndObject
();
result
=
buffer
.
GetString
();
return
true
;
}
bool
JsonModule
::
convertDataPos2Ods
(
const
std
::
string
&
data
,
std
::
string
&
result
)
{
return
true
;
}
bool
JsonModule
::
convertDataOds2Pos
(
const
std
::
string
&
data
,
std
::
string
&
result
)
{
bool
rlt
=
true
;
orderObj
order
;
rlt
=
getPushOrders
(
data
.
data
(),
order
);
if
(
ORDERSTATUS_NEW
==
order
.
status
){
result
=
_convertToNewOrderJson
(
order
);
}
else
if
(
ORDERSTATUS_CONFIRMED
==
order
.
status
||
ORDERSTATUS_CANCELED
==
order
.
status
||
ORDERSTATUS_SHIPPING
==
order
.
status
||
ORDERSTATUS_COMPLETE
==
order
.
status
){
orderStatusObj
statusObj
;
_getStatusObj
(
order
,
statusObj
);
result
=
_convertToOrderStatusJson
(
statusObj
);
}
else
if
(
ORDERSTATUS_REFUND_FULL
==
order
.
status
||
ORDERSTATUS_REFUND_PART
==
order
.
status
){
refundObj
refund
;
_getRefundObj
(
order
,
refund
);
result
=
_convertToRefundJson
(
refund
);
}
return
rlt
;
}
std
::
string
JsonModule
::
_convertToNewOrderJson
(
orderObj
&
obj
)
{
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartObject
();
writer
.
Key
(
"fm_cmd"
);
writer
.
Int
(
REQUEST_TYPE_NEWORDER_PUSH
);
writer
.
Key
(
"channel"
);
writer
.
String
(
obj
.
channel
.
c_str
());
writer
.
Key
(
"order_no"
);
writer
.
Int
(
obj
.
order_no
);
writer
.
Key
(
"order_id"
);
writer
.
String
(
obj
.
order_id
.
c_str
());
writer
.
Key
(
"create_time"
);
writer
.
String
(
obj
.
create_time
.
c_str
());
writer
.
Key
(
"delivery_time"
);
writer
.
String
(
obj
.
delivery_time
.
c_str
());
writer
.
Key
(
"status"
);
writer
.
Int
(
obj
.
status
);
writer
.
Key
(
"status_desc"
);
writer
.
String
(
obj
.
status_desc
.
c_str
());
writer
.
Key
(
"total_price"
);
writer
.
Int
(
obj
.
total_price
);
writer
.
Key
(
"delivery_price"
);
writer
.
Int
(
obj
.
delivery_price
);
writer
.
Key
(
"reduced_price"
);
writer
.
Int
(
obj
.
reduced_price
);
writer
.
Key
(
"pickup_code"
);
writer
.
String
(
obj
.
pickup_code
.
c_str
());
writer
.
Key
(
"pickup_point"
);
writer
.
String
(
obj
.
pickup_point
.
c_str
());
//----------------门店信息----------------
writer
.
Key
(
"store"
);
writer
.
StartObject
();
writer
.
Key
(
"store_id"
);
writer
.
String
(
obj
.
storeInfo
.
store_id
.
c_str
());
writer
.
Key
(
"pos_id"
);
writer
.
String
(
obj
.
storeInfo
.
pos_id
.
c_str
());
writer
.
Key
(
"vem_id"
);
writer
.
String
(
obj
.
storeInfo
.
vem_id
.
c_str
());
writer
.
Key
(
"vem_shelf"
);
writer
.
String
(
obj
.
storeInfo
.
vem_shelf
.
c_str
());
writer
.
EndObject
();
//----------------门店信息 结束-----------
//----------------配送信息----------------
writer
.
Key
(
"delivery"
);
writer
.
StartObject
();
writer
.
Key
(
"type"
);
writer
.
String
(
obj
.
deliveryInfo
.
type
.
c_str
());
writer
.
Key
(
"status"
);
writer
.
Int
(
obj
.
deliveryInfo
.
status
);
writer
.
Key
(
"status_desc"
);
writer
.
String
(
obj
.
deliveryInfo
.
status_desc
.
c_str
());
writer
.
Key
(
"driver_name"
);
writer
.
String
(
obj
.
deliveryInfo
.
driver_name
.
c_str
());
writer
.
Key
(
"driver_phone"
);
writer
.
String
(
obj
.
deliveryInfo
.
driver_phone
.
c_str
());
writer
.
EndObject
();
//----------------配送信息 结束-----------
//----------------顾客信息----------------
writer
.
Key
(
"customer"
);
writer
.
StartObject
();
writer
.
Key
(
"name"
);
writer
.
String
(
obj
.
customerInfo
.
name
.
c_str
());
writer
.
Key
(
"phone"
);
writer
.
String
(
obj
.
customerInfo
.
phone
.
c_str
());
writer
.
Key
(
"address"
);
writer
.
String
(
obj
.
customerInfo
.
address
.
c_str
());
writer
.
Key
(
"account"
);
writer
.
String
(
obj
.
customerInfo
.
account
.
c_str
());
writer
.
Key
(
"account_type"
);
writer
.
Int
(
obj
.
customerInfo
.
account_type
);
writer
.
Key
(
"account_level"
);
writer
.
String
(
obj
.
customerInfo
.
account_level
.
c_str
());
writer
.
EndObject
();
//----------------顾客信息 结束-----------
//----------------商品信息----------------
writer
.
Key
(
"products"
);
writer
.
StartArray
();
for
(
unsigned
int
i
=
0
;
i
<
obj
.
vecProducts
.
size
();
i
++
)
{
//-----------------start 单个商品------------------
writer
.
StartObject
();
writer
.
Key
(
"source"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
source
.
c_str
());
writer
.
Key
(
"attributes"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
attributes
.
c_str
());
writer
.
Key
(
"combo_id"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
combo_id
.
c_str
());
writer
.
Key
(
"bom_id"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
bom_id
.
c_str
());
writer
.
Key
(
"bag_id"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
bag_id
.
c_str
());
writer
.
Key
(
"name"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
name
.
c_str
());
writer
.
Key
(
"price"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
pro
.
price
);
writer
.
Key
(
"qty"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
pro
.
qty
);
writer
.
Key
(
"sku"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
sku
.
c_str
());
//-----------------start 商品规格------------------
writer
.
Key
(
"specs"
);
writer
.
StartArray
();
for
(
unsigned
int
j
=
0
;
j
<
obj
.
vecProducts
[
i
].
vecSpec
.
size
();
j
++
)
{
writer
.
StartObject
();
writer
.
Key
(
"name"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
vecSpec
[
j
].
name
.
c_str
());
writer
.
Key
(
"price"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
vecSpec
[
j
].
price
);
writer
.
Key
(
"qty"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
vecSpec
[
j
].
qty
);
writer
.
Key
(
"sku"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
vecSpec
[
j
].
sku
.
c_str
());
writer
.
EndObject
();
}
writer
.
EndArray
();
//-----------------end 商品规格--------------------
writer
.
EndObject
();
//-----------------end 单个商品------------------
}
writer
.
EndArray
();
//----------------商品信息 结束-----------
//----------------付款明细----------------
writer
.
Key
(
"payment"
);
writer
.
StartObject
();
writer
.
Key
(
"summary"
);
writer
.
String
(
obj
.
payInfo
.
summary
.
c_str
());
//-----------------start 付款详情------------------
writer
.
Key
(
"details"
);
writer
.
StartArray
();
for
(
unsigned
int
i
=
0
;
i
<
obj
.
payInfo
.
vecDetail
.
size
();
i
++
)
{
writer
.
StartObject
();
writer
.
Key
(
"amount"
);
writer
.
Int
(
obj
.
payInfo
.
vecDetail
[
i
].
amount
);
writer
.
Key
(
"type"
);
writer
.
Int
(
obj
.
payInfo
.
vecDetail
[
i
].
type
);
writer
.
Key
(
"trans_id"
);
writer
.
String
(
obj
.
payInfo
.
vecDetail
[
i
].
trans_id
.
c_str
());
writer
.
EndObject
();
}
writer
.
EndArray
();
//-----------------end 付款详情--------------------
writer
.
EndObject
();
//----------------付款明细 结束-----------
//----------------消费积分----------------
writer
.
Key
(
"bonus"
);
writer
.
StartObject
();
writer
.
Key
(
"summary"
);
writer
.
String
(
obj
.
bonusInfo
.
summary
.
c_str
());
//-----------------start 积分详情------------------
writer
.
Key
(
"details"
);
writer
.
StartArray
();
for
(
unsigned
int
i
=
0
;
i
<
obj
.
bonusInfo
.
vecDetail
.
size
();
i
++
)
{
writer
.
StartObject
();
writer
.
Key
(
"type"
);
writer
.
Int
(
obj
.
bonusInfo
.
vecDetail
[
i
].
type
);
writer
.
Key
(
"desc"
);
writer
.
String
(
obj
.
bonusInfo
.
vecDetail
[
i
].
desc
.
c_str
());
writer
.
Key
(
"point"
);
writer
.
Int
(
obj
.
bonusInfo
.
vecDetail
[
i
].
point
);
writer
.
Key
(
"sku"
);
writer
.
String
(
obj
.
bonusInfo
.
vecDetail
[
i
].
sku
.
c_str
());
writer
.
EndObject
();
}
writer
.
EndArray
();
//-----------------end 积分详情--------------------
writer
.
EndObject
();
//----------------消费积分 结束-----------
//----------------促销列表----------------
writer
.
Key
(
"promotions"
);
writer
.
StartObject
();
writer
.
Key
(
"summary"
);
writer
.
String
(
obj
.
promotionInfo
.
summary
.
c_str
());
//-----------------start 促销详情------------------
writer
.
Key
(
"details"
);
writer
.
StartArray
();
for
(
unsigned
int
i
=
0
;
i
<
obj
.
promotionInfo
.
vecDetail
.
size
();
i
++
)
{
writer
.
StartObject
();
writer
.
Key
(
"type"
);
writer
.
Int
(
obj
.
promotionInfo
.
vecDetail
[
i
].
type
);
writer
.
Key
(
"desc"
);
writer
.
String
(
obj
.
promotionInfo
.
vecDetail
[
i
].
desc
.
c_str
());
writer
.
Key
(
"offer"
);
writer
.
Int
(
obj
.
promotionInfo
.
vecDetail
[
i
].
offer
);
writer
.
Key
(
"sku"
);
writer
.
String
(
obj
.
promotionInfo
.
vecDetail
[
i
].
sku
.
c_str
());
writer
.
EndObject
();
}
writer
.
EndArray
();
//-----------------end 促销详情--------------------
writer
.
EndObject
();
//----------------促销列表 结束-----------
writer
.
EndObject
();
return
buffer
.
GetString
();
}
std
::
string
JsonModule
::
_convertToOrderStatusJson
(
orderStatusObj
&
obj
)
{
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartObject
();
writer
.
Key
(
"fm_cmd"
);
writer
.
Int
(
REQUEST_TYPE_STATUS_CHANGE
);
writer
.
Key
(
"order_id"
);
writer
.
String
(
obj
.
order_id
.
c_str
());
writer
.
Key
(
"order_status"
);
writer
.
Int
(
obj
.
order_status
);
writer
.
Key
(
"delivery_status"
);
writer
.
Int
(
obj
.
delivery_status
);
writer
.
EndObject
();
return
buffer
.
GetString
();
}
std
::
string
JsonModule
::
_convertToRefundJson
(
refundObj
&
obj
)
{
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartObject
();
writer
.
Key
(
"fm_cmd"
);
writer
.
Int
(
REQUEST_TYPE_REFUND
);
writer
.
Key
(
"channel"
);
writer
.
String
(
obj
.
channel
.
c_str
());
writer
.
Key
(
"order_id"
);
writer
.
String
(
obj
.
order_id
.
c_str
());
writer
.
Key
(
"refund_amount"
);
writer
.
Int
(
obj
.
refund_amount
);
//----------------商品信息----------------
writer
.
Key
(
"products"
);
writer
.
StartArray
();
for
(
unsigned
int
i
=
0
;
i
<
obj
.
vecProducts
.
size
();
i
++
)
{
//-----------------start 单个商品------------------
writer
.
StartObject
();
writer
.
Key
(
"source"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
source
.
c_str
());
writer
.
Key
(
"attributes"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
attributes
.
c_str
());
writer
.
Key
(
"combo_id"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
combo_id
.
c_str
());
writer
.
Key
(
"bom_id"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
bom_id
.
c_str
());
writer
.
Key
(
"bag_id"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
bag_id
.
c_str
());
writer
.
Key
(
"name"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
name
.
c_str
());
writer
.
Key
(
"price"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
pro
.
price
);
writer
.
Key
(
"qty"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
pro
.
qty
);
writer
.
Key
(
"sku"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
sku
.
c_str
());
//-----------------start 商品规格------------------
writer
.
Key
(
"specs"
);
writer
.
StartArray
();
for
(
unsigned
int
j
=
0
;
j
<
obj
.
vecProducts
[
i
].
vecSpec
.
size
();
j
++
)
{
writer
.
StartObject
();
writer
.
Key
(
"name"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
vecSpec
[
j
].
name
.
c_str
());
writer
.
Key
(
"price"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
vecSpec
[
j
].
price
);
writer
.
Key
(
"qty"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
vecSpec
[
j
].
qty
);
writer
.
Key
(
"sku"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
vecSpec
[
j
].
sku
.
c_str
());
writer
.
EndObject
();
}
writer
.
EndArray
();
//-----------------end 商品规格--------------------
writer
.
EndObject
();
//-----------------end 单个商品------------------
}
writer
.
EndArray
();
//----------------商品信息 结束-----------
writer
.
EndObject
();
return
buffer
.
GetString
();
}
std
::
string
JsonModule
::
_convertToStockWarnJson
(
stockWarnObj
&
obj
)
{
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartObject
();
writer
.
Key
(
"fm_cmd"
);
writer
.
Int
(
REQUEST_TYPE_STOCK_WARN
);
//----------------商品信息----------------
writer
.
Key
(
"products"
);
writer
.
StartArray
();
for
(
unsigned
int
i
=
0
;
i
<
obj
.
vecProducts
.
size
();
i
++
)
{
//-----------------start 单个商品------------------
writer
.
StartObject
();
writer
.
Key
(
"source"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
source
.
c_str
());
writer
.
Key
(
"attributes"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
attributes
.
c_str
());
writer
.
Key
(
"combo_id"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
combo_id
.
c_str
());
writer
.
Key
(
"bom_id"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
bom_id
.
c_str
());
writer
.
Key
(
"bag_id"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
bag_id
.
c_str
());
writer
.
Key
(
"name"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
name
.
c_str
());
writer
.
Key
(
"price"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
price
);
writer
.
Key
(
"stock"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
stock
);
writer
.
Key
(
"sku"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
sku
.
c_str
());
writer
.
EndObject
();
//-----------------end 单个商品------------------
}
writer
.
EndArray
();
//----------------商品信息 结束-----------
writer
.
EndObject
();
return
buffer
.
GetString
();
}
std
::
string
JsonModule
::
_getDeliveryTypeString
(
int
type
)
{
std
::
string
rlt
;
switch
(
type
)
{
case
ODS_DELIVERY_TYPE_SELF
:
rlt
=
DELIVERY_TYPE_SELF
;
break
;
case
ODS_DELIVERY_TYPE_PLATFORM
:
rlt
=
DELIVERY_TYPE_PLATFORM
;
break
;
default
:
break
;
}
return
rlt
;
}
int
JsonModule
::
_getPOSOrderStatus
(
int
status
)
{
int
rltStatus
=
0
;
switch
(
status
)
{
case
ODS_ORDERSTATUS_NEW
:
rltStatus
=
ORDERSTATUS_NEW
;
break
;
case
ODS_ORDERSTATUS_CONFIRMED
:
rltStatus
=
ORDERSTATUS_CONFIRMED
;
break
;
case
ODS_ORDERSTATUS_CANCELED
:
rltStatus
=
ORDERSTATUS_CANCELED
;
break
;
case
ODS_ORDERSTATUS_SHIPPING
:
rltStatus
=
ORDERSTATUS_SHIPPING
;
break
;
case
ODS_ORDERSTATUS_WAIT_SHIPPING
:
rltStatus
=
ORDERSTATUS_CONFIRMED
;
break
;
case
ODS_ORDERSTATUS_COMPLETE
:
rltStatus
=
ORDERSTATUS_COMPLETE
;
break
;
case
ODS_ORDERSTATUS_DONE
:
rltStatus
=
ORDERSTATUS_COMPLETE
;
break
;
case
ODS_ORDERSTATUS_REFUND_FULL
:
rltStatus
=
ORDERSTATUS_REFUND_FULL
;
break
;
case
ODS_ORDERSTATUS_REFUND_PART
:
rltStatus
=
ORDERSTATUS_REFUND_PART
;
break
;
case
ODS_ORDERSTATUS_REFUND_COMPLETE
:
rltStatus
=
ORDERSTATUS_REFUND_COMPLETE
;
break
;
default
:
break
;
}
return
rltStatus
;
}
void
JsonModule
::
_getStatusObj
(
IN
orderObj
&
order_obj
,
OUT
orderStatusObj
&
status_obj
)
{
status_obj
.
order_id
=
order_obj
.
order_id
;
status_obj
.
order_status
=
order_obj
.
status
;
status_obj
.
delivery_status
=
order_obj
.
deliveryInfo
.
status
;
}
void
JsonModule
::
_getRefundObj
(
IN
orderObj
&
order_obj
,
OUT
refundObj
&
refund_obj
)
{
refund_obj
.
order_id
=
order_obj
.
order_id
;
refund_obj
.
channel
=
order_obj
.
channel
;
refund_obj
.
refund_amount
=
order_obj
.
total_price
;
}
#include "JsonModule.h"
#include "../3rdParty/rapidjson/rapidjson.h"
#include "../3rdParty/rapidjson/document.h"
#include "../3rdParty/rapidjson/reader.h"
#include "../3rdParty/rapidjson/writer.h"
#include "../3rdParty/rapidjson/stringbuffer.h"
#include "../3rdParty/easylogging/easylogging++.h"
using
namespace
rapidjson
;
// std::string GetTestJson(const int statuscode,const char* msg,const char* orderid)
// {
// rapidjson::StringBuffer buffer;
// rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
// writer.StartObject();
// writer.Key("statusCode");
// writer.Int(statuscode);
// writer.Key("msg");
// writer.String(msg);
// writer.Key("orderid");
// writer.String(orderid);
// writer.EndObject();
// return buffer.GetString();
// }
// void parseJson(const char* json)
// {
// rapidjson::Document document; // 定义一个Document对象
// document.Parse(json); // 解析,Parse()无返回值,也不会抛异常
// if (document.HasParseError()) // 通过HasParseError()来判断解析是否成功
// {
// // 可通过GetParseError()取得出错代码,
// // 注意GetParseError()返回的是一个rapidjson::ParseErrorCode类型的枚举值
// // 使用函数rapidjson::GetParseError_En()得到错误码的字符串说明,这里的En为English简写
// // 函数GetErrorOffset()返回出错发生的位置
// LOG(ERROR)<<"JSON parse error:"<<document.GetParseError()<<":"<<document.GetErrorOffset();
// }
// else
// {
// rapidjson::Value& vStatusCode = document["statusCode"];
// rapidjson::Value& vMsg = document["msg"];
// rapidjson::Value& vOrderid = document["orderid"];
// int iStatusCode = vStatusCode.GetInt();
// std::string strMsg = vMsg.GetString();
// std::string strOrderid = vOrderid.GetString();
// LOG(INFO)<<"statusCode:"<<iStatusCode;
// LOG(INFO)<<"msg:"<<strMsg;
// LOG(INFO)<<"orderId:"<<strOrderid;
// }
// }
JsonModule
::
JsonModule
()
{
}
JsonModule
::~
JsonModule
()
{
}
bool
JsonModule
::
getPushOrders
(
IN
const
char
*
json
,
OUT
orderObj
&
order
)
{
rapidjson
::
Document
document
;
// 定义一个Document对象
document
.
Parse
(
json
);
// 解析,Parse()无返回值,也不会抛异常
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
{
// 可通过GetParseError()取得出错代码,
// 注意GetParseError()返回的是一个rapidjson::ParseErrorCode类型的枚举值
// 使用函数rapidjson::GetParseError_En()得到错误码的字符串说明,这里的En为English简写
// 函数GetErrorOffset()返回出错发生的位置
LOG
(
ERROR
)
<<
"JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
return
false
;
}
else
{
rapidjson
::
Value
&
channel
=
document
[
"channel"
];
order
.
channel
=
channel
.
GetString
();
rapidjson
::
Value
&
token
=
document
[
"token"
];
token
.
GetString
();
rapidjson
::
Value
&
ver
=
document
[
"ver"
];
ver
.
GetInt
();
//配送信息
{
rapidjson
::
Value
&
delivery_obj
=
document
[
"delivery"
];
rapidjson
::
Value
&
customerAddress
=
delivery_obj
[
"customerAddress"
];
order
.
customerInfo
.
address
=
customerAddress
.
GetString
();
rapidjson
::
Value
&
customerName
=
delivery_obj
[
"customerName"
];
order
.
customerInfo
.
name
=
customerName
.
GetString
();
rapidjson
::
Value
&
customerPhone
=
delivery_obj
[
"customerPhone"
];
order
.
customerInfo
.
phone
=
customerPhone
.
GetString
();
rapidjson
::
Value
&
deliveryTime
=
delivery_obj
[
"deliveryTime"
];
order
.
delivery_time
=
deliveryTime
.
GetString
();
rapidjson
::
Value
&
name
=
delivery_obj
[
"name"
];
order
.
deliveryInfo
.
driver_name
=
name
.
GetString
();
rapidjson
::
Value
&
phone
=
delivery_obj
[
"phone"
];
order
.
deliveryInfo
.
driver_phone
=
phone
.
GetString
();
rapidjson
::
Value
&
type
=
delivery_obj
[
"type"
];
order
.
deliveryInfo
.
type
=
type
.
GetString
();
}
//发票信息
{
rapidjson
::
Value
&
invoice_obj
=
document
[
"invoice"
];
rapidjson
::
Value
&
companyName
=
invoice_obj
[
"companyName"
];
companyName
.
GetString
();
rapidjson
::
Value
&
invoiceType
=
invoice_obj
[
"invoiceType"
];
invoiceType
.
GetInt
();
rapidjson
::
Value
&
taxNum
=
invoice_obj
[
"taxNum"
];
taxNum
.
GetString
();
rapidjson
::
Value
&
title
=
invoice_obj
[
"title"
];
title
.
GetString
();
rapidjson
::
Value
&
transNum
=
invoice_obj
[
"transNum"
];
transNum
.
GetString
();
}
//订单内容
{
rapidjson
::
Value
&
orderContent_obj
=
document
[
"orderContent"
];
rapidjson
::
Value
&
createTime
=
orderContent_obj
[
"createTime"
];
order
.
create_time
=
createTime
.
GetString
();
//用户信息
//TODO 顾客信息为数组 因接口改版目前只有一个顾客信息
rapidjson
::
Value
&
customer_array
=
orderContent_obj
[
"customer"
];
if
(
customer_array
.
IsArray
())
{
for
(
unsigned
int
i
=
0
;
i
<
customer_array
.
Size
();
i
++
){
rapidjson
::
Value
&
customer_obj
=
customer_array
[
i
];
rapidjson
::
Value
&
accountId
=
customer_obj
[
"accountId"
];
order
.
customerInfo
.
account
=
accountId
.
GetString
();
rapidjson
::
Value
&
accountType
=
customer_obj
[
"accountType"
];
order
.
customerInfo
.
account_type
=
atoi
(
accountType
.
GetString
());
rapidjson
::
Value
&
level
=
customer_obj
[
"level"
];
order
.
customerInfo
.
account_level
=
level
.
GetString
();
}
}
rapidjson
::
Value
&
deliveryFee
=
orderContent_obj
[
"deliveryFee"
];
order
.
delivery_price
=
deliveryFee
.
GetInt
();
//订单信息
{
rapidjson
::
Value
&
orders_obj
=
orderContent_obj
[
"orders"
];
rapidjson
::
Value
&
deliveryStatus
=
orders_obj
[
"deliveryStatus"
];
order
.
deliveryInfo
.
status
=
atoi
(
deliveryStatus
.
GetString
());
rapidjson
::
Value
&
deliveryStatusDesc
=
orders_obj
[
"deliveryStatusDesc"
];
order
.
deliveryInfo
.
status_desc
=
deliveryStatusDesc
.
GetString
();
rapidjson
::
Value
&
orderId
=
orders_obj
[
"orderId"
];
order
.
order_id
=
orderId
.
GetString
();
rapidjson
::
Value
&
pickupCode
=
orders_obj
[
"pickupCode"
];
order
.
pickup_code
=
pickupCode
.
GetString
();
rapidjson
::
Value
&
pickupPoint
=
orders_obj
[
"pickupPoint"
];
order
.
pickup_point
=
pickupPoint
.
GetString
();
rapidjson
::
Value
&
remark
=
orders_obj
[
"remark"
];
remark
.
GetString
();
rapidjson
::
Value
&
status
=
orders_obj
[
"status"
];
order
.
status
=
atoi
(
status
.
GetString
());
rapidjson
::
Value
&
statusDesc
=
orders_obj
[
"statusDesc"
];
order
.
status_desc
=
statusDesc
.
GetString
();
//订单商品
{
rapidjson
::
Value
&
products_array
=
orders_obj
[
"products"
];
if
(
products_array
.
IsArray
())
{
for
(
unsigned
int
i
=
0
;
i
<
products_array
.
Size
();
i
++
){
rapidjson
::
Value
&
product_obj
=
products_array
[
i
];
productAttr
structProduct
;
rapidjson
::
Value
&
attributes
=
product_obj
[
"attributes"
];
structProduct
.
pro
.
attributes
=
attributes
.
GetString
();
rapidjson
::
Value
&
catgId
=
product_obj
[
"catgId"
];
structProduct
.
pro
.
combo_id
=
catgId
.
GetString
();
rapidjson
::
Value
&
groupIndex
=
product_obj
[
"groupIndex"
];
structProduct
.
pro
.
bom_id
=
groupIndex
.
GetString
();
rapidjson
::
Value
&
name
=
product_obj
[
"name"
];
structProduct
.
pro
.
name
=
name
.
GetString
();
rapidjson
::
Value
&
price
=
product_obj
[
"price"
];
structProduct
.
pro
.
price
=
price
.
GetInt
();
rapidjson
::
Value
&
productType
=
product_obj
[
"productType"
];
productType
.
GetString
();
rapidjson
::
Value
&
qty
=
product_obj
[
"qty"
];
structProduct
.
pro
.
qty
=
qty
.
GetInt
();
rapidjson
::
Value
&
sku
=
product_obj
[
"sku"
];
structProduct
.
pro
.
sku
=
sku
.
GetString
();
rapidjson
::
Value
&
source
=
product_obj
[
"source"
];
structProduct
.
pro
.
source
=
source
.
GetString
();
//子商品信息
{
rapidjson
::
Value
&
specs_array
=
product_obj
[
"specs"
];
if
(
specs_array
.
IsArray
())
{
for
(
unsigned
int
i
=
0
;
i
<
specs_array
.
Size
();
i
++
){
rapidjson
::
Value
&
specs_obj
=
specs_array
[
i
];
productSpec
structProductSpec
;
rapidjson
::
Value
&
name
=
specs_obj
[
"name"
];
structProductSpec
.
name
=
name
.
GetString
();
rapidjson
::
Value
&
price
=
specs_obj
[
"price"
];
structProductSpec
.
price
=
price
.
GetInt
();
rapidjson
::
Value
&
qty
=
specs_obj
[
"qty"
];
structProductSpec
.
qty
=
qty
.
GetInt
();
rapidjson
::
Value
&
sku
=
specs_obj
[
"sku"
];
structProductSpec
.
sku
=
sku
.
GetString
();
structProduct
.
vecSpec
.
push_back
(
structProductSpec
);
}
}
}
order
.
vecProducts
.
push_back
(
structProduct
);
}
}
}
}
//支付信息
{
//TODO
//sumary未映射字段值
rapidjson
::
Value
&
payInfos_array
=
orderContent_obj
[
"payInfos"
];
if
(
payInfos_array
.
IsArray
())
{
for
(
unsigned
int
i
=
0
;
i
<
payInfos_array
.
Size
();
i
++
){
rapidjson
::
Value
&
payInfos_obj
=
payInfos_array
[
i
];
paymentDetail
detail
;
rapidjson
::
Value
&
amount
=
payInfos_obj
[
"amount"
];
detail
.
amount
=
amount
.
GetInt
();
rapidjson
::
Value
&
payType
=
payInfos_obj
[
"payType"
];
detail
.
type
=
atoi
(
payType
.
GetString
());
rapidjson
::
Value
&
transNum
=
payInfos_obj
[
"transNum"
];
detail
.
trans_id
=
transNum
.
GetString
();
order
.
payInfo
.
vecDetail
.
push_back
(
detail
);
}
}
}
rapidjson
::
Value
&
payType
=
orderContent_obj
[
"payType"
];
payType
.
GetString
();
//积分信息
{
rapidjson
::
Value
&
points_obj
=
orderContent_obj
[
"points"
];
rapidjson
::
Value
&
totalPoint
=
points_obj
[
"totalPoint"
];
char
temp
[
20
]
=
{
0
};
int
iPoint
=
totalPoint
.
GetInt
();
sprintf
(
temp
,
"%d"
,
iPoint
);
order
.
bonusInfo
.
summary
=
temp
;
//积分信息详情
{
rapidjson
::
Value
&
pointDetails_array
=
points_obj
[
"pointDetails"
];
if
(
pointDetails_array
.
IsArray
())
{
for
(
unsigned
int
i
=
0
;
i
<
pointDetails_array
.
Size
();
i
++
){
rapidjson
::
Value
&
pointDetails_obj
=
pointDetails_array
[
i
];
bonusDetail
detail
;
rapidjson
::
Value
&
bomId
=
pointDetails_obj
[
"bomId"
];
bomId
.
GetString
();
rapidjson
::
Value
&
comboId
=
pointDetails_obj
[
"comboId"
];
comboId
.
GetString
();
rapidjson
::
Value
&
desc
=
pointDetails_obj
[
"desc"
];
detail
.
desc
=
desc
.
GetString
();
rapidjson
::
Value
&
groupId
=
pointDetails_obj
[
"groupId"
];
groupId
.
GetString
();
rapidjson
::
Value
&
point
=
pointDetails_obj
[
"point"
];
detail
.
point
=
point
.
GetInt
();
rapidjson
::
Value
&
sku
=
pointDetails_obj
[
"sku"
];
detail
.
sku
=
sku
.
GetString
();
rapidjson
::
Value
&
type
=
pointDetails_obj
[
"type"
];
detail
.
type
=
atoi
(
type
.
GetString
());
order
.
bonusInfo
.
vecDetail
.
push_back
(
detail
);
}
}
}
}
//优惠信息
{
rapidjson
::
Value
&
promotions_obj
=
orderContent_obj
[
"promotions"
];
rapidjson
::
Value
&
totalDiscount
=
promotions_obj
[
"totalDiscount"
];
totalDiscount
.
GetInt
();
rapidjson
::
Value
&
totalOriginalPrice
=
promotions_obj
[
"totalOriginalPrice"
];
totalOriginalPrice
.
GetInt
();
rapidjson
::
Value
&
totalPrmotionPrice
=
promotions_obj
[
"totalPrmotionPrice"
];
totalPrmotionPrice
.
GetInt
();
//优惠信息详情
{
rapidjson
::
Value
&
promtionDetails_array
=
promotions_obj
[
"promtionDetails"
];
if
(
promtionDetails_array
.
IsArray
())
{
for
(
unsigned
int
i
=
0
;
i
<
promtionDetails_array
.
Size
();
i
++
){
rapidjson
::
Value
&
promtionDetails_obj
=
promtionDetails_array
[
i
];
rapidjson
::
Value
&
bomId
=
promtionDetails_obj
[
"bomId"
];
bomId
.
GetString
();
rapidjson
::
Value
&
comboId
=
promtionDetails_obj
[
"comboId"
];
comboId
.
GetString
();
rapidjson
::
Value
&
desc
=
promtionDetails_obj
[
"desc"
];
desc
.
GetString
();
rapidjson
::
Value
&
discount
=
promtionDetails_obj
[
"discount"
];
discount
.
GetInt
();
rapidjson
::
Value
&
groupId
=
promtionDetails_obj
[
"groupId"
];
groupId
.
GetString
();
rapidjson
::
Value
&
originalPrice
=
promtionDetails_obj
[
"originalPrice"
];
originalPrice
.
GetInt
();
rapidjson
::
Value
&
pcode
=
promtionDetails_obj
[
"pcode"
];
pcode
.
GetString
();
rapidjson
::
Value
&
prmotionPrice
=
promtionDetails_obj
[
"prmotionPrice"
];
prmotionPrice
.
GetInt
();
rapidjson
::
Value
&
sku
=
promtionDetails_obj
[
"sku"
];
sku
.
GetString
();
rapidjson
::
Value
&
type
=
promtionDetails_obj
[
"type"
];
type
.
GetString
();
}
}
}
}
rapidjson
::
Value
&
sessionId
=
orderContent_obj
[
"sessionId"
];
sessionId
.
GetString
();
rapidjson
::
Value
&
totalAmount
=
orderContent_obj
[
"totalAmount"
];
order
.
total_price
=
totalAmount
.
GetInt
();
rapidjson
::
Value
&
totalDiscount
=
orderContent_obj
[
"totalDiscount"
];
order
.
reduced_price
=
totalDiscount
.
GetInt
();
}
//第三方商户信息
{
rapidjson
::
Value
&
sellerInfo_obj
=
document
[
"sellerInfo"
];
rapidjson
::
Value
&
sellerId
=
sellerInfo_obj
[
"sellerId"
];
sellerId
.
GetString
();
rapidjson
::
Value
&
sellerName
=
sellerInfo_obj
[
"sellerName"
];
sellerName
.
GetString
();
}
//门店信息
{
rapidjson
::
Value
&
shopInfo_obj
=
document
[
"shopInfo"
];
rapidjson
::
Value
&
barCounter
=
shopInfo_obj
[
"barCounter"
];
barCounter
.
GetString
();
rapidjson
::
Value
&
vOperator
=
shopInfo_obj
[
"operator"
];
vOperator
.
GetString
();
rapidjson
::
Value
&
posId
=
shopInfo_obj
[
"posId"
];
order
.
storeInfo
.
pos_id
=
posId
.
GetString
();
rapidjson
::
Value
&
storeId
=
shopInfo_obj
[
"storeId"
];
order
.
storeInfo
.
store_id
=
storeId
.
GetString
();
//自助机信息
rapidjson
::
Value
&
selfHelpMac_obj
=
shopInfo_obj
[
"selfHelpMac"
];
rapidjson
::
Value
&
id
=
selfHelpMac_obj
[
"id"
];
order
.
storeInfo
.
vem_id
=
id
.
GetString
();
rapidjson
::
Value
&
shelf
=
selfHelpMac_obj
[
"shelf"
];
order
.
storeInfo
.
vem_shelf
=
shelf
.
GetString
();
}
}
return
true
;
}
bool
JsonModule
::
isInitData
(
const
std
::
string
&
data
)
{
rapidjson
::
Document
document
;
// 定义一个Document对象
document
.
Parse
(
data
.
c_str
());
// 解析,Parse()无返回值,也不会抛异常
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
{
LOG
(
ERROR
)
<<
"JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
return
false
;
}
return
document
[
"fm_cmd"
].
GetInt
()
==
1000
;
}
bool
JsonModule
::
checkInitData
(
const
std
::
string
&
data
,
int
&
posListenPort
)
{
rapidjson
::
Document
document
;
// 定义一个Document对象
document
.
Parse
(
data
.
c_str
());
// 解析,Parse()无返回值,也不会抛异常
if
(
document
.
HasParseError
())
// 通过HasParseError()来判断解析是否成功
{
LOG
(
ERROR
)
<<
"JSON parse error:"
<<
document
.
GetParseError
()
<<
":"
<<
document
.
GetErrorOffset
();
return
false
;
}
if
(
!
document
.
HasMember
(
"store_id"
)
||
!
document
.
HasMember
(
"pos_id"
)
||
!
document
.
HasMember
(
"operator_id"
)
||
!
document
.
HasMember
(
"is_master"
)
||
document
[
"listen_port"
].
GetInt
()
<
0
)
{
return
false
;
}
posListenPort
=
document
[
"listen_port"
].
GetInt
();
return
true
;
}
bool
JsonModule
::
getPosResponseData
(
int
status
,
const
std
::
string
&
msg
,
std
::
string
&
result
)
{
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartObject
();
writer
.
Key
(
"status_code"
);
writer
.
Int
(
status
);
writer
.
Key
(
"msg"
);
writer
.
String
(
msg
.
c_str
());
writer
.
EndObject
();
result
=
buffer
.
GetString
();
return
true
;
}
bool
JsonModule
::
getPosResponseData
(
const
std
::
string
&
odsResponse
,
std
::
string
&
result
)
{
result
=
"{
\"
status_code
\"
:100,
\"
msg
\"
:
\"\"
}"
;
return
true
;
}
bool
JsonModule
::
getOdsResponseData
(
int
status_code
,
const
std
::
string
&
msg
,
std
::
string
&
result
)
{
/*
{
"type" : 2,
"order_id" : "xxxxx",
"status" : 1,
"status_code" : 100,
"msg" : "接收订单成功"
}
*/
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartObject
();
writer
.
Key
(
"type"
);
writer
.
Int
(
2
);
writer
.
Key
(
"order_id"
);
writer
.
String
(
""
);
writer
.
Key
(
"status"
);
writer
.
Int
(
0
);
writer
.
Key
(
"status_code"
);
writer
.
Int
(
status_code
);
writer
.
Key
(
"msg"
);
writer
.
String
(
msg
.
c_str
());
writer
.
EndObject
();
result
=
buffer
.
GetString
();
return
true
;
}
bool
JsonModule
::
getOdsResponseData
(
const
std
::
string
&
posResponse
,
const
std
::
string
&
orderData
,
std
::
string
&
result
)
{
int
status_code
;
std
::
string
msg
;
std
::
string
order_id
;
int
status
;
if
(
posResponse
.
empty
()
||
orderData
.
empty
()
)
return
false
;
rapidjson
::
Document
document
,
document1
;
document
.
Parse
(
posResponse
.
c_str
());
document1
.
Parse
(
orderData
.
c_str
());
if
(
document
.
HasParseError
()
||
document1
.
HasParseError
())
{
return
false
;
}
if
(
!
document
.
HasMember
(
"status_code"
)
||
!
document1
.
HasMember
(
"order_id"
)
||
!
document1
.
HasMember
(
"status"
)
)
{
return
false
;
}
status_code
=
document
[
"status_code"
].
GetInt
();
msg
=
document
[
"msg"
].
GetString
();
order_id
=
document1
[
"order_id"
].
GetString
();
status
=
document1
[
"status"
].
GetInt
();
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartObject
();
writer
.
Key
(
"type"
);
writer
.
Int
(
2
);
writer
.
Key
(
"order_id"
);
writer
.
String
(
order_id
.
c_str
());
writer
.
Key
(
"status"
);
writer
.
Int
(
status
);
writer
.
Key
(
"status_code"
);
writer
.
Int
(
status_code
);
writer
.
Key
(
"msg"
);
writer
.
String
(
msg
.
c_str
());
writer
.
EndObject
();
result
=
buffer
.
GetString
();
return
true
;
}
bool
JsonModule
::
convertDataPos2Ods
(
const
std
::
string
&
data
,
std
::
string
&
result
)
{
return
true
;
}
bool
JsonModule
::
convertDataOds2Pos
(
const
std
::
string
&
data
,
std
::
string
&
result
)
{
bool
rlt
=
true
;
orderObj
order
;
rlt
=
getPushOrders
(
data
.
c_str
(),
order
);
if
(
ORDERSTATUS_NEW
==
order
.
status
){
result
=
_convertToNewOrderJson
(
order
);
}
else
if
(
ORDERSTATUS_CONFIRMED
==
order
.
status
||
ORDERSTATUS_CANCELED
==
order
.
status
||
ORDERSTATUS_SHIPPING
==
order
.
status
||
ORDERSTATUS_COMPLETE
==
order
.
status
){
orderStatusObj
statusObj
;
_getStatusObj
(
order
,
statusObj
);
result
=
_convertToOrderStatusJson
(
statusObj
);
}
else
if
(
ORDERSTATUS_REFUND_FULL
==
order
.
status
||
ORDERSTATUS_REFUND_PART
==
order
.
status
){
refundObj
refund
;
_getRefundObj
(
order
,
refund
);
result
=
_convertToRefundJson
(
refund
);
}
return
rlt
;
}
std
::
string
JsonModule
::
_convertToNewOrderJson
(
orderObj
&
obj
)
{
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartObject
();
writer
.
Key
(
"fm_cmd"
);
writer
.
Int
(
REQUEST_TYPE_NEWORDER_PUSH
);
writer
.
Key
(
"channel"
);
writer
.
String
(
obj
.
channel
.
c_str
());
writer
.
Key
(
"order_no"
);
writer
.
Int
(
obj
.
order_no
);
writer
.
Key
(
"order_id"
);
writer
.
String
(
obj
.
order_id
.
c_str
());
writer
.
Key
(
"create_time"
);
writer
.
String
(
obj
.
create_time
.
c_str
());
writer
.
Key
(
"delivery_time"
);
writer
.
String
(
obj
.
delivery_time
.
c_str
());
writer
.
Key
(
"status"
);
writer
.
Int
(
obj
.
status
);
writer
.
Key
(
"status_desc"
);
writer
.
String
(
obj
.
status_desc
.
c_str
());
writer
.
Key
(
"total_price"
);
writer
.
Int
(
obj
.
total_price
);
writer
.
Key
(
"delivery_price"
);
writer
.
Int
(
obj
.
delivery_price
);
writer
.
Key
(
"reduced_price"
);
writer
.
Int
(
obj
.
reduced_price
);
writer
.
Key
(
"pickup_code"
);
writer
.
String
(
obj
.
pickup_code
.
c_str
());
writer
.
Key
(
"pickup_point"
);
writer
.
String
(
obj
.
pickup_point
.
c_str
());
//----------------门店信息----------------
writer
.
Key
(
"store"
);
writer
.
StartObject
();
writer
.
Key
(
"store_id"
);
writer
.
String
(
obj
.
storeInfo
.
store_id
.
c_str
());
writer
.
Key
(
"pos_id"
);
writer
.
String
(
obj
.
storeInfo
.
pos_id
.
c_str
());
writer
.
Key
(
"vem_id"
);
writer
.
String
(
obj
.
storeInfo
.
vem_id
.
c_str
());
writer
.
Key
(
"vem_shelf"
);
writer
.
String
(
obj
.
storeInfo
.
vem_shelf
.
c_str
());
writer
.
EndObject
();
//----------------门店信息 结束-----------
//----------------配送信息----------------
writer
.
Key
(
"delivery"
);
writer
.
StartObject
();
writer
.
Key
(
"type"
);
writer
.
String
(
obj
.
deliveryInfo
.
type
.
c_str
());
writer
.
Key
(
"status"
);
writer
.
Int
(
obj
.
deliveryInfo
.
status
);
writer
.
Key
(
"status_desc"
);
writer
.
String
(
obj
.
deliveryInfo
.
status_desc
.
c_str
());
writer
.
Key
(
"driver_name"
);
writer
.
String
(
obj
.
deliveryInfo
.
driver_name
.
c_str
());
writer
.
Key
(
"driver_phone"
);
writer
.
String
(
obj
.
deliveryInfo
.
driver_phone
.
c_str
());
writer
.
EndObject
();
//----------------配送信息 结束-----------
//----------------顾客信息----------------
writer
.
Key
(
"customer"
);
writer
.
StartObject
();
writer
.
Key
(
"name"
);
writer
.
String
(
obj
.
customerInfo
.
name
.
c_str
());
writer
.
Key
(
"phone"
);
writer
.
String
(
obj
.
customerInfo
.
phone
.
c_str
());
writer
.
Key
(
"address"
);
writer
.
String
(
obj
.
customerInfo
.
address
.
c_str
());
writer
.
Key
(
"account"
);
writer
.
String
(
obj
.
customerInfo
.
account
.
c_str
());
writer
.
Key
(
"account_type"
);
writer
.
Int
(
obj
.
customerInfo
.
account_type
);
writer
.
Key
(
"account_level"
);
writer
.
String
(
obj
.
customerInfo
.
account_level
.
c_str
());
writer
.
EndObject
();
//----------------顾客信息 结束-----------
//----------------商品信息----------------
writer
.
Key
(
"products"
);
writer
.
StartArray
();
for
(
unsigned
int
i
=
0
;
i
<
obj
.
vecProducts
.
size
();
i
++
)
{
//-----------------start 单个商品------------------
writer
.
StartObject
();
writer
.
Key
(
"source"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
source
.
c_str
());
writer
.
Key
(
"attributes"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
attributes
.
c_str
());
writer
.
Key
(
"combo_id"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
combo_id
.
c_str
());
writer
.
Key
(
"bom_id"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
bom_id
.
c_str
());
writer
.
Key
(
"bag_id"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
bag_id
.
c_str
());
writer
.
Key
(
"name"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
name
.
c_str
());
writer
.
Key
(
"price"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
pro
.
price
);
writer
.
Key
(
"qty"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
pro
.
qty
);
writer
.
Key
(
"sku"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
sku
.
c_str
());
//-----------------start 商品规格------------------
writer
.
Key
(
"specs"
);
writer
.
StartArray
();
for
(
unsigned
int
j
=
0
;
j
<
obj
.
vecProducts
[
i
].
vecSpec
.
size
();
j
++
)
{
writer
.
StartObject
();
writer
.
Key
(
"name"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
vecSpec
[
j
].
name
.
c_str
());
writer
.
Key
(
"price"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
vecSpec
[
j
].
price
);
writer
.
Key
(
"qty"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
vecSpec
[
j
].
qty
);
writer
.
Key
(
"sku"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
vecSpec
[
j
].
sku
.
c_str
());
writer
.
EndObject
();
}
writer
.
EndArray
();
//-----------------end 商品规格--------------------
writer
.
EndObject
();
//-----------------end 单个商品------------------
}
writer
.
EndArray
();
//----------------商品信息 结束-----------
//----------------付款明细----------------
writer
.
Key
(
"payment"
);
writer
.
StartObject
();
writer
.
Key
(
"summary"
);
writer
.
String
(
obj
.
payInfo
.
summary
.
c_str
());
//-----------------start 付款详情------------------
writer
.
Key
(
"details"
);
writer
.
StartArray
();
for
(
unsigned
int
i
=
0
;
i
<
obj
.
payInfo
.
vecDetail
.
size
();
i
++
)
{
writer
.
StartObject
();
writer
.
Key
(
"amount"
);
writer
.
Int
(
obj
.
payInfo
.
vecDetail
[
i
].
amount
);
writer
.
Key
(
"type"
);
writer
.
Int
(
obj
.
payInfo
.
vecDetail
[
i
].
type
);
writer
.
Key
(
"trans_id"
);
writer
.
String
(
obj
.
payInfo
.
vecDetail
[
i
].
trans_id
.
c_str
());
writer
.
EndObject
();
}
writer
.
EndArray
();
//-----------------end 付款详情--------------------
writer
.
EndObject
();
//----------------付款明细 结束-----------
//----------------消费积分----------------
writer
.
Key
(
"bonus"
);
writer
.
StartObject
();
writer
.
Key
(
"summary"
);
writer
.
String
(
obj
.
bonusInfo
.
summary
.
c_str
());
//-----------------start 积分详情------------------
writer
.
Key
(
"details"
);
writer
.
StartArray
();
for
(
unsigned
int
i
=
0
;
i
<
obj
.
bonusInfo
.
vecDetail
.
size
();
i
++
)
{
writer
.
StartObject
();
writer
.
Key
(
"type"
);
writer
.
Int
(
obj
.
bonusInfo
.
vecDetail
[
i
].
type
);
writer
.
Key
(
"desc"
);
writer
.
String
(
obj
.
bonusInfo
.
vecDetail
[
i
].
desc
.
c_str
());
writer
.
Key
(
"point"
);
writer
.
Int
(
obj
.
bonusInfo
.
vecDetail
[
i
].
point
);
writer
.
Key
(
"sku"
);
writer
.
String
(
obj
.
bonusInfo
.
vecDetail
[
i
].
sku
.
c_str
());
writer
.
EndObject
();
}
writer
.
EndArray
();
//-----------------end 积分详情--------------------
writer
.
EndObject
();
//----------------消费积分 结束-----------
//----------------促销列表----------------
writer
.
Key
(
"promotions"
);
writer
.
StartObject
();
writer
.
Key
(
"summary"
);
writer
.
String
(
obj
.
promotionInfo
.
summary
.
c_str
());
//-----------------start 促销详情------------------
writer
.
Key
(
"details"
);
writer
.
StartArray
();
for
(
unsigned
int
i
=
0
;
i
<
obj
.
promotionInfo
.
vecDetail
.
size
();
i
++
)
{
writer
.
StartObject
();
writer
.
Key
(
"type"
);
writer
.
Int
(
obj
.
promotionInfo
.
vecDetail
[
i
].
type
);
writer
.
Key
(
"desc"
);
writer
.
String
(
obj
.
promotionInfo
.
vecDetail
[
i
].
desc
.
c_str
());
writer
.
Key
(
"offer"
);
writer
.
Int
(
obj
.
promotionInfo
.
vecDetail
[
i
].
offer
);
writer
.
Key
(
"sku"
);
writer
.
String
(
obj
.
promotionInfo
.
vecDetail
[
i
].
sku
.
c_str
());
writer
.
EndObject
();
}
writer
.
EndArray
();
//-----------------end 促销详情--------------------
writer
.
EndObject
();
//----------------促销列表 结束-----------
writer
.
EndObject
();
return
buffer
.
GetString
();
}
std
::
string
JsonModule
::
_convertToOrderStatusJson
(
orderStatusObj
&
obj
)
{
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartObject
();
writer
.
Key
(
"fm_cmd"
);
writer
.
Int
(
REQUEST_TYPE_STATUS_CHANGE
);
writer
.
Key
(
"order_id"
);
writer
.
String
(
obj
.
order_id
.
c_str
());
writer
.
Key
(
"order_status"
);
writer
.
Int
(
obj
.
order_status
);
writer
.
Key
(
"delivery_status"
);
writer
.
Int
(
obj
.
delivery_status
);
writer
.
EndObject
();
return
buffer
.
GetString
();
}
std
::
string
JsonModule
::
_convertToRefundJson
(
refundObj
&
obj
)
{
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartObject
();
writer
.
Key
(
"fm_cmd"
);
writer
.
Int
(
REQUEST_TYPE_REFUND
);
writer
.
Key
(
"channel"
);
writer
.
String
(
obj
.
channel
.
c_str
());
writer
.
Key
(
"order_id"
);
writer
.
String
(
obj
.
order_id
.
c_str
());
writer
.
Key
(
"refund_amount"
);
writer
.
Int
(
obj
.
refund_amount
);
//----------------商品信息----------------
writer
.
Key
(
"products"
);
writer
.
StartArray
();
for
(
unsigned
int
i
=
0
;
i
<
obj
.
vecProducts
.
size
();
i
++
)
{
//-----------------start 单个商品------------------
writer
.
StartObject
();
writer
.
Key
(
"source"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
source
.
c_str
());
writer
.
Key
(
"attributes"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
attributes
.
c_str
());
writer
.
Key
(
"combo_id"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
combo_id
.
c_str
());
writer
.
Key
(
"bom_id"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
bom_id
.
c_str
());
writer
.
Key
(
"bag_id"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
bag_id
.
c_str
());
writer
.
Key
(
"name"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
name
.
c_str
());
writer
.
Key
(
"price"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
pro
.
price
);
writer
.
Key
(
"qty"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
pro
.
qty
);
writer
.
Key
(
"sku"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
pro
.
sku
.
c_str
());
//-----------------start 商品规格------------------
writer
.
Key
(
"specs"
);
writer
.
StartArray
();
for
(
unsigned
int
j
=
0
;
j
<
obj
.
vecProducts
[
i
].
vecSpec
.
size
();
j
++
)
{
writer
.
StartObject
();
writer
.
Key
(
"name"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
vecSpec
[
j
].
name
.
c_str
());
writer
.
Key
(
"price"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
vecSpec
[
j
].
price
);
writer
.
Key
(
"qty"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
vecSpec
[
j
].
qty
);
writer
.
Key
(
"sku"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
vecSpec
[
j
].
sku
.
c_str
());
writer
.
EndObject
();
}
writer
.
EndArray
();
//-----------------end 商品规格--------------------
writer
.
EndObject
();
//-----------------end 单个商品------------------
}
writer
.
EndArray
();
//----------------商品信息 结束-----------
writer
.
EndObject
();
return
buffer
.
GetString
();
}
std
::
string
JsonModule
::
_convertToStockWarnJson
(
stockWarnObj
&
obj
)
{
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartObject
();
writer
.
Key
(
"fm_cmd"
);
writer
.
Int
(
REQUEST_TYPE_STOCK_WARN
);
//----------------商品信息----------------
writer
.
Key
(
"products"
);
writer
.
StartArray
();
for
(
unsigned
int
i
=
0
;
i
<
obj
.
vecProducts
.
size
();
i
++
)
{
//-----------------start 单个商品------------------
writer
.
StartObject
();
writer
.
Key
(
"source"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
source
.
c_str
());
writer
.
Key
(
"attributes"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
attributes
.
c_str
());
writer
.
Key
(
"combo_id"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
combo_id
.
c_str
());
writer
.
Key
(
"bom_id"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
bom_id
.
c_str
());
writer
.
Key
(
"bag_id"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
bag_id
.
c_str
());
writer
.
Key
(
"name"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
name
.
c_str
());
writer
.
Key
(
"price"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
price
);
writer
.
Key
(
"stock"
);
writer
.
Int
(
obj
.
vecProducts
[
i
].
stock
);
writer
.
Key
(
"sku"
);
writer
.
String
(
obj
.
vecProducts
[
i
].
sku
.
c_str
());
writer
.
EndObject
();
//-----------------end 单个商品------------------
}
writer
.
EndArray
();
//----------------商品信息 结束-----------
writer
.
EndObject
();
return
buffer
.
GetString
();
}
std
::
string
JsonModule
::
_getDeliveryTypeString
(
int
type
)
{
std
::
string
rlt
;
switch
(
type
)
{
case
ODS_DELIVERY_TYPE_SELF
:
rlt
=
DELIVERY_TYPE_SELF
;
break
;
case
ODS_DELIVERY_TYPE_PLATFORM
:
rlt
=
DELIVERY_TYPE_PLATFORM
;
break
;
default
:
break
;
}
return
rlt
;
}
int
JsonModule
::
_getPOSOrderStatus
(
int
status
)
{
int
rltStatus
=
0
;
switch
(
status
)
{
case
ODS_ORDERSTATUS_NEW
:
rltStatus
=
ORDERSTATUS_NEW
;
break
;
case
ODS_ORDERSTATUS_CONFIRMED
:
rltStatus
=
ORDERSTATUS_CONFIRMED
;
break
;
case
ODS_ORDERSTATUS_CANCELED
:
rltStatus
=
ORDERSTATUS_CANCELED
;
break
;
case
ODS_ORDERSTATUS_SHIPPING
:
rltStatus
=
ORDERSTATUS_SHIPPING
;
break
;
case
ODS_ORDERSTATUS_WAIT_SHIPPING
:
rltStatus
=
ORDERSTATUS_CONFIRMED
;
break
;
case
ODS_ORDERSTATUS_COMPLETE
:
rltStatus
=
ORDERSTATUS_COMPLETE
;
break
;
case
ODS_ORDERSTATUS_DONE
:
rltStatus
=
ORDERSTATUS_COMPLETE
;
break
;
case
ODS_ORDERSTATUS_REFUND_FULL
:
rltStatus
=
ORDERSTATUS_REFUND_FULL
;
break
;
case
ODS_ORDERSTATUS_REFUND_PART
:
rltStatus
=
ORDERSTATUS_REFUND_PART
;
break
;
case
ODS_ORDERSTATUS_REFUND_COMPLETE
:
rltStatus
=
ORDERSTATUS_REFUND_COMPLETE
;
break
;
default
:
break
;
}
return
rltStatus
;
}
void
JsonModule
::
_getStatusObj
(
IN
orderObj
&
order_obj
,
OUT
orderStatusObj
&
status_obj
)
{
status_obj
.
order_id
=
order_obj
.
order_id
;
status_obj
.
order_status
=
order_obj
.
status
;
status_obj
.
delivery_status
=
order_obj
.
deliveryInfo
.
status
;
}
void
JsonModule
::
_getRefundObj
(
IN
orderObj
&
order_obj
,
OUT
refundObj
&
refund_obj
)
{
refund_obj
.
order_id
=
order_obj
.
order_id
;
refund_obj
.
channel
=
order_obj
.
channel
;
refund_obj
.
refund_amount
=
order_obj
.
total_price
;
}
src/JsonModule.h
View file @
d28fc2cc
#ifndef JSON_MODULE_H
#define JSON_MODULE_H
#include "../base/CommonStruct.h"
#include "../base/BaseDefine.h"
//std::string GetTestJson(const int statuscode,const char* msg,const char* orderid);
//void parseJson(const char* json);
class
JsonModule
{
public
:
JsonModule
();
~
JsonModule
();
bool
getPushOrders
(
IN
const
char
*
json
,
OUT
orderObj
&
order
);
/* 功能:判断是否是初始化数据
* 参数:[1]待判断数据
* 返回:...
* */
bool
isInitData
(
IN
const
std
::
string
&
data
);
/* 功能:检查初始化数据是否可用
* 参数:[1]待检查数据[2]POS监听端口
* 返回:是否正确格式
* */
bool
checkInitData
(
IN
const
std
::
string
&
data
,
OUT
int
&
posListenPort
);
/* 功能:获取POS请求的返回数据
* 参数:[1]状态码[2]消息[3]转换后数据
* 重载:[1]ODS返回数据[2]转换后数据
* 返回:是否转换成功
* */
bool
getPosResponseData
(
IN
int
status
,
IN
const
std
::
string
&
msg
,
OUT
std
::
string
&
result
);
bool
getPosResponseData
(
IN
const
std
::
string
&
odsResponse
,
OUT
std
::
string
&
result
);
/* 功能:获取ODS推送的返回数据
* 参数:[1]状态码[2]消息[3]转换后数据
* 重载:[1]POS返回数据[2]订单数据[3]转换后数据
* 返回:是否转换成功
* */
bool
getOdsResponseData
(
IN
int
status_code
,
IN
const
std
::
string
&
msg
,
OUT
std
::
string
&
result
);
bool
getOdsResponseData
(
IN
const
std
::
string
&
posResponse
,
IN
const
std
::
string
&
orderData
,
OUT
std
::
string
&
result
);
/* 功能:转换POS数据格式到中台数据格式
* 参数:[1]POS数据格式[2]转换后数据
* 返回:是否转换成功
* */
bool
convertDataPos2Ods
(
IN
const
std
::
string
&
data
,
OUT
std
::
string
&
result
);
/* 功能:转换中台数据格式到POS数据格式
* 参数:[1]中台数据格式[2]转换后数据
* 返回:是否转换成功
* */
bool
convertDataOds2Pos
(
IN
const
std
::
string
&
data
,
OUT
std
::
string
&
result
);
private
:
std
::
string
_getDeliveryTypeString
(
int
type
);
//订单状态转换(转换为POS对应的状态)
int
_getPOSOrderStatus
(
int
status
);
void
_getStatusObj
(
IN
orderObj
&
order_obj
,
OUT
orderStatusObj
&
status_obj
);
void
_getRefundObj
(
IN
orderObj
&
order_obj
,
OUT
refundObj
&
refund_obj
);
std
::
string
_convertToNewOrderJson
(
orderObj
&
obj
);
std
::
string
_convertToOrderStatusJson
(
orderStatusObj
&
obj
);
std
::
string
_convertToRefundJson
(
refundObj
&
obj
);
std
::
string
_convertToStockWarnJson
(
stockWarnObj
&
obj
);
};
#endif
#ifndef JSON_MODULE_H
#define JSON_MODULE_H
#include <stdlib.h>
#include <stdio.h>
#include "../base/CommonStruct.h"
#include "../base/BaseDefine.h"
//std::string GetTestJson(const int statuscode,const char* msg,const char* orderid);
//void parseJson(const char* json);
class
JsonModule
{
public
:
JsonModule
();
~
JsonModule
();
bool
getPushOrders
(
IN
const
char
*
json
,
OUT
orderObj
&
order
);
/* 功能:判断是否是初始化数据
* 参数:[1]待判断数据
* 返回:...
* */
bool
isInitData
(
IN
const
std
::
string
&
data
);
/* 功能:检查初始化数据是否可用
* 参数:[1]待检查数据[2]POS监听端口
* 返回:是否正确格式
* */
bool
checkInitData
(
IN
const
std
::
string
&
data
,
OUT
int
&
posListenPort
);
/* 功能:获取POS请求的返回数据
* 参数:[1]状态码[2]消息[3]转换后数据
* 重载:[1]ODS返回数据[2]转换后数据
* 返回:是否转换成功
* */
bool
getPosResponseData
(
IN
int
status
,
IN
const
std
::
string
&
msg
,
OUT
std
::
string
&
result
);
bool
getPosResponseData
(
IN
const
std
::
string
&
odsResponse
,
OUT
std
::
string
&
result
);
/* 功能:获取ODS推送的返回数据
* 参数:[1]状态码[2]消息[3]转换后数据
* 重载:[1]POS返回数据[2]订单数据[3]转换后数据
* 返回:是否转换成功
* */
bool
getOdsResponseData
(
IN
int
status_code
,
IN
const
std
::
string
&
msg
,
OUT
std
::
string
&
result
);
bool
getOdsResponseData
(
IN
const
std
::
string
&
posResponse
,
IN
const
std
::
string
&
orderData
,
OUT
std
::
string
&
result
);
/* 功能:转换POS数据格式到中台数据格式
* 参数:[1]POS数据格式[2]转换后数据
* 返回:是否转换成功
* */
bool
convertDataPos2Ods
(
IN
const
std
::
string
&
data
,
OUT
std
::
string
&
result
);
/* 功能:转换中台数据格式到POS数据格式
* 参数:[1]中台数据格式[2]转换后数据
* 返回:是否转换成功
* */
bool
convertDataOds2Pos
(
IN
const
std
::
string
&
data
,
OUT
std
::
string
&
result
);
private
:
std
::
string
_getDeliveryTypeString
(
int
type
);
//订单状态转换(转换为POS对应的状态)
int
_getPOSOrderStatus
(
int
status
);
void
_getStatusObj
(
IN
orderObj
&
order_obj
,
OUT
orderStatusObj
&
status_obj
);
void
_getRefundObj
(
IN
orderObj
&
order_obj
,
OUT
refundObj
&
refund_obj
);
std
::
string
_convertToNewOrderJson
(
orderObj
&
obj
);
std
::
string
_convertToOrderStatusJson
(
orderStatusObj
&
obj
);
std
::
string
_convertToRefundJson
(
refundObj
&
obj
);
std
::
string
_convertToStockWarnJson
(
stockWarnObj
&
obj
);
};
#endif
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