CZhengcanOrderItem.cpp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. #include "../pch/pch.h"
  2. #include "CZhengcanOrderItem.h"
  3. #include "../tool/CSqlite3.h"
  4. bool CZhengcanOrderItem::operator==(CZhengcanOrderItem& t)
  5. {
  6. if (this->m_is_taocan != t.m_is_taocan)
  7. {
  8. return false;
  9. }
  10. if (this->is_dabao != t.is_dabao)
  11. {
  12. return false;
  13. }
  14. if (this->m_is_taocan == true)
  15. {
  16. if (this->foodpackage_id != t.foodpackage_id)
  17. {
  18. return false;
  19. }
  20. int i = 0;
  21. for (std::vector<FoodNatureSelectValue>::iterator it = this->natureSelectedArray.begin(); it != this->natureSelectedArray.end(); it++)
  22. {
  23. if ((*it).nature_name != t.natureSelectedArray[i].nature_name)
  24. {
  25. return false;
  26. }
  27. if ((*it).nature_select_index != t.natureSelectedArray[i].nature_select_index)
  28. {
  29. return false;
  30. }
  31. i++;
  32. }
  33. }
  34. else
  35. {
  36. if (this->food_id != t.food_id)
  37. {
  38. return false;
  39. }
  40. if (this->is_nature != t.is_nature)
  41. {
  42. return false;
  43. }
  44. if (this->is_nature == true)
  45. {
  46. int i = 0;
  47. for (std::vector<FoodNatureSelectValue>::iterator it = this->natureSelectedArray.begin(); it != this->natureSelectedArray.end(); it++)
  48. {
  49. if ((*it).nature_name != t.natureSelectedArray[i].nature_name)
  50. {
  51. return false;
  52. }
  53. if ((*it).nature_select_index != t.natureSelectedArray[i].nature_select_index)
  54. {
  55. return false;
  56. }
  57. i++;
  58. }
  59. }
  60. }
  61. return true;
  62. }
  63. void CZhengcanOrderItem::SetFoodInfo(CFood info)
  64. {
  65. m_foodinfo = info;
  66. }
  67. void CZhengcanOrderItem::SetFoodpackageInfo(CFoodpackage info)
  68. {
  69. m_foodpackageinfo = info;
  70. m_is_taocan = true;
  71. }
  72. void CZhengcanOrderItem::SetIsTaocan(bool is_taocan)
  73. {
  74. m_is_taocan = is_taocan;
  75. }
  76. void CZhengcanOrderItem::SetDabao()
  77. {
  78. is_dabao = true;
  79. }
  80. CFood CZhengcanOrderItem::GetFoodInfo()
  81. {
  82. return m_foodinfo;
  83. }
  84. CFoodpackage CZhengcanOrderItem::GetFoodpackageInfo()
  85. {
  86. return m_foodpackageinfo;
  87. }
  88. bool CZhengcanOrderItem::GetIsTaocan()
  89. {
  90. return m_is_taocan;
  91. }
  92. //根据当前选中的商品属性、份数,计算商品的展示价格
  93. void CZhengcanOrderItem::UpdateShowPrice()
  94. {
  95. if (m_is_taocan == true)
  96. {
  97. show_price = CLewaimaiString::DoubleToString(std::stod(price) * std::stod(num), 2);
  98. }
  99. else
  100. {
  101. if (!is_nature)
  102. {
  103. show_price = CLewaimaiString::DoubleToString(std::stod(price) * std::stod(num), 2);
  104. }
  105. else
  106. {
  107. double nature_price = 0;
  108. for (std::vector<FoodNatureSelectValue>::iterator it = this->natureSelectedArray.begin(); it != this->natureSelectedArray.end(); it++)
  109. {
  110. nature_price += (*it).nature_select_value;
  111. }
  112. double new_price = std::stod(price) + nature_price;
  113. show_price = CLewaimaiString::DoubleToString(new_price * std::stod(num), 2);
  114. }
  115. }
  116. }
  117. std::string CZhengcanOrderItem::getSinglePrice()
  118. {
  119. if (m_is_taocan == true)
  120. {
  121. return price;
  122. }
  123. else
  124. {
  125. if (!is_nature)
  126. {
  127. return price;
  128. }
  129. else
  130. {
  131. double nature_price = 0;
  132. for (std::vector<FoodNatureSelectValue>::iterator it = this->natureSelectedArray.begin(); it != this->natureSelectedArray.end(); it++)
  133. {
  134. nature_price += (*it).nature_select_value;
  135. }
  136. double new_price = std::stod(price) + nature_price;
  137. show_price = CLewaimaiString::DoubleToString(new_price, 2);
  138. return show_price;
  139. }
  140. }
  141. }
  142. std::string CZhengcanOrderItem::getNameShow()
  143. {
  144. if (m_is_taocan)
  145. {
  146. if (is_dabao)
  147. {
  148. return CLewaimaiString::UnicodeToUTF8(L"【打包】") + foodpackage_name;
  149. }
  150. else
  151. {
  152. return foodpackage_name;
  153. }
  154. }
  155. else
  156. {
  157. if (is_dabao)
  158. {
  159. return CLewaimaiString::UnicodeToUTF8(L"【打包】") + food_name;
  160. }
  161. else
  162. {
  163. return food_name;
  164. }
  165. }
  166. }
  167. //获取用于展示的属性名字
  168. std::string CZhengcanOrderItem::getNatureShow()
  169. {
  170. std::string show = "";
  171. if (m_is_taocan)
  172. {
  173. size_t i = 0;
  174. for (std::vector<FoodNatureSelectValue>::iterator it = this->natureSelectedArray.begin(); it != this->natureSelectedArray.end(); it++)
  175. {
  176. show += (*it).nature_select_name;
  177. if (i < natureSelectedArray.size() - 1)
  178. {
  179. show += CLewaimaiString::UnicodeToUTF8(L"、");
  180. }
  181. i++;
  182. }
  183. }
  184. else
  185. {
  186. if (!is_nature)
  187. {
  188. return "";
  189. }
  190. size_t i = 0;
  191. for (std::vector<FoodNatureSelectValue>::iterator it = this->natureSelectedArray.begin(); it != this->natureSelectedArray.end(); it++)
  192. {
  193. show += (*it).nature_select_name;
  194. if (i < natureSelectedArray.size() - 1)
  195. {
  196. show += CLewaimaiString::UnicodeToUTF8(L"、");
  197. }
  198. i++;
  199. }
  200. }
  201. return show;
  202. }
  203. //获取用于完整展示的商品名字,包含商品本身的名字和属性,例如“【打包】珍珠奶茶【大杯、热、多糖】”
  204. std::string CZhengcanOrderItem::getNameWanzhengShow()
  205. {
  206. std::string name_first = getNameShow();
  207. std::string nature = "";
  208. //后面再加上属性或者套餐商品名字
  209. if (m_is_taocan)
  210. {
  211. nature = CLewaimaiString::UnicodeToUTF8(L"【") + getNatureShow() + CLewaimaiString::UnicodeToUTF8(L"】");
  212. }
  213. else
  214. {
  215. if (is_nature)
  216. {
  217. nature = CLewaimaiString::UnicodeToUTF8(L"【") + getNatureShow() + CLewaimaiString::UnicodeToUTF8(L"】");
  218. }
  219. else
  220. {
  221. nature = "";
  222. }
  223. }
  224. std::string total_name = name_first + nature;
  225. return total_name;
  226. }
  227. double CZhengcanOrderItem::getMemberYouhui(std::string member_level)
  228. {
  229. if (is_member_price_used == false)
  230. {
  231. return 0;
  232. }
  233. for (std::vector<MemberPrice>::iterator it = m_member_price.begin(); it != m_member_price.end(); it++)
  234. {
  235. MemberPrice cur = *it;
  236. if (cur.level == member_level)
  237. {
  238. double member_food_price = atof(cur.price.c_str());
  239. double yuan_price = atof(price.c_str());
  240. double chajia = (yuan_price - member_food_price) * atof(num.c_str());
  241. return chajia;
  242. }
  243. }
  244. return 0;
  245. }
  246. double CZhengcanOrderItem::getDabaoMoney()
  247. {
  248. if (is_dabao)
  249. {
  250. return atof(dabao_money.c_str()) * (int)atof(num.c_str());
  251. }
  252. return 0;
  253. }
  254. //获取点单相关的参数(仅用于非套餐)
  255. std::map<string, string> CZhengcanOrderItem::getDiandanParam()
  256. {
  257. std::map<string, string> param;
  258. if (m_is_taocan)
  259. {
  260. return param;
  261. }
  262. param["food_id"] = food_id;
  263. if (is_nature)
  264. {
  265. param["food_name"] = food_name + CLewaimaiString::UnicodeToUTF8(L"【") + getNatureShow() + CLewaimaiString::UnicodeToUTF8(L"】");
  266. }
  267. else
  268. {
  269. param["food_name"] = food_name;
  270. }
  271. param["food_price"] = getSinglePrice();
  272. if (is_dabao)
  273. {
  274. param["is_dabao"] = "1";
  275. }
  276. else
  277. {
  278. param["is_dabao"] = "0";
  279. }
  280. param["dabao_money"] = dabao_money;
  281. param["quantity"] = num;
  282. param["type_id"] = m_foodinfo.type_id;
  283. param["foodpackage_id"] = "0";
  284. param["is_foodpackage"] = "0";
  285. param["is_jiacai"] = is_jiacai;
  286. param["is_tuicai"] = "0";
  287. param["isOpenVip"] = "0";
  288. return param;
  289. }
  290. //获取点单相关的套餐参数(仅用于套餐)
  291. rapidjson::Document CZhengcanOrderItem::getDiandanTaocanParam(rapidjson::Document::AllocatorType &allocator)
  292. {
  293. rapidjson::Document doc(&allocator);
  294. doc.SetObject();
  295. if (m_is_taocan == false)
  296. {
  297. return doc;
  298. }
  299. Value v_foodpackage_id;
  300. v_foodpackage_id.SetString(foodpackage_id.c_str(), foodpackage_id.length(), allocator);
  301. doc.AddMember("foodpackage_id", v_foodpackage_id, allocator);
  302. std::string show_name = foodpackage_name;
  303. Value v_show_name;
  304. v_show_name.SetString(show_name.c_str(), show_name.length(), allocator);
  305. doc.AddMember("food_name", v_show_name, allocator);
  306. std::string single_price = getSinglePrice();
  307. Value v_single_price;
  308. v_single_price.SetString(single_price.c_str(), single_price.length(), allocator);
  309. doc.AddMember("food_price", v_single_price, allocator);
  310. if (is_dabao)
  311. {
  312. doc.AddMember("is_dabao", "1", allocator);
  313. }
  314. else
  315. {
  316. doc.AddMember("is_dabao", "0", allocator);
  317. }
  318. Value v_dabao_money;
  319. v_dabao_money.SetString(dabao_money.c_str(), dabao_money.length(), allocator);
  320. doc.AddMember("dabao_money", v_dabao_money, allocator);
  321. Value v_num;
  322. v_num.SetString(num.c_str(), num.length(), allocator);
  323. doc.AddMember("quantity", v_num, allocator);
  324. Value v_is_jiacai;
  325. v_is_jiacai.SetString(is_jiacai.c_str(), is_jiacai.length(), allocator);
  326. doc.AddMember("is_jiacai", v_is_jiacai, allocator);
  327. Value v_is_tuicai;
  328. v_is_tuicai.SetString(is_tuicai.c_str(), is_tuicai.length(), allocator);
  329. doc.AddMember("is_tuicai", v_is_tuicai, allocator);
  330. std::string is_openvip = "0";
  331. Value v_is_openvip;
  332. v_is_openvip.SetString(is_openvip.c_str(), is_openvip.length(), allocator);
  333. doc.AddMember("isOpenVip", v_is_openvip, allocator);
  334. std::string open_dabao = "0";
  335. Value v_open_dabao;
  336. v_open_dabao.SetString(open_dabao.c_str(), open_dabao.length(), allocator);
  337. doc.AddMember("open_dabao", v_open_dabao, allocator);
  338. std::string vip_price = "0";
  339. Value v_vip_price;
  340. v_vip_price.SetString(vip_price.c_str(), vip_price.length(), allocator);
  341. doc.AddMember("vipPrice", v_vip_price, allocator);
  342. std::vector<std::map<string, string>> item;
  343. //遍历套餐的每个商品
  344. for (std::vector<FoodNatureSelectValue>::iterator it = natureSelectedArray.begin(); it != natureSelectedArray.end(); it++)
  345. {
  346. std::map<string, string> curFood;
  347. FoodNatureSelectValue curNature = *it;
  348. std::string foodpackage_nature = m_foodpackageinfo.nature;
  349. rapidjson::Document doc_tmp = CLewaimaiJson::StringToJson(foodpackage_nature, allocator);
  350. std::string food_id = doc_tmp[curNature.nNameIndex]["value"][curNature.nature_select_index].GetString();
  351. curFood["food_id"] = food_id;
  352. CFood foodinfo;
  353. CSqlite3 sqlite;
  354. bool is_found = sqlite.GetFoodById(food_id, foodinfo);
  355. if (!is_found)
  356. {
  357. continue;
  358. }
  359. curFood["food_name"] = foodinfo.name;
  360. curFood["food_price"] = foodinfo.price;
  361. if (is_dabao)
  362. {
  363. curFood["is_dabao"] = "1";
  364. }
  365. else
  366. {
  367. curFood["is_dabao"] = "0";
  368. }
  369. curFood["quantity"] = num;
  370. curFood["type_id"] = foodinfo.type_id;
  371. curFood["foodpackage_id"] = foodpackage_id;
  372. curFood["is_foodpackage"] = "1";
  373. curFood["is_jiacai"] = is_jiacai;
  374. curFood["is_tuicai"] = is_tuicai;
  375. curFood["isOpenVip"] = "0";
  376. curFood["open_dabao"] = "0";
  377. curFood["vipPrice"] = "0";
  378. curFood["dabao_money"] = "0";
  379. item.push_back(curFood);
  380. }
  381. Value& data = CLewaimaiJson::ParamArrayToJson(item, allocator);
  382. doc.AddMember("item", data, allocator);
  383. return doc;
  384. }