Commit e40833f5 by guanghui.cui

增加订单接口:订单确认,订单取消

parent e0484b4f
......@@ -54,6 +54,9 @@
#define RESPONSE_CODE_SUCCESS 100 //成功
#define RESPONSE_CODE_FAILED 101 //失败
//POS操作类型
#define OPERATION_POS_CONFIRM 1011 //确认接单
#define OPERATION_POS_CANCEL 1012 //拒绝接单
/***********************************
ODS相关预定义变量
......
......@@ -163,10 +163,27 @@ struct refundObj
std::vector<productAttr> vecProducts; //商品数组
};
//库存预警
struct stockWarnObj
{
int fm_cmd=0; //请求类型(1006)
std::vector<product> vecProducts; //商品数组
};
//POS订单处理请求
struct orderOperationObj
{
int fm_cmd=0; //请求类型 •1011 确认接单 •1012 拒绝接单
std::string order_id; //订单编号
std::string comment; //操作原因描述
};
//服务端返回值(POS订单处理请求)
struct serverResponseOperationObj
{
std::string code;
std::string message;
std::string ver;
};
#endif
\ No newline at end of file
......@@ -535,8 +535,13 @@ bool JsonModule::getPosResponseData(int status, const std::string &msg, std::str
bool JsonModule::getPosResponseData(const std::string &odsResponse, std::string &result)
{
result = "{\"status_code\":100, \"msg\":\"\"}";
serverResponseOperationObj obj;
if(_getServerResponseData(odsResponse.data(),obj)){
result=_convertServerResponseToJson(obj);
return true;
}
return false;
//result = "{\"status_code\":100, \"msg\":\"\"}";
}
bool JsonModule::getOdsResponseData(int status_code, const std::string &msg, std::string &result)
......@@ -634,7 +639,13 @@ bool JsonModule::getOdsResponseData(const std::string &posResponse, const std::s
bool JsonModule::convertDataPos2Ods(const std::string &data, std::string &result)
{
orderOperationObj obj;
if(_getPOSOperationObj(data.data(),obj)){
result=_convertPosOperationToOdsJson(obj);
return true;
}
return false;
}
bool JsonModule::convertDataOds2Pos(const std::string &data, std::string &result)
......@@ -1177,3 +1188,113 @@ void JsonModule::_getRefundObj(IN orderObj &order_obj,OUT refundObj &refund_obj)
refund_obj.channel=order_obj.channel;
refund_obj.refund_amount=order_obj.total_price;
}
bool JsonModule::_getPOSOperationObj(IN const char* data,OUT orderOperationObj &operation_obj)
{
rapidjson::Document document; // 定义一个Document对象
document.Parse(data); // 解析,Parse()无返回值,也不会抛异常
if (document.HasParseError()) // 通过HasParseError()来判断解析是否成功
{
// 可通过GetParseError()取得出错代码,
// 注意GetParseError()返回的是一个rapidjson::ParseErrorCode类型的枚举值
// 使用函数rapidjson::GetParseError_En()得到错误码的字符串说明,这里的En为English简写
// 函数GetErrorOffset()返回出错发生的位置
LOG(ERROR)<<"_getPOSOperationObj JSON parse error:"<<document.GetParseError()<<":"<<document.GetErrorOffset();
}
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;
rapidjson::Value& order_id = document["order_id"];
operation_obj.order_id=order_id.GetString();
if(document.HasMember("comment")){
rapidjson::Value& comment = document["comment"];
operation_obj.comment=comment.GetString();
}
return true;
}
}
}
return false;
}
std::string JsonModule::_convertPosOperationToOdsJson(orderOperationObj &operation_obj)
{
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
writer.StartObject();
writer.Key("channel");
writer.String("");
writer.Key("storeId");
writer.String("");
writer.Key("order_id");
writer.String(operation_obj.order_id.c_str());
if(operation_obj.fm_cmd==OPERATION_POS_CONFIRM){
writer.Key("code");
writer.Int(0);
writer.Key("reason");
writer.String(operation_obj.comment.c_str());
}
writer.EndObject();
return buffer.GetString();
}
bool JsonModule::_getServerResponseData(IN const char* json,OUT serverResponseOperationObj &obj)
{
rapidjson::Document document; // 定义一个Document对象
document.Parse(json); // 解析,Parse()无返回值,也不会抛异常
if (document.HasParseError()) // 通过HasParseError()来判断解析是否成功
{
// 可通过GetParseError()取得出错代码,
// 注意GetParseError()返回的是一个rapidjson::ParseErrorCode类型的枚举值
// 使用函数rapidjson::GetParseError_En()得到错误码的字符串说明,这里的En为English简写
// 函数GetErrorOffset()返回出错发生的位置
LOG(ERROR)<<"_getServerResponseData JSON parse error:"<<document.GetParseError()<<":"<<document.GetErrorOffset();
}
else
{
rapidjson::Value& code = document["code"];
obj.code=code.GetString();
rapidjson::Value& message = document["message"];
obj.message=message.GetString();
rapidjson::Value& ver = document["ver"];
obj.ver=ver.GetString();
return true;
}
return false;
}
std::string JsonModule::_convertServerResponseToJson(serverResponseOperationObj &response_obj)
{
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
writer.StartObject();
writer.Key("status_code");
writer.Int(atoi(response_obj.code.data()));
writer.Key("msg");
writer.String("");
writer.Key("status");
writer.Int(0);
writer.Key("status_desc");
writer.String("");
writer.EndObject();
return buffer.GetString();
}
\ No newline at end of file
......@@ -71,6 +71,14 @@ private:
void _getStatusObj(IN orderObj &order_obj,OUT orderStatusObj &status_obj);
void _getRefundObj(IN orderObj &order_obj,OUT refundObj &refund_obj);
//pos操作请求json转换为结构体
bool _getPOSOperationObj(IN const char* data,OUT orderOperationObj &operation_obj);
std::string _convertPosOperationToOdsJson(orderOperationObj &operation_obj);
//服务器返回值(针对pos操作订单请求)
bool _getServerResponseData(IN const char* json,OUT serverResponseOperationObj &obj);
std::string _convertServerResponseToJson(serverResponseOperationObj &operation_obj);
std::string _convertToNewOrderJson(orderObj &obj);
std::string _convertToOrderStatusJson(orderStatusObj &obj);
std::string _convertToRefundJson(refundObj &obj);
......
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