Commit 609da0c9 by gujin.wang

1.修改插件的实现方式 2.在会员支付界面添加虚拟支付的入口(按钮)

parent 7c692847
......@@ -2,14 +2,13 @@
#include "fmp_ve_handlers.h"
#include "fmp_vip.h"
FMPStartEventHandler::FMPStartEventHandler(ctkPluginContext *ctx, FMPVip *vip)
FMPStartEventHandler::FMPStartEventHandler(FMPVip *vip)
: FMPVipEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_ACK_START "/"
+ QString::number(ctx->getPlugin()->getPluginId()), vip),
_ctx(ctx)
+ QString::number(vip->GetPluginId()), vip)
{
FMPProps props;
props[ctkEventConstants::EVENT_TOPIC] = _topic;
_ctx->registerService<ctkEventHandler>(this, props);
FMP::RegisterService<ctkEventHandler>(this, props);
}
......
......@@ -27,11 +27,8 @@ class FMPStartEventHandler : public QObject, public FMPVipEventHandler
Q_OBJECT
Q_INTERFACES(ctkEventHandler)
public:
explicit FMPStartEventHandler(ctkPluginContext *ctx, FMPVip *vip);
explicit FMPStartEventHandler(FMPVip *vip);
void handleEvent(const ctkEvent &event);
private:
ctkPluginContext* _ctx;
};
#endif // FMP_MANAGER_EVENT_HANDLERS_H
#include "fmp_vip_p.h"
#include "fmp_ve_handlers.h"
class ctkPluginContext;
FMPVip::FMPVip(ctkPluginContext *context)
: FMPVipInterface(context),
FMPVip::FMPVip(const FMPContext ctx)
: FMPVipInterface(),
context(ctx),
_inited(false),
d_ptr(new FMPVipPrivate(this))
{
FMPStartEventHandler *handler = new FMPStartEventHandler(_ctx, this);
FMPLoggerInterface::InitContext(context);
FMPStartEventHandler *handler = new FMPStartEventHandler(this);
}
FMPVip::~FMPVip()
{
StopService();
FMPLoggerInterface::InitContext(nullptr, false);
if (d_ptr) {
delete d_ptr;
d_ptr = nullptr;
......
......@@ -14,15 +14,19 @@ class FMPVip : public FMPVipInterface
Q_DECLARE_PRIVATE(FMPVip)
public:
explicit FMPVip(ctkPluginContext *context);
explicit FMPVip(const FMPContext context);
virtual ~FMPVip();
protected:
const FMPContext GetContext()const {return context;}
protected:
void InitService();
void UninitService();
private:
bool _inited;
bool _inited;
FMPVipPrivate* d_ptr;
const FMPContext context;
};
#endif // FMP_VIP_H
......@@ -13,7 +13,7 @@ class FMPVipInterface : public QObject, public FMPluginInterface
Q_INTERFACES(FMPBaseInterface)
Q_INTERFACES(FMPluginInterface)
public:
explicit FMPVipInterface(ctkPluginContext *ctx) : FMPluginInterface(ctx)
explicit FMPVipInterface() : FMPluginInterface()
{
connect(this, &FMPVipInterface::TriggerInit, this, &FMPVipInterface::OnTriggerInit);
connect(this, &FMPVipInterface::TriggerUninit, this, &FMPVipInterface::OnTriggerUninit);
......@@ -28,7 +28,7 @@ protected slots:
void OnTriggerUninit() { FMPluginInterface::OnTriggerUninit(); }
};
Q_DECLARE_INTERFACE(FMPVipInterface, "com.fmp.vip")
Q_DECLARE_INTERFACE(FMPVipInterface, "fmp.vip")
#endif // FMP_LOGGER_I_H
......@@ -19,16 +19,16 @@ FMPVipPrivate::FMPVipPrivate(FMPVip *vip):
int FMPVipPrivate::Init()
{
Q_Q(FMPVip);
FMPHomeInterface *home = q->GetService<FMPHomeInterface>(q->_ctx);
FMPHomeInterface* home = FMP::GetService<FMPHomeInterface>();
if(q->_inited) {
home->notification(QString::fromLocal8Bit("[非码POS插件]已在运行!"));
} else {
_settings = q->GetService<FMPSettingsInterface>(q->_ctx);
_settings = FMP::GetService<FMPSettingsInterface>();
FMPVipSettings::instance()->init(_settings);
auto resend = new ReSend();
resend->start();
FMPVipServer::instance()->SetPluginContext(q->_ctx);
FMPVipServer::instance();
q->_inited = true;
......
......@@ -28,10 +28,16 @@ void FMPVipServer::Listen(quint16 port)
}
void FMPVipServer::Write(const QByteArray &data)
{
qDebug() << data;
{
if(isFromPay)
{
if(!socket || socket->write(data) == -1) {
FMP_ERROR() << "Write error: " << (socket ? socket->errorString() + QString::number(socket->error()) : "connection closed.");
}
return;
}
QTcpSocket client;
//client.connectToHost("172.16.13.191", 23771);
client.connectToHost("127.0.0.1", 23771);
if(!client.waitForConnected())
{
......@@ -68,11 +74,6 @@ void FMPVipServer::Write(const QByteArray &data)
reply = nullptr;
}
void FMPVipServer::SetPluginContext(ctkPluginContext *ctx)
{
dispatcher->setPluginContext(ctx);
}
void FMPVipServer::onNewConnection()
{
socket = nextPendingConnection();
......@@ -84,14 +85,26 @@ void FMPVipServer::onNewConnection()
void FMPVipServer::onDisconnected()
{
FMP_DEBUG() << "Socket disconnected.";
if(isFromPay)
{
socket->close();
socket->deleteLater();
socket = nullptr;
isFromPay = 0;
}
}
void FMPVipServer::onReadyRead()
{
QByteArray recvData = socket->readAll();
socket->close();
socket->deleteLater();
socket = nullptr;
QJsonObject reqData = QJsonDocument::fromJson(recvData).object();
isFromPay = reqData["from_pay"].toInt();
if(!isFromPay)
{
socket->close();
socket->deleteLater();
socket = nullptr;
}
if(isNeedSocketHeader) {
FMSOCKEHEADER header = {0, 0, 0};
......
......@@ -21,13 +21,11 @@ public:
void Listen(quint16 port);
void Write(const QByteArray &data);
void SetPluginContext(ctkPluginContext *ctx);
private slots:
void onNewConnection();
void onDisconnected();
void onReadyRead();
private:
explicit FMPVipServer();
......@@ -35,6 +33,7 @@ private:
FMVipDispatcher *dispatcher;
bool isNeedSocketHeader;
int isFromPay;
};
#endif // FMP_VIP_SERVER_H
......@@ -19,8 +19,7 @@
FMVipDispatcher::FMVipDispatcher(QObject *parent) :
QObject(parent),
fmTask(nullptr),
_ctx(nullptr)
fmTask(nullptr)
{
}
......@@ -57,17 +56,12 @@ void FMVipDispatcher::doTask(const QByteArray &reqData, QByteArray &rspData)
break;
}
case FM_QR_Pay: {
if (_ctx) {
ctkServiceReference ref =_ctx->getServiceReference<FMPePayInterface>();
FMPePayInterface *epay = _ctx->getService<FMPePayInterface>(ref);
epay->DockPayRequest(reqData);
epay->StartService();
rspData = epay->DockPayRespond();
}
else {
rspData = QString::fromLocal8Bit("{\"msg:\":\"支付服务不可用\"}").toUtf8();
}
case FM_QR_Pay: {
FMPePayInterface* epay = FMP::GetService<FMPePayInterface>();
epay->StartService();
epay->DockPayRequest(reqData);
rspData = epay->DockPayRespond();
epay->StopService();
break;
}
case FM_Refund: {
......@@ -87,16 +81,10 @@ void FMVipDispatcher::doTask(const QByteArray &reqData, QByteArray &rspData)
// break;
// }
case FM_QR_Refund: {
if (_ctx) {
ctkServiceReference ref =_ctx->getServiceReference<FMPePayInterface>();
FMPePayInterface *epay = _ctx->getService<FMPePayInterface>(ref);
epay->DockRefundRequest(reqData);
epay->StartService();
rspData = epay->DockRefundRespond();
}
else {
rspData = QString::fromLocal8Bit("{\"msg:\":\"退款服务不可用\"}").toUtf8();
}
FMPePayInterface* epay = FMP::GetService<FMPePayInterface>();
epay->DockRefundRequest(rspData);
epay->StartService();
rspData = epay->DockRefundRespond();
break;
}
case FM_Final: {
......@@ -111,18 +99,4 @@ void FMVipDispatcher::doTask(const QByteArray &reqData, QByteArray &rspData)
}
FMP_INFO() << "Send to pos: " << rspData;
}
void FMVipDispatcher::setPluginContext(ctkPluginContext *ctx)
{
if (ctx && _ctx != ctx) {
try {
//! Verify pointer
ctx->getPlugin();
_ctx = ctx;
}
catch(const ctkException&) {
FMP_ERROR() << "Invalid context:" << ctx;
}
}
}
}
\ No newline at end of file
......@@ -20,12 +20,8 @@ public:
void doTask(const QByteArray &reqData, QByteArray &rspData);
void setPluginContext(ctkPluginContext *ctx);
private:
FMTask * fmTask;
ctkPluginContext* _ctx;
Session session;
};
......
......@@ -32,8 +32,8 @@ enum FM_TYPE {
FM_Order_Revoke,
FM_QR_Pay = 10031,
FM_QR_Refund = 10041,
FM_Refund_Pay = 1004,
FM_Refund_Order = 1005
FM_Refund_Pay = 1005,
FM_Refund_Order = 1004
};
enum Member_Type {
......
......@@ -99,7 +99,7 @@ void TaskFinal::packagePOSRsp()
posRspJsonObj[PosProps.Msg] = getServerJsonValue(PosProps.Msg);
posRspJsonObj[PosProps.Fm_id] = getServerJsonValue(PosProps.Fm_id);
posRspJsonObj[PosProps.Prompt] = 1;
posRspJsonObj[PosProps.TransId] = getPosJsonValue(ServerProps(PosProps.TransId)).toString();
posRspJsonObj[PosProps.TransId] = getPosJsonValue(PosProps.TransId).toString();
posRspJsonObj[PosProps.Pay_id] = "1003";
}
......
......@@ -2,6 +2,7 @@
#include "tasklogin.h"
#include "fmviporder.h"
#include "fmp_logger_i.h"
#include "fmp_epay_i.h"
#include "fmp_home_i.h"
#include "fmp_vip_settings.h"
#include "fmnetwork.h"
......@@ -16,6 +17,7 @@ TaskPay::TaskPay(QJsonObject &jsonObj, Session *session, QObject *parent)
:FMTask(jsonObj, FM_Pay, session, parent)
{
payAmount = 0; //该次支付金额
isCodePay = false;
}
TaskPay::~TaskPay()
......@@ -37,6 +39,7 @@ QByteArray TaskPay::doTask()
result[PosProps.TransId] = getPosJsonValue(PosProps.TransId).toString();
result[PosProps.Pay_id] = FM_Pay;
loginRst = QJsonDocument(result).toJson(QJsonDocument::Compact);
FMMsgWnd::FailureWnd(result[PosProps.Msg].toString());
return loginRst;
}
this->_session = preTask->session();
......@@ -47,13 +50,25 @@ QByteArray TaskPay::doTask()
session()->addData(PosProps.UndisAmount, getPosJsonValue(PosProps.UndisAmount).toInt());
couponThread = new TaskCouponThread(posReqJsonObj, _session, this);
couponThread->start();
connect(couponThread, SIGNAL(finished(Session*)), SLOT(onGetCoupons(Session*)));
couponThread->start();
QByteArray resultArray = FMTask::doTask();
//如果是扫码支付,则直接返回其支付结果即可
if(isCodePay)
{
return codePayResult;
}
QJsonObject resultJson = QJsonDocument::fromJson(resultArray).object();
if(resultJson[PosProps.StatusCode].toInt() != FM_API_SUCCESS)
{
FMP_INFO() << "Pay failed: timeout. To reversal.";
TaskRefundPay taskRefundPay(posReqJsonObj);
taskRefundPay.doTask();
FMMsgWnd::FailureWnd(resultJson[PosProps.Msg].toString());
resultJson[PosProps.Pay_id] = FM_Pay;
resultJson[PosProps.TransId] = getPosJsonValue(PosProps.TransId).toString();
QByteArray reply = QJsonDocument(resultJson).toJson(QJsonDocument::Compact);
......@@ -175,6 +190,7 @@ void TaskPay::setWindow()
_window = new FMVipOrder;
connect(qobject_cast<FMVipOrder*>(_window), SIGNAL(pay()), this, SLOT(onPay()));
connect(qobject_cast<FMVipOrder*>(_window), SIGNAL(codePay()), this, SLOT(onCodePay()));
}
void TaskPay::packageServerReq()
......@@ -261,7 +277,8 @@ void TaskPay::packagePOSRsp()
posRspJsonObj[PosProps.Settlement] = 1;
posRspJsonObj[PosProps.Fm_open_id] = session()->data(PosProps.Fm_open_id).toString();
posRspJsonObj[PosProps.TransId] = getPosJsonValue(PosProps.TransId);
posRspJsonObj[PosProps.Fm_id] = getPosJsonValue(PosProps.Fm_id).toString();
posRspJsonObj[PosProps.Fm_id] = getServerJsonValue(ServerProps(PosProps.Fm_id)).toString();
posRspJsonObj[PosProps.Fm_transId] = getPosJsonValue(PosProps.TransId).toString();
QJsonArray servPayArray = getServerJsonValue("payList").toArray();
......@@ -299,11 +316,28 @@ void TaskPay::onPay()
{
sendToServer();
if(error() == FM_API_TIMEOUT) {
FMP_INFO() << "Pay failed: timeout. To reversal.";
TaskRefundPay taskRefundPay(posReqJsonObj);
taskRefundPay.doTask();
}
// if(error() == FM_API_TIMEOUT) {
// FMP_INFO() << "Pay failed: timeout. To reversal.";
// TaskRefundPay taskRefundPay(posReqJsonObj);
// taskRefundPay.doTask();
// }
_window->accept();
}
void TaskPay::onCodePay()
{
FMPePayInterface* epay = FMP::GetService<FMPePayInterface>();
epay->StartService();
posReqJsonObj[PosProps.Fm_open_id] = session()->data(PosProps.Fm_open_id).toString();
posReqJsonObj[PosProps.Fm_cmd] = FM_QR_Pay;
QByteArray reqData = QJsonDocument(posReqJsonObj).toJson(QJsonDocument::Compact);
epay->DockPayRequest(reqData);
QByteArray rspData = epay->DockPayRespond();
epay->StopService();
isCodePay = true;
codePayResult = rspData;
//_window->accept();
_window->reject();
}
......@@ -21,10 +21,13 @@ public:
private slots:
void onPay();
void onGetCoupons(Session* session);
void onCodePay();
private:
TaskCouponThread *couponThread;
int payAmount;
bool isCodePay;
QByteArray codePayResult;
};
// 加载代金券的线程类
......
......@@ -3,6 +3,7 @@
#include "ui_fmviporder.h"
#include "itemdelegate.h"
#include "couponmodel.h"
#include "fmp_epay_i.h"
#include <QScrollBar>
#include <QItemSelectionModel>
......@@ -75,7 +76,7 @@ bool FMVipOrder::initWnd(Session *session)
return true;
}
void FMVipOrder::on_pay_btn_clicked()
void FMVipOrder::on_vip_pay_btn_clicked()
{
session()->addData(PosProps.CouponMap, orderInfo->selectCouponMap);
int codeAmount = ui->pay_edit->text().toDouble()*100;
......@@ -92,6 +93,11 @@ void FMVipOrder::on_pay_btn_clicked()
emit pay();
}
void FMVipOrder::on_code_pay_btn_clicked()
{
emit codePay();
}
//! 点击元素时选中/取消选中代金券
void FMVipOrder::on_coupon_page_clicked(const QModelIndex &index)
{
......
......@@ -30,9 +30,11 @@ public:
signals:
void pay();
void codePay();
public slots:
void on_pay_btn_clicked();
void on_vip_pay_btn_clicked();
void on_code_pay_btn_clicked();
private slots:
void on_coupon_prev_btn_clicked();
......
......@@ -211,7 +211,7 @@
image: url(:/img/chk_checked.png);
}
#pay_btn {
#vip_pay_btn {
background: rgb(99, 148, 235);
font: 400 28px &quot;Microsoft YaHei&quot;;
color: white;
......@@ -219,7 +219,19 @@
border: 0 solid white;
border-right: 1 solid silver;
}
#pay_btn:hover {
#vip_pay_btn:hover {
padding: 2 0 0 2;
}
#code_pay_btn {
background: rgb(99, 148, 235);
font: 400 28px &quot;Microsoft YaHei&quot;;
color: white;
min-width: 200px;
border: 0 solid white;
border-right: 1 solid silver;
}
#code_pay_btn:hover {
padding: 2 0 0 2;
}
......@@ -286,7 +298,7 @@
margin: 0 6 10 6;
}</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
</property>
......@@ -697,7 +709,7 @@
</item>
<item>
<widget class="QWidget" name="pay" native="true">
<layout class="QHBoxLayout" name="payLay">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
......@@ -843,20 +855,56 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="pay_btn">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>支 付</string>
</property>
</widget>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="vip_pay_btn">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>201</width>
<height>85</height>
</size>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>会员支付</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>18</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="code_pay_btn">
<property name="minimumSize">
<size>
<width>201</width>
<height>85</height>
</size>
</property>
<property name="text">
<string>扫码支付</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
......
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