| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471 |
- #include "../pch/pch.h"
- #include "CZhengcanOrderItem.h"
- #include "../tool/CSqlite3.h"
- bool CZhengcanOrderItem::operator==(CZhengcanOrderItem& t)
- {
- if (this->m_is_taocan != t.m_is_taocan)
- {
- return false;
- }
- if (this->is_dabao != t.is_dabao)
- {
- return false;
- }
- if (this->m_is_taocan == true)
- {
- if (this->foodpackage_id != t.foodpackage_id)
- {
- return false;
- }
- int i = 0;
- for (std::vector<FoodNatureSelectValue>::iterator it = this->natureSelectedArray.begin(); it != this->natureSelectedArray.end(); it++)
- {
- if ((*it).nature_name != t.natureSelectedArray[i].nature_name)
- {
- return false;
- }
- if ((*it).nature_select_index != t.natureSelectedArray[i].nature_select_index)
- {
- return false;
- }
- i++;
- }
- }
- else
- {
- if (this->food_id != t.food_id)
- {
- return false;
- }
- if (this->is_nature != t.is_nature)
- {
- return false;
- }
- if (this->is_nature == true)
- {
- int i = 0;
- for (std::vector<FoodNatureSelectValue>::iterator it = this->natureSelectedArray.begin(); it != this->natureSelectedArray.end(); it++)
- {
- if ((*it).nature_name != t.natureSelectedArray[i].nature_name)
- {
- return false;
- }
- if ((*it).nature_select_index != t.natureSelectedArray[i].nature_select_index)
- {
- return false;
- }
- i++;
- }
- }
- }
- return true;
- }
- void CZhengcanOrderItem::SetFoodInfo(CFood info)
- {
- m_foodinfo = info;
- }
- void CZhengcanOrderItem::SetFoodpackageInfo(CFoodpackage info)
- {
- m_foodpackageinfo = info;
- m_is_taocan = true;
- }
- void CZhengcanOrderItem::SetIsTaocan(bool is_taocan)
- {
- m_is_taocan = is_taocan;
- }
- void CZhengcanOrderItem::SetDabao()
- {
- is_dabao = true;
- }
- CFood CZhengcanOrderItem::GetFoodInfo()
- {
- return m_foodinfo;
- }
- CFoodpackage CZhengcanOrderItem::GetFoodpackageInfo()
- {
- return m_foodpackageinfo;
- }
- bool CZhengcanOrderItem::GetIsTaocan()
- {
- return m_is_taocan;
- }
- //根据当前选中的商品属性、份数,计算商品的展示价格
- void CZhengcanOrderItem::UpdateShowPrice()
- {
- if (m_is_taocan == true)
- {
- show_price = CLewaimaiString::DoubleToString(std::stod(price) * std::stod(num), 2);
- }
- else
- {
- if (!is_nature)
- {
- show_price = CLewaimaiString::DoubleToString(std::stod(price) * std::stod(num), 2);
- }
- else
- {
- double nature_price = 0;
- for (std::vector<FoodNatureSelectValue>::iterator it = this->natureSelectedArray.begin(); it != this->natureSelectedArray.end(); it++)
- {
- nature_price += (*it).nature_select_value;
- }
- double new_price = std::stod(price) + nature_price;
- show_price = CLewaimaiString::DoubleToString(new_price * std::stod(num), 2);
- }
- }
- }
- std::string CZhengcanOrderItem::getSinglePrice()
- {
- if (m_is_taocan == true)
- {
- return price;
- }
- else
- {
- if (!is_nature)
- {
- return price;
- }
- else
- {
- double nature_price = 0;
- for (std::vector<FoodNatureSelectValue>::iterator it = this->natureSelectedArray.begin(); it != this->natureSelectedArray.end(); it++)
- {
- nature_price += (*it).nature_select_value;
- }
- double new_price = std::stod(price) + nature_price;
- show_price = CLewaimaiString::DoubleToString(new_price, 2);
- return show_price;
- }
- }
- }
- std::string CZhengcanOrderItem::getNameShow()
- {
- if (m_is_taocan)
- {
- if (is_dabao)
- {
- return CLewaimaiString::UnicodeToUTF8(L"【打包】") + foodpackage_name;
- }
- else
- {
- return foodpackage_name;
- }
- }
- else
- {
- if (is_dabao)
- {
- return CLewaimaiString::UnicodeToUTF8(L"【打包】") + food_name;
- }
- else
- {
- return food_name;
- }
- }
- }
- //获取用于展示的属性名字
- std::string CZhengcanOrderItem::getNatureShow()
- {
- std::string show = "";
- if (m_is_taocan)
- {
- size_t i = 0;
- for (std::vector<FoodNatureSelectValue>::iterator it = this->natureSelectedArray.begin(); it != this->natureSelectedArray.end(); it++)
- {
- show += (*it).nature_select_name;
- if (i < natureSelectedArray.size() - 1)
- {
- show += CLewaimaiString::UnicodeToUTF8(L"、");
- }
- i++;
- }
- }
- else
- {
- if (!is_nature)
- {
- return "";
- }
- size_t i = 0;
- for (std::vector<FoodNatureSelectValue>::iterator it = this->natureSelectedArray.begin(); it != this->natureSelectedArray.end(); it++)
- {
- show += (*it).nature_select_name;
- if (i < natureSelectedArray.size() - 1)
- {
- show += CLewaimaiString::UnicodeToUTF8(L"、");
- }
- i++;
- }
- }
- return show;
- }
- //获取用于完整展示的商品名字,包含商品本身的名字和属性,例如“【打包】珍珠奶茶【大杯、热、多糖】”
- std::string CZhengcanOrderItem::getNameWanzhengShow()
- {
- std::string name_first = getNameShow();
- std::string nature = "";
- //后面再加上属性或者套餐商品名字
- if (m_is_taocan)
- {
- nature = CLewaimaiString::UnicodeToUTF8(L"【") + getNatureShow() + CLewaimaiString::UnicodeToUTF8(L"】");
- }
- else
- {
- if (is_nature)
- {
- nature = CLewaimaiString::UnicodeToUTF8(L"【") + getNatureShow() + CLewaimaiString::UnicodeToUTF8(L"】");
- }
- else
- {
- nature = "";
- }
- }
- std::string total_name = name_first + nature;
- return total_name;
- }
- double CZhengcanOrderItem::getMemberYouhui(std::string member_level)
- {
- if (is_member_price_used == false)
- {
- return 0;
- }
- for (std::vector<MemberPrice>::iterator it = m_member_price.begin(); it != m_member_price.end(); it++)
- {
- MemberPrice cur = *it;
- if (cur.level == member_level)
- {
- double member_food_price = atof(cur.price.c_str());
- double yuan_price = atof(price.c_str());
- double chajia = (yuan_price - member_food_price) * atof(num.c_str());
- return chajia;
- }
- }
- return 0;
- }
- double CZhengcanOrderItem::getDabaoMoney()
- {
- if (is_dabao)
- {
- return atof(dabao_money.c_str()) * (int)atof(num.c_str());
- }
- return 0;
- }
- //获取点单相关的参数(仅用于非套餐)
- std::map<string, string> CZhengcanOrderItem::getDiandanParam()
- {
- std::map<string, string> param;
- if (m_is_taocan)
- {
- return param;
- }
- param["food_id"] = food_id;
- if (is_nature)
- {
- param["food_name"] = food_name + CLewaimaiString::UnicodeToUTF8(L"【") + getNatureShow() + CLewaimaiString::UnicodeToUTF8(L"】");
- }
- else
- {
- param["food_name"] = food_name;
- }
- param["food_price"] = getSinglePrice();
- if (is_dabao)
- {
- param["is_dabao"] = "1";
- }
- else
- {
- param["is_dabao"] = "0";
- }
- param["dabao_money"] = dabao_money;
- param["quantity"] = num;
- param["type_id"] = m_foodinfo.type_id;
- param["foodpackage_id"] = "0";
- param["is_foodpackage"] = "0";
- param["is_jiacai"] = is_jiacai;
- param["is_tuicai"] = "0";
- param["isOpenVip"] = "0";
- return param;
- }
- //获取点单相关的套餐参数(仅用于套餐)
- rapidjson::Document CZhengcanOrderItem::getDiandanTaocanParam(rapidjson::Document::AllocatorType &allocator)
- {
- rapidjson::Document doc(&allocator);
- doc.SetObject();
- if (m_is_taocan == false)
- {
- return doc;
- }
- Value v_foodpackage_id;
- v_foodpackage_id.SetString(foodpackage_id.c_str(), foodpackage_id.length(), allocator);
- doc.AddMember("foodpackage_id", v_foodpackage_id, allocator);
- std::string show_name = foodpackage_name;
- Value v_show_name;
- v_show_name.SetString(show_name.c_str(), show_name.length(), allocator);
- doc.AddMember("food_name", v_show_name, allocator);
- std::string single_price = getSinglePrice();
- Value v_single_price;
- v_single_price.SetString(single_price.c_str(), single_price.length(), allocator);
- doc.AddMember("food_price", v_single_price, allocator);
- if (is_dabao)
- {
- doc.AddMember("is_dabao", "1", allocator);
- }
- else
- {
- doc.AddMember("is_dabao", "0", allocator);
- }
- Value v_dabao_money;
- v_dabao_money.SetString(dabao_money.c_str(), dabao_money.length(), allocator);
- doc.AddMember("dabao_money", v_dabao_money, allocator);
- Value v_num;
- v_num.SetString(num.c_str(), num.length(), allocator);
- doc.AddMember("quantity", v_num, allocator);
- Value v_is_jiacai;
- v_is_jiacai.SetString(is_jiacai.c_str(), is_jiacai.length(), allocator);
- doc.AddMember("is_jiacai", v_is_jiacai, allocator);
- Value v_is_tuicai;
- v_is_tuicai.SetString(is_tuicai.c_str(), is_tuicai.length(), allocator);
- doc.AddMember("is_tuicai", v_is_tuicai, allocator);
- std::string is_openvip = "0";
- Value v_is_openvip;
- v_is_openvip.SetString(is_openvip.c_str(), is_openvip.length(), allocator);
- doc.AddMember("isOpenVip", v_is_openvip, allocator);
- std::string open_dabao = "0";
- Value v_open_dabao;
- v_open_dabao.SetString(open_dabao.c_str(), open_dabao.length(), allocator);
- doc.AddMember("open_dabao", v_open_dabao, allocator);
- std::string vip_price = "0";
- Value v_vip_price;
- v_vip_price.SetString(vip_price.c_str(), vip_price.length(), allocator);
- doc.AddMember("vipPrice", v_vip_price, allocator);
- std::vector<std::map<string, string>> item;
- //遍历套餐的每个商品
- for (std::vector<FoodNatureSelectValue>::iterator it = natureSelectedArray.begin(); it != natureSelectedArray.end(); it++)
- {
- std::map<string, string> curFood;
- FoodNatureSelectValue curNature = *it;
- std::string foodpackage_nature = m_foodpackageinfo.nature;
- rapidjson::Document doc_tmp = CLewaimaiJson::StringToJson(foodpackage_nature, allocator);
- std::string food_id = doc_tmp[curNature.nNameIndex]["value"][curNature.nature_select_index].GetString();
- curFood["food_id"] = food_id;
- CFood foodinfo;
- CSqlite3 sqlite;
- bool is_found = sqlite.GetFoodById(food_id, foodinfo);
- if (!is_found)
- {
- continue;
- }
- curFood["food_name"] = foodinfo.name;
- curFood["food_price"] = foodinfo.price;
- if (is_dabao)
- {
- curFood["is_dabao"] = "1";
- }
- else
- {
- curFood["is_dabao"] = "0";
- }
- curFood["quantity"] = num;
- curFood["type_id"] = foodinfo.type_id;
- curFood["foodpackage_id"] = foodpackage_id;
- curFood["is_foodpackage"] = "1";
- curFood["is_jiacai"] = is_jiacai;
- curFood["is_tuicai"] = is_tuicai;
- curFood["isOpenVip"] = "0";
- curFood["open_dabao"] = "0";
- curFood["vipPrice"] = "0";
- curFood["dabao_money"] = "0";
- item.push_back(curFood);
- }
- Value& data = CLewaimaiJson::ParamArrayToJson(item, allocator);
- doc.AddMember("item", data, allocator);
- return doc;
- }
|