Commit 75a22813 by gujin.wang

修改查询核销记录为请求服务端接口

parent 62d46658
......@@ -18,16 +18,16 @@ Level=4
[Home]
Server=http://115.159.226.87:20001/api/user/login
PartnerId=1371
StoreId=aaa
PosId=bbb
Position=2561, 423
PartnerId=1739
StoreId=SH058
PosId=01
Position=2592, 158
CashierId=001
OperatorId=01
ShowStoreInfo=0
[Pay]
Server=https://115.159.18.100/api
Server="http://115.159.119.32:27935/api?partner=yhdw"
Timeout=60
[Vip]
......@@ -35,6 +35,7 @@ Server=http://member.freemudorder.com/member_today/service/restful/pos
[Coupon]
Server=http://115.159.142.32/api
RedeemLog=http://115.159.119.32:27935/getRedeemLog
[Syncer]
Interval=3
......
......@@ -27,6 +27,6 @@ void ConsumOkDialog::showConsumOk(const QString& act_name, const QString& code_n
v.ui->labCode->setText( coupon);
v.ui->labActName->setText( act_name);
v.ui->labTime->setText( time_name);
v.ui->labCodeName->setText( code_name);
v.ui->labChannel->setText(QString::fromLocal8Bit("渠道:") + code_name);
v.exec();
}
\ No newline at end of file
......@@ -57,9 +57,9 @@
font-weight:bold;
color: rgb(255, 255, 0);
}
#labCodeName{
#labChannel{
font: 72 23pt "微软雅黑";
color: rgb(146, 53, 50);
color: rgb(255, 255, 255);
}
#labTime{
......@@ -179,7 +179,7 @@
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="labCodeName">
<widget class="QLabel" name="labChannel">
<property name="geometry">
<rect>
<x>0</x>
......@@ -201,10 +201,10 @@
</size>
</property>
<property name="text">
<string>键位促销</string>
<string>渠道:浦发银行</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
<widget class="QLabel" name="labTime">
......
#include "consumptiondialog.h"
#include "ui_consumptiondialog.h"
#include <QDebug>
ConsumptionDialog::ConsumptionDialog(QWidget * parent, Qt::WindowFlags f) :
QDialog(parent, f),
......@@ -21,7 +21,7 @@ ConsumptionDialog::~ConsumptionDialog()
delete ui;
}
bool ConsumptionDialog::ShowForUnConsum(const QString& act_name, const QString& code_name, const QString& time_name, const QString& coupon, QWidget *parent)
bool ConsumptionDialog::ShowForUnConsum(const QString& act_name, double face_amount, double actual_amount, const QString& eb_name, const QString& time_name, const QString& coupon, QWidget *parent)
{
ConsumptionDialog v(parent);
// v.setGeometry( 0,0,350,470);
......@@ -32,7 +32,7 @@ bool ConsumptionDialog::ShowForUnConsum(const QString& act_name, const QString&
v.ui->btnConsumption->setStyleSheet( v.ui->btnConsumption->styleSheet());
v.ui->btnConsumption->setEnabled( true);
v.setData( act_name,code_name ,time_name,coupon );
v.setData(act_name, face_amount, actual_amount, eb_name, time_name, coupon);
if( v.exec() == QDialog::Accepted){
return true;
......@@ -52,8 +52,9 @@ bool ConsumptionDialog::ShowForHasConsum(const QString& act_name, const QString&
v.ui->btnConsumption->setObjectName( "btnConsumNull");
v.ui->btnConsumption->setStyleSheet( v.ui->btnConsumption->styleSheet());
v.ui->btnConsumption->setEnabled( false);
v.setData( act_name,code_name ,time_name,coupon );
v.setData( act_name,code_name ,time_name,coupon );
v.ui->labActName->setStyleSheet("color:white;");
if( v.exec() == QDialog::Accepted){
return true;
}
......@@ -61,10 +62,66 @@ bool ConsumptionDialog::ShowForHasConsum(const QString& act_name, const QString&
return false;
}
int timerId = 0;
void ConsumptionDialog::ShowForWaiting(QString context, QString coupon, QWidget *parent)
{
ui->labTime->hide();
ui->labCodeName->hide();
ui->actualAmount->hide();
ui->ebname->hide();
ui->topNoConsumeWidget->setObjectName( "topWaitingWidget");
ui->topNoConsumeWidget->setStyleSheet( ui->topNoConsumeWidget->styleSheet());
ui->btnConsumption->setEnabled(false);
ui->btnConsumption->setStyleSheet("border-image: url(:/img/btn_consumption_invalid.png);");
ui->labActName->setText(context);
ui->labCode->setText(coupon);
timerId = startTimer(500);
show();
}
void ConsumptionDialog::timerEvent(QTimerEvent *)
{
static int i = 0;
QString str = ui->labActName->text();
if(i == 0)
{
str.remove(QRegularExpression("\\."));
ui->labActName->setText(str);
}
else
{
str.append(".");
ui->labActName->setText(str);
}
i++;
i = i % 4;
}
void ConsumptionDialog::HideForWaiting()
{
killTimer(timerId);
reject();
}
void ConsumptionDialog::setData(const QString& act_name, const QString& code_name, const QString& time_name, const QString& coupon)
{
ui->labCode->setText( coupon);
ui->labCodeName->setAlignment(Qt::AlignCenter);
ui->actualAmount->hide();
ui->ebname->hide();
ui->labCodeName->setText( code_name);
ui->labActName->setText( act_name);
ui->labTime->setText( time_name);
}
void ConsumptionDialog::setData(const QString &act_name, double face_amount, double actual_amount, const QString& eb_name, const QString& time_name, const QString& coupon)
{
ui->labCode->setText(coupon);
ui->labCodeName->setText(QString::fromLocal8Bit("面值: %1 元").arg(face_amount));
ui->actualAmount->setText(QString::fromLocal8Bit("实收: %1 元").arg(actual_amount));
ui->ebname->setText(QString::fromLocal8Bit("渠道: ") + eb_name);
ui->labActName->setText(act_name);
ui->labTime->setText(time_name);
}
#ifndef CONSUMPTIONDIALOG_H
#ifndef CONSUMPTIONDIALOG_H
#define CONSUMPTIONDIALOG_H
#include <QDialog>
......@@ -19,8 +19,14 @@ public:
~ConsumptionDialog();
void setData(const QString& act_name, const QString& code_name, const QString& time_name, const QString& coupon);
static bool ShowForUnConsum(const QString &act_name, const QString& code_name, const QString& time_name, const QString& coupon, QWidget *parent = 0);
void setData(const QString &act_name, double face_amount, double actual_amount, const QString& eb_name, const QString& time_name, const QString& coupon);
static bool ShowForUnConsum(const QString &act_name, double face_amount, double actual_amount, const QString& eb_name, const QString& time_name, const QString& coupon, QWidget *parent = 0);
static bool ShowForHasConsum(const QString& act_name, const QString& code_name, const QString& time_name, const QString& coupon, QWidget *parent = 0);
void ShowForWaiting(QString context, QString coupon, QWidget *parent = 0);
void HideForWaiting();
protected:
void timerEvent(QTimerEvent *);
signals:
void sgBtnOk();
......
......@@ -50,17 +50,29 @@
border-top-left-radius:12px;
border-top-right-radius:12px;
}
#topWaitingWidget{
background-image: url(:/img/bg_waiting.png);
border:none;
border-top-left-radius:12px;
border-top-right-radius:12px;
}
/**/
#labActName{
/*font: 30 bold &quot;微软雅黑&quot;;*/
font-size:30px;
font-size:25px;
font-family:&quot;微软雅黑&quot;;
font-weight:bold;
color: rgb(255, 255, 0);
border:none;
}
#labCodeName{
#ebname{
font: 65 20pt &quot;微软雅黑&quot;;
color: rgb(255,255,255);
border:none;
}
#labCodeName, #actualAmount{
font: 65 15pt &quot;微软雅黑&quot;;
color: rgb(255, 255, 0);
border:none;
......@@ -162,25 +174,25 @@
<property name="geometry">
<rect>
<x>0</x>
<y>105</y>
<y>90</y>
<width>330</width>
<height>80</height>
<height>50</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>330</width>
<height>80</height>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>330</width>
<height>80</height>
<height>50</height>
</size>
</property>
<property name="text">
<string>查询中...</string>
<string>查询中</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
......@@ -218,7 +230,7 @@
<property name="geometry">
<rect>
<x>0</x>
<y>205</y>
<y>186</y>
<width>330</width>
<height>37</height>
</rect>
......@@ -239,10 +251,81 @@
<string notr="true"/>
</property>
<property name="text">
<string>键位促销</string>
<string>面值: </string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="indent">
<number>10</number>
</property>
</widget>
<widget class="QLabel" name="actualAmount">
<property name="geometry">
<rect>
<x>0</x>
<y>220</y>
<width>330</width>
<height>37</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>330</width>
<height>37</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>330</width>
<height>37</height>
</size>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>实收: </string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="indent">
<number>10</number>
</property>
</widget>
<widget class="QLabel" name="ebname">
<property name="geometry">
<rect>
<x>0</x>
<y>150</y>
<width>330</width>
<height>37</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>330</width>
<height>37</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>330</width>
<height>37</height>
</size>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>渠道: </string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="indent">
<number>10</number>
</property>
</widget>
</widget>
......
#include "couponkeypad.h"
#include "couponkeypad.h"
#include "ui_couponkeypad.h"
CouponKeypad::CouponKeypad(QWidget *parent, Qt::WindowFlags f) :
......@@ -53,3 +53,11 @@ void CouponKeypad::onDigitClicked()
QPushButton *btn = qobject_cast<QPushButton*>(sender());
ui->text->setText(ui->text->text() + btn->text());
}
void CouponKeypad::keyPressEvent(QKeyEvent *e)
{
if( e->key() == Qt::Key_Enter || e->key() == Qt::Key_End || e->key() == 16777220 )
{
on_btnOK_clicked();
}
}
\ No newline at end of file
#ifndef COUPONKEYPAD_H
#ifndef COUPONKEYPAD_H
#define COUPONKEYPAD_H
#include <QDialog>
#include <QKeyEvent>
namespace Ui {
class CouponKeypad;
......@@ -22,6 +23,9 @@ public slots:
void on_btnClear_clicked();
void onDigitClicked();
protected:
void keyPressEvent(QKeyEvent *e);
public:
QString code;
......
#include "datedialog.h"
#include "ui_datedialog.h"
DateDialog::DateDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::DateDialog)
{
ui->setupUi(this);
setAttribute(Qt::WA_QuitOnClose, false);
setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
connect(ui->calendarWidget, SIGNAL(selectionChanged()), this, SLOT(OnSelectedChanged()));
connect(ui->closeBtn, SIGNAL(clicked(bool)), this, SLOT(close()));
}
DateDialog::~DateDialog()
{
delete ui;
}
void DateDialog::mousePressEvent(QMouseEvent *e)
{
mouse_pressed = true;
movePosition = e->globalPos() - pos();
return QDialog::mousePressEvent(e);
}
void DateDialog::mouseMoveEvent(QMouseEvent *e)
{
if(mouse_pressed && (e->buttons() & Qt::LeftButton) && (e->globalPos()-movePosition).manhattanLength() > QApplication::startDragDistance())
{
move(e->globalPos() - movePosition);
movePosition = e->globalPos() - pos();
}
return QDialog::mouseMoveEvent(e);
}
void DateDialog::mouseReleaseEvent(QMouseEvent *e)
{
mouse_pressed = false;
return QDialog::mouseReleaseEvent(e);
}
void DateDialog::keyPressEvent(QKeyEvent *e)
{
switch(e->key())
{
case Qt::Key_Return:
case Qt::Key_Enter:
return;
default:
break;
}
QDialog::keyPressEvent(e);
}
void DateDialog::OnSelectedChanged()
{
QDate cur = ui->calendarWidget->selectedDate();
emit DateChanged(cur);
}
#ifndef DATEDIALOG_H
#define DATEDIALOG_H
#include <QDialog>
#include <QMouseEvent>
#include <QDate>
namespace Ui {
class DateDialog;
}
class DateDialog : public QDialog
{
Q_OBJECT
public:
explicit DateDialog(QWidget *parent = 0);
~DateDialog();
protected:
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
void keyPressEvent(QKeyEvent *e);
private slots:
void OnSelectedChanged();
signals:
void DateChanged(QDate curDate);
private:
Ui::DateDialog *ui;
bool mouse_pressed;
QPoint movePosition;
};
#endif // DATEDIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DateDialog</class>
<widget class="QDialog" name="DateDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>464</width>
<height>346</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="styleSheet">
<string notr="true">#titleLabel{
background: rgb(56, 56, 64);
color:rgb(255, 255, 255);
font: normal 16px &quot;Microsoft YaHei&quot;;
}
#closeBtn{
border:none;
background-color:rgb(56,56,64);
background-image:url(:/img/close_02.png);
background-repeat:no-repeat;
background-position:center;
}
#closeBtn{
padding:1 0 0 2;
}
QCalendarWidget QWidget#qt_calendar_navigationbar{
min-height:30px;
background: lightgrey;
}
QCalendarWidget QTableView{
font-size:25px;
}
#qt_calendar_monthbutton,#qt_calendar_yearbutton,#qt_calendar_monthbutton:focus,#qt_calendar_yearbutton:focus{
color:black;
font-size:25px;
}
#qt_calendar_yearedit{
min-width:50px;
}</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">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="titleLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>40</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closeBtn">
<property name="minimumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCalendarWidget" name="calendarWidget">
<property name="verticalHeaderFormat">
<enum>QCalendarWidget::NoVerticalHeader</enum>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -28,8 +28,7 @@ void ErrCodeDialog::showForInvalid(const QString& coupon, QWidget *parent)
v.ui->labTime->setVisible( false);
v.ui->labActName->setVisible( false);
v.ui->labCodeName->setVisible( false);
v.ui->labFolat->setVisible( false);
v.ui->labChannel->setVisible( false);
v.ui->labCode->setText(coupon );
......@@ -45,12 +44,13 @@ void ErrCodeDialog::showForExpird(const QString& act_name, const QString& code_n
v.ui->labTime->setVisible( true);
v.ui->labActName->setVisible( true);
v.ui->labCodeName->setVisible( true);
v.ui->labChannel->setVisible( true);
v.ui->labCode->setText(coupon );
v.ui->labTime->setText( time_name);
v.ui->labActName->setText( act_name);
v.ui->labCodeName->setText( code_name);
v.ui->labActName->setStyleSheet("color:white;");
v.ui->labChannel->setText( code_name);
v.exec();
}
......@@ -64,31 +64,42 @@ void ErrCodeDialog::showForErr(const QString& coupon, const QString& mess, QWidg
v.ui->labTime->setVisible( false);
v.ui->labCodeName->setVisible( false);
v.ui->labFolat->setVisible( false);
v.ui->labChannel->setVisible( true);
//100 -> 浦发银行
//88 -> 交通银行
QString channel;
if(coupon.left(3) == "100" && coupon.length()==12)
channel = QString::fromLocal8Bit("浦发银行");
else if(coupon.left(2) == "88" && coupon.length()==12)
channel = QString::fromLocal8Bit("交通银行");
else
channel = QString::fromLocal8Bit("未知");
v.ui->labActName->setVisible( true);
v.ui->labCode->setText(coupon );
v.ui->labActName->setText( mess);
v.exec();
}
void ErrCodeDialog::showForMismatch(const QString &coupon, const QString &mess, QWidget *parent)
{
ErrCodeDialog v(parent);
// v.setGeometry( 0,0,350,470);
v.ui->topInvalidWidget->setObjectName("topExpirdWidget");
v.ui->topInvalidWidget->setStyleSheet( v.ui->topInvalidWidget->styleSheet());
v.ui->labTime->setVisible( false);
v.ui->labCodeName->setVisible( false);
v.ui->labFolat->setVisible( false);
v.ui->labChannel->setText(QString::fromLocal8Bit("渠道: ") + channel);
v.ui->labActName->setVisible( true);
v.ui->labCode->setText(coupon );
v.ui->labActName->setText( mess);
//换行显示
int w = v.ui->labActName->width();
QFontMetrics fm = v.ui->labActName->fontMetrics();
QString tmp, newStr;
for(int i = 0; i < mess.length(); i++)
{
tmp.append(mess.at(i));
int nw = fm.width(tmp);
if(nw >= w - 20)
{
tmp.append(QChar::LineFeed);
newStr.append(tmp);
tmp.clear();
}
}
if(!tmp.isEmpty())
newStr.append(tmp);
v.ui->labActName->setText(newStr);
v.ui->labActName->setStyleSheet("color:white;");
v.exec();
}
\ No newline at end of file
#ifndef ERRCODEDIALOG_H
#ifndef ERRCODEDIALOG_H
#define ERRCODEDIALOG_H
#include <QDialog>
......@@ -18,7 +18,6 @@ public:
static void showForInvalid(const QString& coupon, QWidget *parent = 0);
static void showForExpird(const QString& act_name, const QString& code_name, const QString& time_name, const QString& coupon, QWidget *parent = 0);
static void showForErr(const QString& coupon, const QString& mess, QWidget *parent = 0);
static void showForMismatch(const QString& coupon, const QString& mess, QWidget *parent = 0);
private:
Ui::ErrCodeDialog *ui;
......
......@@ -38,7 +38,8 @@
}
/**/
#topInvalidWidget{
background-image: url(:/img/bg_invalid_code.png);
/*background-image: url(:/img/bg_invalid_code.png);*/
background-image: url(:/img/bg_be_invalid.png);
border:none;
border-top-left-radius:12px;
border-top-right-radius:12px;
......@@ -53,7 +54,6 @@
#labFolat{
border:none;
background-image: url(:/img/folat_be_invalid.png);
}
/**/
......@@ -65,13 +65,13 @@
}
/*label*/
#labActName{
font: 75 30pt &quot;微软雅黑&quot;;
font: 60 20pt &quot;微软雅黑&quot;;
color: rgb(81, 81, 81);
}
#labCodeName{
font: 72 25pt &quot;微软雅黑&quot;;
color: rgb(81, 81, 81);
#labChannel{
font: 65 15pt &quot;微软雅黑&quot;;
color: rgb(255, 255, 255);
}
#labTime{
......@@ -197,9 +197,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>90</y>
<y>60</y>
<width>330</width>
<height>80</height>
<height>100</height>
</rect>
</property>
<property name="minimumSize">
......@@ -211,17 +211,17 @@
<property name="maximumSize">
<size>
<width>330</width>
<height>80</height>
<height>100</height>
</size>
</property>
<property name="text">
<string>5元脆骨鸡</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
</widget>
<widget class="QLabel" name="labCodeName">
<widget class="QLabel" name="labChannel">
<property name="geometry">
<rect>
<x>0</x>
......@@ -246,35 +246,13 @@
<string notr="true"/>
</property>
<property name="text">
<string>键位促销</string>
<string>渠道:浦发银行</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="labFolat">
<property name="geometry">
<rect>
<x>68</x>
<y>0</y>
<width>262</width>
<height>167</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>262</width>
<height>167</height>
</size>
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="maximumSize">
<size>
<width>262</width>
<height>167</height>
</size>
</property>
<property name="text">
<string/>
<property name="indent">
<number>15</number>
</property>
</widget>
</widget>
......
#include "fmloading.h"
#include "ui_fmloading.h"
FMLoading::FMLoading(QWidget *parent) :
QDialog(parent),
movie(Q_NULLPTR),
ui(new Ui::FMLoading)
{
ui->setupUi(this);
setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::Tool | Qt::WindowStaysOnTopHint);
setAttribute(Qt::WA_TranslucentBackground, true);
movie = new QMovie(":/img/loading.gif");
if(movie->isValid())
{
connect(movie, SIGNAL(finished()), movie, SLOT(start()));
movie->start();
ui->label->setMovie(movie);
}
else
{
ui->label->setText(QString::fromLocal8Bit("无效动画"));
}
}
FMLoading::~FMLoading()
{
if(movie != Q_NULLPTR)
{
delete movie;
movie = Q_NULLPTR;
}
delete ui;
}
#ifndef FMLOADING_H
#define FMLOADING_H
#include <QDialog>
#include <QMovie>
namespace Ui {
class FMLoading;
}
class FMLoading : public QDialog
{
Q_OBJECT
public:
explicit FMLoading(QWidget *parent = 0);
~FMLoading();
private:
Ui::FMLoading *ui;
QMovie* movie;
};
#endif // FMLOADING_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FMLoading</class>
<widget class="QDialog" name="FMLoading">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>90</x>
<y>50</y>
<width>241</width>
<height>191</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
......@@ -10,6 +10,7 @@
#include "fmp_epay_i.h"
#include "fmp_home_i.h"
#include "redeemdetail.h"
#include "fmp_redeem_def.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonParseError>
......@@ -23,9 +24,10 @@
#include <QResource>
#include <QSettings>
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QtConcurrent>
#include <QFutureWatcher>
bool isRedeeming = false;
......@@ -70,7 +72,8 @@ bool FMPRedeem::IsRedeeming()const
void FMPRedeem::ShowRedeemDetail()
{
RedeemDetail dlg;
LoadStoreInfo();
RedeemDetail dlg(_partner_id, _store_id, _redeem_log_url);
dlg.exec();
}
......@@ -123,7 +126,7 @@ QJsonObject FMPRedeem::Reverse(QJsonObject request)
{
QString apppath = QCoreApplication::applicationDirPath();
QSettings settings(QString("%1/FreemudPOS.ini").arg(apppath), QSettings::IniFormat);
_url = settings.value(FMP_INIKEY_EPAYURL).toString();
_redeem_url = settings.value(FMP_INIKEY_EPAYURL).toString();
request["reqtype"] = 3;
QByteArray reqData = QJsonDocument(request).toJson(QJsonDocument::Compact);
reqData = CheckSendArray(reqData);
......@@ -137,24 +140,23 @@ QJsonObject FMPRedeem::Redeem(const QJsonArray& productsInfo)
isRedeeming = true;
FMP_DEBUG() << "Recv redeem data: " << QJsonDocument(productsInfo).toJson(QJsonDocument::Compact);
_products_info = productsInfo;
//读取门店信息
QString apppath = QCoreApplication::applicationDirPath();
QSettings settings(QString("%1/FreemudPOS.ini").arg(apppath), QSettings::IniFormat);
_store_id = settings.value(FMP_INIKEY_LOGINSTOREID).toString();
_station_id = settings.value(FMP_INIKEY_LOGINPOSID).toString();
_operator_id = settings.value(FMP_INIKEY_LOGINCASHIER).toString();
_url = settings.value(FMP_INIKEY_EPAYURL).toString();
_partner_id = settings.value(FMP_INIKEY_LOGINPARTNERID).toInt();
LoadStoreInfo();
if(_store_id.isEmpty() || _station_id.isEmpty())
{
StoreDialog storeDialog;
if(storeDialog.exec() == QDialog::Accepted)
{
QString apppath = QCoreApplication::applicationDirPath();
QSettings settings(QString("%1/FreemudPOS.ini").arg(apppath), QSettings::IniFormat);
_store_id = storeDialog.storeId;
_station_id = storeDialog.posId;
settings.setValue(FMP_INIKEY_LOGINSTOREID, _store_id);
settings.setValue(FMP_INIKEY_LOGINPOSID, _station_id);
settings.sync();
}
else
{
......@@ -184,7 +186,7 @@ QJsonObject FMPRedeem::Redeem(const QJsonArray& productsInfo)
json.insert("ver", 2);
json.insert("clientReqCount", ++_clientReqCount%=10000000);
json.insert("reqtype", 0);
json.insert("partnerId", _partner_id);
// json.insert("partnerId", _partner_id);
json.insert("store_id", _store_id);
json.insert("station_id", _station_id);
json.insert("operator_id", _operator_id);
......@@ -192,13 +194,20 @@ QJsonObject FMPRedeem::Redeem(const QJsonArray& productsInfo)
QByteArray reqData = QJsonDocument(json).toJson(QJsonDocument::Compact);
reqData = CheckSendArray(reqData);
ConsumptionDialog v;
v.ShowForWaiting(QString::fromLocal8Bit("查询中"), _coupon);
_reply = nullptr;
connect(&v, &ConsumptionDialog::rejected, this, [=]{if(_reply)_reply->abort();});
QJsonObject retJson = SendRequest(reqData);
v.HideForWaiting();
int statusCode = retJson["statusCode"].toInt();
switch (statusCode)
{
case 100: //成功
retJson = ShowForUnConsum(retJson);
break;
#if 0
case 11: //无效码
retJson = ShowForInvalid(retJson);
break;
......@@ -208,6 +217,7 @@ QJsonObject FMPRedeem::Redeem(const QJsonArray& productsInfo)
case 14: //已核销
retJson = ShowForHasConsum(retJson);
break;
#endif
default: //出错
retJson = ShowForErr(retJson);
break;
......@@ -219,12 +229,12 @@ QJsonObject FMPRedeem::Redeem(const QJsonArray& productsInfo)
QJsonObject FMPRedeem::SendRequest(const QByteArray &reqData)
{
FMP_DEBUG() << "Send data: " << reqData;
FMP_DEBUG() << "Send url: " << _url;
FMP_DEBUG() << "Send url: " << _redeem_url;
QJsonObject retJson;
QNetworkAccessManager nam;
QNetworkRequest req;
QNetworkReply* reply = nullptr;
_reply = nullptr;
QSslConfiguration config;
QList<QSslCertificate> certs = QSslCertificate::fromPath(qApp->applicationDirPath() + "/client01.pem");
......@@ -232,12 +242,12 @@ QJsonObject FMPRedeem::SendRequest(const QByteArray &reqData)
config.setProtocol(QSsl::SslV3);
config.setCaCertificates(certs);
req.setSslConfiguration(config);
req.setUrl(_url);
// req.setSslConfiguration(config);
req.setUrl(_redeem_url);
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
req.setHeader(QNetworkRequest::ContentLengthHeader, reqData.length());
reply = nam.post(req, reqData);
_reply = nam.post(req, reqData);
// 使用定时器处理超时
QEventLoop loop;
......@@ -251,27 +261,28 @@ QJsonObject FMPRedeem::SendRequest(const QByteArray &reqData)
if(timer.isActive())
{
timer.stop();
if(reply->error() == QNetworkReply::NoError)
if(_reply->error() == QNetworkReply::NoError)
{
QByteArray respons = reply->readAll();
QByteArray respons = _reply->readAll();
retJson = QJsonDocument::fromJson(respons).object();
}
else
{
//网络错误
retJson["statusCode"] = FM_API_NETWORKERROR;
retJson["msg"] = reply->errorString();
retJson["msg"] = _reply->errorString();
}
}
else
{
//超时
disconnect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
reply->abort();
disconnect(_reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
_reply->abort();
retJson["statusCode"] = FM_API_TIMEOUT;
retJson["msg"] = QString::fromLocal8Bit("请求超时");
}
reply->deleteLater();
_reply->deleteLater();
_reply = nullptr;
FMP_DEBUG() << "Server response: " << QJsonDocument(retJson).toJson(QJsonDocument::Compact);
return retJson;
}
......@@ -282,23 +293,22 @@ QJsonObject FMPRedeem::ShowForUnConsum(QJsonObject json)
QString act_name = codeInfo["act_name"].toString();
QString act_id = codeInfo["act_id"].toString();
QString vdata = codeInfo["vdata"].toString();
QString coupon = codeInfo["code"].toString();
QString coupon = _coupon;
QString ebcode = codeInfo["ebcode"].toString();
QString ebname = codeInfo["ebname"].toString();
QString time_name = QString::fromLocal8Bit("有效期至: ").append(vdata);
QString channel = json["channel"].toString();
double realAmount = codeInfo["amount"].toInt()/100.0;
double amount = codeInfo["paid"].toInt()/100.0;
QString time_name = QString::fromLocal8Bit("有效期至: ").append(QDate::fromString(vdata, "yyyyMMdd").toString("yyyy-MM-dd"));
int couponType = json["couponType"].toInt();
double amount = codeInfo["amount"].toInt()/100.0;
QString info = QString::fromLocal8Bit("面值:%1元 实收:%2元 渠道:%3")
.arg(amount)
.arg(amount)
.arg(ebname);
if( ConsumptionDialog::ShowForUnConsum(act_name, info,time_name,coupon))
if( ConsumptionDialog::ShowForUnConsum(act_name, amount, realAmount, channel, "", coupon))
{
_redeem_json = QJsonObject();
_redeem_json["ver"] = 2;
_redeem_json["clientReqCount"] = (++_clientReqCount%=10000000);
_redeem_json["reqtype"] = 71;
_redeem_json["partnerId"] = _partner_id;
// _redeem_json["partnerId"] = _partner_id;
_redeem_json["store_id"] = _store_id;
_redeem_json["station_id"] = _station_id;
_redeem_json["trans_id"] = QString::number(QDateTime::currentDateTimeUtc().toTime_t());
......@@ -311,29 +321,15 @@ QJsonObject FMPRedeem::ShowForUnConsum(QJsonObject json)
transaction["code"] = coupon;
transaction["ebcode"] = ebcode;
//得到该券所对应商品id,目前一张券只对应一种商品
QString canUsedProduct = SearchJsonObject(json, "pid").toString();
//遍历传入的商品信息,查找是否有相同的商品id,
//若有则进行核销,否则,直接返回失败
int i;
for(i = 0; i < _products_info.size(); i++){
QJsonObject obj = _products_info[i].toObject();
if(obj["pid"].toString() == canUsedProduct)
break;
}
if(i >= _products_info.size())
{
//不存在对应商品
return ShowForMismatch(json);
}
QJsonArray products;
for(int i = 0; i < _products_info.size(); i++)
{
QJsonObject product;
product.insert("seq", 1);
product.insert("seq", i+1);
product.insert("pid", _products_info[i].toObject()["pid"]);
product.insert("consume_num", _products_info[i].toObject()["consume_num"]);
products.append(product);
}
transaction["products"] = products;
transactions.append(transaction);
......@@ -353,14 +349,21 @@ QJsonObject FMPRedeem::ShowForUnConsum(QJsonObject json)
reqData = CheckSendArray(reqData);
QJsonObject redeemResult;
ConsumptionDialog v;
v.ShowForWaiting(QString::fromLocal8Bit("核销中"), _coupon);
_reply = nullptr;
connect(&v, &ConsumptionDialog::rejected, this, [=]{if(_reply)_reply->abort();});
QJsonObject retJson = SendRequest(reqData);
v.HideForWaiting();
int statusCode = retJson["statusCode"].toInt();
QString msg = retJson["msg"].toString();
switch(statusCode)
{
case 100:
{
ConsumOkDialog::showConsumOk( act_name, "", time_name, coupon);
ConsumOkDialog::showConsumOk( act_name, channel, "", coupon);
if(couponType == 0) //商品券
{
......@@ -376,9 +379,6 @@ QJsonObject FMPRedeem::ShowForUnConsum(QJsonObject json)
redeemResult["couponDesc"] = act_name;
redeemResult["code"] = coupon;
redeemResult["redeem_json"] = _redeem_json;
//save redeem result
SaveRedeemResult(coupon, act_name, ebname, amount);
}
break;
default:
......@@ -423,15 +423,6 @@ QJsonObject FMPRedeem::ShowForErr(QJsonObject json)
return json;
}
QJsonObject FMPRedeem::ShowForMismatch(QJsonObject json)
{
ErrCodeDialog::showForMismatch(_coupon, QString::fromLocal8Bit("券和商品不匹配"));
QJsonObject mismatch;
mismatch["statusCode"] = 31;
mismatch["msg"] = QString::fromLocal8Bit("券和商品不匹配");
return mismatch;
}
QJsonObject FMPRedeem::GetRedeemJson() const
{
return _redeem_json;
......@@ -495,34 +486,28 @@ QByteArray FMPRedeem::CheckSendArray(QByteArray &jsonArray)
return array;
}
void FMPRedeem::SaveRedeemResult(QString code, QString code_name, QString ebname, double amount)
ctkPlugin::State FMPRedeem::GetPluginState()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
QString path = QApplication::applicationDirPath();
db.setDatabaseName(path + "/redeem.db");
if(!db.open())
{
FMP_DEBUG() << "open redeem.db failed: " << db.lastError().driverText();
return ;
}
QSqlQuery query(db);
QString sql = "create table if not exists redeem(code varchar(20), code_name varchar(20), ebname varchar(20), amount double)";
if(!query.exec(sql))
{
FMP_DEBUG() << "create redeem table failed: " << query.lastError().driverText();
db.close();
return;
}
sql = "insert into redeem values(?,?,?,?)";
query.prepare(sql);
query.addBindValue(code);
query.addBindValue(code_name);
query.addBindValue(ebname);
query.addBindValue(amount);
if(!query.exec())
{
FMP_DEBUG() << "insert into redeem failed: " << query.lastError().driverText() << " code=" << code;
return;
}
FMP_DEBUG() << "insert into redeem success: code=" << code;
return GetContext()->getPlugin()->getState();
}
void FMPRedeem::LoadStoreInfo()
{
//读取门店信息
QString apppath = QCoreApplication::applicationDirPath();
//QSettings tmp(apppath+"/../storeinfo.ini", QSettings::IniFormat);
//QString si = tmp.value("info/storeid").toString();
//QString pi = tmp.value("info/posno").toString();
QSettings settings(QString("%1/FreemudPOS.ini").arg(apppath), QSettings::IniFormat);
//settings.setValue(FMP_INIKEY_LOGINSTOREID, si);
//settings.setValue(FMP_INIKEY_LOGINPOSID, pi);
//settings.sync();
_store_id = settings.value(FMP_INIKEY_LOGINSTOREID).toString();
_station_id = settings.value(FMP_INIKEY_LOGINPOSID).toString();
_operator_id = settings.value(FMP_INIKEY_LOGINCASHIER).toString();
_redeem_url = settings.value(FMP_INIKEY_EPAYURL).toString();
_redeem_log_url = settings.value(FMP_INIKEY_REDEEM_LOG).toString();
_partner_id = settings.value(FMP_INIKEY_LOGINPARTNERID).toInt();
}
......@@ -6,6 +6,9 @@
#include <QJsonObject>
#include <QJsonArray>
#include <QPointer>
#include <QNetworkReply>
#include <QSqlDatabase>
class FMPStartEventHandler;
class FMPRedeem : public FMPRedeemInterface
{
......@@ -34,6 +37,7 @@ public:
QJsonObject GetRedeemJson()const;
virtual bool IsRedeeming() const;
virtual void ShowRedeemDetail();
virtual ctkPlugin::State GetPluginState();
protected:
const FMPContext GetContext() const { return _context; }
......@@ -49,12 +53,11 @@ private:
QJsonObject ShowForInvalid(QJsonObject json);
QJsonObject ShowForExpird(QJsonObject json);
QJsonObject ShowForErr(QJsonObject json);
QJsonObject ShowForMismatch(QJsonObject json);
int ZH_caclChkValue(char * pJsonData, int startPos, int endPos);
QByteArray CheckSendArray( QByteArray & jsonArray);
QJsonValue SearchJsonObject(QJsonObject& searchJson, QString searchKey);
QJsonValue SearchJsonArray(QJsonArray& searchJson, QString searchKey);
void SaveRedeemResult(QString code, QString code_name, QString ebname, double amount);
void LoadStoreInfo();
private:
bool _inited;
......@@ -63,12 +66,14 @@ private:
QString _operator_id;
QString _coupon;
int _partner_id;
QString _url;
QString _redeem_url;
QString _redeem_log_url;
QJsonArray _products_info;
QJsonObject _redeem_json; //存放核销请求字符串
int _clientReqCount;
const FMPContext _context;
QPointer<FMPStartEventHandler> _ste_handler;
QNetworkReply* _reply;
};
#endif // FMP_REDEEM_H
......
......@@ -5,7 +5,7 @@
#-------------------------------------------------
TEMPLATE = lib
QT += core gui network winextras sql
QT += core gui network winextras sql concurrent
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
......@@ -65,8 +65,10 @@ HEADERS += \
scanningdialog.h \
fmp_pe_handlers.h \
storedialog.h \
mysqltablemodel.h \
redeemdetail.h
redeemdetail.h \
datedialog.h \
fmp_redeem_def.h \
fmloading.h
SOURCES += \
fmp_redeem.cpp \
......@@ -78,8 +80,9 @@ SOURCES += \
scanningdialog.cpp \
fmp_pe_handlers.cpp \
storedialog.cpp \
mysqltablemodel.cpp \
redeemdetail.cpp
redeemdetail.cpp \
datedialog.cpp \
fmloading.cpp
FORMS += \
consumokdialog.ui \
......@@ -88,4 +91,6 @@ FORMS += \
errcodedialog.ui \
scanningdialog.ui \
storedialog.ui \
redeemdetail.ui
\ No newline at end of file
redeemdetail.ui \
datedialog.ui \
fmloading.ui
\ No newline at end of file
#ifndef FMP_REDEEM_DEF_H
#define FMP_REDEEM_DEF_H
#define FMP_INIKEY_REDEEM_LOG "Coupon/RedeemLog"
#endif // FMP_REDEEM_DEF_H
......@@ -25,6 +25,7 @@ public:
virtual QJsonObject GetRedeemJson()const = 0;
virtual bool IsRedeeming()const = 0;
virtual void ShowRedeemDetail() = 0;
virtual ctkPlugin::State GetPluginState() = 0;
signals:
void TriggerInit();
......
......@@ -14,7 +14,6 @@ class FMPRedeemPlugin : public QObject, public ctkPluginActivator
public:
explicit FMPRedeemPlugin();
void start(ctkPluginContext* context);
void stop(ctkPluginContext* context);
......
#include "mysqltablemodel.h"
MySqlTableModel::MySqlTableModel(QObject *parent, QSqlDatabase db)
:QSqlTableModel(parent, db)
{
}
QVariant MySqlTableModel::data(const QModelIndex &idx, int role) const
{
QVariant value = QSqlTableModel::data(idx, role);
if(role == Qt::TextAlignmentRole)
return Qt::AlignCenter;
return value;
}
\ No newline at end of file
#ifndef MYSQLTABLEMODEL_H
#define MYSQLTABLEMODEL_H
#include <QSqlTableModel>
class MySqlTableModel : public QSqlTableModel
{
public:
MySqlTableModel(QObject * parent = 0, QSqlDatabase db = QSqlDatabase());
QVariant data(const QModelIndex &idx, int role) const;
};
#endif // MYSQLTABLEMODEL_H
#include "redeemdetail.h"
#include "ui_redeemdetail.h"
#include "fmp_logger_i.h"
#include "fmp_home_i.h"
#include <QMouseEvent>
#include <QTableWidgetItem>
#include <QMessageBox>
#include <QDebug>
#include <QMovie>
#include <QSqlResult>
#include <QApplication>
#include <QSettings>
#include <QTimer>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QJsonArray>
#include <QtConcurrent>
extern bool isRedeeming;
RedeemDetail::RedeemDetail(QWidget *parent) :
RedeemDetail::RedeemDetail(int partnerId, QString storeId, QString url, QWidget *parent) :
QDialog(parent),
dateDlg(this),
loadingDlg(this),
reply(NULL),
ui(new Ui::RedeemDetail)
{
ui->setupUi(this);
setAttribute(Qt::WA_QuitOnClose, false);
setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
connect(ui->closeBtn, SIGNAL(clicked(bool)), this, SLOT(close()));
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
connect(ui->findBtn, SIGNAL(clicked(bool)), this, SLOT(FindByCode()));
connect(ui->codeEdit, SIGNAL(textChanged(QString)), this, SLOT(FindByCode(QString)));
connect(ui->refundBtn, SIGNAL(clicked(bool)), this, SLOT(RefundByCode()));
connect(ui->keyBtn, SIGNAL(clicked(bool)), this, SLOT(ShowKeyboard(bool)));
connect(ui->preBtn, SIGNAL(clicked(bool)), this, SLOT(PrevDay()));
connect(ui->nextBtn, SIGNAL(clicked(bool)), this, SLOT(NextDay()));
connect(ui->oneBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed()));
connect(ui->twoBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed()));
connect(ui->threeBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed()));
connect(ui->fourBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed()));
connect(ui->fiveBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed()));
connect(ui->sixBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed()));
connect(ui->sevenBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed()));
connect(ui->eightBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed()));
connect(ui->nineBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed()));
connect(ui->zeroBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed()));
connect(ui->delBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed()));
connect(ui->startDateBtn, SIGNAL(clicked(bool)), this, SLOT(OnStartDateClicked()));
connect(ui->endDateBtn, SIGNAL(clicked(bool)), this, SLOT(OnEndDateClicked()));
connect(ui->oneBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed(bool)));
connect(ui->twoBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed(bool)));
connect(ui->threeBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed(bool)));
connect(ui->fourBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed(bool)));
connect(ui->fiveBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed(bool)));
connect(ui->sixBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed(bool)));
connect(ui->sevenBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed(bool)));
connect(ui->eightBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed(bool)));
connect(ui->nineBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed(bool)));
connect(ui->zeroBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed(bool)));
connect(ui->delBtn, SIGNAL(clicked(bool)), this, SLOT(keyboardPressed(bool)));
connect(this, SIGNAL(Loaded(QJsonObject)), this, SLOT(ShowRedeemRecord(QJsonObject)));
ui->numWidget->hide();
ui->refundBtn->hide();
InitSqlite();
LoadRedeemRecord();
startDate = endDate = QDate::currentDate();
ui->startDateBtn->setText(QString::fromLocal8Bit("开始日期:") + startDate.toString("yyyy-MM-dd"));
ui->endDateBtn->setText(QString::fromLocal8Bit("结束日期:") + endDate.toString("yyyy-MM-dd"));
isRedeeming = true;
this->partnerId = partnerId;
this->storeId = storeId;
this->url = url;
QString apppath = QCoreApplication::applicationDirPath();
QSettings ver(apppath+"/../update.ini", QSettings::IniFormat);
ui->companyLabel->setText(QString::fromLocal8Bit("由非码提供技术支持 ") + "V" + ver.value("SoftInfo/version").toString());
ui->titleLabel->setText(QString::fromLocal8Bit("核销详情 门店编码: ")+storeId);
InitModel();
QTimer::singleShot(100, this, SLOT(FirstLoadRecord()));
}
RedeemDetail::~RedeemDetail()
{
isRedeeming = false;
db.close();
if(reply)
{
reply->abort();
future.waitForFinished();
}
delete ui;
}
......@@ -90,23 +122,26 @@ void RedeemDetail::keyPressEvent(QKeyEvent *e)
void RedeemDetail::FindByCode()
{
QString code = ui->codeEdit->text().trimmed();
if(code.isEmpty())
return;
model->setFilter("code="+code);
FindByCode(code);
}
void RedeemDetail::FindByCode(QString str)
{
model->setFilter("code like '%"+str+"%'");
}
void RedeemDetail::RefundByCode()
{
QModelIndex idx = ui->tableView->currentIndex();
if(!idx.isValid())
ui->tableView->clearSelection();
int rows = model.rowCount();
for(int r = 0; r < rows; r++)
{
QStandardItem* item = model.item(r, 0);
if(item)
{
if(item->text().contains(str))
{
ui->tableView->selectRow(r);
ui->tableView->scrollTo(item->index());
return;
QString code = model->data(model->index(idx.row(), 0), Qt::EditRole).toString();
QMessageBox::information(this, QString::fromLocal8Bit("测试"), QString::fromLocal8Bit("退款成功!券码:")+code);
}
}
}
}
void RedeemDetail::ShowKeyboard(bool checked)
......@@ -117,116 +152,138 @@ void RedeemDetail::ShowKeyboard(bool checked)
ui->numWidget->hide();
}
bool RedeemDetail::InitSqlite()
void RedeemDetail::LoadRedeemRecord()
{
db = QSqlDatabase::addDatabase("QSQLITE");
QJsonObject reqObj;
reqObj["partnerId"] = partnerId;
reqObj["storeId"] = storeId;
reqObj["start"] = startDate.toString("yyyy-MM-dd 00:00:00");
reqObj["end"] = endDate.toString("yyyy-MM-dd 23:59:59");
QByteArray reqData = QJsonDocument(reqObj).toJson();
db.setDatabaseName(QApplication::applicationDirPath() + "\\redeem.db");
if(!db.open())
{
FMP_DEBUG() << "open redeem.db failed: " << db.lastError().driverText();
return false;
}
FMP_DEBUG() << "Send data: " << reqData;
FMP_DEBUG() << "Send url: " << url;
QSqlQuery query(db);
QString sql = "create table if not exists redeem(code varchar(20), code_name varchar(20), ebname varchar(20), amount double, redeem_date datetime default CURRENT_TIMESTAMP)";
if(!query.exec(sql))
{
FMP_DEBUG() << "create redeem table failed: " << query.lastError().databaseText();
db.close();
return false;
}
QJsonObject retJson;
QNetworkAccessManager nam;
QNetworkRequest req;
return true;
}
req.setUrl(url);
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
req.setHeader(QNetworkRequest::ContentLengthHeader, reqData.length());
void RedeemDetail::ComputeCurrentData()
{
QSqlQuery query;
QString sql = QString("select count(*) from redeem where date(redeem_date)=date('%1')").arg(curDate.toString("yyyy-MM-dd"));
if(!query.exec(sql))
reply = nam.post(req, reqData);
// 使用定时器处理超时
QEventLoop loop;
connect(&nam, &QNetworkAccessManager::finished, &loop, &QEventLoop::quit);
QTimer timer;
timer.setSingleShot(true);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
timer.start(1000 * 30);
loop.exec();
if(timer.isActive())
{
FMP_DEBUG() << "select redeem record failed: " << query.lastError().driverText();
db.close();
return;
timer.stop();
if(reply->error() == QNetworkReply::NoError)
{
QByteArray respons = reply->readAll();
retJson = QJsonDocument::fromJson(respons).object();
}
query.next();
ui->totalRedeem->setText(QString::number(query.value(0).toInt()));
sql = QString("select sum(amount) from redeem where date(redeem_date)=date('%1')").arg(curDate.toString("yyyy-MM-dd"));
if(!query.exec(sql))
else
{
FMP_DEBUG() << "select redeem record failed: " << query.lastError().driverText();
db.close();
return;
//网络错误
retJson["statusCode"] = FM_API_NETWORKERROR;
retJson["msg"] = reply->errorString();
}
}
else
{
//超时
disconnect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
reply->abort();
retJson["statusCode"] = FM_API_TIMEOUT;
retJson["msg"] = QString::fromLocal8Bit("请求超时");
}
query.next();
ui->totalRedeemMoney->setText(QString::number(query.value(0).toDouble()));
reply->deleteLater();
reply = nullptr;
FMP_DEBUG() << "Server response: " << QJsonDocument(retJson).toJson(QJsonDocument::Compact);
emit Loaded(retJson);
}
void RedeemDetail::LoadRedeemRecord()
void RedeemDetail::ShowRedeemRecord(QJsonObject obj)
{
curDate = QDate::currentDate();
QSqlQuery query(db);
//删除90天之前的数据
QString sql = "delete from redeem where julianday('now')-julianday(redeem_date)>90";
if(!query.exec(sql))
{
FMP_DEBUG() << "delete from redeem failed: " << query.lastError().databaseText();
}
SetBusy(false);
if(model.rowCount() > 0)
model.removeRows(0, model.rowCount());
ui->totalRedeem->setText(QString::fromLocal8Bit("总核销数: 0"));
ui->totalRedeemMoney->setText(QString::fromLocal8Bit("总核销额: 0"));
//查询出当前数据库中的最小日期
sql = "select min(redeem_date) from redeem";
if(!query.exec(sql))
if(obj["statusCode"].toInt() != FM_API_SUCCESS)
{
FMP_DEBUG() << query.lastError().databaseText();
ui->totalLabel->setText(QString::fromLocal8Bit("总核销 [%1]").arg(obj["msg"].toString()));
return;
}
else
ui->totalLabel->setText(QString::fromLocal8Bit("总核销 [%1 - %2]").arg(startDate.toString("yyyy/MM/dd")).arg(endDate.toString("yyyy/MM/dd")));
double totalMoney = 0.0;
QJsonArray logList = obj["logList"].toArray();
for(int i = 0; i < logList.size(); i++)
{
query.next();
minDate = query.value(0).toDate();
minDate = minDate.isValid() ? minDate : QDate::currentDate();
}
QJsonObject tmp = logList[i].toObject();
QString couponCode = tmp["couponCode"].toString();
QString activeName = tmp["activeName"].toString();
QString channel = tmp["channel"].toString();
double faceAmount = tmp["amount"].toInt()/100.0;
double realAmount = tmp["realAmount"].toInt()/100.0;
QString redeemDate = tmp["redeemDate"].toString();
totalMoney += realAmount;
ComputeCurrentData();
QList<QStandardItem*> row;
model = new MySqlTableModel(this, db);
model->setTable("redeem");
model->setFilter("date(redeem_date) = date('now')");
model->select();
model->setHeaderData(0, Qt::Horizontal, QString::fromLocal8Bit("券码"));
model->setHeaderData(1, Qt::Horizontal, QString::fromLocal8Bit("名称"));
model->setHeaderData(2, Qt::Horizontal, QString::fromLocal8Bit("渠道"));
model->setHeaderData(3, Qt::Horizontal, QString::fromLocal8Bit("金额"));
model->setHeaderData(4, Qt::Horizontal, QString::fromLocal8Bit("核销时间"));
ui->tableView->setModel(model);
QStandardItem* couponCodeItem = new QStandardItem(couponCode);
couponCodeItem->setTextAlignment(Qt::AlignCenter);
QStandardItem* activeNameItem = new QStandardItem(activeName);
activeNameItem->setTextAlignment(Qt::AlignCenter);
QStandardItem* channelItem = new QStandardItem(channel);
channelItem->setTextAlignment(Qt::AlignCenter);
QStandardItem* faceAmountItem = new QStandardItem(QString::number(faceAmount));
faceAmountItem->setTextAlignment(Qt::AlignCenter);
QStandardItem* realAmountItem = new QStandardItem(QString::number(realAmount));
realAmountItem->setTextAlignment(Qt::AlignCenter);
QStandardItem* redeemDateItem = new QStandardItem(redeemDate);
redeemDateItem->setTextAlignment(Qt::AlignCenter);
row << couponCodeItem << activeNameItem << channelItem << faceAmountItem << realAmountItem << redeemDateItem;
model.appendRow(row);
}
ui->totalRedeem->setText(QString::fromLocal8Bit("总核销数: %1").arg(logList.size()));
ui->totalRedeemMoney->setText(QString::fromLocal8Bit("总核销额: %1").arg(totalMoney));
}
void RedeemDetail::PrevDay()
void RedeemDetail::OnStartDateClicked()
{
QDate d(curDate.year(), curDate.month(), curDate.day()-1);
if(d < minDate)
return;
model->setFilter("date(redeem_date)=date('" + d.toString("yyyy-MM-dd") + "')");
curDate = d;
ComputeCurrentData();
connect(&dateDlg, SIGNAL(DateChanged(QDate)), this, SLOT(OnStartDateChanged(QDate)));
dateDlg.exec();
disconnect(&dateDlg, SIGNAL(DateChanged(QDate)), this, SLOT(OnStartDateChanged(QDate)));
}
void RedeemDetail::NextDay()
void RedeemDetail::OnEndDateClicked()
{
if(curDate == QDate::currentDate())
return;
QDate d(curDate.year(), curDate.month(), curDate.day()+1);
model->setFilter("date(redeem_date)=date('" + d.toString("yyyy-MM-dd") + "')");
curDate = d;
ComputeCurrentData();
connect(&dateDlg, SIGNAL(DateChanged(QDate)), this, SLOT(OnEndDateChanged(QDate)));
dateDlg.exec();
disconnect(&dateDlg, SIGNAL(DateChanged(QDate)), this, SLOT(OnEndDateChanged(QDate)));
}
void RedeemDetail::keyboardPressed()
void RedeemDetail::keyboardPressed(bool)
{
QPushButton* btn = qobject_cast<QPushButton*>(sender());
if(!btn)
return;
if(!btn) return;
if(btn == ui->delBtn)
{
QString txt = ui->codeEdit->text();
......@@ -242,3 +299,76 @@ void RedeemDetail::keyboardPressed()
ui->codeEdit->setText(txt);
}
}
void RedeemDetail::OnStartDateChanged(QDate cur)
{
startDate = cur;
ui->startDateBtn->setText(QString::fromLocal8Bit("开始日期:") + startDate.toString("yyyy-MM-dd"));
if(reply != Q_NULLPTR)
{
reply->abort();
future.waitForFinished();
}
future = QtConcurrent::run(this, &RedeemDetail::LoadRedeemRecord);
SetBusy(true);
}
void RedeemDetail::OnEndDateChanged(QDate cur)
{
endDate = cur;
ui->endDateBtn->setText(QString::fromLocal8Bit("结束日期:") + endDate.toString("yyyy-MM-dd"));
if(reply != Q_NULLPTR)
{
reply->abort();
future.waitForFinished();
}
future = QtConcurrent::run(this, &RedeemDetail::LoadRedeemRecord);
SetBusy(true);
}
void RedeemDetail::InitModel()
{
model.setColumnCount(6);
model.setHeaderData(0, Qt::Horizontal, QString::fromLocal8Bit("券码"));
model.setHeaderData(1, Qt::Horizontal, QString::fromLocal8Bit("名称"));
model.setHeaderData(2, Qt::Horizontal, QString::fromLocal8Bit("渠道"));
model.setHeaderData(3, Qt::Horizontal, QString::fromLocal8Bit("面值"));
model.setHeaderData(4, Qt::Horizontal, QString::fromLocal8Bit("实收"));
model.setHeaderData(5, Qt::Horizontal, QString::fromLocal8Bit("核销时间"));
ui->tableView->setModel(&model);
ui->tableView->horizontalHeader()->setStretchLastSection(true);
ui->tableView->setColumnWidth(0, 150);
ui->tableView->setColumnWidth(1, 250);
ui->tableView->setColumnWidth(2, 100);
ui->tableView->setColumnWidth(3, 100);
ui->tableView->setColumnWidth(4, 100);
}
void RedeemDetail::FirstLoadRecord()
{
if(reply != Q_NULLPTR)
{
reply->abort();
future.waitForFinished();
}
future = QtConcurrent::run(this, &RedeemDetail::LoadRedeemRecord);
SetBusy(true);
}
void RedeemDetail::SetBusy(bool busy)
{
if(busy)
{
if(loadingDlg.isVisible())
loadingDlg.hide();
loadingDlg.show();
}
else
{
loadingDlg.hide();
}
}
......@@ -6,7 +6,12 @@
#include <QSqlQuery>
#include <QSqlError>
#include <QDate>
#include "mysqltablemodel.h"
#include <QFuture>
#include <QStandardItemModel>
#include <QNetworkReply>
#include <QJsonObject>
#include "datedialog.h"
#include "fmloading.h"
namespace Ui {
class RedeemDetail;
......@@ -15,9 +20,19 @@ class RedeemDetail;
class RedeemDetail : public QDialog
{
Q_OBJECT
enum {
FM_API_SUCCESS = 100,
FM_API_ERROR,
FM_API_TIMEOUT,
FM_API_BADJSON,
FM_API_NETWORKERROR,
FM_API_SERVERERROR,
FM_API_WINDOWCLOSE,
FM_API_TYPEERROR
};
public:
explicit RedeemDetail(QWidget *parent = 0);
explicit RedeemDetail(int partnerId, QString storeId, QString url, QWidget *parent = 0);
~RedeemDetail();
protected:
......@@ -29,23 +44,33 @@ protected:
private slots:
void FindByCode();
void FindByCode(QString str);
void RefundByCode();
void ShowKeyboard(bool checked);
bool InitSqlite();
void ComputeCurrentData();
void LoadRedeemRecord();
void PrevDay();
void NextDay();
void keyboardPressed();
void OnStartDateClicked();
void OnEndDateClicked();
void keyboardPressed(bool);
void OnStartDateChanged(QDate cur);
void OnEndDateChanged(QDate cur);
void InitModel();
void ShowRedeemRecord(QJsonObject obj);
void FirstLoadRecord();
void SetBusy(bool busy);
signals:
void Loaded(QJsonObject);
private:
Ui::RedeemDetail *ui;
bool mouse_pressed;
QPoint movePosition;
QSqlDatabase db;
MySqlTableModel* model;
QDate curDate;
QDate minDate;
QStandardItemModel model;
DateDialog dateDlg;
FMLoading loadingDlg;
int partnerId;
QString storeId, url;
QDate startDate, endDate;
QFuture<void> future;
QNetworkReply* reply;
};
#endif // DIALOG_H
......@@ -6,20 +6,20 @@
<rect>
<x>0</x>
<y>0</y>
<width>700</width>
<height>750</height>
<width>900</width>
<height>700</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>700</width>
<width>900</width>
<height>700</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>700</width>
<height>750</height>
<width>900</width>
<height>700</height>
</size>
</property>
<property name="windowTitle">
......@@ -55,7 +55,7 @@ QHeaderView::section{
border:none;
min-height:40px;
}
#totalRedeem{
#totalRedeem, totalOrdersLabel{
font-size:30px;
font-weight:bold;
}
......@@ -82,12 +82,12 @@ QHeaderView::section{
#codeLabel{
font: normal 16px &quot;Microsoft YaHei&quot;;
}
#findBtn, #refundBtn, #preBtn, #nextBtn, #keyBtn{
#findBtn, #startDateBtn, #endDateBtn, #keyBtn{
background-color:lightgrey;
font: normal 16px &quot;MicroSoft YaHei&quot;;
border-radius:15px;
}
#findBtn:pressed, #refundBtn:pressed, #preBtn:pressed, #nextBtn:pressed{
#findBtn:pressed, #startDateBtn:pressed, #endDateBtn:pressed{
padding: 1 0 0 2;
}
#oneBtn, #twoBtn, #threeBtn, #fourBtn, #fiveBtn, #sixBtn, #sevenBtn, #eightBtn, #nineBtn, #zeroBtn, #delBtn{
......@@ -107,15 +107,19 @@ QHeaderView::section{
}
#oneBtn:pressed, #twoBtn:pressed, #threeBtn:pressed, #fourBtn:pressed, #fiveBtn:pressed, #sixBtn:pressed, #sevenBtn:pressed, #eightBtn:pressed, #nineBtn:pressed, #zeroBtn:pressed{
padding:1 0 0 2
}
#companyLabel{
font: normal 16px &quot;微软雅黑&quot;;
color: rgb(150,150,150);
}
#tableView{
selection-background-color:rgb(0, 120, 215);
}</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<property name="leftMargin">
<number>0</number>
</property>
......@@ -132,13 +136,13 @@ QHeaderView::section{
<widget class="QWidget" name="widget_4" native="true">
<property name="minimumSize">
<size>
<width>700</width>
<width>900</width>
<height>40</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>700</width>
<width>900</width>
<height>40</height>
</size>
</property>
......@@ -162,7 +166,7 @@ QHeaderView::section{
<widget class="QLabel" name="titleLabel">
<property name="minimumSize">
<size>
<width>0</width>
<width>860</width>
<height>40</height>
</size>
</property>
......@@ -173,7 +177,7 @@ QHeaderView::section{
</size>
</property>
<property name="text">
<string>当日核销详情</string>
<string>当日核销详情 门店编码:SH004</string>
</property>
<property name="margin">
<number>0</number>
......@@ -209,13 +213,13 @@ QHeaderView::section{
<widget class="QWidget" name="widget" native="true">
<property name="minimumSize">
<size>
<width>700</width>
<height>0</height>
<width>900</width>
<height>200</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>700</width>
<width>900</width>
<height>200</height>
</size>
</property>
......@@ -270,40 +274,24 @@ QHeaderView::section{
<number>0</number>
</property>
<item>
<widget class="QLabel" name="totalOrdersLabel">
<widget class="QLabel" name="totalRedeem">
<property name="minimumSize">
<size>
<width>351</width>
<height>40</height>
<height>100</height>
</size>
</property>
<property name="text">
<string>总核销数</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="margin">
<number>0</number>
</property>
<property name="indent">
<number>10</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="totalRedeem">
<property name="minimumSize">
<property name="maximumSize">
<size>
<width>351</width>
<height>40</height>
<width>16777215</width>
<height>200</height>
</size>
</property>
<property name="text">
<string>256</string>
<string>总核销数 0</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="margin">
<number>0</number>
......@@ -325,25 +313,6 @@ QHeaderView::section{
<number>0</number>
</property>
<item>
<widget class="QLabel" name="totalMoneyLabel">
<property name="minimumSize">
<size>
<width>330</width>
<height>40</height>
</size>
</property>
<property name="text">
<string>总核销额</string>
</property>
<property name="margin">
<number>0</number>
</property>
<property name="indent">
<number>10</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="totalRedeemMoney">
<property name="minimumSize">
<size>
......@@ -352,10 +321,10 @@ QHeaderView::section{
</size>
</property>
<property name="text">
<string>256.00</string>
<string>总核销额 0</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="margin">
<number>0</number>
......@@ -375,13 +344,13 @@ QHeaderView::section{
<widget class="QTableView" name="tableView">
<property name="minimumSize">
<size>
<width>700</width>
<width>900</width>
<height>300</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>700</width>
<width>900</width>
<height>400</height>
</size>
</property>
......@@ -406,29 +375,17 @@ QHeaderView::section{
<widget class="QWidget" name="widget_3" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<width>700</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<width>1000</width>
<height>50</height>
</size>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<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>
<widget class="QLabel" name="codeLabel">
<property name="minimumSize">
......@@ -469,19 +426,6 @@ QHeaderView::section{
</widget>
</item>
<item>
<widget class="QPushButton" name="refundBtn">
<property name="minimumSize">
<size>
<width>75</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>退款</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="findBtn">
<property name="minimumSize">
<size>
......@@ -495,28 +439,28 @@ QHeaderView::section{
</widget>
</item>
<item>
<widget class="QPushButton" name="preBtn">
<widget class="QPushButton" name="startDateBtn">
<property name="minimumSize">
<size>
<width>75</width>
<width>200</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>前一天</string>
<string>开始日期:2018-08-24</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="nextBtn">
<widget class="QPushButton" name="endDateBtn">
<property name="minimumSize">
<size>
<width>75</width>
<width>200</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>后一天</string>
<string>结束日期:2018-08-24</string>
</property>
</widget>
</item>
......@@ -527,13 +471,13 @@ QHeaderView::section{
<widget class="QWidget" name="numWidget" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<width>900</width>
<height>40</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<width>700</width>
<height>45</height>
</size>
</property>
......@@ -765,6 +709,28 @@ QHeaderView::section{
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="companyLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>20</height>
</size>
</property>
<property name="text">
<string>由非码提供技术支持 V1.0.8</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
......
......@@ -19,5 +19,7 @@
<file>img/close_02.png</file>
<file>img/dlt.png</file>
<file>img/dlt_onclick.png</file>
<file>img/bg_waiting.png</file>
<file>img/loading.gif</file>
</qresource>
</RCC>
......@@ -16,16 +16,20 @@ Level=0
[Home]
Server=http://115.159.226.87:20001/api/user/login
PartnerId=1739
StoreId=WH026
StoreId=SH058
PosId=01
Position=1591, 268
Position=2586, 177
CashierId=001
ShowStoreInfo=1
ShowStoreInfo=0
[Pay]
Server=https://115.159.18.100/api
Server="http://115.159.119.32:27935/api?partner=yhdw"
Timeout=60
[Coupon]
Server=http://115.159.142.32/api
RedeemLog=http://115.159.119.32:27935/getRedeemLog
[Vip]
Server=http://member.freemudorder.com/member_today/service/restful/pos
......
No preview for this file type
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