CHuiyuanPageUI.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. #include "../pch/pch.h"
  2. #include "CHuiyuanPageUI.h"
  3. #include "../wnd/CHuiyuanChongzhiWnd.h"
  4. #include "../wnd/CHuiyuanAddWnd.h"
  5. #include "../zhipuzi/CHuiyuanchognzhiOrder.h"
  6. #include "../print/CPosPrinter.h"
  7. CHuiyuanPageUI::CHuiyuanPageUI()
  8. {
  9. }
  10. CHuiyuanPageUI::~CHuiyuanPageUI()
  11. {
  12. }
  13. //初始化当前页面的展示,处理默认展示效果,在页面被加载的时候调用
  14. void CHuiyuanPageUI::InitShow()
  15. {
  16. CEditUI* pFukuanEdit = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
  17. pFukuanEdit->SetFocus();
  18. }
  19. //处理按钮点击类事件
  20. void CHuiyuanPageUI::HandleClickMsg(TNotifyUI& msg)
  21. {
  22. CDuiString senderName = msg.pSender->GetName();
  23. if (senderName == L"jianpan_1")
  24. {
  25. CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
  26. wstring wsReason = pContent->GetText();
  27. wsReason += L"1";
  28. pContent->SetText(wsReason.c_str());
  29. pContent->SetFocus();
  30. }
  31. else if (senderName == L"jianpan_2")
  32. {
  33. CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
  34. wstring wsReason = pContent->GetText();
  35. wsReason += L"2";
  36. pContent->SetText(wsReason.c_str());
  37. pContent->SetFocus();
  38. }
  39. else if (senderName == L"jianpan_3")
  40. {
  41. CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
  42. wstring wsReason = pContent->GetText();
  43. wsReason += L"3";
  44. pContent->SetText(wsReason.c_str());
  45. pContent->SetFocus();
  46. }
  47. else if (senderName == L"jianpan_4")
  48. {
  49. CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
  50. wstring wsReason = pContent->GetText();
  51. wsReason += L"4";
  52. pContent->SetText(wsReason.c_str());
  53. pContent->SetFocus();
  54. }
  55. else if (senderName == L"jianpan_5")
  56. {
  57. CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
  58. wstring wsReason = pContent->GetText();
  59. wsReason += L"5";
  60. pContent->SetText(wsReason.c_str());
  61. pContent->SetFocus();
  62. }
  63. else if (senderName == L"jianpan_6")
  64. {
  65. CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
  66. wstring wsReason = pContent->GetText();
  67. wsReason += L"6";
  68. pContent->SetText(wsReason.c_str());
  69. pContent->SetFocus();
  70. }
  71. else if (senderName == L"jianpan_7")
  72. {
  73. CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
  74. wstring wsReason = pContent->GetText();
  75. wsReason += L"7";
  76. pContent->SetText(wsReason.c_str());
  77. pContent->SetFocus();
  78. }
  79. else if (senderName == L"jianpan_8")
  80. {
  81. CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
  82. wstring wsReason = pContent->GetText();
  83. wsReason += L"8";
  84. pContent->SetText(wsReason.c_str());
  85. pContent->SetFocus();
  86. }
  87. else if (senderName == L"jianpan_9")
  88. {
  89. CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
  90. wstring wsReason = pContent->GetText();
  91. wsReason += L"9";
  92. pContent->SetText(wsReason.c_str());
  93. pContent->SetFocus();
  94. }
  95. else if (senderName == L"jianpan_0")
  96. {
  97. CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
  98. wstring wsReason = pContent->GetText();
  99. wsReason += L"0";
  100. pContent->SetText(wsReason.c_str());
  101. pContent->SetFocus();
  102. }
  103. else if (senderName == L"jianpan_x")
  104. {
  105. CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
  106. wstring wsReason = pContent->GetText();
  107. wsReason = wsReason.substr(0, wsReason.length() - 1);
  108. pContent->SetText(wsReason.c_str());
  109. pContent->SetFocus();
  110. }
  111. else if (senderName == L"jianpan_qingkong")
  112. {
  113. CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
  114. wstring wsReason = pContent->GetText();
  115. wsReason.clear();
  116. pContent->SetText(wsReason.c_str());
  117. pContent->SetFocus();
  118. }
  119. else if (senderName == _T("huiiyuan_page_sousuo_btn"))
  120. {
  121. //如果是手动点击了,就重置这个搜索手机号
  122. CEditUI* m_pEdit = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
  123. wstring ws_Value = m_pEdit->GetText();
  124. m_sousuo_phone = CLewaimaiString::UnicodeToUTF8(ws_Value);
  125. StartHuiyuanSousuo();
  126. }
  127. else if (senderName == L"huiiyuan_page_chongzhi_btn")
  128. {
  129. StartHuiyuanChongzhi();
  130. }
  131. else if (senderName == L"huiyuan_page_add_btn")
  132. {
  133. StartAddHuiyuan();
  134. }
  135. }
  136. //处理option切换事件
  137. void CHuiyuanPageUI::HandleSelectChangeMsg(TNotifyUI& msg)
  138. {
  139. }
  140. //处理下拉框、radio的切换事件
  141. void CHuiyuanPageUI::HandleItemSelectMsg(TNotifyUI& msg)
  142. {
  143. }
  144. //处理编辑框输入内容改变事件
  145. void CHuiyuanPageUI::HandleTextChangedMsg(TNotifyUI& msg)
  146. {
  147. DuiLib::CDuiString senderName = msg.pSender->GetName();
  148. if (senderName == L"huiyuan_page_shoujihao_edit")
  149. {
  150. //只能输入数字,其他的全部删除
  151. CEditUI* m_pEdit = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
  152. if (!m_pEdit->GetText().IsEmpty())
  153. {
  154. wstring ws_Value = m_pEdit->GetText();
  155. string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
  156. m_sousuo_phone = strValue;
  157. for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
  158. {
  159. unsigned char tmp = strValue.at(nIndex);
  160. if (tmp > 57 || tmp < 48)
  161. {
  162. //ASCII码不是数字的都过滤掉
  163. strValue = strValue.substr(0, nIndex);
  164. m_sousuo_phone = strValue;
  165. m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
  166. m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
  167. break;
  168. }
  169. }
  170. }
  171. }
  172. }
  173. //处理扫码枪捕捉到的扫码信息
  174. void CHuiyuanPageUI::HandleTextCapture(std::string content)
  175. {
  176. if (m_is_show_modal_wnd == true)
  177. {
  178. m_curModalWnd->HandleTextCapture(content);
  179. }
  180. }
  181. void CHuiyuanPageUI::StartHuiyuanSousuo()
  182. {
  183. if (m_is_handle == true)
  184. {
  185. return;
  186. }
  187. std::wstring ws_phone = CLewaimaiString::UTF8ToUnicode(m_sousuo_phone);
  188. if (ws_phone.length() != 11)
  189. {
  190. //手机号格式错误
  191. ShowError(L"手机号格式不对!");
  192. }
  193. //手机号格式正确,开始处理
  194. m_is_handle = true;
  195. m_phone = CLewaimaiString::UnicodeToUTF8(ws_phone);
  196. std::map<string, string> params;
  197. params["phone"] = m_phone;
  198. std::string response;
  199. bool ret = CZhipuziHttpClient::GetInstance()->Request("/member/membercheckbyphone", params, response);
  200. if (!ret)
  201. {
  202. ShowError(L"网络请求出错");
  203. m_is_handle = false;
  204. return;
  205. }
  206. rapidjson::Document document;
  207. document.Parse(response.c_str());
  208. if (document.HasParseError())
  209. {
  210. ShowError(L"服务器返回数据格式错误");
  211. m_is_handle = false;
  212. return;
  213. }
  214. else
  215. {
  216. if (!document.HasMember("errcode") || !document.HasMember("errmsg"))
  217. {
  218. ShowError(L"服务器返回数据格式错误");
  219. m_is_handle = false;
  220. return;
  221. }
  222. rapidjson::Value& v_errcode = document["errcode"];
  223. int errcode = v_errcode.GetInt();
  224. if (errcode != 0)
  225. {
  226. std::string errmsg = CLewaimaiString::UnicodeToUTF8(L"搜索结果:") + string(document["errmsg"].GetString());
  227. std::wstring m_errorInfo = CLewaimaiString::UTF8ToUnicode(errmsg);
  228. ShowError(m_errorInfo);
  229. m_is_handle = false;
  230. return;
  231. }
  232. rapidjson::Value& data = document["data"];
  233. rapidjson::Value& rows = data["rows"];
  234. if (rows.Size() < 1)
  235. {
  236. ShowError(L"会员信息为空");
  237. m_is_handle = false;
  238. return;
  239. }
  240. rapidjson::Value& rowinfo = rows[0];
  241. std::string card_no = rowinfo["card_no"].GetString();
  242. std::string member_name = rowinfo["name"].GetString();
  243. std::string phone = rowinfo["phone"].GetString();
  244. std::string sex = rowinfo["sex"].GetString();
  245. std::string birthday = rowinfo["birthday"].GetString();
  246. std::string balance = rowinfo["balance"].GetString();
  247. std::string member_level_name = rowinfo["member_level_name"].GetString();
  248. std::string address = rowinfo["address"].GetString();
  249. std::string card_identify = rowinfo["card_identify"].GetString();
  250. bool is_card;
  251. if (card_identify == "")
  252. {
  253. is_card = false;
  254. }
  255. else
  256. {
  257. is_card = true;
  258. }
  259. m_member_id = rowinfo["id"].GetString();
  260. m_balance = balance;
  261. m_member_card_no = rowinfo["card_no"].GetString();
  262. this->FindSubControl(L"huiyuan_num")->SetText((L"会员卡号:" + CLewaimaiString::UTF8ToUnicode(card_no)).c_str());
  263. this->FindSubControl(L"huiyuan_name")->SetText((L"会员姓名:" + CLewaimaiString::UTF8ToUnicode(member_name)).c_str());
  264. this->FindSubControl(L"huiyuan_phone")->SetText((L"电话:" + CLewaimaiString::UTF8ToUnicode(phone)).c_str());
  265. this->FindSubControl(L"huiyuan_sex")->SetText((L"性别:" + CLewaimaiString::UTF8ToUnicode(sex)).c_str());
  266. this->FindSubControl(L"huiyuan_address")->SetText((L"地址:" + CLewaimaiString::UTF8ToUnicode(address)).c_str());
  267. this->FindSubControl(L"huiyuan_birthday")->SetText((L"生日:" + CLewaimaiString::UTF8ToUnicode(birthday)).c_str());
  268. this->FindSubControl(L"huiyuan_levelname")->SetText((L"会员级别:" + CLewaimaiString::UTF8ToUnicode(member_level_name)).c_str());
  269. this->FindSubControl(L"huiyuan_yue")->SetText((L"当前余额:" + CLewaimaiString::UTF8ToUnicode(balance)).c_str());
  270. if (is_card)
  271. {
  272. this->FindSubControl(L"huiyuan_shitika")->SetText(L"实体会员卡:已绑定");
  273. }
  274. else
  275. {
  276. this->FindSubControl(L"huiyuan_shitika")->SetText(L"实体会员卡:未绑定");
  277. }
  278. this->FindSubControl(L"huiyuan_info_layout")->SetVisible(true);
  279. this->FindSubControl(L"huiyuan_page_no_layout")->SetVisible(false);
  280. m_is_handle = false;
  281. HideError();
  282. }
  283. }
  284. void CHuiyuanPageUI::ShowError(std::wstring err)
  285. {
  286. CLabelUI* m_pLabel= static_cast<CLabelUI*>(this->FindSubControl(_T("errorinfo")));
  287. m_pLabel->SetText(err.c_str());
  288. m_pLabel->SetVisible(true);
  289. this->FindSubControl(L"huiyuan_info_layout")->SetVisible(false);
  290. this->FindSubControl(L"huiyuan_page_no_layout")->SetVisible(true);
  291. }
  292. void CHuiyuanPageUI::StartAddHuiyuan()
  293. {
  294. if (m_is_show_modal_wnd == true)
  295. {
  296. return;
  297. }
  298. CHuiyuanAddWnd* pShoukuanWnd = new CHuiyuanAddWnd();
  299. if (pShoukuanWnd != NULL)
  300. {
  301. m_is_show_modal_wnd = true;
  302. m_curModalWnd = pShoukuanWnd;
  303. pShoukuanWnd->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW);
  304. pShoukuanWnd->SetIcon(IDI_ICON_DUILIB);
  305. pShoukuanWnd->CenterWindow();
  306. UINT ret = pShoukuanWnd->ShowModal();
  307. if (ret == IDOK)
  308. {
  309. //会员开通成功
  310. m_pMainWnd->ShowToast(L"会员开通成功");
  311. m_sousuo_phone = pShoukuanWnd->m_phone;
  312. StartHuiyuanSousuo();
  313. }
  314. m_is_show_modal_wnd = false;
  315. delete pShoukuanWnd;
  316. }
  317. }
  318. void CHuiyuanPageUI::StartHuiyuanChongzhi()
  319. {
  320. if (m_is_show_modal_wnd == true)
  321. {
  322. return;
  323. }
  324. //充值之前,保存一下搜索电话,因为充值成功后要刷新的
  325. m_sousuo_phone = m_phone;
  326. CHuiyuanChongzhiWnd* pShoukuanWnd = new CHuiyuanChongzhiWnd();
  327. if (pShoukuanWnd != NULL)
  328. {
  329. m_is_show_modal_wnd = true;
  330. m_curModalWnd = pShoukuanWnd;
  331. pShoukuanWnd->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW);
  332. pShoukuanWnd->SetIcon(IDI_ICON_DUILIB);
  333. pShoukuanWnd->CenterWindow();
  334. pShoukuanWnd->SetCurBalance(m_balance);
  335. pShoukuanWnd->m_member_id = m_member_id;
  336. pShoukuanWnd->m_member_card_no = m_member_card_no;
  337. UINT ret = pShoukuanWnd->ShowModal();
  338. if (ret == IDOK)
  339. {
  340. //然后处理小票打印
  341. CHuiyuanchongzhiOrder order;
  342. order.shopname = CShopinfo::GetInstance()->m_shop_name;
  343. order.show_trade_no = pShoukuanWnd->m_show_trade_no;
  344. order.init_time = CLewaimaiTime::DatetimeToString(time(NULL));
  345. order.account = CSetting::GetInstance()->getUsername();
  346. order.member_num = pShoukuanWnd->m_member_card_no;
  347. order.chongzhi_value = pShoukuanWnd->m_chongzhi;
  348. order.zengsong_value = pShoukuanWnd->m_zengsong;
  349. order.balance_before = pShoukuanWnd->m_cur_balance;
  350. order.balance_after = CLewaimaiString::DoubleToString(atof(m_balance.c_str()) + atof(order.chongzhi_value.c_str()) + atof(order.zengsong_value.c_str()), 2);
  351. if (pShoukuanWnd->m_fukuanma_type == 1)
  352. {
  353. order.pay_type = "微信支付";
  354. }
  355. else if (pShoukuanWnd->m_fukuanma_type == 2)
  356. {
  357. order.pay_type = "支付宝";
  358. }
  359. else if (pShoukuanWnd->m_fukuanma_type == 2)
  360. {
  361. order.pay_type = "云闪付";
  362. }
  363. CPosPrinter printer;
  364. printer.PrintHuiyuanchongzhiOrder(order);
  365. //这个表示充值成功了,这个时候刷新会员信息
  366. StartHuiyuanSousuo();
  367. }
  368. m_is_show_modal_wnd = false;
  369. delete pShoukuanWnd;
  370. }
  371. }
  372. void CHuiyuanPageUI::HideError()
  373. {
  374. CLabelUI* m_pLabel = static_cast<CLabelUI*>(this->FindSubControl(_T("errorinfo")));
  375. m_pLabel->SetVisible(true);
  376. }