| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471 |
- #include "../pch/pch.h"
- #include "CHuiyuanPageUI.h"
- #include "../wnd/CHuiyuanChongzhiWnd.h"
- #include "../wnd/CHuiyuanAddWnd.h"
- #include "../zhipuzi/CHuiyuanchognzhiOrder.h"
- #include "../print/CPosPrinter.h"
- CHuiyuanPageUI::CHuiyuanPageUI()
- {
- }
- CHuiyuanPageUI::~CHuiyuanPageUI()
- {
- }
- //初始化当前页面的展示,处理默认展示效果,在页面被加载的时候调用
- void CHuiyuanPageUI::InitShow()
- {
- CEditUI* pFukuanEdit = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
- pFukuanEdit->SetFocus();
- }
- //处理按钮点击类事件
- void CHuiyuanPageUI::HandleClickMsg(TNotifyUI& msg)
- {
- CDuiString senderName = msg.pSender->GetName();
- if (senderName == L"jianpan_1")
- {
- CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
- wstring wsReason = pContent->GetText();
- wsReason += L"1";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_2")
- {
- CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
- wstring wsReason = pContent->GetText();
- wsReason += L"2";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_3")
- {
- CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
- wstring wsReason = pContent->GetText();
- wsReason += L"3";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_4")
- {
- CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
- wstring wsReason = pContent->GetText();
- wsReason += L"4";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_5")
- {
- CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
- wstring wsReason = pContent->GetText();
- wsReason += L"5";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_6")
- {
- CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
- wstring wsReason = pContent->GetText();
- wsReason += L"6";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_7")
- {
- CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
- wstring wsReason = pContent->GetText();
- wsReason += L"7";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_8")
- {
- CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
- wstring wsReason = pContent->GetText();
- wsReason += L"8";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_9")
- {
- CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
- wstring wsReason = pContent->GetText();
- wsReason += L"9";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_0")
- {
- CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
- wstring wsReason = pContent->GetText();
- wsReason += L"0";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_x")
- {
- CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
- wstring wsReason = pContent->GetText();
- wsReason = wsReason.substr(0, wsReason.length() - 1);
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_qingkong")
- {
- CEditUI* pContent = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
- wstring wsReason = pContent->GetText();
- wsReason.clear();
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == _T("huiiyuan_page_sousuo_btn"))
- {
- //如果是手动点击了,就重置这个搜索手机号
- CEditUI* m_pEdit = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
- wstring ws_Value = m_pEdit->GetText();
- m_sousuo_phone = CLewaimaiString::UnicodeToUTF8(ws_Value);
- StartHuiyuanSousuo();
- }
- else if (senderName == L"huiiyuan_page_chongzhi_btn")
- {
- StartHuiyuanChongzhi();
- }
- else if (senderName == L"huiyuan_page_add_btn")
- {
- StartAddHuiyuan();
- }
- }
- //处理option切换事件
- void CHuiyuanPageUI::HandleSelectChangeMsg(TNotifyUI& msg)
- {
- }
- //处理下拉框、radio的切换事件
- void CHuiyuanPageUI::HandleItemSelectMsg(TNotifyUI& msg)
- {
- }
- //处理编辑框输入内容改变事件
- void CHuiyuanPageUI::HandleTextChangedMsg(TNotifyUI& msg)
- {
- DuiLib::CDuiString senderName = msg.pSender->GetName();
- if (senderName == L"huiyuan_page_shoujihao_edit")
- {
- //只能输入数字,其他的全部删除
- CEditUI* m_pEdit = static_cast<CEditUI*>(this->FindSubControl(_T("huiyuan_page_shoujihao_edit")));
- if (!m_pEdit->GetText().IsEmpty())
- {
- wstring ws_Value = m_pEdit->GetText();
- string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
- m_sousuo_phone = strValue;
- for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
- {
- unsigned char tmp = strValue.at(nIndex);
- if (tmp > 57 || tmp < 48)
- {
- //ASCII码不是数字的都过滤掉
- strValue = strValue.substr(0, nIndex);
- m_sousuo_phone = strValue;
- m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
- m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
- break;
- }
- }
- }
- }
- }
- //处理扫码枪捕捉到的扫码信息
- void CHuiyuanPageUI::HandleTextCapture(std::string content)
- {
- if (m_is_show_modal_wnd == true)
- {
- m_curModalWnd->HandleTextCapture(content);
- }
- }
- void CHuiyuanPageUI::StartHuiyuanSousuo()
- {
- if (m_is_handle == true)
- {
- return;
- }
- std::wstring ws_phone = CLewaimaiString::UTF8ToUnicode(m_sousuo_phone);
- if (ws_phone.length() != 11)
- {
- //手机号格式错误
- ShowError(L"手机号格式不对!");
- }
- //手机号格式正确,开始处理
- m_is_handle = true;
- m_phone = CLewaimaiString::UnicodeToUTF8(ws_phone);
- std::map<string, string> params;
- params["phone"] = m_phone;
- std::string response;
- bool ret = CZhipuziHttpClient::GetInstance()->Request("/member/membercheckbyphone", params, response);
- if (!ret)
- {
- ShowError(L"网络请求出错");
- m_is_handle = false;
- return;
- }
- rapidjson::Document document;
- document.Parse(response.c_str());
- if (document.HasParseError())
- {
- ShowError(L"服务器返回数据格式错误");
- m_is_handle = false;
- return;
- }
- else
- {
- if (!document.HasMember("errcode") || !document.HasMember("errmsg"))
- {
- ShowError(L"服务器返回数据格式错误");
- m_is_handle = false;
- return;
- }
- rapidjson::Value& v_errcode = document["errcode"];
- int errcode = v_errcode.GetInt();
- if (errcode != 0)
- {
- std::string errmsg = CLewaimaiString::UnicodeToUTF8(L"搜索结果:") + string(document["errmsg"].GetString());
- std::wstring m_errorInfo = CLewaimaiString::UTF8ToUnicode(errmsg);
- ShowError(m_errorInfo);
- m_is_handle = false;
- return;
- }
- rapidjson::Value& data = document["data"];
- rapidjson::Value& rows = data["rows"];
- if (rows.Size() < 1)
- {
- ShowError(L"会员信息为空");
- m_is_handle = false;
- return;
- }
- rapidjson::Value& rowinfo = rows[0];
- std::string card_no = rowinfo["card_no"].GetString();
- std::string member_name = rowinfo["name"].GetString();
- std::string phone = rowinfo["phone"].GetString();
- std::string sex = rowinfo["sex"].GetString();
- std::string birthday = rowinfo["birthday"].GetString();
- std::string balance = rowinfo["balance"].GetString();
- std::string member_level_name = rowinfo["member_level_name"].GetString();
- std::string address = rowinfo["address"].GetString();
- std::string card_identify = rowinfo["card_identify"].GetString();
- bool is_card;
- if (card_identify == "")
- {
- is_card = false;
- }
- else
- {
- is_card = true;
- }
- m_member_id = rowinfo["id"].GetString();
- m_balance = balance;
- m_member_card_no = rowinfo["card_no"].GetString();
- this->FindSubControl(L"huiyuan_num")->SetText((L"会员卡号:" + CLewaimaiString::UTF8ToUnicode(card_no)).c_str());
- this->FindSubControl(L"huiyuan_name")->SetText((L"会员姓名:" + CLewaimaiString::UTF8ToUnicode(member_name)).c_str());
- this->FindSubControl(L"huiyuan_phone")->SetText((L"电话:" + CLewaimaiString::UTF8ToUnicode(phone)).c_str());
- this->FindSubControl(L"huiyuan_sex")->SetText((L"性别:" + CLewaimaiString::UTF8ToUnicode(sex)).c_str());
- this->FindSubControl(L"huiyuan_address")->SetText((L"地址:" + CLewaimaiString::UTF8ToUnicode(address)).c_str());
- this->FindSubControl(L"huiyuan_birthday")->SetText((L"生日:" + CLewaimaiString::UTF8ToUnicode(birthday)).c_str());
- this->FindSubControl(L"huiyuan_levelname")->SetText((L"会员级别:" + CLewaimaiString::UTF8ToUnicode(member_level_name)).c_str());
- this->FindSubControl(L"huiyuan_yue")->SetText((L"当前余额:" + CLewaimaiString::UTF8ToUnicode(balance)).c_str());
- if (is_card)
- {
- this->FindSubControl(L"huiyuan_shitika")->SetText(L"实体会员卡:已绑定");
- }
- else
- {
- this->FindSubControl(L"huiyuan_shitika")->SetText(L"实体会员卡:未绑定");
- }
- this->FindSubControl(L"huiyuan_info_layout")->SetVisible(true);
- this->FindSubControl(L"huiyuan_page_no_layout")->SetVisible(false);
- m_is_handle = false;
- HideError();
- }
- }
- void CHuiyuanPageUI::ShowError(std::wstring err)
- {
- CLabelUI* m_pLabel= static_cast<CLabelUI*>(this->FindSubControl(_T("errorinfo")));
- m_pLabel->SetText(err.c_str());
- m_pLabel->SetVisible(true);
- this->FindSubControl(L"huiyuan_info_layout")->SetVisible(false);
- this->FindSubControl(L"huiyuan_page_no_layout")->SetVisible(true);
- }
- void CHuiyuanPageUI::StartAddHuiyuan()
- {
- if (m_is_show_modal_wnd == true)
- {
- return;
- }
- CHuiyuanAddWnd* pShoukuanWnd = new CHuiyuanAddWnd();
- if (pShoukuanWnd != NULL)
- {
- m_is_show_modal_wnd = true;
- m_curModalWnd = pShoukuanWnd;
- pShoukuanWnd->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW);
- pShoukuanWnd->SetIcon(IDI_ICON_DUILIB);
- pShoukuanWnd->CenterWindow();
- UINT ret = pShoukuanWnd->ShowModal();
- if (ret == IDOK)
- {
- //会员开通成功
- m_pMainWnd->ShowToast(L"会员开通成功");
- m_sousuo_phone = pShoukuanWnd->m_phone;
- StartHuiyuanSousuo();
- }
- m_is_show_modal_wnd = false;
- delete pShoukuanWnd;
- }
- }
- void CHuiyuanPageUI::StartHuiyuanChongzhi()
- {
- if (m_is_show_modal_wnd == true)
- {
- return;
- }
- //充值之前,保存一下搜索电话,因为充值成功后要刷新的
- m_sousuo_phone = m_phone;
- CHuiyuanChongzhiWnd* pShoukuanWnd = new CHuiyuanChongzhiWnd();
- if (pShoukuanWnd != NULL)
- {
- m_is_show_modal_wnd = true;
- m_curModalWnd = pShoukuanWnd;
- pShoukuanWnd->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW);
- pShoukuanWnd->SetIcon(IDI_ICON_DUILIB);
- pShoukuanWnd->CenterWindow();
- pShoukuanWnd->SetCurBalance(m_balance);
- pShoukuanWnd->m_member_id = m_member_id;
- pShoukuanWnd->m_member_card_no = m_member_card_no;
- UINT ret = pShoukuanWnd->ShowModal();
- if (ret == IDOK)
- {
- //然后处理小票打印
- CHuiyuanchongzhiOrder order;
- order.shopname = CShopinfo::GetInstance()->m_shop_name;
- order.show_trade_no = pShoukuanWnd->m_show_trade_no;
- order.init_time = CLewaimaiTime::DatetimeToString(time(NULL));
- order.account = CSetting::GetInstance()->getUsername();
- order.member_num = pShoukuanWnd->m_member_card_no;
- order.chongzhi_value = pShoukuanWnd->m_chongzhi;
- order.zengsong_value = pShoukuanWnd->m_zengsong;
- order.balance_before = pShoukuanWnd->m_cur_balance;
- order.balance_after = CLewaimaiString::DoubleToString(atof(m_balance.c_str()) + atof(order.chongzhi_value.c_str()) + atof(order.zengsong_value.c_str()), 2);
- if (pShoukuanWnd->m_fukuanma_type == 1)
- {
- order.pay_type = "微信支付";
- }
- else if (pShoukuanWnd->m_fukuanma_type == 2)
- {
- order.pay_type = "支付宝";
- }
- else if (pShoukuanWnd->m_fukuanma_type == 2)
- {
- order.pay_type = "云闪付";
- }
-
- CPosPrinter printer;
- printer.PrintHuiyuanchongzhiOrder(order);
- //这个表示充值成功了,这个时候刷新会员信息
- StartHuiyuanSousuo();
- }
- m_is_show_modal_wnd = false;
- delete pShoukuanWnd;
- }
- }
- void CHuiyuanPageUI::HideError()
- {
- CLabelUI* m_pLabel = static_cast<CLabelUI*>(this->FindSubControl(_T("errorinfo")));
- m_pLabel->SetVisible(true);
- }
|