张洋 5 роки тому
батько
коміт
b90fb95ba7

+ 21 - 0
lewaimai_pos_windows/network/CLewaimaiHttpClient.cpp

@@ -78,6 +78,22 @@ bool CLewaimaiHttpClient::Login(std::string& errmsg)
 			errmsg = CLewaimaiString::UnicodeToUTF8(L"乐外卖PC版仅支持商户类型的子账号登录");
 			return false;
 		}
+
+		//获取店铺ID
+
+		//店铺ID默认为0
+		m_client.m_shop_id = "0";
+
+		rapidjson::Value& v_rows = data["shop_ids"];
+
+		for (rapidjson::SizeType i = 0; i < v_rows.Size(); ++i)
+		{
+			rapidjson::Value& v_row_i = v_rows[i];
+
+			std::string shop_id = v_row_i.GetString();
+
+			m_client.m_shop_id = shop_id;
+		}
 	}
 
 	//LOG_INFO("login success!");
@@ -160,3 +176,8 @@ bool CLewaimaiHttpClient::Request(std::string url, std::map<string, string> para
 
 	return false;
 }
+
+std::string CLewaimaiHttpClient::getShopId()
+{
+	return m_client.m_shop_id;
+}

+ 5 - 0
lewaimai_pos_windows/network/CLewaimaiHttpClient.h

@@ -15,6 +15,8 @@ public:
 
 	static bool Request(std::string url, std::map<string, string> params, std::string& response);
 
+	static std::string getShopId();
+
 public:
 	static CLewaimaiHttpClient m_client;
 
@@ -23,5 +25,8 @@ private:
 	std::string m_password;
 
 	std::string m_url = "https://api.lewaimai.com/seller";
+
+	//这个是当前登陆的账号对应的店铺ID(如果是连锁店账号就是返回的第一个店铺),主要用于厨房打印的分类打印时候用于获取商品分类
+	std::string m_shop_id;
 };
 

+ 38 - 34
lewaimai_pos_windows/wnd/CMainWnd.cpp

@@ -1863,53 +1863,57 @@ void CMainWnd::InitSettingStatus()
     //先清空一次分类(主要考虑退出登陆重新登录的情况)
     CSetting::ClearFoodtype();
 
-    std::map<string, string> params;
-    params["shop_id"] = "424298";
+	std::string shop_id = CLewaimaiHttpClient::getShopId();
+	if (shop_id != "0")
+	{
+		std::map<string, string> params;
+		params["shop_id"] = shop_id;
 
-    std::string response;
+		std::string response;
 
-    std::string url = "/goodstype/getlist";
+		std::string url = "/goodstype/getlist";
 
-    CLewaimaiHttpClient::Request(url.c_str(), params, response);
+		CLewaimaiHttpClient::Request(url.c_str(), params, response);
 
-    rapidjson::Document document;
-    document.Parse(response.c_str());
+		rapidjson::Document document;
+		document.Parse(response.c_str());
 
-    if(document.HasParseError())
-    {
-        LOG_INFO("parse response error!");
-        return;
-    }
+		if (document.HasParseError())
+		{
+			LOG_INFO("parse response error!");
+			return;
+		}
 
-    if(!document.HasMember("errcode") || !document.HasMember("errmsg") || !document.HasMember("data"))
-    {
-        LOG_INFO("json error!");
-        return;
-    }
+		if (!document.HasMember("errcode") || !document.HasMember("errmsg") || !document.HasMember("data"))
+		{
+			LOG_INFO("json error!");
+			return;
+		}
 
-    rapidjson::Value& v_errcode = document["errcode"];
-    int errcode = v_errcode.GetInt();
+		rapidjson::Value& v_errcode = document["errcode"];
+		int errcode = v_errcode.GetInt();
 
-    if(errcode != 0)
-    {
-        LOG_INFO("response failed! message:" << document["errmsg"].GetString());
-        return;
-    }
+		if (errcode != 0)
+		{
+			LOG_INFO("response failed! message:" << document["errmsg"].GetString());
+			return;
+		}
 
-    //获得数据成功,把分类信息保存起来
-    rapidjson::Value& data = document["data"];
+		//获得数据成功,把分类信息保存起来
+		rapidjson::Value& data = document["data"];
 
-    rapidjson::Value& v_rows = data["goods_types"];
+		rapidjson::Value& v_rows = data["goods_types"];
 
-    for(rapidjson::SizeType i = 0; i < v_rows.Size(); ++i)
-    {
-        rapidjson::Value& v_row_i = v_rows[i];
+		for (rapidjson::SizeType i = 0; i < v_rows.Size(); ++i)
+		{
+			rapidjson::Value& v_row_i = v_rows[i];
 
-        std::string type_id = v_row_i["type_id"].GetString();
-        std::string name = v_row_i["name"].GetString();
+			std::string type_id = v_row_i["type_id"].GetString();
+			std::string name = v_row_i["name"].GetString();
 
-        CSetting::AddFoodtype(name, type_id);
-    }
+			CSetting::AddFoodtype(name, type_id);
+		}
+	}
 
     //获取厨房打印机的集合
     std::vector<ChufangPrinter> printers = CSetting::getChufangPrints();