Commit 264cc8f9 by NitefullWind

1.修复程序界面弹起期间退出程序会卡死问题。2.修复没有使用第三方支付向服务器发送的请求缺少字段问题。3.新增提示和限制使用余额支付金额的最大值。4.暂时修复程序第一次运行弹窗没有焦点问题。

parent 9407e487
...@@ -127,15 +127,14 @@ void FMVipDispatcher::onRequest(const QJsonObject &jsonObj) ...@@ -127,15 +127,14 @@ void FMVipDispatcher::onRequest(const QJsonObject &jsonObj)
else if (type == Type_Final) { else if (type == Type_Final) {
final(); final();
} }
#ifdef _DEBUG
else if (type == "-1") { else if (type == "-1") {
serverIsBusy.wakeAll();
qDebug() << "Quit"; qDebug() << "Quit";
jsonObj["reqType"] = -1; jsonObj["reqType"] = -1;
QJsonDocument d = QJsonDocument(jsonObj); QJsonDocument d = QJsonDocument(jsonObj);
_serverRspData = d.toJson(); _serverRspData = d.toJson();
qApp->quit(); qApp->quit();
} }
#endif
else if(type == Type_Pay || type == Type_Fund) { else if(type == Type_Pay || type == Type_Fund) {
requestSuccess = true; requestSuccess = true;
// 支付、充值先检查登陆状态。 // 支付、充值先检查登陆状态。
......
...@@ -220,6 +220,7 @@ void FMVipForward::final(const QJsonObject &job, QJsonObject &fmjob) ...@@ -220,6 +220,7 @@ void FMVipForward::final(const QJsonObject &job, QJsonObject &fmjob)
QJsonArray coupons = posTransObj["coupons"].toArray(); QJsonArray coupons = posTransObj["coupons"].toArray();
int codeAmount=0, scoreAmount=0, cashAmount=0, thirdAmount=0; int codeAmount=0, scoreAmount=0, cashAmount=0, thirdAmount=0;
transObj["thirdPayType"] = 4;
foreach (QJsonValue pay_v , pay_ids) foreach (QJsonValue pay_v , pay_ids)
{ {
QJsonObject pay_ob = pay_v.toObject(); QJsonObject pay_ob = pay_v.toObject();
......
...@@ -9,6 +9,27 @@ FMVipOrder::FMVipOrder(QDialog *parent) : ...@@ -9,6 +9,27 @@ FMVipOrder::FMVipOrder(QDialog *parent) :
FMVipWnd(parent), FMVipWnd(parent),
ui(new Ui::FMVipOrder) ui(new Ui::FMVipOrder)
{ {
// OrderInfo o1("10000","0","1000");
// qDebug() << o1.getMaxWillPay() << "/10";
// OrderInfo o2("2000","0","10000");
// qDebug() << o2.getMaxWillPay() << "/20";
// OrderInfo o3("1000","2000","4000");
// qDebug() << o3.getMaxWillPay() << "/10";
// o3.setUseScore(true);
// qDebug() << o3.getMaxWillPay() << "/10";
// OrderInfo o4("0","5000","1000");
// qDebug() << o4.getMaxWillPay() << "/0";
// o4.setUseScore(true);
// qDebug() << o4.getMaxWillPay() << "/0";
// OrderInfo o5("2000","9000","10000");
// qDebug() << o5.getMaxWillPay() << "/20";
// o5.setUseScore(true);
// qDebug() << o5.getMaxWillPay() << "/10";
ui->setupUi(this); ui->setupUi(this);
QString operator_id = SESSIONDATA_STRING("operator_id"); QString operator_id = SESSIONDATA_STRING("operator_id");
QString business_date = SESSIONDATA_STRING("business_date"); QString business_date = SESSIONDATA_STRING("business_date");
...@@ -20,6 +41,7 @@ FMVipOrder::FMVipOrder(QDialog *parent) : ...@@ -20,6 +41,7 @@ FMVipOrder::FMVipOrder(QDialog *parent) :
QString birthday = SESSIONDATA_STRING("birthday"); QString birthday = SESSIONDATA_STRING("birthday");
double standard_amount = SESSIONDATA_INT("standard_amount") / 100.0; double standard_amount = SESSIONDATA_INT("standard_amount") / 100.0;
// orderInfo = new OrderInfo("1000","4500","4000");
orderInfo = new FMVipOrder::OrderInfo(amount_str, score_str, needPay_str); orderInfo = new FMVipOrder::OrderInfo(amount_str, score_str, needPay_str);
orderInfo->setCouponMap(SESSIONDATA_COUPONMAP("couponMap")); orderInfo->setCouponMap(SESSIONDATA_COUPONMAP("couponMap"));
...@@ -35,17 +57,19 @@ FMVipOrder::FMVipOrder(QDialog *parent) : ...@@ -35,17 +57,19 @@ FMVipOrder::FMVipOrder(QDialog *parent) :
initCouponItems(); initCouponItems();
connect(ui->coupon_page, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(onItemClicked(QListWidgetItem*))); connect(ui->coupon_page, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(onItemClicked(QListWidgetItem*)));
ui->pay_chk->setText(QString("使用积分最多可抵用 %1 元").arg(orderInfo->getScoreAmount())); ui->pay_chk->setText(QString("使用积分抵用 %1 元").arg(orderInfo->getScoreAmount()));
if(standard_amount > 0) { if(standard_amount > 0) {
ui->standard_label->setText(QString("满 %1 元可享受储值金满额优惠").arg(standard_amount)); ui->standard_label->setText(QString("满 %1 元可享受储值金满额优惠").arg(standard_amount));
} else { } else {
ui->standard_label->setText(""); ui->standard_label->setText("");
} }
ui->pay_edit->setText(orderInfo->getNeedPayStr());
ui->pay_edit->setFocus();
ui->pay_edit->selectAll(); oldPayText = DOUBLE_STR(orderInfo->getMaxWillPay());
ui->pay_edit->setText(oldPayText);
QRegExp regexp("^[0-9]+(.[0-9]{2})?$");
ui->pay_edit->setValidator(new QRegExpValidator(regexp));
setWillPayText();
} }
FMVipOrder::~FMVipOrder() FMVipOrder::~FMVipOrder()
...@@ -74,6 +98,8 @@ void FMVipOrder::on_pay_chk_clicked(bool checked) ...@@ -74,6 +98,8 @@ void FMVipOrder::on_pay_chk_clicked(bool checked)
{ {
int is = checked ? 1 : 0; int is = checked ? 1 : 0;
SESSIONDATA_ADD("isUseScore", QString::number(is)); SESSIONDATA_ADD("isUseScore", QString::number(is));
orderInfo->setUseScore(checked);
setWillPayText();
} }
void FMVipOrder::onItemClicked(QListWidgetItem *item) void FMVipOrder::onItemClicked(QListWidgetItem *item)
...@@ -84,6 +110,7 @@ void FMVipOrder::onItemClicked(QListWidgetItem *item) ...@@ -84,6 +110,7 @@ void FMVipOrder::onItemClicked(QListWidgetItem *item)
if(orderInfo->selectCouponMap.contains(code)) { if(orderInfo->selectCouponMap.contains(code)) {
ui->coupon_page->itemWidget(item)->setStyleSheet("#FMCouponWidget{background-color: rgb(255, 255, 255); border: none; border-left: 5 solid rgb(255, 170, 37);}"); ui->coupon_page->itemWidget(item)->setStyleSheet("#FMCouponWidget{background-color: rgb(255, 255, 255); border: none; border-left: 5 solid rgb(255, 170, 37);}");
orderInfo->selectCouponMap.remove(code); orderInfo->selectCouponMap.remove(code);
orderInfo->enoughCoupon(); // 计算一下当前代金券金额
}else{ }else{
ui->coupon_page->itemWidget(item)->setStyleSheet("#FMCouponWidget{background-color: rgb(255, 255, 255); border: none; border-image: url(:/coupon_select.png);}"); ui->coupon_page->itemWidget(item)->setStyleSheet("#FMCouponWidget{background-color: rgb(255, 255, 255); border: none; border-image: url(:/coupon_select.png);}");
orderInfo->selectCouponMap[code] = orderInfo->couponMap()[code]; orderInfo->selectCouponMap[code] = orderInfo->couponMap()[code];
...@@ -92,6 +119,7 @@ void FMVipOrder::onItemClicked(QListWidgetItem *item) ...@@ -92,6 +119,7 @@ void FMVipOrder::onItemClicked(QListWidgetItem *item)
FMMsgWnd::WarningWnd("请注意代金券总额已超过待付金额!"); FMMsgWnd::WarningWnd("请注意代金券总额已超过待付金额!");
} }
} }
setWillPayText();
} }
void FMVipOrder::initCouponItems() void FMVipOrder::initCouponItems()
...@@ -109,6 +137,14 @@ void FMVipOrder::initCouponItems() ...@@ -109,6 +137,14 @@ void FMVipOrder::initCouponItems()
} }
} }
void FMVipOrder::setWillPayText()
{
on_pay_edit_textChanged(oldPayText);
ui->pay_edit->setFocus();
ui->pay_edit->selectAll();
}
void FMVipOrder::on_coupon_prev_btn_clicked() void FMVipOrder::on_coupon_prev_btn_clicked()
{ {
int pos = ui->coupon_page->verticalScrollBar()->value(); int pos = ui->coupon_page->verticalScrollBar()->value();
...@@ -120,3 +156,24 @@ void FMVipOrder::on_coupon_next_btn_clicked() ...@@ -120,3 +156,24 @@ void FMVipOrder::on_coupon_next_btn_clicked()
int pos = ui->coupon_page->verticalScrollBar()->value(); int pos = ui->coupon_page->verticalScrollBar()->value();
ui->coupon_page->verticalScrollBar()->setValue(pos + 125); ui->coupon_page->verticalScrollBar()->setValue(pos + 125);
} }
void FMVipOrder::on_pay_edit_textChanged(const QString &text)
{
double num = text.toDouble();
double maxPay = orderInfo->getMaxWillPay();
if (num > maxPay) {
ui->pay_edit->setText(DOUBLE_STR(maxPay));
QString maxPay_info = "余额只需支付 %1 元";
if (maxPay >= orderInfo->getAmountStr().toDouble()) {
maxPay_info = "余额最多支付 %1 元";
}
ui->pay_max->setText(maxPay_info.arg(maxPay));
ui->pay_edit->setFocus();
ui->pay_edit->selectAll();
} else {
oldPayText = text;
ui->pay_max->setText("");
}
}
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "fmvipforward.h" #include "fmvipforward.h"
#define MIN(a,b) ((a<b) ? a : b) #define MIN(a,b) ((a<b) ? a : b)
#define MAX(a,b) ((a<b) ? b : a)
#define DOUBLE_STR(num) QString::number(num, 'f', 2) #define DOUBLE_STR(num) QString::number(num, 'f', 2)
namespace Ui { namespace Ui {
...@@ -19,6 +20,8 @@ public: ...@@ -19,6 +20,8 @@ public:
explicit FMVipOrder(QDialog *parent = 0); explicit FMVipOrder(QDialog *parent = 0);
~FMVipOrder(); ~FMVipOrder();
void setWillPayText();
public slots: public slots:
void on_pay_btn_clicked(); void on_pay_btn_clicked();
void on_pay_chk_clicked(bool checked); void on_pay_chk_clicked(bool checked);
...@@ -30,20 +33,16 @@ private slots: ...@@ -30,20 +33,16 @@ private slots:
void on_coupon_next_btn_clicked(); void on_coupon_next_btn_clicked();
private: void on_pay_edit_textChanged(const QString &text);
enum DataIndex
{
Coupon_Code = Qt::UserRole,
Coupon_Amount
};
private:
class OrderInfo class OrderInfo
{ {
public: public:
OrderInfo() OrderInfo()
{ {
_amountStr = _scoreStr = _needPayStr = ""; _amountStr = _scoreStr = _needPayStr = "";
_amount = _score = _needPay; _amount = _score = _needPay = _maxWillPay = _useScore = _couponAmount = 0;
} }
OrderInfo(QString amountStr, QString scoreStr, QString needPayStr) OrderInfo(QString amountStr, QString scoreStr, QString needPayStr)
{ {
...@@ -55,6 +54,8 @@ private: ...@@ -55,6 +54,8 @@ private:
_score = _scoreStr.toInt() / 100.0; _score = _scoreStr.toInt() / 100.0;
_needPay = _needPayStr.toInt() / 100.0; _needPay = _needPayStr.toInt() / 100.0;
_maxWillPay = _useScore = _couponAmount = 0;
setMaxWillPay();
} }
QString getAmountStr() QString getAmountStr()
...@@ -69,7 +70,7 @@ private: ...@@ -69,7 +70,7 @@ private:
QString getScoreAmount() QString getScoreAmount()
{ {
return DOUBLE_STR(_score); return DOUBLE_STR(MIN(_score, _needPay));
} }
QString getPayAmountStr(QString amountStr) QString getPayAmountStr(QString amountStr)
...@@ -78,18 +79,40 @@ private: ...@@ -78,18 +79,40 @@ private:
return QString::number(payAmount); return QString::number(payAmount);
} }
// 代金券总额超过待付时范围true // 代金券总额超过待付时返回true
bool enoughCoupon() bool enoughCoupon()
{ {
double coupon_amount = 0.0; _couponAmount = 0.0;
for(auto coupon : selectCouponMap) for(auto coupon : selectCouponMap)
{ {
coupon_amount += coupon.disAmount; _couponAmount += coupon.disAmount;
} }
bool isEnough = (coupon_amount > _needPay); bool isEnough = (_couponAmount > _needPay);
setMaxWillPay();
return isEnough; return isEnough;
} }
void setUseScore(bool isUse)
{
if(isUse) {
_useScore = MIN(_score, _needPay);
} else {
_useScore = 0;
}
setMaxWillPay();
}
// 设置付款金额的最大值
void setMaxWillPay()
{
double willPay = _needPay - _useScore - _couponAmount;
_maxWillPay = MIN(MAX(willPay, 0), _amount);
}
double getMaxWillPay()
{
return _maxWillPay;
}
/// 代金券列表 /// 代金券列表
void setCouponMap(QMap<QString, Coupon> couponMap) void setCouponMap(QMap<QString, Coupon> couponMap)
{ {
...@@ -140,6 +163,8 @@ private: ...@@ -140,6 +163,8 @@ private:
double _amount, _score, _needPay; double _amount, _score, _needPay;
QMap<QString, Coupon> _couponMap; QMap<QString, Coupon> _couponMap;
int _maxPage, _nowPage; int _maxPage, _nowPage;
// 代金券金额 使用积分金额 余额将付金额
double _couponAmount, _useScore, _maxWillPay;
}; };
private: private:
...@@ -147,6 +172,8 @@ private: ...@@ -147,6 +172,8 @@ private:
FMVipOrder::OrderInfo *orderInfo; FMVipOrder::OrderInfo *orderInfo;
QString oldPayText;
void initCouponItems(); void initCouponItems();
}; };
......
...@@ -170,6 +170,11 @@ ...@@ -170,6 +170,11 @@
border-bottom: 1px solid silver; border-bottom: 1px solid silver;
} }
#pay_max {
font: 400 20px &quot;Microsoft YaHei&quot;;
color: red;
}
#pay_edit { #pay_edit {
min-height: 60px; min-height: 60px;
border: 1 solid silver; border: 1 solid silver;
...@@ -735,7 +740,7 @@ ...@@ -735,7 +740,7 @@
<number>60</number> <number>60</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>40</number> <number>10</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>60</number> <number>60</number>
...@@ -744,6 +749,16 @@ ...@@ -744,6 +749,16 @@
<number>40</number> <number>40</number>
</property> </property>
<item> <item>
<widget class="QLabel" name="pay_max">
<property name="text">
<string>余额最多支付 0.00 元</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="pay_edit"> <widget class="QLineEdit" name="pay_edit">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
...@@ -751,6 +766,9 @@ ...@@ -751,6 +766,9 @@
<height>16777215</height> <height>16777215</height>
</size> </size>
</property> </property>
<property name="inputMask">
<string/>
</property>
<property name="text"> <property name="text">
<string>0.00</string> <string>0.00</string>
</property> </property>
......
...@@ -74,5 +74,9 @@ int main(int argc, char *argv[]) ...@@ -74,5 +74,9 @@ int main(int argc, char *argv[])
server.Listen(23770); server.Listen(23770);
QWidget w;
w.show();
w.hide();
return a.exec(); return a.exec();
} }
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