Commit 2c93a60f by NitefllWind

1.新增警告类型弹窗。2.修复结算时未传给服务器代金券。3.新增Coupon(代金券)结构体,代金券以此类型存储在map中。4.修改代金券展示列表,选中的代金券总额超过待付时弹出警告框。

parent ccbedfbc
......@@ -26,6 +26,9 @@ void FMMsgWnd::show(InfoType type, const QString &info)
case InfoType::T_Failure:
iconUrl = ":/tip_error.png";
break;
case InfoType::T_Warning:
iconUrl = ":/tip_warning.png";
break;
default:
iconUrl = "";
break;
......@@ -43,6 +46,17 @@ void FMMsgWnd::show(InfoType type, const QString &info)
QDialog::exec();
}
void FMMsgWnd::FailureWnd(const QString &info)
{
FMMsgWnd window;
window.show(FMMsgWnd::T_Failure, info);
}
void FMMsgWnd::WarningWnd(const QString &info)
{
FMMsgWnd window;
window.show(FMMsgWnd::T_Warning, info);
}
void FMMsgWnd::on_alertBtnOk_clicked()
{
this->close();
......
......@@ -19,9 +19,13 @@ public:
{
T_Normal,
T_Success,
T_Failure
T_Failure,
T_Warning
};
void show(InfoType type = T_Normal, const QString &info = "");
static void FailureWnd(const QString &info);
static void WarningWnd(const QString &info);
private slots:
void on_alertBtnOk_clicked();
......
......@@ -189,8 +189,7 @@ void FMVipDispatcher::onServerResponsed(const QJsonObject &rspObj)
if(prompt == 0)
{
QString msg = rspObj["msg"].toString();
FMMsgWnd msgWnd;
msgWnd.show(FMMsgWnd::T_Failure, msg);
FMMsgWnd::FailureWnd(msg);
}
requestSuccess = false;
_vindow = 0;
......
......@@ -218,19 +218,22 @@ void FMVipForward::final(const QJsonObject &job, QJsonObject &fmjob)
QJsonArray pay_ids = posTransObj["pay_ids"].toArray();
fmjob["memberTransId"] = job["fm_id"];
transObj["coupons"] = posTransObj["coupons"];
QJsonArray coupons = posTransObj["coupons"].toArray();
int codeAmount=0, scoreAmount=0, cashAmount=0, thirdAmount=0;
foreach (QJsonValue pay_v , pay_ids)
{
QJsonObject pay_ob = pay_v.toObject();
if(pay_ob["pay_id"] == "24") {
QString type = pay_ob["pay_id"].toString();
if(type == "24") {
codeAmount = pay_ob["paid_total_amount"].toInt();
}
if(pay_ob["pay_id"] == "25") {
} else if(type == "25") {
scoreAmount = pay_ob["paid_total_amount"].toInt();
} else if(type == "77") {
coupons.append(pay_ob["code"].toString());
}
}
transObj["coupons"] = coupons;
cashAmount = paidAmount - codeAmount -scoreAmount - thirdAmount;
transObj["amount"] = amount;
transObj["payAmount"] = paidAmount;
......@@ -287,13 +290,10 @@ void FMVipForward::logined(const QJsonObject &serverJob, QJsonObject &posJob)
{
QJsonObject co = value.toObject();
QString codeStr = co["couponCode"].toString();
double amountStr = co["disAmount"].toInt()/100.0;
double amount = co["disAmount"].toInt()/100.0;
QString desc = co["desc"].toString();
QString couponInfo = QString("券码:%1 金额:%2 备注:%3")
.arg(codeStr)
.arg(amountStr)
.arg(desc);
_sessionCouponMap[co["couponCode"].toString()] = couponInfo;
_sessionCouponMap[co["couponCode"].toString()] = Coupon{codeStr, amount, desc};
}
QString name = memberObj["name"].toString();
......@@ -443,11 +443,6 @@ void FMVipForward::addSessionData(const QString key, const QString value)
_sessionDataMap.insert(key, value);
}
void FMVipForward::setSessionCouponMap(QMap<QString, QString> couponMap)
{
_sessionCouponMap = couponMap;
}
QString FMVipForward::sessionData(const QString key) const
{
QString value = "";
......@@ -463,7 +458,12 @@ int FMVipForward::sessionDataInt(const QString key) const
return value.toInt();
}
QMap<QString, QString> FMVipForward::sessionCouponMap() const
void FMVipForward::setSessionCouponMap(QMap<QString, Coupon> couponMap)
{
_sessionCouponMap = couponMap;
}
QMap<QString, Coupon> FMVipForward::sessionCouponMap() const
{
return _sessionCouponMap;
}
......@@ -29,6 +29,13 @@
#define FM_VIP_COUPON 1006
#define FM_VIP_FINAL 1007
struct Coupon
{
QString code;
double disAmount;
QString desc;
};
class FMVipForward : public QObject
{
Q_OBJECT
......@@ -43,9 +50,9 @@ public:
void addSessionData(const QString key, const QString value);
QString sessionData(const QString key) const;
int sessionDataInt(const QString key) const;
QMap<QString, QString> sessionCouponMap() const;
void clearSessionData();
void setSessionCouponMap(QMap<QString, QString>);
QMap<QString, Coupon> sessionCouponMap() const;
void setSessionCouponMap(QMap<QString, Coupon>);
QString getString(int num) { return QString::number(num);}
int getInt(QString num_str) {return num_str.toInt();}
......@@ -89,7 +96,7 @@ private:
QMap<QString, QString> _sessionDataMap;
QStringList _sessionDataList;
QJsonObject _sessionForward;
QMap<QString, QString> _sessionCouponMap;
QMap<QString, Coupon> _sessionCouponMap;
signals:
void serverResponsed(const QJsonObject& rspData);
private slots:
......
#include "fmviporder.h"
#include "fmvipforward.h"
#include "fmmsgwnd.h"
#include "ui_fmviporder.h"
#include <QApplication>
#include <QDebug>
FMVipOrder::FMVipOrder(QDialog *parent) :
......@@ -30,11 +29,15 @@ FMVipOrder::FMVipOrder(QDialog *parent) :
ui->name_label->setText(name);
couponMap = FMVipForward::instance()->sessionCouponMap();
for(QString code : couponMap.keys())
for(Coupon coupon : couponMap.values())
{
QString desc = couponMap[code];
auto item = new QListWidgetItem(desc);
item->setData(1, code);
QString value = QString("券码:%1 金额:%2 备注:%3")
.arg(coupon.code)
.arg(coupon.disAmount)
.arg(coupon.desc);
auto item = new QListWidgetItem(value);
item->setData(Coupon_Code, coupon.code);
item->setData(Coupon_Amount, coupon.disAmount);
item->setCheckState(Qt::Unchecked);
ui->scrollAreaWidgetContents->addItem(item);
}
......@@ -69,7 +72,7 @@ void FMVipOrder::on_pay_btn_clicked()
{
auto item = ui->scrollAreaWidgetContents->item(i);
if(item->checkState() == Qt::Checked) {
checkedCode << item->data(1).toString();
checkedCode << item->data(Coupon_Code).toString();
}
}
for(QString key : couponMap.keys())
......@@ -102,14 +105,21 @@ void FMVipOrder::on_item_clicked(QListWidgetItem *item)
if(item != NULL)
{
Qt::CheckState state = item->checkState();
double amount = item->data(Coupon_Amount).toDouble();
bool isAddCoupon = false;
switch (state) {
case Qt::Checked:
item->setCheckState(Qt::Unchecked);
break;
case Qt::Unchecked:
item->setCheckState(Qt::Checked);
isAddCoupon = true;
default:
break;
}
bool isOK = orderInfo->setCouponAmount(isAddCoupon, amount);
if(!isOK){
FMMsgWnd::WarningWnd("请注意代金券总额已超过待付金额!");
}
}
}
......@@ -2,6 +2,7 @@
#define FMVIPORDER_H
#include <QListWidgetItem>
#include "fmvipwnd.h"
#include "fmvipforward.h"
#define MIN(a,b) ((a<b) ? a : b)
#define DOUBLE_STR(num) QString::number(num, 'f', 2)
......@@ -25,13 +26,19 @@ public slots:
void on_item_clicked(QListWidgetItem*);
private:
enum DataIndex
{
Coupon_Code = Qt::UserRole,
Coupon_Amount
};
class OrderInfo
{
public:
OrderInfo()
{
_amountStr = _scoreStr = _needPayStr = "";
_amount = _score = _needPay = 0.0;
_amount = _score = _needPay = _couponAmount = 0.0;
}
OrderInfo(QString amountStr, QString scoreStr, QString needPayStr)
{
......@@ -43,6 +50,7 @@ private:
_score = _scoreStr.toInt() / 100.0;
_needPay = _needPayStr.toInt() / 100.0;
_couponAmount = 0.0;
}
QString getAmountStr()
......@@ -66,16 +74,30 @@ private:
return QString::number(payAmount);
}
// 可以正常加时返回true,否则返回false
bool setCouponAmount(bool isAdd, double amount)
{
bool isOK = true;
if(isAdd) {
_couponAmount += amount;
isOK = (_couponAmount <= _needPay);
}else{
_couponAmount -= amount;
}
return isOK;
}
private:
QString _amountStr, _scoreStr, _needPayStr;
double _amount, _score, _needPay;
double _couponAmount;
};
private:
Ui::FMVipOrder *ui;
FMVipOrder::OrderInfo *orderInfo;
QMap<QString, QString> couponMap;
QMap<QString, Coupon> couponMap;
};
#endif // FMVIPORDER_H
......@@ -13,5 +13,6 @@
<file>data/user</file>
<file>loading.gif</file>
<file>alert_bg.png</file>
<file>tip_warning.png</file>
</qresource>
</RCC>
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