zhangyang 6 years ago
parent
commit
6bea5124aa

+ 6 - 8
bin/Win32/Debug/zhipuzi_pos_windows/skin/GameRes/desk.xml

@@ -1,12 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Window>
-	<Container width="182" height="152" inset="2,2,2,2" bkimage="file='table.png' source='0,0,64,64' dest='59,36,123,100'">
-		<Button float="true" normalimage="user.png" pos="92,6,132,46" />
-		<Button float="true" normalimage="user.png" pos="22,80,62,120" />
-		<Button float="true" normalimage="user.png" pos="120,64,160,104" />
-		<Label float="true" textcolor="#FFDDDDDD" align="center" mouse="false" pos="70,132,116,150" />
-		<Label float="true" text="上面这人名字" textcolor="#FF558CC4" pos="0,6,182,26" mouse="false" />
-		<Label float="true" text="左边这人名字" textcolor="#FF558CC4" pos="0,60,182,80" mouse="false" />
-		<Label float="true" text="右边这人名字" textcolor="#FF558CC4" align="right" pos="0,100,182,120" mouse="false"/>
+	<Container width="1000" height="200" padding="10,10,10,10" bkcolor="#FFFFFFFF" childpadding="20">
+		<Label float="true" name="waimai_order_list_name" text="姓名:" textcolor="#FF558CC4" pos="0,6,182,36" mouse="false" />
+		<Label float="true" name="waimai_order_list_phone" text="电话:" textcolor="#FF558CC4" pos="0,36,182,66" mouse="false" />
+		<Label float="true" name="waimai_order_list_address" text="地址:" textcolor="#FF558CC4" pos="0,66,182,96" mouse="false" />
+		<Label float="true" name="waimai_order_list_price" text="价格:" textcolor="#FF558CC4" pos="300,6,482,36" mouse="false" />
+		<Label float="true" name="waimai_order_list_order_no" text="订单编号:" textcolor="#FF558CC4" pos="300,36,482,66" mouse="false" />
 	</Container>
 </Window>

+ 5 - 2
bin/Win32/Debug/zhipuzi_pos_windows/skin/GameRes/main.xml

@@ -30,7 +30,8 @@
     			</HorizontalLayout>
     		</HorizontalLayout>
 			
-			<TabLayout name="switch">	
+			<TabLayout name="switch">
+				<!--外卖的 -->
 				<HorizontalLayout>
 					<HorizontalLayout width="300" bkcolor="#FFFFFFFF">
 						<VerticalLayout childpadding="20">
@@ -44,9 +45,11 @@
 					</HorizontalLayout>
 					
 					<VerticalLayout bkcolor="#FF103668" vscrollbar="true">
-					
+						<DeskList name="orderlist" bkcolor="#FF103668" vscrollbar="true" />
 					</VerticalLayout>
 				</HorizontalLayout>
+				
+				<!--扫码下单的-->
 			</TabLayout>
         </VerticalLayout>
         

BIN
bin/Win32/Debug/zhipuzi_pos_windows/zhipuzi_pos_windows.exe


+ 3 - 0
lewaimai_dispatch/lewaimai_dispatch_windows.vcxproj

@@ -202,12 +202,14 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
     <ClInclude Include="helper\CRandomHelper.h" />
     <ClInclude Include="helper\define.h" />
     <ClInclude Include="network\CHttpClient.h" />
+    <ClInclude Include="wnd\ControlEx.h" />
     <ClInclude Include="wnd\MiniDumper.h" />
     <ClInclude Include="resource\resource.h" />
     <ClInclude Include="tool\CLewaimaiLog.h" />
     <ClInclude Include="pch\pch.h" />
     <ClInclude Include="tool\CLewaimaiTime.h" />
     <ClInclude Include="helper\CSystem.h" />
+    <ClInclude Include="wnd\OrderListUI.h" />
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="wnd\CGameFrameWnd.cpp" />
@@ -224,6 +226,7 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
     <ClCompile Include="lewaimai_dispatch_windows.cpp" />
     <ClCompile Include="pch\pch.cpp" />
     <ClCompile Include="tool\CLewaimaiTime.cpp" />
+    <ClCompile Include="wnd\OrderListUI.cpp" />
   </ItemGroup>
   <ItemGroup>
     <None Include="conf\dispatch.conf" />

