Commit fe2dd05d by NitefullWind

1. 米有会员系统初步对接。

parent 2f19af5a
...@@ -52,6 +52,7 @@ int FMNetwork::send(const QString &url, const QByteArray &reqData, QByteArray &r ...@@ -52,6 +52,7 @@ int FMNetwork::send(const QString &url, const QByteArray &reqData, QByteArray &r
timer.stop(); timer.stop();
if (reply->error() == QNetworkReply::NoError) { if (reply->error() == QNetworkReply::NoError) {
rspData = reply->readAll(); rspData = reply->readAll();
FMP_INFO() << "Server Response: " << rspData;
} else { } else {
int err = reply->error(); int err = reply->error();
error = FM_API_NETWORERROR; error = FM_API_NETWORERROR;
......
...@@ -38,7 +38,10 @@ SOURCES += \ ...@@ -38,7 +38,10 @@ SOURCES += \
fmvipdispatcher.cpp \ fmvipdispatcher.cpp \
fmp_ve_handlers.cpp \ fmp_ve_handlers.cpp \
fmp_vip_server.cpp \ fmp_vip_server.cpp \
fmp_vip_settings.cpp fmp_vip_settings.cpp \
task/coupon.cpp \
windows/couponmodel.cpp \
windows/itemdelegate.cpp
HEADERS +=\ HEADERS +=\
fmp_vip.h \ fmp_vip.h \
...@@ -69,7 +72,10 @@ HEADERS +=\ ...@@ -69,7 +72,10 @@ HEADERS +=\
global.h \ global.h \
fmp_ve_handlers.h \ fmp_ve_handlers.h \
fmp_vip_server.h \ fmp_vip_server.h \
fmp_vip_settings.h fmp_vip_settings.h \
task/coupon.h \
windows/couponmodel.h \
windows/itemdelegate.h
unix { unix {
target.path = /usr/lib target.path = /usr/lib
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
#include <string> #include <string>
// 商家信息 // 商家信息
#define APP_ID "T007" #define APP_ID "T013"
#define KEY_CODE "98d094a7-0d07-4cf5-b23b-d18783f0d76a" #define KEY_CODE "25c62f3d-f3ee-422d-b7c1-37eeb6909776"
#define PARTNER_ID "a8bee0dd-09d1-4fa9-a9eb-80cb36d3d611" #define PARTNER_ID "e8fbddcc-d828-4cd4-9bf7-d44f903df18b"
// 请求类型链表 // 请求类型链表
const static QStringList FM_Type_List = QString( const static QStringList FM_Type_List = QString(
...@@ -19,8 +19,17 @@ const static QStringList FM_Type_List = QString( ...@@ -19,8 +19,17 @@ const static QStringList FM_Type_List = QString(
"order_refund_request," "order_refund_request,"
"charge_refund_request," "charge_refund_request,"
"order_revoke_request" ).split(","); "order_revoke_request" ).split(",");
// 服务端请求类型 // 服务端请求类型
const static int FM_Server_Type[] = {1001,1006,1002,1003,1007,1004,1004,1005}; const static QStringList FM_Server_Type = QString(
"member_check_request,"
"coupon_check_request,"
"member_charge_request,"
"order_request,"
"integral_request,"
"order_refund_request,"
"charge_refund_request,"
"order_revoke_request" ).split(",");
// 请求类型的枚举值 // 请求类型的枚举值
enum FM_TYPE { enum FM_TYPE {
...@@ -34,6 +43,14 @@ enum FM_TYPE { ...@@ -34,6 +43,14 @@ enum FM_TYPE {
FM_Order_Revoke FM_Order_Revoke
}; };
enum Member_Type {
Unknow = 0,
PayCode,
Phone,
Account,
OriginalCard
};
// JSON数据各字段名称 // JSON数据各字段名称
#ifndef POSPROPS #ifndef POSPROPS
#define POSPROPS #define POSPROPS
...@@ -41,7 +58,7 @@ struct PP{ ...@@ -41,7 +58,7 @@ struct PP{
PP() PP()
{ {
AppId = "appId"; AppId = "appId";
PartnerId = "partnerId"; PartnerId = "partner_id";
T = "t"; T = "t";
StoreId = "store_id"; StoreId = "store_id";
PosId = "pos_id"; PosId = "pos_id";
...@@ -51,12 +68,14 @@ struct PP{ ...@@ -51,12 +68,14 @@ struct PP{
FM_Type = "FM_Type"; FM_Type = "FM_Type";
TransId = "trans_id"; TransId = "trans_id";
Member_sign = "member_sign"; Member_sign = "member_sign";
Member_type = "member_type";
Name = "name"; Name = "name";
Birthday = "birthday"; Birthday = "birthday";
Amount = "amount"; Amount = "amount";
Mobile = "mobile"; Mobile = "mobile";
Fm_open_id = "fm_open_id"; Fm_open_id = "fm_open_id";
Account = "account";
CanPay = "CanPay"; CanPay = "CanPay";
Score = "score"; Score = "score";
...@@ -74,12 +93,14 @@ struct PP{ ...@@ -74,12 +93,14 @@ struct PP{
Transaction = "transactions"; Transaction = "transactions";
OrderAmount = "order_amount"; OrderAmount = "order_amount";
PaidAmount = "paid_amount"; PaidAmount = "paid_amount";
StandardAmount = "standard_amount"; UndisAmount = "undis_amount";
Fm_transId = "fm_transId";
Fm_id = "fm_id"; Fm_id = "fm_id";
Pay_ids = "pay_ids"; Pay_ids = "pay_ids";
Pay_id = "pay_id"; Pay_id = "pay_id";
Pay_str = "pay_str"; Pay_str = "pay_str";
Pay_amount = "pay_amount";
Paid_total_amount= "paid_total_amount"; Paid_total_amount= "paid_total_amount";
Pay_transId = "pay_transId"; Pay_transId = "pay_transId";
CouponList = "couponList"; // 代金券列表 CouponList = "couponList"; // 代金券列表
...@@ -113,11 +134,13 @@ struct PP{ ...@@ -113,11 +134,13 @@ struct PP{
QString FM_Type ; QString FM_Type ;
QString TransId ; QString TransId ;
QString Member_sign ; QString Member_sign ;
QString Member_type ;
QString Name ; QString Name ;
QString Birthday ; QString Birthday ;
QString Amount ; QString Amount ;
QString Mobile ; QString Mobile ;
QString Account ;
QString Fm_open_id ; QString Fm_open_id ;
QString CanPay ; QString CanPay ;
...@@ -137,12 +160,14 @@ struct PP{ ...@@ -137,12 +160,14 @@ struct PP{
QString Transaction ; QString Transaction ;
QString OrderAmount ; QString OrderAmount ;
QString PaidAmount ; QString PaidAmount ;
QString StandardAmount ; QString UndisAmount ;
QString Fm_transId ;
QString Fm_id ; QString Fm_id ;
// 支付方式 // 支付方式
QString Pay_ids ; QString Pay_ids ;
QString Pay_id ; QString Pay_id ;
QString Pay_str ; QString Pay_str ;
QString Pay_amount ;
QString Paid_total_amount ; QString Paid_total_amount ;
QString Pay_transId ; QString Pay_transId ;
QString CouponList ; QString CouponList ;
...@@ -175,15 +200,14 @@ const static PP PosProps; ...@@ -175,15 +200,14 @@ const static PP PosProps;
typedef std::map<QString, QString> PropsMap; typedef std::map<QString, QString> PropsMap;
const PropsMap::value_type PropsMapPairs[] = const PropsMap::value_type PropsMapPairs[] =
{ {
PropsMap::value_type(PosProps.Fm_cmd, "reqType"), PropsMap::value_type(PosProps.StatusCode, "status_code"),
PropsMap::value_type(PosProps.Member_sign, "code"), PropsMap::value_type(PosProps.Fm_transId, "trans_id"),
PropsMap::value_type(PosProps.StoreId, "storeId"), PropsMap::value_type(PosProps.OrderAmount, "amount"),
PropsMap::value_type(PosProps.PosId, "stationId"), PropsMap::value_type(PosProps.PaidAmount, "pay_amount"),
PropsMap::value_type(PosProps.OperatorId, "operatorId"), PropsMap::value_type(PosProps.CodeAmount, "code_amount"),
PropsMap::value_type(PosProps.Mobile, "mobile"), PropsMap::value_type(PosProps.Transaction, "transaction"),
PropsMap::value_type(PosProps.TransId, "transId"), PropsMap::value_type(PosProps.CouponList, "coupon_list"),
PropsMap::value_type(PosProps.Coupon, "couponCode"), PropsMap::value_type(PosProps.Coupon_disAmount, "dis_amount"),
PropsMap::value_type(PosProps.BussinessDate,"businessDate")
}; };
static PropsMap PosToServerProps(PropsMapPairs, PropsMapPairs + (sizeof(PropsMapPairs)/sizeof(PropsMapPairs[0]))); static PropsMap PosToServerProps(PropsMapPairs, PropsMapPairs + (sizeof(PropsMapPairs)/sizeof(PropsMapPairs[0])));
...@@ -269,4 +293,8 @@ const FMErrorMap fm_error(fm_error_pairs, fm_error_pairs + (sizeof fm_error_pair ...@@ -269,4 +293,8 @@ const FMErrorMap fm_error(fm_error_pairs, fm_error_pairs + (sizeof fm_error_pair
#define QuitCMD "{\"reqType\":-1}" #define QuitCMD "{\"reqType\":-1}"
#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)
#endif // GLOBAL_H #endif // GLOBAL_H
#include "coupon.h"
#include <QPainter>
#include <QPalette>
#include <QDebug>
const int PaintingWidth = 220;
const int PaintingHeight = 116;
Coupon::Coupon(QString name, QString code, double disAmount, double limitAmount, bool isCompatible) :
_name(name),
_code(code),
_disAmount(disAmount),
_limitAmount(limitAmount),
_isCompatible(isCompatible)
{
}
void Coupon::paint(QPainter *painter, const QRect &rect, const QPalette &palette) const
{
Q_UNUSED(palette);
painter->save();
painter->setRenderHint(QPainter::Antialiasing, true);
// 白色背景
painter->fillRect(rect, Qt::white);
// 左边橘黄色矩形
painter->fillRect(QRect(rect.x(), rect.y(), 5, rect.height()), QColor(255, 170, 37));
int centerY = rect.y()+rect.height()/2;
// 中间虚线
painter->setPen(Qt::DotLine);
painter->drawLine(rect.x()+10, centerY, rect.x()+rect.width()-10, centerY);
// 抵扣金额
QPen pen;
pen.setColor(QColor(229, 11, 72));
painter->setPen(pen);
QFont font("Microsoft YaHei", 30, 500);
painter->setFont(font);
QString disStr = QString::number(this->_disAmount, 'f', 2);
QRect topRect(rect.x(), rect.y(), rect.width(), rect.height()/2);
painter->drawText(topRect, Qt::AlignCenter, disStr);
// ¥标识
QString flagStr = QString::fromLocal8Bit("¥");
int fontWidth = painter->fontMetrics().width(disStr);
font.setPixelSize(11);
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);
// 满额条件
pen.setColor(QColor(127,127,127));
painter->setPen(pen);
font.setPixelSize(10);
font.setWeight(1);
painter->setFont(font);
QRect limitRect(rect.x(), rect.y(), rect.width(), rect.height()-flagHeight);
QString limitStr = QString::fromLocal8Bit("满 %1 元可用").arg(this->limitAmount());
painter->drawText(limitRect, Qt::AlignCenter, limitStr);
// 优惠券名
font.setPixelSize(15);
painter->setFont(font);
pen.setColor(Qt::white);
painter->setPen(pen);
fontWidth = painter->fontMetrics().width(this->_name)+20;
int fontHeight = painter->fontMetrics().height();
QRect nameRect(rect.x()+(rect.width()-fontWidth)/2, centerY+10, fontWidth, fontHeight);
painter->fillRect(nameRect, QColor(229, 11, 72));
painter->drawText(nameRect, Qt::AlignCenter, this->_name);
// 券码
font.setPixelSize(12);
painter->setFont(font);
pen.setColor(QColor(127,127,127));
painter->setPen(pen);
fontHeight = painter->fontMetrics().height();
QRect codeRect(rect.x(), rect.y()+rect.height()-fontHeight-5, rect.width(), fontHeight);
painter->drawText(codeRect, Qt::AlignCenter, this->_code);
painter->restore();
}
QSize Coupon::sizeHint() const
{
return QSize(PaintingWidth, PaintingHeight);
}
#ifndef COUPON_H
#define COUPON_H
#include <QVariant>
#include <QString>
#include <QPolygonF>
class QPainter;
class Coupon
{
public:
explicit Coupon(QString name="", QString code="", double disAmount=0, double limitAmount=0, bool isCompatible=true);
void paint(QPainter *painter, const QRect &rect,
const QPalette &palette) const;
QSize sizeHint() const;
QString name() const {return _name;}
QString code() const {return _code;}
double disAmount() const {return _disAmount;}
double limitAmount() const {return _limitAmount;}
bool isCompatible() const {return _isCompatible;}
private:
QString _name;
QString _code;
double _disAmount;
double _limitAmount;
bool _isCompatible;
};
Q_DECLARE_METATYPE(Coupon)
#endif // COUPON_H
...@@ -139,9 +139,6 @@ bool FMTask::sendToServer(bool isShowMsg) ...@@ -139,9 +139,6 @@ bool FMTask::sendToServer(bool isShowMsg)
} }
} }
FMP_INFO() << "Server rsponse: " << serverRspJsonObj;
if(_window != nullptr) { if(_window != nullptr) {
_window->setIsBusy(false); _window->setIsBusy(false);
} }
...@@ -198,7 +195,7 @@ QString FMTask::sign() const ...@@ -198,7 +195,7 @@ QString FMTask::sign() const
} }
} }
if (serverRspJsonObj[ServerProps(PosProps.Fm_cmd)].toInt() == FM_Server_Type[FM_Fund]) { if (serverRspJsonObj[ServerProps(PosProps.Fm_cmd)].toString() == FM_Server_Type[FM_Fund]) {
mapData[ServerProps(PosProps.TransId)] = serverReqJsonObj[ServerProps(PosProps.TransId)].toString(); mapData[ServerProps(PosProps.TransId)] = serverReqJsonObj[ServerProps(PosProps.TransId)].toString();
} }
......
...@@ -30,7 +30,7 @@ void Session::addData(const QString key, const QMap<QString, Coupon> couponMap) ...@@ -30,7 +30,7 @@ void Session::addData(const QString key, const QMap<QString, Coupon> couponMap)
foreach(const Coupon coupon , couponMap) { foreach(const Coupon coupon , couponMap) {
QVariant v; QVariant v;
v.setValue(coupon); v.setValue(coupon);
v_couponMap[coupon.code] = v; v_couponMap[coupon.code()] = v;
} }
addData(key, v_couponMap); addData(key, v_couponMap);
} }
...@@ -41,7 +41,7 @@ QMap<QString, Coupon> Session::getCouponMap(const QString key) ...@@ -41,7 +41,7 @@ QMap<QString, Coupon> Session::getCouponMap(const QString key)
QMap<QString, Coupon> couponMap; QMap<QString, Coupon> couponMap;
foreach(const QVariant v_coupon , v_couponMap) { foreach(const QVariant v_coupon , v_couponMap) {
Coupon coupon = v_coupon.value<Coupon>(); Coupon coupon = v_coupon.value<Coupon>();
couponMap[coupon.code] = coupon; couponMap[coupon.code()] = coupon;
} }
return couponMap; return couponMap;
} }
...@@ -3,31 +3,7 @@ ...@@ -3,31 +3,7 @@
#include <QVariant> #include <QVariant>
#include "global.h" #include "global.h"
#include "coupon.h"
// 代金券结构体
struct Coupon
{
Coupon() {
code = "";
disAmount = 0.0;
desc = "";
}
Coupon(const Coupon& C) {
code = C.code;
disAmount = C.disAmount;
desc = C.desc;
}
Coupon(const QString &c, const double amount, const QString &d) {
code = c;
disAmount = amount;
desc = d;
}
QString code;
double disAmount;
QString desc;
};
Q_DECLARE_METATYPE(Coupon) // 使Coupon类型可以和QVariant类型互相转换
class Session class Session
{ {
...@@ -48,6 +24,7 @@ public: ...@@ -48,6 +24,7 @@ public:
void addData(const QString key, const QVariant value); void addData(const QString key, const QVariant value);
void addData(const QString key, const QMap<QString, Coupon> couponMap); void addData(const QString key, const QMap<QString, Coupon> couponMap);
bool contains(const QString key) {return _sessionDataMap.contains(key);}
QMap<QString, Coupon> getCouponMap(const QString key); QMap<QString, Coupon> getCouponMap(const QString key);
QMap<QString, QVariant> sessionDataMap() const { return this->_sessionDataMap;} QMap<QString, QVariant> sessionDataMap() const { return this->_sessionDataMap;}
......
...@@ -35,19 +35,19 @@ void TaskFinal::packageServerReq() ...@@ -35,19 +35,19 @@ void TaskFinal::packageServerReq()
{ {
QJsonObject pay_ob = pay_v.toObject(); QJsonObject pay_ob = pay_v.toObject();
QString type = pay_ob[PosProps.Pay_id].toString(); QString type = pay_ob[PosProps.Pay_id].toString();
if(type == "24") { if(type == "20001") {
codeAmount = pay_ob[PosProps.Paid_total_amount].toInt(); codeAmount = pay_ob[PosProps.Pay_amount].toInt();
} else if(type == "25") { } else if(type == "20002") {
scoreAmount = pay_ob[PosProps.Paid_total_amount].toInt(); scoreAmount = pay_ob[PosProps.Pay_amount].toInt();
} else if(type == "77") { // 代金券 } else if(type == "20003") { // 代金券
coupons.append(pay_ob[PosProps.Coupon_code].toString()); coupons.append(pay_ob[PosProps.Coupon_code].toString());
} else if(type == "72" || type == "73") { } else if(type == "10001" || type == "10004") {
thirdAmount = pay_ob[PosProps.Paid_total_amount].toInt(); thirdAmount = pay_ob[PosProps.Pay_amount].toInt();
trans[ServerProps(PosProps.Pay_transId)] = pay_ob[PosProps.Pay_transId]; trans[ServerProps(PosProps.Pay_transId)] = pay_ob[PosProps.Pay_transId];
if (type == "72") { // 支付宝 if (type == "10001") { // 支付宝
trans["thirdPayType"] = 1; trans["thirdPayType"] = 1;
} else if(type == "73") { // 微信 } else if(type == "10004") { // 微信
trans["thirdPayType"] = 2; trans["thirdPayType"] = 2;
} }
} }
......
...@@ -17,6 +17,7 @@ void TaskLogin::setWindow() ...@@ -17,6 +17,7 @@ void TaskLogin::setWindow()
void TaskLogin::packageServerReq() void TaskLogin::packageServerReq()
{ {
serverReqJsonObj[ServerProps(PosProps.Member_sign)] = _session->data(PosProps.Member_sign).toString(); serverReqJsonObj[ServerProps(PosProps.Member_sign)] = _session->data(PosProps.Member_sign).toString();
serverReqJsonObj[ServerProps(PosProps.Member_type)] = _session->data(PosProps.Member_type).toString();
} }
void TaskLogin::packagePOSRsp() void TaskLogin::packagePOSRsp()
...@@ -55,7 +56,8 @@ void TaskLogin::onLogin() ...@@ -55,7 +56,8 @@ void TaskLogin::onLogin()
// } // }
// 认证成功 // 认证成功
else { else {
QString account = getServerJsonValue(PosProps.Fm_open_id).toString(); QString fm_open_id = getServerJsonValue(PosProps.Fm_open_id).toString();
QString account = getServerJsonValue(PosProps.Account).toString();
QString birthday = getServerJsonValue(PosProps.Birthday).toString(); QString birthday = getServerJsonValue(PosProps.Birthday).toString();
QString name = getServerJsonValue(PosProps.Name).toString(); QString name = getServerJsonValue(PosProps.Name).toString();
...@@ -66,18 +68,19 @@ void TaskLogin::onLogin() ...@@ -66,18 +68,19 @@ void TaskLogin::onLogin()
session()->addData(PosProps.Amount, getServerJsonValue(PosProps.Amount).toInt()); session()->addData(PosProps.Amount, getServerJsonValue(PosProps.Amount).toInt());
session()->addData(PosProps.Birthday, birthday); session()->addData(PosProps.Birthday, birthday);
session()->addData(PosProps.Mobile, getServerJsonValue(PosProps.Mobile).toString()); session()->addData(PosProps.Mobile, getServerJsonValue(PosProps.Mobile).toString());
session()->addData(PosProps.Fm_open_id, account); session()->addData(PosProps.Account, account);
session()->addData(PosProps.Fm_open_id, fm_open_id);
session()->addData(PosProps.Score, getServerJsonValue(PosProps.Score).toInt()); session()->addData(PosProps.Score, getServerJsonValue(PosProps.Score).toInt());
QMap<QString, QVariant> couponMap; QMap<QString, QVariant> couponMap;
foreach (auto value , getServerJsonValue(PosProps.CouponList).toArray()) foreach (QJsonValue value, getServerJsonValue(PosProps.CouponList).toArray())
{ {
QJsonObject couponOb = value.toObject(); QJsonObject couponOb = value.toObject();
QString code = couponOb[ServerProps(PosProps.Coupon_code)].toString(); QString code = couponOb[ServerProps(PosProps.Coupon_code)].toString();
double amount = couponOb[ServerProps(PosProps.Coupon_disAmount)].toInt() / 100.0; double amount = couponOb[ServerProps(PosProps.Coupon_disAmount)].toInt() / 100.0;
QString desc = couponOb[ServerProps(PosProps.Coupon_desc)].toString(); QString desc = couponOb[ServerProps(PosProps.Coupon_desc)].toString();
Coupon c(code, amount, desc); Coupon c(desc, code, amount, 0, 1);
QVariant v; QVariant v;
v.setValue(c); v.setValue(c);
couponMap[code] = v; couponMap[code] = v;
......
#include "taskothers.h" #include "taskothers.h"
TaskCoupon::TaskCoupon(QJsonObject &jsonObj, QObject *parent)
:FMTaskNoWnd(jsonObj, FM_Coupon, 0, parent) /// 优惠券查询
TaskCoupon::TaskCoupon(QJsonObject &jsonObj, Session *session, QObject *parent)
:FMTaskNoWnd(jsonObj, FM_Coupon, session, parent)
{ {
} }
void TaskCoupon::packageServerReq() void TaskCoupon::packageServerReq()
{ {
serverReqJsonObj[ServerProps(PosProps.Coupon)] = getPosJsonValue(PosProps.Coupon); serverReqJsonObj[ServerProps(PosProps.TransId)] = getPosJsonValue(PosProps.TransId);
QJsonObject transaction;
transaction[ServerProps(PosProps.Fm_open_id)] = session()->data(PosProps.Fm_open_id).toString();
transaction[ServerProps(PosProps.PaidAmount)] = getPosJsonValue(PosProps.OrderAmount);
// 产品列表
QJsonArray propducts;
foreach(auto pValue, getPosJsonValue(PosProps.Products).toArray())
{
auto po = pValue.toObject();
QJsonObject spo;
spo[ServerProps(PosProps.ConsumeNum)] = po[PosProps.ConsumeNum];
spo[ServerProps(PosProps.ProductId)] = po[PosProps.ProductId];
double price = po[PosProps.Price].toDouble() / po[PosProps.ConsumeNum].toDouble();
spo[ServerProps(PosProps.Price)] = price;
propducts.append(spo);
}
transaction[ServerProps(PosProps.Products)] = propducts;
serverReqJsonObj[ServerProps(PosProps.Transaction)] = transaction;
} }
void TaskCoupon::packagePOSRsp() void TaskCoupon::packagePOSRsp()
...@@ -17,16 +38,29 @@ void TaskCoupon::packagePOSRsp() ...@@ -17,16 +38,29 @@ void TaskCoupon::packagePOSRsp()
p.push_back(PosProps.Fm_open_id); p.push_back(PosProps.Fm_open_id);
p.push_back(PosProps.StatusCode); p.push_back(PosProps.StatusCode);
p.push_back(PosProps.Msg); p.push_back(PosProps.Msg);
foreach(auto prop, p) {
foreach(auto prop , p) {
posRspJsonObj[prop] = getServerJsonValue(ServerProps(prop)); posRspJsonObj[prop] = getServerJsonValue(ServerProps(prop));
} }
posRspJsonObj["pid"] = serverRspJsonObj["productCode"];
posRspJsonObj[PosProps.Prompt] = 1; QMap<QString, QVariant> couponMap;
foreach (auto value, getServerJsonValue(PosProps.CouponList).toArray())
{
QJsonObject couponOb = value.toObject();
QString code = couponOb[ServerProps(PosProps.Coupon_code)].toString();
double amount = couponOb[ServerProps(PosProps.Coupon_disAmount)].toInt() / 100.0;
QString desc = couponOb[ServerProps(PosProps.Coupon_desc)].toString();
Coupon c(desc, code, amount);
QVariant v;
v.setValue(c);
couponMap[code] = v;
}
session()->addData(PosProps.CouponMap, couponMap);
} }
TaskRefundPay::TaskRefundPay(QJsonObject &jsonObj, QObject *parent) TaskRefundPay::TaskRefundPay(QJsonObject &jsonObj, QObject *parent)
:FMTaskNoWnd(jsonObj, FM_Order_Revoke, 0, parent) :FMTaskNoWnd(jsonObj, FM_Order_Revoke, 0, parent)
{ {
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
#include "fmtasknownd.h" #include "fmtasknownd.h"
// 优惠券查询 // 获取可用代金券列表
class TaskCoupon : public FMTaskNoWnd class TaskCoupon : public FMTaskNoWnd
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit TaskCoupon(QJsonObject &jsonObj, QObject *parent = 0); explicit TaskCoupon(QJsonObject &jsonObj, Session *session=0, QObject *parent = 0);
void packageServerReq(); void packageServerReq();
void packagePOSRsp(); void packagePOSRsp();
}; };
......
...@@ -17,9 +17,25 @@ QByteArray TaskPay::doTask() ...@@ -17,9 +17,25 @@ QByteArray TaskPay::doTask()
return loginRst; return loginRst;
} }
this->_session = preTask->session(); this->_session = preTask->session();
// couponThread = new TaskCouponThread(posReqJsonObj, _session, this);
// couponThread->start();
// connect(couponThread, SIGNAL(finished(Session*)), SLOT(onGetCoupons(Session*)));
return FMTask::doTask(); return FMTask::doTask();
} }
void TaskPay::onGetCoupons(Session* session)
{
// couponThread->exit();
_session->addData(PosProps.CouponMap, session->getCouponMap(PosProps.CouponMap));
if(_window != nullptr) {
qobject_cast<FMVipOrder*>(_window)->initCouponItems();
_window->setIsBusy(false);
_window->setEnabled(true);
}
}
void TaskPay::setWindow() void TaskPay::setWindow()
{ {
_window = new FMVipOrder; _window = new FMVipOrder;
...@@ -27,7 +43,6 @@ void TaskPay::setWindow() ...@@ -27,7 +43,6 @@ void TaskPay::setWindow()
std::vector<QString> p; std::vector<QString> p;
p.push_back(PosProps.OrderAmount); p.push_back(PosProps.OrderAmount);
p.push_back(PosProps.PaidAmount); p.push_back(PosProps.PaidAmount);
p.push_back(PosProps.StandardAmount);
foreach (QString prop , p) { foreach (QString prop , p) {
session()->addData(prop, getPosJsonValue(prop).toInt()); session()->addData(prop, getPosJsonValue(prop).toInt());
} }
......
#ifndef TASKPAY_H #ifndef TASKPAY_H
#define TASKPAY_H #define TASKPAY_H
#include "fmtask.h" #include "fmtask.h"
#include "taskothers.h"
#include <QThread>
class TaskCouponThread;
class TaskPay : public FMTask class TaskPay : public FMTask
{ {
...@@ -15,6 +19,33 @@ public: ...@@ -15,6 +19,33 @@ public:
private slots: private slots:
void onPay(); void onPay();
void TaskPay::onGetCoupons(Session* session);
private:
TaskCouponThread *couponThread;
}; };
// 加载代金券的线程类
class TaskCouponThread : public QThread
{
Q_OBJECT
public:
TaskCouponThread(QJsonObject &jsonObj, Session *session, QObject *parent = 0) {
_session = session;
task = new TaskCoupon(jsonObj, session, parent);
}
~TaskCouponThread() {
del_p(task);
}
void run() {
task->doTask();
emit finished(_session);
}
TaskCoupon *task;
Session *_session;
signals:
void finished(Session*);
};
#endif // TASKPAY_H #endif // TASKPAY_H
#include "couponmodel.h"
#include <QModelIndex>
#include <QDebug>
CouponModel::CouponModel(QObject *parent) : QAbstractListModel(parent)
{
}
int CouponModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return couponList.length();
}
QVariant CouponModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid()) {
return QVariant();
}
if(role == Qt::TextAlignmentRole) {
return int(Qt::AlignRight | Qt::AlignVCenter);
} else if(role == Qt::DisplayRole) {
QVariant v = QVariant::fromValue(couponList.at(index.row()));
return v;
}
return QVariant();
}
Coupon CouponModel::coupon(const QModelIndex &index)
{
if(!index.isValid()) {
return Coupon();
}
return couponList.at(index.row());
}
void CouponModel::push_back(Coupon coupon)
{
int rowNum = rowCount();
QModelIndex beginIndex = index(rowNum);
beginInsertRows(beginIndex, rowNum, rowNum);
couponList.append(coupon);
endInsertRows();
}
#ifndef COUPONMODEL_H
#define COUPONMODEL_H
#include <QObject>
#include <QAbstractListModel>
#include <QList>
#include "coupon.h"
class CouponModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit CouponModel(QObject *parent = 0);
int rowCount(const QModelIndex &parent=QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override;
Coupon coupon(const QModelIndex &index);
void push_back(Coupon coupon);
private:
QList<Coupon> couponList;
};
#endif // COUPONMODEL_H
#include "fmcouponwidget.h" #include "fmcouponwidget.h"
#include "ui_fmcouponwidget.h" #include "ui_fmcouponwidget.h"
#include <QPainter> #include <QPainter>
...@@ -7,9 +7,9 @@ FMCouponWidget::FMCouponWidget(Coupon conpon, QWidget *parent) : ...@@ -7,9 +7,9 @@ FMCouponWidget::FMCouponWidget(Coupon conpon, QWidget *parent) :
ui(new Ui::FMCouponWidget) ui(new Ui::FMCouponWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->code_lab->setText(conpon.code); ui->code_lab->setText(conpon.code());
ui->amount_lab->setText(QString::number(conpon.disAmount, 'f', 2)); ui->amount_lab->setText(QString::number(conpon.disAmount(), 'f', 2));
ui->desc_lab->setText(conpon.desc); ui->desc_lab->setText(conpon.name());
} }
FMCouponWidget::~FMCouponWidget() FMCouponWidget::~FMCouponWidget()
......
...@@ -20,19 +20,19 @@ void FMMsgWnd::show(InfoType type, const QString &info) ...@@ -20,19 +20,19 @@ void FMMsgWnd::show(InfoType type, const QString &info)
{ {
QString iconUrl; QString iconUrl;
switch (type) { switch (type) {
case InfoType::T_Normal: case T_Normal:
iconUrl = ""; iconUrl = "";
break; break;
case InfoType::T_Success: case T_Success:
iconUrl = ":/tip_ok.png"; iconUrl = ":/tip_ok.png";
break; break;
case InfoType::T_Failure: case T_Failure:
iconUrl = ":/tip_error.png"; iconUrl = ":/tip_error.png";
break; break;
case InfoType::T_Warning: case T_Warning:
iconUrl = ":/tip_warning.png"; iconUrl = ":/tip_warning.png";
break; break;
case InfoType::T_LoginSuccess: case T_LoginSuccess:
ui->label_msg->setText(QString::fromLocal8Bit("会员认证成功")); ui->label_msg->setText(QString::fromLocal8Bit("会员认证成功"));
iconUrl = ":/tip_ok.png"; iconUrl = ":/tip_ok.png";
break; break;
......
...@@ -14,13 +14,13 @@ FMVipFund::~FMVipFund() ...@@ -14,13 +14,13 @@ FMVipFund::~FMVipFund()
delete ui; delete ui;
} }
void FMVipFund::initWnd(Session *session) bool FMVipFund::initWnd(Session *session)
{ {
_session = session; _session = session;
QString operator_id = session->data(PosProps.OperatorId).toString(); QString operator_id = session->data(PosProps.OperatorId).toString();
QString business_date = session->data(PosProps.BussinessDate).toString(); QString business_date = session->data(PosProps.BussinessDate).toString();
QString account = session->data(PosProps.Fm_open_id).toString(); QString account = session->data(PosProps.Account).toString();
QString name = session->data(PosProps.Name).toString(); QString name = session->data(PosProps.Name).toString();
double amount = session->data(PosProps.Amount).toInt() / 100.0; double amount = session->data(PosProps.Amount).toInt() / 100.0;
...@@ -39,6 +39,7 @@ void FMVipFund::initWnd(Session *session) ...@@ -39,6 +39,7 @@ void FMVipFund::initWnd(Session *session)
ui->name_label->setText(name); ui->name_label->setText(name);
ui->fund_btn->setFocus(); ui->fund_btn->setFocus();
return true;
} }
void FMVipFund::on_fund_btn_clicked() void FMVipFund::on_fund_btn_clicked()
......
#ifndef FMVIPFUND_H #ifndef FMVIPFUND_H
#define FMVIPFUND_H #define FMVIPFUND_H
#include "fmvipwnd.h" #include "fmvipwnd.h"
...@@ -16,7 +16,7 @@ public: ...@@ -16,7 +16,7 @@ public:
~FMVipFund(); ~FMVipFund();
void initWnd(Session *session); bool initWnd(Session *session);
signals: signals:
void fund(); void fund();
public slots: public slots:
......
...@@ -17,7 +17,7 @@ FMVipLogin::~FMVipLogin() ...@@ -17,7 +17,7 @@ FMVipLogin::~FMVipLogin()
delete ui; delete ui;
} }
void FMVipLogin::initWnd(Session *session) bool FMVipLogin::initWnd(Session *session)
{ {
this->_session = session; this->_session = session;
...@@ -32,6 +32,7 @@ void FMVipLogin::initWnd(Session *session) ...@@ -32,6 +32,7 @@ void FMVipLogin::initWnd(Session *session)
ui->operator_label->setText(session->data(PosProps.OperatorId).toString()); ui->operator_label->setText(session->data(PosProps.OperatorId).toString());
ui->bd_label->setText(session->data(PosProps.BussinessDate).toString()); ui->bd_label->setText(session->data(PosProps.BussinessDate).toString());
ui->login_edit->setPlaceholderText(placeText); ui->login_edit->setPlaceholderText(placeText);
return true;
} }
QString FMVipLogin::getVersionInfo() QString FMVipLogin::getVersionInfo()
...@@ -51,8 +52,27 @@ QString FMVipLogin::getVersionInfo() ...@@ -51,8 +52,27 @@ QString FMVipLogin::getVersionInfo()
void FMVipLogin::on_login_btn_clicked() void FMVipLogin::on_login_btn_clicked()
{ {
QString id = ui->login_edit->text(); QString id = ui->login_edit->text();
switch (id.length()) {
case 20:
session()->addData(PosProps.Member_type, PayCode);
break;
case 18:
session()->addData(PosProps.Member_type, OriginalCard);
break;
case 11:
session()->addData(PosProps.Member_type, Phone);
break;
case 10:
session()->addData(PosProps.Member_type, Account);
break;
default:
session()->addData(PosProps.Member_type, Unknow);
break;
}
_session->addData(PosProps.Member_sign, id); _session->addData(PosProps.Member_sign, id);
_session->addData(PosProps.Member_type, session()->data(PosProps.Member_type));
this->setEnabled(false); this->setEnabled(false);
......
#ifndef FMVIPLOGIN_H #ifndef FMVIPLOGIN_H
#define FMVIPLOGIN_H #define FMVIPLOGIN_H
#include "fmvipwnd.h" #include "fmvipwnd.h"
...@@ -19,7 +19,7 @@ public: ...@@ -19,7 +19,7 @@ public:
QString getVersionInfo(); QString getVersionInfo();
void initWnd(Session *session); bool initWnd(Session *session);
protected: protected:
void resetWnd(); void resetWnd();
signals: signals:
......
#include "fmviporder.h" #include "fmviporder.h"
#include "fmmsgwnd.h" #include "fmmsgwnd.h"
#include "fmcouponwidget.h"
#include "ui_fmviporder.h" #include "ui_fmviporder.h"
#include "itemdelegate.h"
#include "couponmodel.h"
#include <QScrollBar> #include <QScrollBar>
#include <QItemSelectionModel>
FMVipOrder::FMVipOrder(QDialog *parent) : FMVipOrder::FMVipOrder(QDialog *parent) :
FMVipWnd(parent), FMVipWnd(parent),
ui(new Ui::FMVipOrder) ui(new Ui::FMVipOrder)
{ {
numpad = NULL;
ui->setupUi(this); ui->setupUi(this);
} }
FMVipOrder::~FMVipOrder() FMVipOrder::~FMVipOrder()
{ {
del_p(orderInfo); del_p(orderInfo);
if(numpad != NULL)
{
delete numpad;
numpad = NULL;
}
delete ui; delete ui;
} }
void FMVipOrder::initWnd(Session *session) bool FMVipOrder::initWnd(Session *session)
{ {
this->_session = session; this->_session = session;
QString operator_id = session->data(PosProps.OperatorId).toString(); QString operator_id = session->data(PosProps.OperatorId).toString();
QString business_date = session->data(PosProps.BussinessDate).toString(); QString business_date = session->data(PosProps.BussinessDate).toString();
QString fm_id = session->data(PosProps.Fm_open_id).toString(); QString fm_id = session->data(PosProps.Account).toString();
QString name = session->data(PosProps.Name).toString(); QString name = session->data(PosProps.Name).toString();
QString birthday = session->data(PosProps.Birthday).toString();
QString amount_str = QString::number(session->data(PosProps.Amount).toInt()); QString amount_str = QString::number(session->data(PosProps.Amount).toInt());
QString score_str = QString::number(session->data(PosProps.Score).toInt()); QString score_str = QString::number(session->data(PosProps.Score).toInt());
int needPay = session->data(PosProps.OrderAmount).toInt() - session->data(PosProps.PaidAmount).toInt(); int orderAmount = session->data(PosProps.OrderAmount).toInt();
int needPay = orderAmount - session->data(PosProps.PaidAmount).toInt();
QString needPay_str = QString::number(needPay); QString needPay_str = QString::number(needPay);
double standard_amount = session->data(PosProps.StandardAmount).toInt() / 100.0;
orderInfo = new FMVipOrder::OrderInfo(amount_str, score_str, needPay_str); // 积分可抵扣金额(分)
orderInfo->setCouponMap(session->getCouponMap(PosProps.CouponMap)); int socre_value = session->data(PosProps.Score).toInt();
orderInfo = new FMVipOrder::OrderInfo(amount_str, socre_value, needPay_str);
double maxDisAmount = (orderAmount - session->data(PosProps.UndisAmount).toInt()) / 100.0;
orderInfo->setMaxDisAmount(maxDisAmount);
ui->store_label->setText(session->data(PosProps.StoreId).toString());
ui->pos_label->setText(session->data(PosProps.PosId).toString());
ui->operator_label->setText(operator_id); ui->operator_label->setText(operator_id);
ui->bd_label->setText(business_date); ui->bd_label->setText(business_date);
ui->id_label->setText(fm_id); ui->id_label->setText(fm_id);
...@@ -46,30 +56,30 @@ void FMVipOrder::initWnd(Session *session) ...@@ -46,30 +56,30 @@ void FMVipOrder::initWnd(Session *session)
ui->price_label->setText(orderInfo->getNeedPayStr()); ui->price_label->setText(orderInfo->getNeedPayStr());
ui->name_label->setText(name); ui->name_label->setText(name);
couponModel = new CouponModel(this);
ui->coupon_page->setModel(couponModel);
ItemDelegate *delegate = new ItemDelegate(this);
ui->coupon_page->setItemDelegate(delegate);
selectionModel = ui->coupon_page->selectionModel();
connect(selectionModel, &QItemSelectionModel::selectionChanged, this, &FMVipOrder::onSelectionChanged);
initCouponItems(); initCouponItems();
connect(ui->coupon_page, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(onItemClicked(QListWidgetItem*)));
ui->pay_chk->setText(QString::fromLocal8Bit("使用积分抵用 %1 元").arg(orderInfo->getScoreAmount())); ui->pay_chk->setText(QString::fromLocal8Bit("使用积分抵用 %1 元").arg(orderInfo->getScoreAmount()));
if(standard_amount > 0) {
ui->standard_label->setText(QString::fromLocal8Bit("满 %1 元可享受储值金满额优惠").arg(standard_amount));
} else {
ui->standard_label->setText("");
}
oldPayText = DOUBLE_STR(orderInfo->getMaxWillPay()); oldPayText = DOUBLE_STR(orderInfo->getMaxWillPay());
ui->pay_edit->setText(oldPayText); ui->pay_edit->setText(oldPayText);
QRegExp regexp("^[0-9]+(.[0-9]{2})?$"); QRegExp regexp("^[0-9]+(.[0-9]{2})?$");
ui->pay_edit->setValidator(new QRegExpValidator(regexp)); ui->pay_edit->setValidator(new QRegExpValidator(regexp));
setWillPayText(); setWillPayText();
return true;
} }
void FMVipOrder::on_pay_btn_clicked() void FMVipOrder::on_pay_btn_clicked()
{ {
session()->addData(PosProps.CouponMap, orderInfo->selectCouponMap); session()->addData(PosProps.CouponMap, orderInfo->selectCouponMap);
int codeAmount = orderInfo->getPayAmount(ui->pay_edit->text()); QString codeAmountStr = orderInfo->getPayAmountStr(ui->pay_edit->text());
session()->addData(PosProps.CodeAmount, codeAmount); session()->addData(PosProps.CodeAmount, codeAmountStr.toInt());
session()->addData(PosProps.IsUseScore, orderInfo->isUseScore());
this->setEnabled(false); this->setEnabled(false);
...@@ -80,43 +90,75 @@ void FMVipOrder::on_pay_btn_clicked() ...@@ -80,43 +90,75 @@ void FMVipOrder::on_pay_btn_clicked()
void FMVipOrder::on_pay_chk_clicked(bool checked) void FMVipOrder::on_pay_chk_clicked(bool checked)
{ {
int is = checked ? 1 : 0;
session()->addData(ServerProps(PosProps.IsUseScore), is);
orderInfo->setUseScore(checked); orderInfo->setUseScore(checked);
setWillPayText(); setWillPayText();
} }
void FMVipOrder::onItemClicked(QListWidgetItem *item)
//! 点击元素时选中/取消选中代金券
void FMVipOrder::on_coupon_page_clicked(const QModelIndex &index)
{ {
QString code = item->data(Qt::UserRole).toString(); // 如果选中状态则取消选中
if(selectionModel->isSelected(index)) {
// 如果代金券已被选中则取消,否则选中 selectionModel->select(index, QItemSelectionModel::Deselect);
if(orderInfo->selectCouponMap.contains(code)) { } else {
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); if(selectionModel->selectedIndexes().length() == 1) {
orderInfo->enoughCoupon(); // 计算一下当前代金券金额 QModelIndex firstIndex = selectionModel->selectedIndexes().first();
}else{ if(!couponModel->coupon(firstIndex).isCompatible()) {
ui->coupon_page->itemWidget(item)->setStyleSheet("#FMCouponWidget{background-color: rgb(255, 255, 255); border: none; border-image: url(:/coupon_select.png);}"); FMMsgWnd::FailureWnd(QString::fromLocal8Bit("已经选中了一张不可叠加券,不能再选用其他代金券"));
orderInfo->selectCouponMap[code] = orderInfo->couponMap()[code]; return;
if(orderInfo->enoughCoupon()) }
{ }
FMMsgWnd::WarningWnd(QString::fromLocal8Bit("请注意代金券总额已超过待付金额!"), this); Coupon coupon = couponModel->coupon(index);
// 判断是否满足使用条件
if(orderInfo->getMaxDisAmount() < coupon.limitAmount()) {
FMMsgWnd::FailureWnd(QString::fromLocal8Bit("该代金券不满足使用条件"));
return;
}
// 处理不可叠加券
if(!coupon.isCompatible()) {
if(!selectionModel->selectedIndexes().isEmpty()) {
FMMsgWnd::FailureWnd("该代金券不可与其他代金券叠加使用,请取消选中其他代金券");
return;
}
selectionModel->select(index, QItemSelectionModel::ClearAndSelect);
} else {
selectionModel->select(index, QItemSelectionModel::Select);
} }
} }
setWillPayText();
} }
void FMVipOrder::initCouponItems() void FMVipOrder::initCouponItems()
{ {
foreach(Coupon coupon , orderInfo->couponMap().values()) orderInfo->setCouponMap(_session->getCouponMap(PosProps.CouponMap));
foreach(Coupon coupon, orderInfo->couponMap().values())
{ {
auto item = new QListWidgetItem(); couponModel->push_back(coupon);
item->setData(Qt::UserRole, coupon.code);
ui->coupon_page->addItem(item);
ui->coupon_page->update();
auto itemWidget = new FMCouponWidget(coupon);
ui->coupon_page->setItemWidget(item, itemWidget);
//item大小
item->setSizeHint (itemWidget->size());
} }
ui->pay_edit->setFocus();
ui->pay_edit->selectAll();
}
void FMVipOrder::onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
{
foreach (QModelIndex index, selected.indexes()) {
Coupon coupon = couponModel->coupon(index);
orderInfo->selectCouponMap[coupon.code()] = orderInfo->couponMap()[coupon.code()];
orderInfo->setMaxDisAmount(orderInfo->getMaxDisAmount() - coupon.limitAmount());
}
foreach (QModelIndex index, deselected.indexes()) {
Coupon coupon = couponModel->coupon(index);
orderInfo->selectCouponMap.remove(coupon.code());
orderInfo->setMaxDisAmount(orderInfo->getMaxDisAmount() + coupon.limitAmount());
}
orderInfo->enoughCoupon();
setWillPayText();
} }
void FMVipOrder::setWillPayText() void FMVipOrder::setWillPayText()
......
#ifndef FMVIPORDER_H #ifndef FMVIPORDER_H
#define FMVIPORDER_H #define FMVIPORDER_H
#include <QListWidgetItem> #include <QListWidgetItem>
#include <QModelIndex>
#include "fmvipwnd.h" #include "fmvipwnd.h"
#include "global.h"
#define MIN(a,b) ((a<b) ? a : b) class FMNumPad;
#define MAX(a,b) ((a<b) ? b : a) class CouponModel;
#define DOUBLE_STR(num) QString::number(num, 'f', 2) class QItemSelectionModel;
namespace Ui { namespace Ui {
class FMVipOrder; class FMVipOrder;
...@@ -19,7 +22,8 @@ public: ...@@ -19,7 +22,8 @@ public:
explicit FMVipOrder(QDialog *parent = 0); explicit FMVipOrder(QDialog *parent = 0);
~FMVipOrder(); ~FMVipOrder();
void initWnd(Session *session); bool initWnd(Session *session);
void initCouponItems();
void setWillPayText(); void setWillPayText();
signals: signals:
...@@ -29,8 +33,6 @@ public slots: ...@@ -29,8 +33,6 @@ 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);
void onItemClicked(QListWidgetItem*);
private slots: private slots:
void on_coupon_prev_btn_clicked(); void on_coupon_prev_btn_clicked();
...@@ -38,23 +40,25 @@ private slots: ...@@ -38,23 +40,25 @@ private slots:
void on_pay_edit_textChanged(const QString &text); void on_pay_edit_textChanged(const QString &text);
void onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
void on_coupon_page_clicked(const QModelIndex &index);
private: private:
class OrderInfo class OrderInfo
{ {
public: public:
OrderInfo() OrderInfo()
{ {
_amountStr = _scoreStr = _needPayStr = ""; _amountStr = _needPayStr = "";
_amount = _score = _needPay = _maxWillPay = _useScore = _couponAmount = 0; _amount = _score = _needPay = _maxWillPay = _useScore = _couponAmount = 0;
} }
OrderInfo(QString amountStr, QString scoreStr, QString needPayStr) OrderInfo(QString amountStr, int score, QString needPayStr)
{ {
this->_amountStr = amountStr; this->_amountStr = amountStr;
this->_scoreStr = scoreStr;
this->_needPayStr = needPayStr; this->_needPayStr = needPayStr;
_amount = _amountStr.toInt() / 100.0; _amount = _amountStr.toInt() / 100.0;
_score = _scoreStr.toInt() / 100.0; _score = score / 100.0;
_needPay = _needPayStr.toInt() / 100.0; _needPay = _needPayStr.toInt() / 100.0;
_maxWillPay = _useScore = _couponAmount = 0; _maxWillPay = _useScore = _couponAmount = 0;
...@@ -76,19 +80,19 @@ private: ...@@ -76,19 +80,19 @@ private:
return DOUBLE_STR(MIN(_score, _needPay)); return DOUBLE_STR(MIN(_score, _needPay));
} }
int getPayAmount(QString amountStr) QString getPayAmountStr(QString amountStr)
{ {
int payAmount = MIN(_needPay, (amountStr.toDouble() + _couponAmount + _useScore)) * 100; double payAmount = MIN(_needPay, (amountStr.toDouble() + _couponAmount + _useScore)) * 100;
return payAmount; return QString::number(payAmount);
} }
// 代金券总额超过待付时返回true // 代金券总额超过待付时返回true
bool enoughCoupon() bool enoughCoupon()
{ {
_couponAmount = 0.0; _couponAmount = 0.0;
foreach(auto coupon , selectCouponMap) foreach(auto coupon, selectCouponMap)
{ {
_couponAmount += coupon.disAmount; _couponAmount += coupon.disAmount();
} }
bool isEnough = (_couponAmount > _needPay); bool isEnough = (_couponAmount > _needPay);
setMaxWillPay(); setMaxWillPay();
...@@ -105,11 +109,6 @@ private: ...@@ -105,11 +109,6 @@ private:
setMaxWillPay(); setMaxWillPay();
} }
int isUseScore()
{
return (_useScore == 0 ? 0 : 1);
}
// 设置付款金额的最大值 // 设置付款金额的最大值
void setMaxWillPay() void setMaxWillPay()
{ {
...@@ -121,6 +120,16 @@ private: ...@@ -121,6 +120,16 @@ private:
return _maxWillPay; return _maxWillPay;
} }
// 设置/获得最大可优惠金额
void setMaxDisAmount(double amount)
{
this->_maxDisAmount = amount;
}
double getMaxDisAmount()
{
return _maxDisAmount;
}
/// 代金券列表 /// 代金券列表
void setCouponMap(QMap<QString, Coupon> couponMap) void setCouponMap(QMap<QString, Coupon> couponMap)
{ {
...@@ -138,12 +147,12 @@ private: ...@@ -138,12 +147,12 @@ private:
QMap<QString, Coupon> selectCouponMap; QMap<QString, Coupon> selectCouponMap;
private: private:
QString _amountStr, _scoreStr, _needPayStr; QString _amountStr, _needPayStr;
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; double _couponAmount, _useScore, _maxWillPay, _maxDisAmount;
}; };
private: private:
...@@ -153,7 +162,11 @@ private: ...@@ -153,7 +162,11 @@ private:
QString oldPayText; QString oldPayText;
void initCouponItems(); FMNumPad *numpad;
QItemSelectionModel *selectionModel;
CouponModel *couponModel;
QModelIndex selectedIndex;
}; };
#endif // FMVIPORDER_H #endif // FMVIPORDER_H
...@@ -19,7 +19,7 @@ FMVipPanel::~FMVipPanel() ...@@ -19,7 +19,7 @@ FMVipPanel::~FMVipPanel()
delete ui; delete ui;
} }
void FMVipPanel::initWnd(Session *session) bool FMVipPanel::initWnd(Session *session)
{ {
this->_session = session; this->_session = session;
ui->store_label->setText(session->data(PosProps.StoreId).toString()); ui->store_label->setText(session->data(PosProps.StoreId).toString());
...@@ -31,6 +31,7 @@ void FMVipPanel::initWnd(Session *session) ...@@ -31,6 +31,7 @@ void FMVipPanel::initWnd(Session *session)
ui->name_label->setText(session->data("name").toString()); ui->name_label->setText(session->data("name").toString());
ui->fund_btn->setFocus(); ui->fund_btn->setFocus();
return true;
} }
void FMVipPanel::on_fund_btn_clicked() void FMVipPanel::on_fund_btn_clicked()
......
#ifndef FMVIPPANEL_H #ifndef FMVIPPANEL_H
#define FMVIPPANEL_H #define FMVIPPANEL_H
#include <fmvipwnd.h> #include <fmvipwnd.h>
...@@ -15,7 +15,7 @@ public: ...@@ -15,7 +15,7 @@ public:
explicit FMVipPanel(QDialog *parent = 0); explicit FMVipPanel(QDialog *parent = 0);
~FMVipPanel(); ~FMVipPanel();
void initWnd(Session *session); bool initWnd(Session *session);
public slots: public slots:
void on_fund_btn_clicked(); void on_fund_btn_clicked();
......
#ifndef FMVIPWND_H #ifndef FMVIPWND_H
#define FMVIPWND_H #define FMVIPWND_H
#include <QDialog> #include <QDialog>
...@@ -21,7 +21,7 @@ public: ...@@ -21,7 +21,7 @@ public:
int exec(); int exec();
bool close(); bool close();
virtual void initWnd(Session* session) {this->_session = session;} virtual bool initWnd(Session* session) {this->_session = session; return true;}
Session* session() const {return _session;} Session* session() const {return _session;}
public slots: public slots:
......
...@@ -204,11 +204,11 @@ ...@@ -204,11 +204,11 @@
} }
#pay_chk::indicator:unchecked { #pay_chk::indicator:unchecked {
image: url(:/chk_unchecked.png); image: url(:/img/chk_unchecked.png);
} }
#pay_chk::indicator:checked { #pay_chk::indicator:checked {
image: url(:/chk_checked.png); image: url(:/img/chk_checked.png);
} }
#pay_btn { #pay_btn {
...@@ -550,7 +550,10 @@ ...@@ -550,7 +550,10 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QListWidget" name="coupon_page"> <widget class="QListView" name="coupon_page">
<property name="cursor" stdset="0">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
...@@ -566,8 +569,11 @@ ...@@ -566,8 +569,11 @@
<property name="autoScroll"> <property name="autoScroll">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum> <enum>QAbstractItemView::NoSelection</enum>
</property> </property>
<property name="verticalScrollMode"> <property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerItem</enum> <enum>QAbstractItemView::ScrollPerItem</enum>
...@@ -596,12 +602,6 @@ ...@@ -596,12 +602,6 @@
<property name="uniformItemSizes"> <property name="uniformItemSizes">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="currentRow">
<number>-1</number>
</property>
<property name="widgetResizable" stdset="0">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
...@@ -756,22 +756,6 @@ ...@@ -756,22 +756,6 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="standard_label">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>满 0 元可享受储值金满额优惠</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="pay_chk"> <widget class="QCheckBox" name="pay_chk">
<property name="cursor"> <property name="cursor">
<cursorShape>PointingHandCursor</cursorShape> <cursorShape>PointingHandCursor</cursorShape>
......
#include "itemdelegate.h"
#include "coupon.h"
#include <QPainter>
#include <QStyleOptionViewItem>
#include <QModelIndex>
#include <QApplication>
#include <QDebug>
ItemDelegate::ItemDelegate(QWidget *parent) :
QStyledItemDelegate(parent)
{
}
void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if(index.data().canConvert<Coupon>()) {
Coupon coupon = qvariant_cast<Coupon>(index.data());
QRect rect = QRect(option.rect.x(), option.rect.y(), option.rect.width(), option.rect.height());
coupon.paint(painter, rect, option.palette);
if (option.state & QStyle::State_Selected) {
painter->drawImage(option.rect, QImage(":/img/coupon_select.png"));
}
} else {
QStyledItemDelegate::paint(painter, option, index);
}
}
QSize ItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if(index.data().canConvert<Coupon>()) {
Coupon coupon = qvariant_cast<Coupon>(index.data());
return coupon.sizeHint();
} else {
return QStyledItemDelegate::sizeHint(option, index);
}
}
#ifndef ITEMDELEGATE_H
#define ITEMDELEGATE_H
#include <QStyledItemDelegate>
class ItemDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
ItemDelegate(QWidget *parent = 0);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
};
#endif // ITEMDELEGATE_H
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