浏览代码

同步条码秤商品完成了

zhangyang 4 年之前
父节点
当前提交
2d10feb1f8

+ 6 - 0
bin/Win32/Debug/zhipuzi_pos_windows/skin/setting_tiaomacheng.xml

@@ -37,4 +37,10 @@
 		
 		<Button name="setting_tiaomacheng_tongbushangpin" align="center" width="300" height="38" padding="20,8,0,3" text="同步最新商品信息到条码秤" normalimage="file='Btn_White.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" pushedimage="file='Btn_White_Click.png' corner='5,5,5,5'" />
 	</HorizontalLayout>
+	
+	<HorizontalLayout height="50" padding="0,20,0,0">
+		<Control></Control>
+		<Label name="setting_tiaomacheng_errinfo" font="2" width="400" height="50" multiline="true" text="" visible="false" textcolor="#FF0000" align="center" />
+		<Control></Control>
+	</HorizontalLayout>	
 </Window>

+ 86 - 32
zhipuzi_pos_windows/page/CSettingPageUI.cpp

@@ -1660,13 +1660,17 @@ void CSettingPageUI::HandleTextCapture(std::string content)
 
 void CSettingPageUI::StartTongbuBiaoqiancheng()
 {
+	std::thread(&CSettingPageUI::HandleTongbuBiaoqiancheng, this).detach();
+}
+
+void CSettingPageUI::HandleTongbuBiaoqiancheng()
+{
 	boost::asio::io_service m_io;
 	boost::asio::ip::tcp::socket m_socket(m_io);
 
 	//读取厨房打印机信息
 	std::string ip = CSetting::GetParam("setting_tiaomacheng_ip");
 
-
 	//初始化连接
 	try
 	{
@@ -1676,55 +1680,106 @@ void CSettingPageUI::StartTongbuBiaoqiancheng()
 	catch (std::exception& e)
 	{
 		std::string err = e.what();
-		LOG_INFO("厨房网口打印机连接失败,IP地址:" << ip.c_str() << ",错误信息:" << err.c_str());
+		LOG_INFO("条码秤连接失败,IP地址:" << ip.c_str() << ",错误信息:" << err.c_str());
 
-		MessageBoxW(NULL, (L"厨房网口打印机连接失败,IP地址:" + CLewaimaiString::UTF8ToUnicode(ip)).c_str(), L"打印机连接失败", MB_OK);
+		m_errinfo = L"条码秤连接失败,请检查IP设置,IP地址:" + CLewaimaiString::UTF8ToUnicode(ip);
+		MessageBoxW(NULL, m_errinfo.c_str(), L"条码秤连接失败", MB_OK);
 
-		//连接失败了,处理下一个厨房打印机
 		return;
 	}
 
-	//!0V + 4位PLU + A + 7位商品编码 + 6位数价格(单位分) + 模式(0:称重,1:计件,2:定重) + 000000 + 3位有效期 + 2位店号(01-99)+ 000000000000000 + 2位皮重(00-15)+
-	//+	0000000000000000000000000000000B + 商品名称区位码 + CDE + 换行符
-
 	//这个是要发送的数据
-	std::string data = "";
+	{
+		std::string data = "";
 
-	CSqlite3 sqlite;
+		//先发送清空命令
+		data += "!0IA";
+		data += 0x0d;
+		data += 0x0a;
 
-	/*
-	//先发送清空命令
-	data += "!0IA";
-	data += 0x0d;
+		try
+		{
+			m_socket.write_some(boost::asio::buffer(data.c_str(), data.length()));
+		}
+		catch (const std::exception& e)
+		{
+			LOG_INFO("条码秤发送消息失败,错误信息:" << e.what());
+		}
 
-	data += 0x0a;
+		boost::array<char, 128> buf;
+		boost::system::error_code error;
 
-	//data += 0x03;
+		//size_t len = m_socket.read_some(boost::asio::buffer(buf), error);
+		//std::string result = buf.begin();
+	}
 
-	data += "!0HA";
-	data += 0x0d;
+	{
+		std::string data = "";
 
-	data += 0x0a;
+		///再清除记录
+		data += "!0HA";
+		data += 0x0d;
+		data += 0x0a;
 
-	//data += 0x03;
-	//*/
+		try
+		{
+			m_socket.write_some(boost::asio::buffer(data.c_str(), data.length()));
+		}
+		catch (const std::exception& e)
+		{
+			LOG_INFO("条码秤发送消息失败,错误信息:" << e.what());
+		}
+
+		boost::array<char, 128> buf;
+		boost::system::error_code error;
+
+		//size_t len = m_socket.read_some(boost::asio::buffer(buf), error);
+		//std::string result = buf.begin();
+	}
+
+	//然后开通同步商品
+	//!0V + 4位PLU + A + 7位商品编码 + 6位数价格(单位分) + 模式(0:称重,1:计件,2:定重) + 000000 + 3位有效期 + 2位店号(01-99)+ 000000000000000 + 2位皮重(00-15)+
+	//+	0000000000000000000000000000000B + 商品名称区位码 + CDE + 换行符
+	
+	std::string data = "";
 
-	for (int i = 1; i <= 1; i++)
+	CSqlite3 sqlite;
+	std::vector<CFood> foods = sqlite.GetFoodForTiaomacheng();
+	for (std::vector<CFood>::iterator it = foods.begin(); it != foods.end(); it++)
 	{
 		data += "!0V";
 
-		data += "1001";
+		//处理PLU;
+		int n_plu = atoi(it->weight_plu_code.c_str());
+		if (n_plu < 1)
+		{
+			//无效的plu
+			continue;;
+		}
 
-		data += "A";
+		string plu = to_string(n_plu);
+		plu = CLewaimaiString::BuZifuLeft(plu, 4 - plu.length(), '0');
+		data += plu;
 
-		std::string shangpin_bianma = to_string(50000 + i);
+		data += "A";
 
-		data += CLewaimaiString::BuZifuLeft(shangpin_bianma, 2, '0');
+		//处理商品编码
+		int n_bianma = atoi(it->weight_food_code.c_str());
+		if (n_plu < 1)
+		{
+			//无效的编码
+			continue;;
+		}
 
-		std::string price = to_string((int)(5.50 * 100));
+		string bianma = to_string(n_bianma);
+		bianma = CLewaimaiString::BuZifuLeft(bianma, 7 - bianma.length(), '0');
+		data += bianma;
 
+		//价格
+		std::string price = to_string((int)(atof(it->price.c_str()) * 100));
 		data += CLewaimaiString::BuZifuLeft(price, 6 - price.length(), '0');
 
+		//模式,称重
 		data += '0';
 
 		data += "000000";
@@ -1737,21 +1792,19 @@ void CSettingPageUI::StartTongbuBiaoqiancheng()
 
 		data += "000000000000000";
 
+		//皮重
 		data += "00";
 
 		data += "0000000000000000000000000000000B";
 
-		std::string quweima = CLewaimaiString::GetQuweima(L"刘刘1刘abc");
-
+		//商品区位码
+		std::string quweima = CLewaimaiString::GetQuweima(CLewaimaiString::UTF8ToUnicode(it->name));
 		data += quweima;
 
 		data += "CDE";
 
 		data += 0x0d;
-
 		data += 0x0a;
-
-		//data += 0x03;
 	}
 
 	//网口走这里
@@ -1761,13 +1814,14 @@ void CSettingPageUI::StartTongbuBiaoqiancheng()
 	}
 	catch (const std::exception& e)
 	{
-		LOG_INFO("网口打印机发送消息失败,错误信息:" << e.what());
+		LOG_INFO("条码秤发送消息失败,错误信息:" << e.what());
 	}
 
 	boost::array<char, 128> buf;
 	boost::system::error_code error;
 
 	size_t len = m_socket.read_some(boost::asio::buffer(buf), error);
+	std::string result = buf.begin();
 
 	m_socket.close();
 }

+ 5 - 0
zhipuzi_pos_windows/page/CSettingPageUI.h

@@ -28,5 +28,10 @@ public:
 	void HandleTextCapture(std::string content);
 
 	void StartTongbuBiaoqiancheng();
+
+	void HandleTongbuBiaoqiancheng();
+
+private:
+	std::wstring m_errinfo;
 };
 

+ 94 - 6
zhipuzi_pos_windows/tool/CSqlite3.cpp

@@ -528,6 +528,8 @@ bool CSqlite3::InitPosFood()
 					"is_shouyinji_show    CHAR(20)          NOT NULL," \
 					"expiration_date   CHAR(100)          NOT NULL," \
 					"is_weight    CHAR(20)          NOT NULL," \
+					"weight_plu_code    CHAR(20)          NOT NULL," \
+					"weight_food_code    CHAR(20)          NOT NULL," \
 					"member_price_json    CHAR(100)          NOT NULL);";
 
 				if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
@@ -855,12 +857,32 @@ bool CSqlite3::InitFoodData(rapidjson::Value& foodrows)
 		std::string is_weight = foodinfo["is_weight"].GetString();
 		std::string member_price_json = foodinfo["member_price_json"].GetString();
 
+		std::string weight_plu_code;
+		if (foodinfo["weight_plu_code"].IsString())
+		{
+			weight_plu_code = foodinfo["weight_plu_code"].GetString();
+		}
+		else
+		{
+			weight_plu_code = "";
+		}
+
+		std::string weight_food_code;
+		if (foodinfo["weight_food_code"].IsString())
+		{
+			weight_food_code = foodinfo["weight_food_code"].GetString();
+		}
+		else
+		{
+			weight_food_code = "";
+		}
+
 		//插入一个商品数据
 		std::string sql = "INSERT INTO pos_food (id,shop_id,name,price,tag,status,type_id,is_dabao,dabao_money,is_nature,nature,autostocknum,goods_img,unit,barcode,member_price_used,member_price, \
-			buying_price,stock,stockvalid,stock_warning,is_shouyinji_show,expiration_date,is_weight,member_price_json) VALUES ('" + id + "' ,'" + shop_id + "','" \
+			buying_price,stock,stockvalid,stock_warning,is_shouyinji_show,expiration_date,is_weight,member_price_json,weight_plu_code,weight_food_code) VALUES ('" + id + "' ,'" + shop_id + "','" \
 			+ name + "', '" + price + "', '" + tag + "', '" + status + "', '" + type_id + "', '" + is_dabao + "', '" + dabao_money + "', '" + is_nature + "', '" + nature + "', '" \
 			+ autostocknum + "', '" + goods_img + "', '" + unit + "', '" + barcode + "', '" + member_price_used + "', '" + member_price + "', '" + buying_price + "', '" + stock + "', '" \
-			+ stockvalid + "', '" + stock_warning + "', '" + is_shouyinji_show + "', '" + expiration_date + "','" + is_weight + "','" + member_price_json + "')";
+			+ stockvalid + "', '" + stock_warning + "', '" + is_shouyinji_show + "', '" + expiration_date + "','" + is_weight + "','" + member_price_json + "','" + weight_plu_code + "','" + weight_food_code + "')";
 
 		bool ret = this->ExeSQl(sql);
 		if (!ret)
