|
|
@@ -799,7 +799,20 @@ void CDiandanPageUI::HandleTextCapture(std::string content)
|
|
|
else
|
|
|
{
|
|
|
//没有任何弹框,那么就是按扫描商品条码来处理
|
|
|
- this->SaomiaoBarcode(content);
|
|
|
+ bool ret = this->SaomiaoBarcode(content);
|
|
|
+ if (ret == true)
|
|
|
+ {
|
|
|
+ //已经找到了条码,就不接着处理了
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //如果没有找到条码,就找一下是不是称重的标签秤的码,这个时候要对码进行各种分析了
|
|
|
+ ret = this->BiaoqianchengSaomaBarcode(content);
|
|
|
+ if (ret == false)
|
|
|
+ {
|
|
|
+ m_pMainWnd->ShowToast(L"该条码对应的商品不存在!");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -2944,7 +2957,7 @@ void CDiandanPageUI::UpdateFoodStock(std::string food_stock)
|
|
|
}
|
|
|
|
|
|
//扫描了商品条码的逻辑处理
|
|
|
-void CDiandanPageUI::SaomiaoBarcode(std::string barcode)
|
|
|
+bool CDiandanPageUI::SaomiaoBarcode(std::string barcode)
|
|
|
{
|
|
|
CSqlite3 sqlite;
|
|
|
|
|
|
@@ -2954,8 +2967,7 @@ void CDiandanPageUI::SaomiaoBarcode(std::string barcode)
|
|
|
if (ret == false)
|
|
|
{
|
|
|
//说明没找到对应的商品条码
|
|
|
- m_pMainWnd->ShowToast(L"未找到对应的商品条码");
|
|
|
- return;
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
//这里说明找到了,那么处理添加购物车逻辑,扫码的情况下,这里不管有没有属性,都按没属性处理,不管有没有称重都按没称重处理(以后标签秤可能会修改)
|
|
|
@@ -2964,7 +2976,9 @@ void CDiandanPageUI::SaomiaoBarcode(std::string barcode)
|
|
|
{
|
|
|
//库存为0了,不做任何处理
|
|
|
m_pMainWnd->ShowToast(L"该商品已售完");
|
|
|
- return;
|
|
|
+
|
|
|
+ //只要找到了就返回true
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
CDiandanOrderItem clickItem;
|
|
|
@@ -3027,6 +3041,238 @@ void CDiandanPageUI::SaomiaoBarcode(std::string barcode)
|
|
|
//没有新增,而是修改了一项
|
|
|
this->UpdateDiandanOrderItemShow(index);
|
|
|
}
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+bool CDiandanPageUI::BiaoqianchengSaomaBarcode(std::string barcode)
|
|
|
+{
|
|
|
+ //先根据设置,分辨条码格式
|
|
|
+ std::string bianma;
|
|
|
+ std::string money;
|
|
|
+ std::string weight;
|
|
|
+ std::string jiaoyan;
|
|
|
+
|
|
|
+ std::string setting_tiaomacheng_geshi = CSetting::GetParam("setting_tiaomacheng_geshi");
|
|
|
+ if (setting_tiaomacheng_geshi == "1")
|
|
|
+ {
|
|
|
+ if (barcode.length() == 12)
|
|
|
+ {
|
|
|
+ barcode = CLewaimaiString::BuZifuLeft(barcode, 1, '0');
|
|
|
+ }
|
|
|
+
|
|
|
+ //13位【FWWWWWWEEEEEC】
|
|
|
+ bianma = barcode.substr(1, 6);
|
|
|
+ money = barcode.substr(7, 5);
|
|
|
+ jiaoyan = barcode.substr(12, 1);
|
|
|
+ }
|
|
|
+ else if (setting_tiaomacheng_geshi == "2")
|
|
|
+ {
|
|
|
+ if (barcode.length() == 12)
|
|
|
+ {
|
|
|
+ barcode = CLewaimaiString::BuZifuLeft(barcode, 1, '0');
|
|
|
+ }
|
|
|
+
|
|
|
+ //13位【FWWWWWWNNNNNC】
|
|
|
+ bianma = barcode.substr(1, 6);
|
|
|
+ weight = barcode.substr(7, 5);
|
|
|
+ jiaoyan = barcode.substr(12, 1);
|
|
|
+ }
|
|
|
+ else if (setting_tiaomacheng_geshi == "3")
|
|
|
+ {
|
|
|
+ if (barcode.length() == 12)
|
|
|
+ {
|
|
|
+ barcode = CLewaimaiString::BuZifuLeft(barcode, 1, '0');
|
|
|
+ }
|
|
|
+
|
|
|
+ //13位【FFWWWWWEEEEEC】
|
|
|
+ bianma = barcode.substr(2, 5);
|
|
|
+ money = barcode.substr(7, 5);
|
|
|
+ jiaoyan = barcode.substr(12, 1);
|
|
|
+ }
|
|
|
+ else if (setting_tiaomacheng_geshi == "4")
|
|
|
+ {
|
|
|
+ if (barcode.length() == 12)
|
|
|
+ {
|
|
|
+ barcode = CLewaimaiString::BuZifuLeft(barcode, 1, '0');
|
|
|
+ }
|
|
|
+
|
|
|
+ //13位【FFWWWWWNNNNNC】
|
|
|
+ bianma = barcode.substr(2, 5);
|
|
|
+ weight = barcode.substr(7, 5);
|
|
|
+ jiaoyan = barcode.substr(12, 1);
|
|
|
+ }
|
|
|
+ else if (setting_tiaomacheng_geshi == "5")
|
|
|
+ {
|
|
|
+ if (barcode.length() == 17)
|
|
|
+ {
|
|
|
+ barcode = CLewaimaiString::BuZifuLeft(barcode, 1, '0');
|
|
|
+ }
|
|
|
+
|
|
|
+ //18位【FWWWWWWEEEEENNNNNC】
|
|
|
+ bianma = barcode.substr(1, 6);
|
|
|
+ money = barcode.substr(7, 5);
|
|
|
+ weight = barcode.substr(12, 5);
|
|
|
+ jiaoyan = barcode.substr(17, 1);
|
|
|
+ }
|
|
|
+ else if (setting_tiaomacheng_geshi == "6")
|
|
|
+ {
|
|
|
+ if (barcode.length() == 17)
|
|
|
+ {
|
|
|
+ barcode = CLewaimaiString::BuZifuLeft(barcode, 1, '0');
|
|
|
+ }
|
|
|
+
|
|
|
+ //18位【FWWWWWWNNNNNEEEEEC】
|
|
|
+ bianma = barcode.substr(1, 6);
|
|
|
+ weight = barcode.substr(7, 5);
|
|
|
+ money = barcode.substr(12, 5);
|
|
|
+ jiaoyan = barcode.substr(17, 1);
|
|
|
+ }
|
|
|
+ else if (setting_tiaomacheng_geshi == "7")
|
|
|
+ {
|
|
|
+ if (barcode.length() == 17)
|
|
|
+ {
|
|
|
+ barcode = CLewaimaiString::BuZifuLeft(barcode, 1, '0');
|
|
|
+ }
|
|
|
+
|
|
|
+ //18位【FFWWWWWEEEEENNNNNC】
|
|
|
+ bianma = barcode.substr(2, 5);
|
|
|
+ money = barcode.substr(7, 5);
|
|
|
+ weight = barcode.substr(12, 5);
|
|
|
+ jiaoyan = barcode.substr(17, 1);
|
|
|
+ }
|
|
|
+ else if (setting_tiaomacheng_geshi == "8")
|
|
|
+ {
|
|
|
+ if (barcode.length() == 17)
|
|
|
+ {
|
|
|
+ barcode = CLewaimaiString::BuZifuLeft(barcode, 1, '0');
|
|
|
+ }
|
|
|
+
|
|
|
+ //18位【FFWWWWWNNNNNEEEEEC】
|
|
|
+ bianma = barcode.substr(2, 5);
|
|
|
+ weight = barcode.substr(7, 5);
|
|
|
+ money = barcode.substr(12, 5);
|
|
|
+ jiaoyan = barcode.substr(17, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ //先检查编码是否存在,如果编码不存在直接返回false
|
|
|
+ int i_bianma = atoi(bianma.c_str());
|
|
|
+ if (i_bianma < 1)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ CFood foodinfo;
|
|
|
+
|
|
|
+ CSqlite3 sqlite;
|
|
|
+ bool ret = sqlite.GetFoodByPluBianma(to_string(i_bianma), foodinfo);
|
|
|
+ if (ret == false)
|
|
|
+ {
|
|
|
+ //没找到这个商品
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ //走到这里是找到商品了,那么就开始计算价格和重量
|
|
|
+ double d_money = 0;
|
|
|
+ double d_weight = 0;
|
|
|
+
|
|
|
+ //如果有价格,优先用价格
|
|
|
+ if (money.length() > 0)
|
|
|
+ {
|
|
|
+ //这个出来的单位是分,要把单位转成员
|
|
|
+ d_money = atof(money.c_str());
|
|
|
+
|
|
|
+ d_money = d_money / 100;
|
|
|
+
|
|
|
+ //根据价格计算重量
|
|
|
+ d_weight = d_money / atof(foodinfo.price.c_str());
|
|
|
+ }
|
|
|
+ else if (weight.length() > 0)
|
|
|
+ {
|
|
|
+ //这个单位是克,要转化成千克
|
|
|
+ d_weight = atof(weight.c_str());
|
|
|
+
|
|
|
+ d_weight = d_weight / 1000;
|
|
|
+
|
|
|
+ //有重量了,其实不需要计算价格,价格加到购物车的时候会自己计算
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //价格和重量都没有,这是异常情况
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (foodinfo.stockvalid == "1" && atof(foodinfo.stock.c_str()) < d_weight)
|
|
|
+ {
|
|
|
+ //库存为0了,不做任何处理
|
|
|
+ m_pMainWnd->ShowToast(L"该商品已售完");
|
|
|
+
|
|
|
+ //只要找到了就返回true
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ CDiandanOrderItem clickItem;
|
|
|
+
|
|
|
+ clickItem.food_id = foodinfo.id;
|
|
|
+ clickItem.food_name = foodinfo.name;
|
|
|
+ clickItem.type_id = foodinfo.type_id;
|
|
|
+ clickItem.price = foodinfo.price;
|
|
|
+ clickItem.is_dabao = false;
|
|
|
+ clickItem.dabao_money = foodinfo.dabao_money;
|
|
|
+ clickItem.num = CLewaimaiString::DoubleToString(d_weight, 3); //重量保留3位小数
|
|
|
+
|
|
|
+ if (foodinfo.member_price_used == "1")
|
|
|
+ {
|
|
|
+ clickItem.is_member_price_used = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ clickItem.is_member_price_used = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理会员价的json
|
|
|
+ std::string member_price_json = foodinfo.member_price_json;
|
|
|
+
|
|
|
+ rapidjson::Document document;
|
|
|
+ document.Parse(member_price_json.c_str());
|
|
|
+
|
|
|
+ rapidjson::Value& member_price = document;
|
|
|
+ for (rapidjson::SizeType i = 0; i < member_price.Size(); ++i)
|
|
|
+ {
|
|
|
+ rapidjson::Value& member_price_info = member_price[i];
|
|
|
+
|
|
|
+ MemberPrice newPirce;
|
|
|
+ newPirce.id = member_price_info["id"].GetString();
|
|
|
+ newPirce.level = member_price_info["level"].GetString();
|
|
|
+ newPirce.price = member_price_info["price"].GetString();
|
|
|
+
|
|
|
+ clickItem.m_member_price.push_back(newPirce);
|
|
|
+ }
|
|
|
+
|
|
|
+ //把当前点击商品的信息,保存到orderitem里面,方便后面修改规格的时候使用
|
|
|
+ clickItem.SetFoodInfo(foodinfo);
|
|
|
+ clickItem.SetIsTaocan(false);
|
|
|
+
|
|
|
+ clickItem.is_weight = true;
|
|
|
+ clickItem.is_nature = false;
|
|
|
+
|
|
|
+ //商品没有商品属性
|
|
|
+ bool is_add_new = false;
|
|
|
+
|
|
|
+ int index = m_cur_diandan_order.AddItem(clickItem, is_add_new);
|
|
|
+
|
|
|
+ if (is_add_new)
|
|
|
+ {
|
|
|
+ //说明是新增了一项,要刷新一下购物车展示
|
|
|
+ this->AddDiandanOrderItemShow(index);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //没有新增,而是修改了一项
|
|
|
+ this->UpdateDiandanOrderItemShow(index);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
//开始搜索某个商品名字
|