Commit c0f570ef by NitefullWind

1. 增加折扣券,修改相关界面。

parent 11854b15
......@@ -12,8 +12,9 @@ Coupon::Coupon(QString name, QString code, QString type, double disAmount, doubl
_type(type),
_disAmount(disAmount),
_limitAmount(limitAmount),
_limitTime(limitTime),
_isCompatible(isCompatible)
_discountFactor(1),
_isCompatible(isCompatible),
_limitTime(limitTime)
{
}
......@@ -38,7 +39,12 @@ void Coupon::paint(QPainter *painter, const QRect &rect, const QPalette &palette
painter->setPen(pen);
QFont font("Microsoft YaHei", 30, 500);
painter->setFont(font);
QString disStr = QString::number(this->_disAmount, 'f', 2);
QString disStr;
if(this->_type == "discount") {
disStr = QString::fromLocal8Bit("%1折").arg(this->_discountFactor);
} else {
disStr = QString::number(this->_disAmount, 'f', 2);
}
QRect topRect(rect.x(), rect.y(), rect.width(), rect.height()/2);
painter->drawText(topRect, Qt::AlignCenter, disStr);
// ¥标识
......@@ -48,7 +54,10 @@ void Coupon::paint(QPainter *painter, const QRect &rect, const QPalette &palette
painter->setFont(font);
int flagWidth = painter->fontMetrics().width(flagStr);
int flagHeight = painter->fontMetrics().height();
painter->drawText(rect.x()+(rect.width()-fontWidth)/2-flagWidth, topRect.center().y()+flagHeight, flagStr);
if(this->_type != "discount")
{
painter->drawText(rect.x()+(rect.width()-fontWidth)/2-flagWidth, topRect.center().y()+flagHeight, flagStr);
}
// 满额条件
pen.setColor(QColor(127,127,127));
painter->setPen(pen);
......
......@@ -22,12 +22,15 @@ public:
double disAmount() const {return _disAmount;}
double limitAmount() const {return _limitAmount;}
bool isCompatible() const {return _isCompatible;}
bool discountFactor() const {return _discountFactor;}
void setDiscountFactor(double discountFactor) {this->_discountFactor = discountFactor;}
private:
QString _name;
QString _code;
QString _type;
double _disAmount;
double _limitAmount;
double _discountFactor;
bool _isCompatible;
QString _limitTime;
};
......
......@@ -29,6 +29,8 @@ void TaskCoupon::packageServerReq()
void TaskCoupon::packagePOSRsp()
{
int canDisAmount = session()->data(PosProps.OrderAmount).toInt() - session()->data(PosProps.PaidAmount).toInt() - session()->data(PosProps.UndisAmount).toInt();
QMap<QString, QVariant> couponMap;
foreach (auto value, getServerJsonValue(PosProps.CouponList).toArray())
{
......@@ -39,10 +41,19 @@ void TaskCoupon::packagePOSRsp()
int type = couponOb[ServerProps(PosProps.Coupon_type)].toInt();
QString limitTime = couponOb["expiration_date"].toString();
Coupon c(desc, code, QString::number(type), amount, 0, limitTime, false);
QVariant v;
v.setValue(c);
couponMap[code] = v;
if(amount<1) // 折扣券
{
Coupon c(desc, code, "discount", (1-amount)*canDisAmount/100, 0, limitTime, false);
c.setDiscountFactor(amount*10);
QVariant v;
v.setValue(c);
couponMap[code] = v;
} else {
Coupon c(desc, code, QString::number(type), amount, 0, limitTime, false);
QVariant v;
v.setValue(c);
couponMap[code] = v;
}
}
session()->addData(PosProps.CouponMap, couponMap);
}
......
......@@ -34,6 +34,9 @@ QByteArray TaskPay::doTask()
this->_session = preTask->session();
}
session()->addData(PosProps.OrderAmount, getPosJsonValue(PosProps.OrderAmount).toInt());
session()->addData(PosProps.PaidAmount, getPosJsonValue(PosProps.PaidAmount).toInt());
session()->addData(PosProps.UndisAmount, getPosJsonValue(PosProps.UndisAmount).toInt());
couponThread = new TaskCouponThread(posReqJsonObj, _session, this);
couponThread->start();
......@@ -56,8 +59,6 @@ void TaskPay::onGetCoupons(Session* session)
void TaskPay::setWindow()
{
_window = new FMVipOrder;
session()->addData(PosProps.OrderAmount, getPosJsonValue(PosProps.OrderAmount).toInt());
session()->addData(PosProps.PaidAmount, getPosJsonValue(PosProps.PaidAmount).toInt());
connect(qobject_cast<FMVipOrder*>(_window), SIGNAL(pay()), this, SLOT(onPay()));
}
......
......@@ -40,6 +40,9 @@ bool FMVipOrder::initWnd(Session *session)
session->addData(PosProps.NeedAmount, needPay);
QString needPay_str = QString::number(needPay);
double undisAmount = session->data(PosProps.UndisAmount).toInt()/100.0;
ui->undis_label->setText(DOUBLE_STR(undisAmount));
// 积分可抵扣金额(分)
int score_value = session->data(PosProps.Score).toInt();
orderInfo = new FMVipOrder::OrderInfo(amount_str, score_value, needPay_str);
......
......@@ -84,14 +84,14 @@
border-top: 0px solid silver;
}
#price_desc_label {
#price_desc_label,#undis_desc_label {
background: white;
max-width: 180px;min-width: 180px;
color: rgb(120,120,120);
border: 1 solid silver;
border-top: 0 solid silver;
}
#price_label {
#price_label,#undis_label {
font: 42px &quot;Microsoft YaHei&quot;;
padding-left: 50px;
color: rgb(50,50,50);
......@@ -513,6 +513,23 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="undis_desc_label">
<property name="text">
<string>不可优惠</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="undis_label">
<property name="text">
<string>0.00</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
......
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