@@ -1119,7 +1141,67 @@ std::vector<CFood> CSqlite3::GetFoodByTypeid(std::string type_id, bool is_shouyi
 			newFood.is_shouyinji_show = (char*)sqlite3_column_text(stmt, 21);
 			newFood.expiration_date = (char*)sqlite3_column_text(stmt, 22);
 			newFood.is_weight = (char*)sqlite3_column_text(stmt, 23);
-			newFood.member_price_json = (char*)sqlite3_column_text(stmt, 24);
+			newFood.weight_plu_code = (char*)sqlite3_column_text(stmt, 24);
+			newFood.weight_food_code = (char*)sqlite3_column_text(stmt, 25);
+			newFood.member_price_json = (char*)sqlite3_column_text(stmt, 26);
+
+			data.push_back(newFood);
+		}
+
+		sqlite3_finalize(stmt);
+	}
+	else
+	{
+		//异常情况
+		sqlite3_finalize(stmt);
+	}
+
+	return data;
+}
+
+std::vector<CFood> CSqlite3::GetFoodForTiaomacheng()
+{
+	std::vector<CFood> data;
+
+	std::string sql;
+
+	sql = "SELECT * FROM pos_food WHERE is_weight = '1' AND weight_plu_code != '' AND weight_food_code != ''";
+
+	sqlite3_stmt * stmt = NULL;
+
+	if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
+	{
+		while (sqlite3_step(stmt) == SQLITE_ROW)
+		{
+			CFood newFood;
+
+			newFood.id = (char*)sqlite3_column_text(stmt, 0);
+			newFood.shop_id = (char*)sqlite3_column_text(stmt, 1);
+			newFood.name = (char*)sqlite3_column_text(stmt, 2);
+			newFood.price = (char*)sqlite3_column_text(stmt, 3);
+			newFood.tag = (char*)sqlite3_column_text(stmt, 4);
+			newFood.status = (char*)sqlite3_column_text(stmt, 5);
+			newFood.type_id = (char*)sqlite3_column_text(stmt, 6);
+			newFood.is_dabao = (char*)sqlite3_column_text(stmt, 7);
+			newFood.dabao_money = (char*)sqlite3_column_text(stmt, 8);
+			newFood.is_nature = (char*)sqlite3_column_text(stmt, 9);
+			newFood.nature = (char*)sqlite3_column_text(stmt, 10);
+			newFood.autostocknum = (char*)sqlite3_column_text(stmt, 11);
+			newFood.goods_img = (char*)sqlite3_column_text(stmt, 12);
+			newFood.unit = (char*)sqlite3_column_text(stmt, 13);
+			newFood.barcode = (char*)sqlite3_column_text(stmt, 14);
+			newFood.member_price_used = (char*)sqlite3_column_text(stmt, 15);
+			newFood.member_price = (char*)sqlite3_column_text(stmt, 16);
+			newFood.buying_price = (char*)sqlite3_column_text(stmt, 17);
+			newFood.stock = (char*)sqlite3_column_text(stmt, 18);
+			newFood.stockvalid = (char*)sqlite3_column_text(stmt, 19);
+			newFood.stock_warning = (char*)sqlite3_column_text(stmt, 20);
+			newFood.is_shouyinji_show = (char*)sqlite3_column_text(stmt, 21);
+			newFood.expiration_date = (char*)sqlite3_column_text(stmt, 22);
+			newFood.is_weight = (char*)sqlite3_column_text(stmt, 23);
+			newFood.weight_plu_code = (char*)sqlite3_column_text(stmt, 24);
+			newFood.weight_food_code = (char*)sqlite3_column_text(stmt, 25);
+			newFood.member_price_json = (char*)sqlite3_column_text(stmt, 26);
 
 			data.push_back(newFood);
 		}
@@ -1184,7 +1266,9 @@ std::vector<CFood> CSqlite3::GetFoodByFoodname(std::string foodname, bool is_sho
 			newFood.is_shouyinji_show = (char*)sqlite3_column_text(stmt, 21);
 			newFood.expiration_date = (char*)sqlite3_column_text(stmt, 22);
 			newFood.is_weight = (char*)sqlite3_column_text(stmt, 23);
-			newFood.member_price_json = (char*)sqlite3_column_text(stmt, 24);
+			newFood.weight_plu_code = (char*)sqlite3_column_text(stmt, 24);
+			newFood.weight_food_code = (char*)sqlite3_column_text(stmt, 25);
+			newFood.member_price_json = (char*)sqlite3_column_text(stmt, 26);
 
 			data.push_back(newFood);
 		}
@@ -1290,7 +1374,9 @@ bool CSqlite3::GetFoodById(std::string food_id, CFood& newFood)
 			newFood.is_shouyinji_show = (char*)sqlite3_column_text(stmt, 21);
 			newFood.expiration_date = (char*)sqlite3_column_text(stmt, 22);
 			newFood.is_weight = (char*)sqlite3_column_text(stmt, 23);
-			newFood.member_price_json = (char*)sqlite3_column_text(stmt, 24);
+			newFood.weight_plu_code = (char*)sqlite3_column_text(stmt, 24);
+			newFood.weight_food_code = (char*)sqlite3_column_text(stmt, 25);
+			newFood.member_price_json = (char*)sqlite3_column_text(stmt, 26);
 		}
 
 		sqlite3_finalize(stmt);
@@ -1342,7 +1428,9 @@ bool CSqlite3::GetFoodByBarcode(std::string barcode, CFood& newFood)
 			newFood.is_shouyinji_show = (char*)sqlite3_column_text(stmt, 21);
 			newFood.expiration_date = (char*)sqlite3_column_text(stmt, 22);
 			newFood.is_weight = (char*)sqlite3_column_text(stmt, 23);
-			newFood.member_price_json = (char*)sqlite3_column_text(stmt, 24);
+			newFood.weight_plu_code = (char*)sqlite3_column_text(stmt, 24);
+			newFood.weight_food_code = (char*)sqlite3_column_text(stmt, 25);
+			newFood.member_price_json = (char*)sqlite3_column_text(stmt, 26);
 		}
 
 		sqlite3_finalize(stmt);

+ 3 - 0
zhipuzi_pos_windows/tool/CSqlite3.h

@@ -45,6 +45,9 @@ public:
 	//获取某一个商品分类下的商品
 	std::vector<CFood> GetFoodByTypeid(std::string type_id, bool is_shouyinji_show = true);
 
+	//获取某一个商品分类下的商品
+	std::vector<CFood> GetFoodForTiaomacheng();
+
 	//用于商品搜索
 	std::vector<CFood> GetFoodByFoodname(std::string foodname, bool is_shouyinji_show = true);
 

+ 2 - 0
zhipuzi_pos_windows/zhipuzi/CFood.h

@@ -31,6 +31,8 @@ public:
 	std::string expiration_date;
 	std::string is_weight;
 	std::string member_price_json;
+	std::string weight_plu_code;
+	std::string weight_food_code;
 
 	//获得图片完整的下载地址
 	std::wstring getImageUrl()