+ 9 - 0
lewaimai_dispatch/lewaimai_dispatch_windows.vcxproj.filters

@@ -60,6 +60,12 @@
     <ClInclude Include="resource\resource.h">
       <Filter>头文件</Filter>
     </ClInclude>
+    <ClInclude Include="wnd\ControlEx.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
+    <ClInclude Include="wnd\OrderListUI.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="lewaimai_dispatch_windows.cpp">
@@ -104,6 +110,9 @@
     <ClCompile Include="wnd\CGameFrameWnd.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
+    <ClCompile Include="wnd\OrderListUI.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <None Include="conf\dispatch.conf" />

+ 77 - 27
lewaimai_dispatch/network/CZhipuziHttpClient.cpp

@@ -32,7 +32,7 @@ bool CZhipuziHttpClient::Login(std::string& errmsg)
 	std::map<string, string> params;
 
 	std::string response;
-	bool ret = m_client.Request("/login/login", params, response);
+	bool ret = m_client.RequestNew("/login/login", params, response);
 
 	if (!ret)
 	{
@@ -67,22 +67,17 @@ bool CZhipuziHttpClient::Login(std::string& errmsg)
 	return true;
 }
 
-bool CZhipuziHttpClient::Request(std::string url, std::map<string, string> params, std::string& response)
+bool CZhipuziHttpClient::RequestOld(std::string url, std::map<string, string> params, std::string& response)
 {
 	std::string timestamp = to_string(time(NULL));
 	std::string nonce = "123456";
-	std::string machinecode = "e6bc5694877b2aec";
-
-	std::string lwm_appid = "84b19199fd221a78c491cd553cbb4ab7";
-	std::string open_secret = "#repast!@#AfAS#@!";
 
 	//先添加默认参数,用于计算签名
-	params["machinecode"] = machinecode;
-	params["username"] = m_username;
-	params["password"] = md5(m_password);
-	params["lwm_appid"] = "84b19199fd221a78c491cd553cbb4ab7";
+	params["machinecode"] = m_client.m_machinecode;
+	params["username"] = m_client.m_username;
 	params["nonce"] = nonce;
 	params["timestamp"] = timestamp;
+	params["url"] = m_client.m_old_url + url;
 
 	//计算签名
 	std::string postString;
@@ -101,8 +96,10 @@ bool CZhipuziHttpClient::Request(std::string url, std::map<string, string> param
 	LOG_INFO("postString:" << postString.c_str());
 
 	//用于计算签名的临时变量
-	string tmp = md5(postString);
-	tmp += open_secret;
+	std::string password = md5(m_client.m_password);
+	transform(password.begin(), password.end(), password.begin(), ::toupper);
+
+	string tmp = postString + password;
 
 	std::string sign = md5(tmp);
 	transform(sign.begin(), sign.end(), sign.begin(), ::toupper);
@@ -110,6 +107,7 @@ bool CZhipuziHttpClient::Request(std::string url, std::map<string, string> param
 
 	//加上签名,去掉url,计算post
 	params["sign"] = sign;
+	params.erase("url");
 
 	postString = "";
 	for (std::map<string, string>::iterator it = params.begin(); it != params.end(); )
@@ -126,7 +124,8 @@ bool CZhipuziHttpClient::Request(std::string url, std::map<string, string> param
 
 	LOG_INFO("postString:" << postString.c_str());
 
-	int ret = m_httpClient.Posts(m_url + url, postString, response, NULL);
+	CHttpClient m_httpClient;
+	int ret = m_httpClient.Posts(m_client.m_old_url + url, postString, response, NULL);
 
 	LOG_INFO("response:" << response.c_str());
 
@@ -137,25 +136,76 @@ bool CZhipuziHttpClient::Request(std::string url, std::map<string, string> param
 	}
 
 	return false;
+}
 
-/*
-	rapidjson::Document doc;
-	doc.SetObject();
-	rapidjson::Document::AllocatorType &allocator = doc.GetAllocator(); //获取分配器
+bool CZhipuziHttpClient::RequestNew(std::string url, std::map<string, string> params, std::string& response)
+{
+	std::string timestamp = to_string(time(NULL));
+	std::string nonce = "123456";
+
+	std::string lwm_appid = "84b19199fd221a78c491cd553cbb4ab7";
+	std::string open_secret = "#repast!@#AfAS#@!";
 
-	doc.AddMember(rapidjson::StringRef("useranme"), rapidjson::StringRef(m_username.c_str()), allocator);	
+	//先添加默认参数,用于计算签名
+	params["machinecode"] = m_client.m_machinecode;
+	params["username"] = m_client.m_username;
+	params["password"] = md5(m_client.m_password);
+	params["lwm_appid"] = "84b19199fd221a78c491cd553cbb4ab7";
+	params["nonce"] = nonce;
+	params["timestamp"] = timestamp;
 
-	doc.AddMember(rapidjson::StringRef("timestamp"), rapidjson::StringRef(timestamp.c_str()), allocator);
+	//计算签名
+	std::string postString;
+	for (std::map<string, string>::iterator it = params.begin(); it != params.end(); )
+	{
+		postString += it->first + "=" + it->second;
 
-	
-	doc.AddMember(rapidjson::StringRef("nonce"), rapidjson::StringRef(nonce.c_str()), allocator);
+		it++;
 
-	doc.AddMember(rapidjson::StringRef("machinecode"), rapidjson::StringRef(machinecode.c_str()), allocator);
+		if (it != params.end())
+		{
+			postString += "&";
+		}
+	}
 
-	rapidjson::StringBuffer buffer;
-	rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
-	doc.Accept(writer);
-	std::string json = std::string(buffer.GetString());
+	LOG_INFO("postString:" << postString.c_str());
 
-	LOG_INFO("json:" << json.c_str());*/
+	//用于计算签名的临时变量
+	string tmp = md5(postString);
+	tmp += open_secret;
+
+	std::string sign = md5(tmp);
+	transform(sign.begin(), sign.end(), sign.begin(), ::toupper);
+	LOG_INFO("sign:" << sign.c_str());
+
+	//加上签名,去掉url,计算post
+	params["sign"] = sign;
+
+	postString = "";
+	for (std::map<string, string>::iterator it = params.begin(); it != params.end(); )
+	{
+		postString += it->first + "=" + it->second;
+
+		it++;
+
+		if (it != params.end())
+		{
+			postString += "&";
+		}
+	}
+
+	LOG_INFO("postString:" << postString.c_str());
+
+	CHttpClient m_httpClient;
+	int ret = m_httpClient.Posts(m_client.m_new_url + url, postString, response, NULL);
+
+	LOG_INFO("response:" << response.c_str());
+
+	if (ret == 0)
+	{
+		//ret为0表示没有出错
+		return true;
+	}
+
+	return false;
 }

+ 9 - 7
lewaimai_dispatch/network/CZhipuziHttpClient.h

@@ -1,4 +1,4 @@
-#pragma once
+#pragma once
 
 #include "CHttpClient.h"
 
@@ -13,17 +13,19 @@ public:
 
 	static bool Login(std::string& errmsg);
 
-	bool Request(std::string url, std::map<string, string> params, std::string& response);
+	static bool RequestOld(std::string url, std::map<string, string> params, std::string& response);
+
+	static bool RequestNew(std::string url, std::map<string, string> params, std::string& response);
 
 public:
 	static CZhipuziHttpClient m_client;
 
 private:
-	std::string m_username;
-	std::string m_password;
-
-	std::string m_url = "https://pf-api.zhipuzi.com/pos";
+	std::string m_username = "zhangyang";
+	std::string m_password = "111111";
+	std::string m_machinecode = "e6bc5694877b2aec";
 
-	CHttpClient m_httpClient;
+	std::string m_old_url = "https://cyapi.zhipuzi.com/pos";
+	std::string m_new_url = "https://pf-api.zhipuzi.com/pos";
 };
 

+ 2 - 0
lewaimai_dispatch/pch/pch.h

@@ -19,6 +19,8 @@
 #include <sys/sysinfo.h>
 #endif
 
+#include <atltypes.h>
+
 #include <objbase.h>
 #include <zmouse.h>
 

+ 36 - 0
lewaimai_dispatch/wnd/CGameFrameWnd.cpp

@@ -0,0 +1,36 @@
+#include "../pch/pch.h"
+#include "CGameFrameWnd.h"
+
+#include "ControlEx.h"
+
+void CGameFrameWnd::Init()
+{
+	m_pCloseBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("closebtn")));
+	m_pMaxBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("maxbtn")));
+	m_pRestoreBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("restorebtn")));
+	m_pMinBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("minbtn")));
+}
+
+LRESULT CGameFrameWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+	LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
+	styleValue &= ~WS_CAPTION;
+	::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
+
+	m_pm.Init(m_hWnd);
+	CDialogBuilder builder;
+	CDialogBuilderCallbackEx cb;
+
+	CControlUI* pRoot = builder.Create(_T("main.xml"), (UINT)0, &cb, &m_pm);
+	ASSERT(pRoot && "Failed to parse XML");
+
+	m_pm.AttachDialog(pRoot);
+	m_pm.AddNotifier(this);
+
+	OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
+	orderlist->Refresh();
+
+	Init();
+	return 0;
+}
+

