Commit f31ad1b9 by ss.dai

海鼎POS打通测试

parent 56d262c9
...@@ -5,6 +5,12 @@ ...@@ -5,6 +5,12 @@
#include <QDebug> #include <QDebug>
#include <QSettings> #include <QSettings>
#include <QCoreApplication> #include <QCoreApplication>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QJsonDocument>
#include <QJsonArray>
#include <QTimer>
FmPlugin &FmPlugin::GetInstance() FmPlugin &FmPlugin::GetInstance()
{ {
...@@ -135,49 +141,46 @@ bool FmPlugin::GetOnDutyCashiers(QList<CashierObject> &cashiersList, QString &er ...@@ -135,49 +141,46 @@ bool FmPlugin::GetOnDutyCashiers(QList<CashierObject> &cashiersList, QString &er
bool FmPlugin::DoOrderEntry(const OrderObject *orderObject, const QString &cashierId, const QString &cashierName, const QString &shiftId, const QString &shiftName, QString &error) bool FmPlugin::DoOrderEntry(const OrderObject *orderObject, const QString &cashierId, const QString &cashierName, const QString &shiftId, const QString &shiftName, QString &error)
{ {
// TODO(用于鲜丰演示) QString apppath=QCoreApplication::applicationDirPath();
return true; QString inipath=apppath+QString("/config.ini");
QSettings set(inipath, QSettings::IniFormat);
QUrl url;
url = set.value("HdServer/url").toUrl();
m_orderObject = orderObject; QNetworkAccessManager manger;
if(!m_db.open()) QNetworkRequest qRequset;
qRequset.setUrl(url);
qRequset.setRawHeader("Content-Type","application/json;charset=utf-8");
qRequset.setRawHeader("Accept", "application/json;charset=utf-8");
QNetworkReply *reply = manger.post(qRequset, _GetOrderEntryData(orderObject));
QEventLoop eventLoop;
QObject::connect(&manger, SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)), &eventLoop, SLOT(quit()));
QObject::connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));
QObject::connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), &eventLoop, SLOT(quit()));
// 加用定时器防止网络出现异常长时间不返回导致的阻塞
QTimer::singleShot(10000, &eventLoop, &QEventLoop::quit);
eventLoop.exec();
reply->deleteLater();
if( reply->error() != QNetworkReply::NoError)
{ {
error = m_db.lastError().text(); error = reply->errorString();
return false; return false;
} }
// 先插入顾客信息不管成功与否不影响后续操作 QByteArray recvArray = reply->readAll();
int custid = -1; error = QString(recvArray);
_InsertInto_p_t_fmwm_custinfo(custid); if(recvArray.size() == 0)
// 开启事务
if(!m_db.transaction())
{ {
error = m_db.lastError().text(); error = "nothing recved";
m_db.close();
return false; return false;
} }
// 插入三张临时表后执行存储过程有一个失败则回滚 QJsonObject recvJson;
if(_InsertInto_d_t_food_fmbill0(cashierId, cashierName, shiftId, shiftName, custid)) recvJson = QJsonDocument::fromJson(recvArray).object();
if(recvJson["echoCode"].toString() != "0")
{ {
if(_InsertInto_d_t_food_fmbills0()) error = recvJson["echoMessage"].toString();
{ return false;
if(_InsertInto_d_t_bill_fmpay0())
{
if(_Exec_pr_fmwm())
{
// 都成功则提交
m_db.commit();
error = QString("success");
m_db.close();
return true;
}
}
}
} }
// 回滚 return true;
error = m_lastError;
m_db.rollback();
m_db.close();
return false;
} }
bool FmPlugin::GetStockInfo(QList<StockObject> &stockList, QString &error) bool FmPlugin::GetStockInfo(QList<StockObject> &stockList, QString &error)
...@@ -364,3 +367,32 @@ QString FmPlugin::_Penny2Dollar(int penny) ...@@ -364,3 +367,32 @@ QString FmPlugin::_Penny2Dollar(int penny)
double dollar = (double)penny/100; double dollar = (double)penny/100;
return QString::number(dollar,'f',2); return QString::number(dollar,'f',2);
} }
QByteArray FmPlugin::_GetOrderEntryData(const OrderObject *orderObject)
{
QJsonObject rObj;
rObj.insert("uuid", "b62f44da9a7e421f88cb006159863ab7");
rObj.insert("senderCode", "CWLB");
rObj.insert("sendWrh", "-");
rObj.insert("receiverCode", "95560000001");
rObj.insert("contactor", orderObject->customer);
rObj.insert("phoneNumber", orderObject->phone);
rObj.insert("deliverAddress", orderObject->address);
rObj.insert("remark", "非码测试");
rObj.insert("ocrDate", QDateTime::fromTime_t(orderObject->create_time).toString("yyyy-MM-ddThh:mm:ss.zzz+0800"));
rObj.insert("filler", "*");
rObj.insert("seller", "*");
QJsonArray products;
for(int i=0; i < orderObject->proList.count(); i++)
{
QJsonObject cObj;
cObj.insert("skuId", "01001");
cObj.insert("qty", orderObject->proList.at(i)->productAmount);
cObj.insert("price", orderObject->proList.at(i)->price);
products.insert(i, cObj);
}
rObj.insert("products", products);
qDebug() << rObj;
return QJsonDocument(rObj).toJson(QJsonDocument::Compact);
}
...@@ -89,6 +89,11 @@ private: ...@@ -89,6 +89,11 @@ private:
* 返回:元 * 返回:元
* */ * */
QString _Penny2Dollar(int penny); QString _Penny2Dollar(int penny);
/* 功能:获取写销售单的数据
* 参数:[1]订单对象
* 返回:销售单数据
* */
QByteArray _GetOrderEntryData(const OrderObject*);
}; };
#endif // FMPLUGIN_H #endif // FMPLUGIN_H
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
QT -= gui QT -= gui
QT += sql QT += sql network
TARGET = fmPlugin TARGET = fmPlugin
TEMPLATE = lib TEMPLATE = lib
......
...@@ -175,7 +175,18 @@ bool FlowControl::_PullOrder() ...@@ -175,7 +175,18 @@ bool FlowControl::_PullOrder()
emit changeOrderStatus(orderObject, oldStatus); emit changeOrderStatus(orderObject, oldStatus);
} }
} }
//MARK(测试)
//if(orderObject->status == 6)
//{
QString error;
if(FmPlugin::GetInstance().DoOrderEntry(orderObject,"","","","",error))
{
QLOG_INFO() << QString("DoOrderEntry successful") << error;
}else
{
QLOG_INFO() << QString("DoOrderEntry failed %1").arg(error);
}
//}
m_timestamp = orderObject->timestamp; m_timestamp = orderObject->timestamp;
} }
syncTime = recvJson[JSON_SYNCTIME].toInt()*1000; syncTime = recvJson[JSON_SYNCTIME].toInt()*1000;
......
#include "MateChooser.h"
#include "ui_MateChooser.h"
#include <QTreeWidgetItem>
MateChooser::MateChooser(QWidget *parent) :
QDialog(parent),
ui(new Ui::MateChooser)
{
ui->setupUi(this);
setWindowFlags(windowFlags()|Qt::FramelessWindowHint);
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_QuitOnClose, false);
_group.setExclusive(false);
connect(&_group, SIGNAL(buttonClicked(QAbstractButton*)), SLOT(onMateItemClicked(QAbstractButton*)));
}
MateChooser::~MateChooser()
{
delete ui;
}
void MateChooser::setTitle(const QString &t)
{
ui->mateTitle->setText(t);
}
QString MateChooser::getTitle() const
{
return ui->mateTitle->text();
}
QList<ProductObject *> MateChooser::candidates()
{
QList<ProductObject *> list;
QStringList keys = _candidates_map.keys();
foreach(QString k, keys) {
list << _candidates_map[k];
}
return list;
}
void MateChooser::setMates(const QList<ProductObject *> &pendingMates, QList<ProductObject *> &assignedMates)
{
_selected_mates = assignedMates;
foreach(ProductObject *amo, assignedMates) {
_candidates_map[amo->name] = amo;
}
foreach(ProductObject *mo, pendingMates) {
if (!_candidates_map.contains(mo->name)) {
_candidates_map[mo->name] = mo;
}
}
int row = 0, col = 0;
_group.buttons().clear();
QStringList keys = _candidates_map.keys();
foreach(QString k, keys) {
ProductObject *mate = _candidates_map[k];
QPushButton *mate_btn = new QPushButton(mate->name);
mate_btn->setFocusPolicy(Qt::NoFocus);
mate_btn->setCheckable(true);
if (_selected_mates.contains(mate)) {
mate_btn->setChecked(true);
}
mate_btn->setMinimumSize(60, 40);
mate_btn->setMaximumSize(60, 40);
ui->mateList->addWidget(mate_btn, row, col);
_group.addButton(mate_btn);
++col;
if (col > 2) {
++row;
col = 0;
}
}
}
QList<ProductObject *> MateChooser::selectedMates() const
{
if (this->result() == QDialog::Accepted) {
return _selected_mates;
}
else {
return QList<ProductObject*>();
}
}
void MateChooser::on_mateCancel_clicked()
{
QDialog::reject();
}
void MateChooser::on_mateConfirm_clicked()
{
QDialog::accept();
}
void MateChooser::onMateItemClicked(QAbstractButton *item)
{
if (item->isChecked()) {
_selected_mates << _candidates_map[item->text()];
}
else {
_selected_mates.removeOne(_candidates_map[item->text()]);
}
}
#ifndef MATECHOOSER_H
#define MATECHOOSER_H
#include <QButtonGroup>
#include <QDialog>
#include "../QsLog/QsLog.h"
#include "Model/productObject.h"
namespace Ui {
class MateChooser;
}
class QTreeWidgetItem;
class MateChooser : public QDialog
{
Q_OBJECT
public:
explicit MateChooser(QWidget *parent = 0);
~MateChooser();
void setTitle(const QString &t);
QString getTitle() const;
QList<ProductObject *> candidates();
void setMates(const QList<ProductObject *> &pendingMates,
QList<ProductObject *> &assignedMates);
QList<ProductObject *> selectedMates() const;
public slots:
void on_mateCancel_clicked();
void on_mateConfirm_clicked();
void onMateItemClicked(QAbstractButton *item);
private:
Ui::MateChooser *ui;
QButtonGroup _group;
QList<ProductObject *> _selected_mates;
QMap<QString, ProductObject*> _candidates_map;
};
#endif // MATECHOOSER_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MateChooser</class>
<widget class="QDialog" name="MateChooser">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>253</width>
<height>234</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="styleSheet">
<string notr="true">/*---------------------------------MateChooser[begin]---------------------------------*/
#MateChooser
{
background-color: rgb(255, 255, 255);
border: 1 solid rgb(230, 230, 230);
}
#mateTitle
{
color: rgb(255, 255, 255);
font-size: 11pt;
background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(236, 174, 102), stop:0.5 rgba(236, 128, 69), stop:0.51 rgba(248, 105, 39), stop:1 rgba(238, 172, 102));
}
#scrollArea, #scrollArea QWidget {
background: white;
}
#scrollArea QPushButton {
background: rgb(255, 243, 239);
border: 1 solid silver;
color: rgb(80, 80, 80);
min-height: 40; max-height: 40;
min-width: 65; max-width: 65;
}
#scrollArea QPushButton:checked {
background: rgb(248, 105, 41);
color: white;
}
#scrollArea QScrollBar:vertical
{
background: rgb(207, 208, 209);
width: 10px;
margin: 5 0;
}
#scrollArea QScrollBar::handle:vertical
{
border-radius: 6px;
background: rgb(247, 112, 42);
min-height: 20px;
}
#scrollArea QScrollBar::add-line:vertical
{
height: 0px;
margin: 20px;
}
#scrollArea QScrollBar::sub-line:vertical
{
height: 0px;
}
#scrollArea QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical
{
background: rgb(240, 220, 210);
}
/*
#mateList
{
border: 0 solid silver;
background-color: white;
selection-background-color: white;
margin: 10; margin-right: -20;
font-size: 11pt;
padding-top: 16px;
}
#mateList::item
{
margin: 2;
background: rgba(248, 105, 41, 25);
border: 1 solid silver;
color: rgb(80, 80, 80);
min-height: 40; max-height: 40;
min-width: 60; max-width: 60;
}
#mateList::item:selected
{
background: rgba(248, 105, 41, 255);
color: white;
}
*/
#mateCancel, #mateConfirm
{
font-size: 9pt;
color: rgb(255, 255, 255);
background-color: rgb(248, 105, 41);
border-radius: 5px;
}
#mateCancel:pressed,#mateConfirm:pressed
{
font-size: 9pt;
color: rgb(161, 161, 161);
background-color: rgb(197, 83, 32);
}
/*---------------------------------MateChooser[ end ]---------------------------------*/
</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="mateTitle">
<property name="minimumSize">
<size>
<width>0</width>
<height>34</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWithContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>253</width>
<height>135</height>
</rect>
</property>
<layout class="QGridLayout" name="mateList">
<property name="margin">
<number>16</number>
</property>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="topMargin">
<number>10</number>
</property>
<property name="bottomMargin">
<number>15</number>
</property>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="mateConfirm">
<property name="minimumSize">
<size>
<width>80</width>
<height>40</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>80</width>
<height>40</height>
</size>
</property>
<property name="text">
<string>确认</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="mateCancel">
<property name="minimumSize">
<size>
<width>80</width>
<height>40</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>80</width>
<height>40</height>
</size>
</property>
<property name="text">
<string>取消</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
#include "drinkItem.h"
#include "ui_drinkItem.h"
DrinkItem::DrinkItem(const QString &name, const QString &mate, QWidget *parent) :
QWidget(parent),
ui(new Ui::DrinkItem)
{
ui->setupUi(this);
m_drinkName = name;
m_drinkMate = mate;
ui->drinkName->setText(name);
ui->drinkMates->setText(mate);
}
DrinkItem::~DrinkItem()
{
delete ui;
}
QString DrinkItem::DrinkName()
{
return m_drinkName;
}
void DrinkItem::SetDrinkName(const QString &name)
{
m_drinkName = name;
ui->drinkName->setText(m_drinkName);
}
QString DrinkItem::DrinkMate()
{
return m_drinkMate;
}
void DrinkItem::SetDrinkMate(const QString &mate)
{
m_drinkMate = mate;
ui->drinkMates->setText(m_drinkMate);
}
#ifndef DRINKITEM_H
#define DRINKITEM_H
#include <QWidget>
namespace Ui {
class DrinkItem;
}
class DrinkItem : public QWidget
{
Q_OBJECT
public:
explicit DrinkItem(const QString& name, const QString& mate, QWidget *parent = 0);
~DrinkItem();
QString DrinkName();
void SetDrinkName(const QString& name);
QString DrinkMate();
void SetDrinkMate(const QString &mate);
private:
Ui::DrinkItem *ui;
QString m_drinkName;
QString m_drinkMate;
};
#endif // DRINKITEM_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DrinkItem</class>
<widget class="QWidget" name="DrinkItem">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>185</width>
<height>52</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="drinkMates">
<property name="text">
<string>商品名称</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="drinkName">
<property name="text">
<string>商品属性</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
...@@ -94,7 +94,7 @@ void MainForm::MyShow() ...@@ -94,7 +94,7 @@ void MainForm::MyShow()
void MainForm::_Init() void MainForm::_Init()
{ {
this->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); this->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
this->showFullScreen(); //this->showFullScreen();
// 显示托盘 // 显示托盘
m_tray.show(); m_tray.show();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment