Commit fc9ca9f7 by gujin.wang

完成退款功能

parent c906f78f
...@@ -14,6 +14,7 @@ FMPePay::FMPePay(const FMPContext ctx) ...@@ -14,6 +14,7 @@ FMPePay::FMPePay(const FMPContext ctx)
_databasename(DEFAULT_EPAY_DATABASENAME), _databasename(DEFAULT_EPAY_DATABASENAME),
_table(DEFAULT_EPAY_TABLE), _table(DEFAULT_EPAY_TABLE),
_redeem_table(DEFAULT_REDEEM_TABLE), _redeem_table(DEFAULT_REDEEM_TABLE),
_vip_table(DEFAULT_VIP_TABLE),
_businessdate(QDateTime::currentDateTime().toString("yyyy-MM-dd")), _businessdate(QDateTime::currentDateTime().toString("yyyy-MM-dd")),
_ordershelflife(DEFAULT_EPAY_ORDERLIFE), _ordershelflife(DEFAULT_EPAY_ORDERLIFE),
_operator_id(DEFAULT_EPAY_OPTID), _operator_id(DEFAULT_EPAY_OPTID),
......
...@@ -41,7 +41,8 @@ private: ...@@ -41,7 +41,8 @@ private:
QString _url; QString _url;
QString _databasename; QString _databasename;
QString _table; QString _table;
QString _redeem_table; QString _redeem_table; //存放卡券核销详情
QString _vip_table;
QString _businessdate; QString _businessdate;
QString _store_id; QString _store_id;
QString _station_id; QString _station_id;
......
...@@ -18,6 +18,11 @@ public: ...@@ -18,6 +18,11 @@ public:
QVariant d = QSqlTableModel::data(idx,role); QVariant d = QSqlTableModel::data(idx,role);
return d.toString().toFloat() / 100; return d.toString().toFloat() / 100;
} }
if(idx.column() == 17 && role == Qt::DisplayRole){
QVariant d = QSqlTableModel::data(idx, role);
return d.toString().toFloat()/100;
}
if ((idx.column() == 12) && role == Qt::DisplayRole) { if ((idx.column() == 12) && role == Qt::DisplayRole) {
QVariant d = QSqlTableModel::data(idx,role); QVariant d = QSqlTableModel::data(idx,role);
......
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
#define DEFAULT_EPAY_DATABASENAME "fmp_test.db" #define DEFAULT_EPAY_DATABASENAME "fmp_test.db"
#define DEFAULT_EPAY_TABLE "fmp_pay" #define DEFAULT_EPAY_TABLE "fmp_pay"
#define DEFAULT_REDEEM_TABLE "fmp_redeem" #define DEFAULT_REDEEM_TABLE "fmp_redeem"
#define DEFAULT_VIP_TABLE "fmp_vip"
#define DEFAULT_EPAY_CONNECTNAME "fmp_pay_connect" #define DEFAULT_EPAY_CONNECTNAME "fmp_pay_connect"
#define DEFAULT_EPAY_ORDERLIFE 60 #define DEFAULT_EPAY_ORDERLIFE 60
#define DEFAULT_EPAY_STRID "99999" #define DEFAULT_EPAY_STRID "99999"
......
...@@ -45,6 +45,8 @@ public: ...@@ -45,6 +45,8 @@ public:
void ControlPayJson(QString sum, QString code); void ControlPayJson(QString sum, QString code);
void ControlRefundJson(const QJsonObject &trans); void ControlRefundJson(const QJsonObject &trans);
void ControlVipRefundJson(const QJsonObject &trans);
void GetCheckMode(QString sum); void GetCheckMode(QString sum);
...@@ -108,9 +110,11 @@ signals: ...@@ -108,9 +110,11 @@ signals:
protected slots: protected slots:
void witedata(); void witedata();
protected slots:
void payVip(); void payVip();
void vipFinal(); void vipFinal();
QString final(QString fm_open_id = QString()); QString final(QString fm_open_id = QString());
void WritePosDatabase(QString transId);
public: public:
......
...@@ -883,19 +883,17 @@ void FMPPayDialog::onBtnConfirmClicked() ...@@ -883,19 +883,17 @@ void FMPPayDialog::onBtnConfirmClicked()
{ {
QJsonObject fakeResponse; QJsonObject fakeResponse;
fakeResponse["statusCode"] = 100; fakeResponse["statusCode"] = 100;
fakeResponse["pay_acount"] = ""; fakeResponse["pay_account"] = "";
fakeResponse["pay_ebcode"] = ""; fakeResponse["pay_id"] = QString::fromLocal8Bit("非码优惠券支付");
fakeResponse["pay_id"] = QString::fromLocal8Bit("微信当面付[条码]");
fakeResponse["pay_transId"] = ""; fakeResponse["pay_transId"] = "";
fakeResponse["fmId"] = ""; fakeResponse["fmId"] = "";
fakeResponse["total_amount"] = 0; fakeResponse["total_amount"] = _pay_total;
fakeResponse["alipay_amount"] = 0; fakeResponse["alipay_amount"] = _pay_total;
fakeResponse["mcoupon_amount"] = 0; fakeResponse["mcoupon_amount"] = 0;
fakeResponse["invoice_amount"] = _pay_total; fakeResponse["invoice_amount"] = _pay_total;
fakeResponse["pay_total"] = _pay_total; fakeResponse["pay_total"] = _pay_total;
fakeResponse["pay_ebcode"] = "10004"; fakeResponse["pay_ebcode"] = "30000";
fakeResponse["isrefund"] = false; fakeResponse["isrefund"] = false;
qDebug() << fakeResponse;
_control->writeOrderToSqlite(fakeResponse); _control->writeOrderToSqlite(fakeResponse);
_control->finished(fakeResponse); _control->finished(fakeResponse);
return; return;
...@@ -1040,7 +1038,17 @@ void FMPPayDialog::on_pushButton_2_clicked() ...@@ -1040,7 +1038,17 @@ void FMPPayDialog::on_pushButton_2_clicked()
QJsonObject trans; QJsonObject trans;
trans["refund_amount"] = (int)((model->data(idx.sibling(idx.row(), 6)).toDouble() + 0.005) * 100); trans["refund_amount"] = (int)((model->data(idx.sibling(idx.row(), 6)).toDouble() + 0.005) * 100);
trans["fm_id"] = model->data(idx.sibling(idx.row(),0)).toString(); trans["fm_id"] = model->data(idx.sibling(idx.row(),0)).toString();
_control->ControlRefundJson(trans); trans["trans_id"] = model->record(idx.row()).value("trans_id").toString();
QString pay_ebcode = model->record(idx.row()).value("pay_ebcode").toString();
trans["pay_ebcode"]= pay_ebcode;
if(pay_ebcode == "1003")
{
_control->ControlVipRefundJson(trans);
}
else
{
_control->ControlRefundJson(trans);
}
_wait->show(); _wait->show();
} }
...@@ -1158,7 +1166,7 @@ void FMPPayDialog::redeem() ...@@ -1158,7 +1166,7 @@ void FMPPayDialog::redeem()
FMPRedeemInterface* redeem = FMP::GetService<FMPRedeemInterface>(); FMPRedeemInterface* redeem = FMP::GetService<FMPRedeemInterface>();
redeem->StartService(); redeem->StartService();
QJsonObject result = redeem->Redeem(needPay, _products_info); QJsonObject result = redeem->Redeem( _products_info);
FMP_DEBUG() << "redeem result: " << result; FMP_DEBUG() << "redeem result: " << result;
needPay -= result["discount"].toInt()/100.0; needPay -= result["discount"].toInt()/100.0;
ui->lineedit_num->setText(QString::number(qMax(0.0, needPay))); ui->lineedit_num->setText(QString::number(qMax(0.0, needPay)));
...@@ -1198,15 +1206,27 @@ void FMPPayDialog::ShowPayDetail(const QModelIndex &index) ...@@ -1198,15 +1206,27 @@ void FMPPayDialog::ShowPayDetail(const QModelIndex &index)
DetailDialog detailDlg(x, y, dis, this); DetailDialog detailDlg(x, y, dis, this);
//微信支付详情 QString transId = _control->model()->record(index.row()).value("trans_id").toString();
QSqlRecord record = _control->model()->record(index.row());
detailDlg.AddData(record);
//卡券支付详情
QString transId = record.value("trans_id").toString();
FMPDataBase* database = _control->GetDB(); FMPDataBase* database = _control->GetDB();
QSqlQuery query; QSqlQuery query;
if(!database->find(DEFAULT_REDEEM_TABLE, query, QStringList(), QString("trans_id=%1").arg(transId))) QSqlRecord record;
//微信/支付宝 支付详情
if(!database->find(DEFAULT_EPAY_TABLE, query, QStringList(), QString("trans_id='%1' and pay_ebcode!='%2' and pay_ebcode!='%3'").arg(transId).arg("30000").arg("1003")))
{
FMP_ERROR() << "query fmp_pay failed.";
}
else
{
while(query.next())
{
record = query.record();
detailDlg.AddData(record);
}
}
//卡券支付详情
if(!database->find(DEFAULT_REDEEM_TABLE, query, QStringList(), QString("trans_id='%1'").arg(transId)))
{ {
FMP_ERROR() << "query redeem info failed"; FMP_ERROR() << "query redeem info failed";
} }
...@@ -1214,10 +1234,25 @@ void FMPPayDialog::ShowPayDetail(const QModelIndex &index) ...@@ -1214,10 +1234,25 @@ void FMPPayDialog::ShowPayDetail(const QModelIndex &index)
{ {
while(query.next()) while(query.next())
{ {
QSqlRecord record = query.record(); record = query.record();
detailDlg.AddData(record); detailDlg.AddData(record);
} }
} }
//会员支付详情
if(!database->find(DEFAULT_VIP_TABLE, query, QStringList(), QString("trans_id='%1'").arg(transId)))
{
FMP_ERROR() << "query fmp_vip failed.";
}
else
{
while(query.next())
{
record = query.record();
detailDlg.AddData(record);
}
}
detailDlg.exec(); detailDlg.exec();
} }
...@@ -1235,14 +1270,24 @@ void FMPPayDialog::Reverse() ...@@ -1235,14 +1270,24 @@ void FMPPayDialog::Reverse()
redeem->StartService(); redeem->StartService();
foreach (QJsonObject obj, _reverses) foreach (QJsonObject obj, _reverses)
{ {
QSqlQuery query;
FMPDataBase* database = nullptr; FMPDataBase* database = nullptr;
QString coupon = obj["transactions"].toArray()[0].toObject()["code"].toString(); QString coupon = obj["transactions"].toArray()[0].toObject()["code"].toString();
QJsonObject result = redeem->Reverse(obj); QJsonObject result = redeem->Reverse(obj);
int statusCode = result["statusCode"].toInt(); int statusCode = result["statusCode"].toInt();
if(statusCode == 100) if(statusCode == 100)
{ {
//如果冲正成功,则从数据库中删除该券的核销记录 //先增加 本次消费金额 输入框的值(即冲正掉的金额)
database = _control->GetDB(); database = _control->GetDB();
if(database->find(DEFAULT_REDEEM_TABLE, query, QStringList(), QString("code='%1'").arg(coupon)))
{
FMP_ERROR() << QString::fromLocal8Bit("冲正时查询卡券金额失败. 券码:") << coupon;
}
double cur = ui->lineedit_num->text().toDouble();
cur += query.value("total_amount").toInt()/100.0;
ui->lineedit_num->setText(QString::number(cur));
//如果冲正成功,则从数据库中删除该券的核销记录
if(!database->dlt(DEFAULT_REDEEM_TABLE, "code="+coupon)) if(!database->dlt(DEFAULT_REDEEM_TABLE, "code="+coupon))
{ {
FMP_ERROR() << "delete from redeem_table failed. code=" << coupon; FMP_ERROR() << "delete from redeem_table failed. code=" << coupon;
......
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