+ 1 - 7
lewaimai_dispatch/wnd/CGameFrameWnd.h

@@ -10,13 +10,7 @@ public:
 	UINT GetClassStyle() const { return CS_DBLCLKS; };
 	void OnFinalMessage(HWND /*hWnd*/) { delete this; };
 
-	void Init()
-	{
-		m_pCloseBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("closebtn")));
-		m_pMaxBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("maxbtn")));
-		m_pRestoreBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("restorebtn")));
-		m_pMinBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("minbtn")));
-	}
+	void Init();
 
 	void OnPrepare()
 	{

+ 19 - 0
lewaimai_dispatch/wnd/ControlEx.h

@@ -0,0 +1,19 @@
+#pragma once
+
+#include "../pch/pch.h"
+
+#include "OrderListUI.h"
+
+class CDialogBuilderCallbackEx : public IDialogBuilderCallback
+{
+public:
+	CControlUI* CreateControl(LPCTSTR pstrClass)
+	{
+		if (_tcscmp(pstrClass, _T("DeskList")) == 0)
+		{
+			return new OrderListUI;
+		}
+
+		return NULL;
+	}
+};

+ 34 - 0
lewaimai_dispatch/wnd/OrderListUI.cpp

@@ -0,0 +1,34 @@
+#include "../pch/pch.h"
+#include "OrderListUI.h"
+
+void OrderListUI::Refresh()
+{
+	COptionUI* waimai_open_op = static_cast<COptionUI*>(m_pManager->FindControl(L"waimai_open_switch"));
+	if (waimai_open_op->IsSelected())
+	{
+		//请求外卖的未处理订单
+		std::map<string, string> params;
+		params["page"] = "1";
+		std::string response;
+
+		CZhipuziHttpClient::RequestOld("/waimaiorder/getopenlist", params, response);
+	}
+
+	CDialogBuilder builder;
+	CContainerUI* pDesk = static_cast<CContainerUI*>(builder.Create(_T("desk.xml"), (UINT)0));
+	if (pDesk != NULL) {
+		for (int i = 0; i < 20; ++i)
+		{
+			if (pDesk == NULL) pDesk = static_cast<CContainerUI*>(builder.Create());
+			if (pDesk != NULL) {
+				this->Add(pDesk);
+
+				pDesk = NULL;
+			}
+			else {
+				this->RemoveAll();
+				return;
+			}
+		}
+	}
+}

+ 118 - 0
lewaimai_dispatch/wnd/OrderListUI.h

@@ -0,0 +1,118 @@
+#pragma once
+
+inline double CalculateDelay(double state) {
+	return pow(state, 2);
+}
+
+class OrderListUI : public CTileLayoutUI
+{
+public:
+	enum { SCROLL_TIMERID = 10 };
+
+	OrderListUI() : m_uButtonState(0), m_dwDelayDeltaY(0), m_dwDelayNum(0), m_dwDelayLeft(0)
+	{
+		SetItemSize(CSize(1000, 200));
+	}
+
+	//刷新
+	void Refresh();
+
+	void DoEvent(TEventUI& event)
+	{
+		if (!IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND) {
+			if (m_pParent != NULL) m_pParent->DoEvent(event);
+			else CTileLayoutUI::DoEvent(event);
+			return;
+		}
+
+		if (event.Type == UIEVENT_TIMER && event.wParam == SCROLL_TIMERID)
+		{
+			if ((m_uButtonState & UISTATE_CAPTURED) != 0) {
+				POINT pt = m_pManager->GetMousePos();
+				LONG cy = (pt.y - m_ptLastMouse.y);
+				m_ptLastMouse = pt;
+				SIZE sz = GetScrollPos();
+				sz.cy -= cy;
+				SetScrollPos(sz);
+				return;
+			}
+			else if (m_dwDelayLeft > 0) {
+				--m_dwDelayLeft;
+				SIZE sz = GetScrollPos();
+				LONG lDeltaY = (LONG)(CalculateDelay((double)m_dwDelayLeft / m_dwDelayNum) * m_dwDelayDeltaY);
+				if ((lDeltaY > 0 && sz.cy != 0) || (lDeltaY < 0 && sz.cy != GetScrollRange().cy)) {
+					sz.cy -= lDeltaY;
+					SetScrollPos(sz);
+					return;
+				}
+			}
+			m_dwDelayDeltaY = 0;
+			m_dwDelayNum = 0;
+			m_dwDelayLeft = 0;
+			m_pManager->KillTimer(this, SCROLL_TIMERID);
+			return;
+		}
+		if (event.Type == UIEVENT_BUTTONDOWN && IsEnabled())
+		{
+			m_uButtonState |= UISTATE_CAPTURED;
+			m_ptLastMouse = event.ptMouse;
+			m_dwDelayDeltaY = 0;
+			m_dwDelayNum = 0;
+			m_dwDelayLeft = 0;
+			::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_HAND)));
+			m_pManager->SetTimer(this, SCROLL_TIMERID, 50U);
+			return;
+		}
+		if (event.Type == UIEVENT_BUTTONUP)
+		{
+			if ((m_uButtonState & UISTATE_CAPTURED) != 0) {
+				m_uButtonState &= ~UISTATE_CAPTURED;
+				::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));
+				if (m_ptLastMouse.y != event.ptMouse.y) {
+					m_dwDelayDeltaY = (event.ptMouse.y - m_ptLastMouse.y);
+					if (m_dwDelayDeltaY > 120) m_dwDelayDeltaY = 120;
+					else if (m_dwDelayDeltaY < -120) m_dwDelayDeltaY = -120;
+					m_dwDelayNum = (DWORD)sqrt((double)abs(m_dwDelayDeltaY)) * 5;
+					m_dwDelayLeft = m_dwDelayNum;
+				}
+				else
+					m_pManager->KillTimer(this, SCROLL_TIMERID);
+			}
+			return;
+		}
+		if (event.Type == UIEVENT_SCROLLWHEEL)
+		{
+			LONG lDeltaY = 0;
+			if (m_dwDelayNum > 0) lDeltaY = (LONG)(CalculateDelay((double)m_dwDelayLeft / m_dwDelayNum) * m_dwDelayDeltaY);
+			switch (LOWORD(event.wParam)) {
+			case SB_LINEUP:
+				if (m_dwDelayDeltaY >= 0) m_dwDelayDeltaY = lDeltaY + 8;
+				else m_dwDelayDeltaY = lDeltaY + 12;
+				break;
+			case SB_LINEDOWN:
+				if (m_dwDelayDeltaY <= 0) m_dwDelayDeltaY = lDeltaY - 8;
+				else m_dwDelayDeltaY = lDeltaY - 12;
+				break;
+			}
+			if (m_dwDelayDeltaY > 100) m_dwDelayDeltaY = 100;
+			else if (m_dwDelayDeltaY < -100) m_dwDelayDeltaY = -100;
+			m_dwDelayNum = (DWORD)sqrt((double)abs(m_dwDelayDeltaY)) * 5;
+			m_dwDelayLeft = m_dwDelayNum;
+			m_pManager->SetTimer(this, SCROLL_TIMERID, 50U);
+			return;
+		}
+		CTileLayoutUI::DoEvent(event);
+	}
+
+private:
+	UINT m_uButtonState;
+	POINT m_ptLastMouse;
+	LONG m_dwDelayDeltaY;
+	DWORD m_dwDelayNum;
+	DWORD m_dwDelayLeft;
+
+	int m_status = 1; //1:未处理 2:已确认 3:配送中 4:成功 5:失败 6:退款中
+
+public:
+	CPaintManagerUI m_pm;
+};