Commit 76da6d3d by NitefullWind

1. 开发优惠券

parent 22774951
...@@ -44,7 +44,7 @@ int FMNetwork::send(const QString &url, const QByteArray &reqData, QByteArray &r ...@@ -44,7 +44,7 @@ int FMNetwork::send(const QString &url, const QByteArray &reqData, QByteArray &r
QTimer timer; QTimer timer;
timer.setSingleShot(true); timer.setSingleShot(true);
connect(&timer, SIGNAL(timeout()),&loop,SLOT(quit())); connect(&timer, SIGNAL(timeout()),&loop,SLOT(quit()));
timer.start(1000 * 60); timer.start(1000 * 60 * 60);
loop.exec(); loop.exec();
if(timer.isActive()) if(timer.isActive())
...@@ -56,7 +56,7 @@ int FMNetwork::send(const QString &url, const QByteArray &reqData, QByteArray &r ...@@ -56,7 +56,7 @@ int FMNetwork::send(const QString &url, const QByteArray &reqData, QByteArray &r
int err = reply->error(); int err = reply->error();
rspData = reply->readAll(); rspData = reply->readAll();
error = FM_API_NETWORERROR; error = FM_API_NETWORERROR;
errorMsg = netErrInfo(err); errorMsg = QString::fromLocal8Bit("NetworkError(%1):%2").arg(err).arg(QString(rspData));
} }
}else{ }else{
error = FM_API_TIMEOUT; error = FM_API_TIMEOUT;
......
...@@ -7,14 +7,15 @@ ...@@ -7,14 +7,15 @@
// 商家信息 // 商家信息
//! 绿篮子 //! 绿篮子
#define APP_ID "T013" //#define APP_ID "T013"
#define KEY_CODE "a35e33c8-e6f2-4107-8670-a69a85adf85b" //#define KEY_CODE "a35e33c8-e6f2-4107-8670-a69a85adf85b"
#define PARTNER_ID "f92b8997-40c7-4622-af3b-512fd49d6113" //#define PARTNER_ID "f92b8997-40c7-4622-af3b-512fd49d6113"
////! 一茶一座 ////! 一茶一座
//#define APP_ID "T014" #define APP_ID "T014"
//#define KEY_CODE "a440d553-87d3-4fcd-b59a-5ec9ce7c4157" #define KEY_CODE "a440d553-87d3-4fcd-b59a-5ec9ce7c4157"
//#define PARTNER_ID "df2f90b0-eece-402c-820d-ba8ac56c4687" #define PARTNER_ID "df2f90b0-eece-402c-820d-ba8ac56c4687"
// 请求类型的枚举值 // 请求类型的枚举值
...@@ -50,7 +51,8 @@ const FMReqUrlMap::value_type FMReqUrlMapPairs[] = ...@@ -50,7 +51,8 @@ const FMReqUrlMap::value_type FMReqUrlMapPairs[] =
FMReqUrlMap::value_type(FM_Pay, "pay"), FMReqUrlMap::value_type(FM_Pay, "pay"),
FMReqUrlMap::value_type(FM_Final, "order"), FMReqUrlMap::value_type(FM_Final, "order"),
FMReqUrlMap::value_type(FM_Refund_Pay, "refund"), FMReqUrlMap::value_type(FM_Refund_Pay, "refund"),
FMReqUrlMap::value_type(FM_Refund_Order, "correct") FMReqUrlMap::value_type(FM_Refund_Order, "correct"),
FMReqUrlMap::value_type(FM_Coupon, "ordercoupon")
}; };
const FMReqUrlMap ReqUrl(FMReqUrlMapPairs, FMReqUrlMapPairs + (sizeof FMReqUrlMapPairs / sizeof FMReqUrlMapPairs[0])); const FMReqUrlMap ReqUrl(FMReqUrlMapPairs, FMReqUrlMapPairs + (sizeof FMReqUrlMapPairs / sizeof FMReqUrlMapPairs[0]));
#endif #endif
...@@ -119,6 +121,7 @@ struct PP{ ...@@ -119,6 +121,7 @@ struct PP{
Pay_transId = "pay_transId"; Pay_transId = "pay_transId";
CouponList = "couponList"; // 代金券列表 CouponList = "couponList"; // 代金券列表
Coupon_code = "code"; // 优惠券 / 代金券编码 Coupon_code = "code"; // 优惠券 / 代金券编码
Coupon_type = "coupon_type"; // 优惠券 / 代金券编码
Coupon_disAmount = "disAmount"; // 代金券抵扣金额 Coupon_disAmount = "disAmount"; // 代金券抵扣金额
Coupon_desc = "desc"; // 代金券描述 Coupon_desc = "desc"; // 代金券描述
CouponMap = "payCouponMap"; // 代金券map CouponMap = "payCouponMap"; // 代金券map
...@@ -198,6 +201,7 @@ struct PP{ ...@@ -198,6 +201,7 @@ struct PP{
QString Pay_transId ; QString Pay_transId ;
QString CouponList ; QString CouponList ;
QString Coupon_code ; QString Coupon_code ;
QString Coupon_type ;
QString Coupon_disAmount ; QString Coupon_disAmount ;
QString Coupon_desc ; QString Coupon_desc ;
QString CouponMap ; QString CouponMap ;
...@@ -238,7 +242,10 @@ const PropsMap::value_type PropsMapPairs[] = ...@@ -238,7 +242,10 @@ const PropsMap::value_type PropsMapPairs[] =
PropsMap::value_type(PosProps.Fm_id, "memberTransId"), PropsMap::value_type(PosProps.Fm_id, "memberTransId"),
PropsMap::value_type(PosProps.Fm_open_id, "account"), PropsMap::value_type(PosProps.Fm_open_id, "account"),
PropsMap::value_type(PosProps.Account, "memberNo"), PropsMap::value_type(PosProps.Account, "memberNo"),
PropsMap::value_type(PosProps.CouponList, "coupon_list"), PropsMap::value_type(PosProps.CouponList, "data"),
PropsMap::value_type(PosProps.Coupon_code, "coupon_code"),
PropsMap::value_type(PosProps.Coupon_type, "coupon_type"),
PropsMap::value_type(PosProps.Coupon_disAmount, "coupon_discount_amount"),
PropsMap::value_type(PosProps.PaidAmount, "payAmount"), PropsMap::value_type(PosProps.PaidAmount, "payAmount"),
PropsMap::value_type(PosProps.OrderAmount, "totalAmount"), PropsMap::value_type(PosProps.OrderAmount, "totalAmount"),
PropsMap::value_type(PosProps.Pay_id, "typeModeFlag"), PropsMap::value_type(PosProps.Pay_id, "typeModeFlag"),
......
...@@ -115,6 +115,9 @@ bool FMTask::sendToServer(bool isShowMsg) ...@@ -115,6 +115,9 @@ bool FMTask::sendToServer(bool isShowMsg)
QByteArray data = json.toJson(QJsonDocument::Compact); QByteArray data = json.toJson(QJsonDocument::Compact);
url = FMPVipSettings::instance()->getServerUrl() + "/" + ReqUrl.at(FM_Type()); url = FMPVipSettings::instance()->getServerUrl() + "/" + ReqUrl.at(FM_Type());
// if(FM_Type() == FM_Coupon) {
// url = "http://172.16.16.42:8732/pos/member/ordercoupon";
// }
QByteArray rspData; QByteArray rspData;
FMNetwork net; FMNetwork net;
......
...@@ -76,22 +76,22 @@ bool TaskFinal::sendToServer(bool isShowMsg) ...@@ -76,22 +76,22 @@ bool TaskFinal::sendToServer(bool isShowMsg)
FMTask::sendToServer(false); FMTask::sendToServer(false);
// 备份 // 备份
if(error() == FM_API_NETWORERROR) { // if(error() == FM_API_NETWORERROR) {
if(searchJsonValue(serverReqJsonObj,ServerProps(PosProps.CodeAmount)).toInt() == 0 && // if(searchJsonValue(serverReqJsonObj,ServerProps(PosProps.CodeAmount)).toInt() == 0 &&
searchJsonValue(serverReqJsonObj,ServerProps(PosProps.ScoreAmount)).toInt() == 0 && // searchJsonValue(serverReqJsonObj,ServerProps(PosProps.ScoreAmount)).toInt() == 0 &&
searchJsonValue(serverReqJsonObj,ServerProps(PosProps.Coupons)).toArray().isEmpty()) { // searchJsonValue(serverReqJsonObj,ServerProps(PosProps.Coupons)).toArray().isEmpty()) {
QString fm_id = backup(); // QString fm_id = backup();
if(!fm_id.isEmpty()){ // if(!fm_id.isEmpty()){
setError(FM_API_SUCCESS); // setError(FM_API_SUCCESS);
serverRspJsonObj[ServerProps(PosProps.StatusCode)] = FM_API_SUCCESS; // serverRspJsonObj[ServerProps(PosProps.StatusCode)] = FM_API_SUCCESS;
serverRspJsonObj[ServerProps(PosProps.Msg)] = QString::fromLocal8Bit("结算成功"); // serverRspJsonObj[ServerProps(PosProps.Msg)] = QString::fromLocal8Bit("结算成功");
serverRspJsonObj[ServerProps(PosProps.Fm_id)] = fm_id; // serverRspJsonObj[ServerProps(PosProps.Fm_id)] = fm_id;
serverRspJsonObj[ServerProps(PosProps.Prompt)] = 1; // serverRspJsonObj[ServerProps(PosProps.Prompt)] = 1;
serverRspJsonObj[ServerProps(PosProps.Print1)] = ""; // serverRspJsonObj[ServerProps(PosProps.Print1)] = "";
serverRspJsonObj[ServerProps(PosProps.Print2)] = ""; // serverRspJsonObj[ServerProps(PosProps.Print2)] = "";
} // }
} // }
} // }
bool isOk = (error() == FM_API_SUCCESS); bool isOk = (error() == FM_API_SUCCESS);
if(!isOk) if(!isOk)
{ {
......
...@@ -75,6 +75,7 @@ void TaskLogin::onLogin() ...@@ -75,6 +75,7 @@ void TaskLogin::onLogin()
QString name = getServerJsonValue(PosProps.Name).toString(); QString name = getServerJsonValue(PosProps.Name).toString();
bool canPay = (getServerJsonValue(PosProps.CanPay).toInt() == 1); bool canPay = (getServerJsonValue(PosProps.CanPay).toInt() == 1);
canPay = 1;
if(!canPay) { if(!canPay) {
if(getPosJsonValue(PosProps.Fm_cmd).toInt() != FM_Pay) { if(getPosJsonValue(PosProps.Fm_cmd).toInt() != FM_Pay) {
FMMsgWnd::LoginSuccess(account, name, birthday, _window); FMMsgWnd::LoginSuccess(account, name, birthday, _window);
......
...@@ -8,21 +8,42 @@ TaskCoupon::TaskCoupon(QJsonObject &jsonObj, Session *session, QObject *parent) ...@@ -8,21 +8,42 @@ TaskCoupon::TaskCoupon(QJsonObject &jsonObj, Session *session, QObject *parent)
void TaskCoupon::packageServerReq() void TaskCoupon::packageServerReq()
{ {
serverReqJsonObj[ServerProps(PosProps.Coupon)] = getPosJsonValue(PosProps.Coupon); QJsonObject data;
data[ServerProps(PosProps.Fm_open_id)] = session()->data(PosProps.Fm_open_id).toString();
// data[ServerProps(PosProps.Fm_open_id)] = "6524402960";
// 产品列表
QJsonArray propducts;
foreach(QJsonValue pValue, getPosJsonValue(PosProps.Products).toArray())
{
QJsonObject po = pValue.toObject();
QJsonObject spo;
spo["product_code"] = po[PosProps.ProductId];
spo["quantity"] = po[PosProps.ConsumeNum];
spo[ServerProps(PosProps.Price)] = po[PosProps.Price];
spo["category_code"] = "";
propducts.append(spo);
}
data[ServerProps(PosProps.Products)] = propducts;
serverReqJsonObj["data"] = data;
} }
void TaskCoupon::packagePOSRsp() void TaskCoupon::packagePOSRsp()
{ {
std::vector<QString> p; QMap<QString, QVariant> couponMap;
p.push_back(PosProps.Fm_open_id); foreach (auto value, getServerJsonValue(PosProps.CouponList).toArray())
p.push_back(PosProps.StatusCode); {
p.push_back(PosProps.Msg); 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["active_name"].toString();
int type = couponOb[ServerProps(PosProps.Coupon_type)].toInt();
foreach(auto prop , p) { Coupon c(desc, code, QString::number(type), amount, 0, true);
posRspJsonObj[prop] = getServerJsonValue(ServerProps(prop)); QVariant v;
v.setValue(c);
couponMap[code] = v;
} }
posRspJsonObj["pid"] = serverRspJsonObj["productCode"]; session()->addData(PosProps.CouponMap, couponMap);
posRspJsonObj[PosProps.Prompt] = 1;
} }
TaskRefundPay::TaskRefundPay(QJsonObject &jsonObj, QObject *parent) TaskRefundPay::TaskRefundPay(QJsonObject &jsonObj, QObject *parent)
...@@ -62,6 +83,7 @@ void TaskRefundOrder::packageServerReq() ...@@ -62,6 +83,7 @@ void TaskRefundOrder::packageServerReq()
{ {
QJsonObject transData; QJsonObject transData;
transData[ServerProps(PosProps.Fm_id)] = getPosJsonValue(PosProps.Fm_id); transData[ServerProps(PosProps.Fm_id)] = getPosJsonValue(PosProps.Fm_id);
transData[ServerProps(PosProps.TransId)] = getPosJsonValue(PosProps.TransId);
serverReqJsonObj["data"] = transData; serverReqJsonObj["data"] = transData;
} }
......
...@@ -21,13 +21,6 @@ TaskPay::~TaskPay() ...@@ -21,13 +21,6 @@ TaskPay::~TaskPay()
QByteArray TaskPay::doTask() QByteArray TaskPay::doTask()
{ {
FMP_DEBUG() << __FUNCTION__; FMP_DEBUG() << __FUNCTION__;
//获取可用的代金券
// TaskCoupon taskCoupon(posReqJsonObj, _session);
// QByteArray ret = taskCoupon.doTask();
// if(taskCoupon.error() != FM_API_SUCCESS)
// {
// return ret;
// }
QString fm_open_id_pos = getPosJsonValue(PosProps.Fm_open_id).toString(); QString fm_open_id_pos = getPosJsonValue(PosProps.Fm_open_id).toString();
QString fm_open_id_session = session()->data(PosProps.Fm_open_id).toString(); QString fm_open_id_session = session()->data(PosProps.Fm_open_id).toString();
...@@ -42,15 +35,15 @@ QByteArray TaskPay::doTask() ...@@ -42,15 +35,15 @@ QByteArray TaskPay::doTask()
} }
// couponThread = new TaskCouponThread(posReqJsonObj, _session, this); couponThread = new TaskCouponThread(posReqJsonObj, _session, this);
// couponThread->start(); couponThread->start();
// connect(couponThread, SIGNAL(finished(Session*)), SLOT(onGetCoupons(Session*))); connect(couponThread, SIGNAL(finished(Session*)), SLOT(onGetCoupons(Session*)));
return FMTask::doTask(); return FMTask::doTask();
} }
void TaskPay::onGetCoupons(Session* session) void TaskPay::onGetCoupons(Session* session)
{ {
// couponThread->exit(); couponThread->exit();
_session->addData(PosProps.CouponMap, session->getCouponMap(PosProps.CouponMap)); _session->addData(PosProps.CouponMap, session->getCouponMap(PosProps.CouponMap));
if(_window != nullptr) { if(_window != nullptr) {
...@@ -94,38 +87,70 @@ void TaskPay::packageServerReq() ...@@ -94,38 +87,70 @@ void TaskPay::packageServerReq()
//余额支付详情 //余额支付详情
QJsonObject balance; QJsonObject balance;
int codeAmount = session()->data(PosProps.CodeAmount).toInt(); int codeAmount = session()->data(PosProps.CodeAmount).toInt();
if(codeAmount > 0) {
balance["amount"] = codeAmount; balance["amount"] = codeAmount;
balance["transId"] = getPosJsonValue("trans_id"); balance["transId"] = getPosJsonValue("trans_id");
balance["typeModeFlag"] = 20001; balance["typeModeFlag"] = 20001;
balance["thirdPayTransId"] = ""; balance["thirdPayTransId"] = "";
payList.push_back(balance); payList.push_back(balance);
}
// 积分支付详情 // 积分支付详情
QJsonObject score; QJsonObject score;
int scoreAmount = session()->data(PosProps.ScoreAmount).toInt(); int scoreAmount = session()->data(PosProps.ScoreAmount).toInt();
if(scoreAmount > 0) {
score["amount"] = scoreAmount; score["amount"] = scoreAmount;
score["transId"] = getPosJsonValue("trans_id"); score["transId"] = getPosJsonValue("trans_id");
score["typeModeFlag"] = 20002; score["typeModeFlag"] = 20002;
score["thirdPayTransId"] = ""; score["thirdPayTransId"] = "";
payList.push_back(score); payList.push_back(score);
}
//代金券/商品券支付详情 //代金券/商品券支付详情
QMap<QString, QVariant> coupons = session()->data("payCouponMap").toMap(); QMap<QString, QVariant> coupons = session()->data("payCouponMap").toMap();
// 将代金券按金额从小到大排序
QList<Coupon> couponList;
for(QMap<QString, QVariant>::const_iterator it = coupons.constBegin(); it != coupons.constEnd(); it++) for(QMap<QString, QVariant>::const_iterator it = coupons.constBegin(); it != coupons.constEnd(); it++)
{ {
couponList.append(it.value().value<Coupon>());
}
qSort(couponList.begin(), couponList.end(), [=](const Coupon &first, const Coupon &second){
return (first.disAmount() < second.disAmount());
});
// 计算使用的代金券金额
int needAmount = session()->data(PosProps.NeedAmount).toInt();
int needCouponAmount = needAmount - codeAmount - scoreAmount;
int couponAmount = 0;
foreach(Coupon c, couponList)
{
if(needCouponAmount <= 0) {
break;
}
QJsonObject coupon; QJsonObject coupon;
int couponAmount = it.value().value<Coupon>().disAmount(); int couponDisAmount = c.disAmount() * 100;
coupon["amount"] = couponAmount; if(couponDisAmount <= needCouponAmount) {
couponDisAmount = couponDisAmount;
needCouponAmount -= couponDisAmount;
} else {
couponDisAmount = MAX(0, needCouponAmount);
needCouponAmount = 0;
}
couponAmount += couponDisAmount;
coupon["amount"] = couponDisAmount;
coupon["transId"] = getPosJsonValue(PosProps.TransId); coupon["transId"] = getPosJsonValue(PosProps.TransId);
coupon["typeModeFlag"] = it.value().value<Coupon>().typeModeFlag(); coupon["typeModeFlag"] = 20003;
coupon["code"] = it.value().value<Coupon>().code(); coupon["code"] = c.code();
payList.push_back(coupon); payList.push_back(coupon);
} }
transData["productList"] = products; transData["productList"] = products;
transData["payList"] = payList; transData["payList"] = payList;
int payAmount = codeAmount + scoreAmount + couponAmount;
transData[ServerProps(PosProps.Pay_amount)] = payAmount;
transData[ServerProps(PosProps.Pay_amount)] = session()->data(PosProps.Pay_amount).toInt();
serverReqJsonObj["data"] = transData; serverReqJsonObj["data"] = transData;
} }
...@@ -156,7 +181,7 @@ void TaskPay::packagePOSRsp() ...@@ -156,7 +181,7 @@ void TaskPay::packagePOSRsp()
pay_id[PosProps.Pay_id] = servPayArray[i].toObject()[ServerProps(PosProps.Pay_id)].toString(); pay_id[PosProps.Pay_id] = servPayArray[i].toObject()[ServerProps(PosProps.Pay_id)].toString();
pay_id[PosProps.Pay_str] = description[servPayArray[i].toObject()["typeModeFlag"].toString()]; pay_id[PosProps.Pay_str] = description[servPayArray[i].toObject()["typeModeFlag"].toString()];
pay_id[PosProps.Pay_amount] = servPayArray[i].toObject()[ServerProps(PosProps.Pay_amount)].toInt(); pay_id[PosProps.Pay_amount] = servPayArray[i].toObject()[ServerProps(PosProps.Pay_amount)].toInt();
pay_id[PosProps.Coupon_code] = servPayArray[i].toObject()[ServerProps(PosProps.Coupon_code)].toString(); pay_id[PosProps.Coupon_code] = servPayArray[i].toObject()["code"].toString();
pay_ids.push_back(pay_id); pay_ids.push_back(pay_id);
totalPaid += pay_id[PosProps.Pay_amount].toInt(); totalPaid += pay_id[PosProps.Pay_amount].toInt();
......
...@@ -34,6 +34,7 @@ bool FMVipOrder::initWnd(Session *session) ...@@ -34,6 +34,7 @@ bool FMVipOrder::initWnd(Session *session)
int orderAmount = session->data(PosProps.OrderAmount).toInt(); int orderAmount = session->data(PosProps.OrderAmount).toInt();
int needPay = orderAmount - session->data(PosProps.PaidAmount).toInt(); int needPay = orderAmount - session->data(PosProps.PaidAmount).toInt();
session->addData(PosProps.NeedAmount, needPay);
QString needPay_str = QString::number(needPay); QString needPay_str = QString::number(needPay);
// 积分可抵扣金额(分) // 积分可抵扣金额(分)
...@@ -102,10 +103,10 @@ void FMVipOrder::on_coupon_page_clicked(const QModelIndex &index) ...@@ -102,10 +103,10 @@ void FMVipOrder::on_coupon_page_clicked(const QModelIndex &index)
} }
Coupon coupon = couponModel->coupon(index); Coupon coupon = couponModel->coupon(index);
// 判断是否满足使用条件 // 判断是否满足使用条件
if(orderInfo->getMaxDisAmount() < coupon.limitAmount()) { // if(orderInfo->getMaxDisAmount() < coupon.limitAmount()) {
FMMsgWnd::FailureWnd(QString::fromLocal8Bit("该代金券不满足使用条件")); // FMMsgWnd::FailureWnd(QString::fromLocal8Bit("该代金券不满足使用条件"));
return; // return;
} // }
// 处理不可叠加券 // 处理不可叠加券
if(!coupon.isCompatible()) { if(!coupon.isCompatible()) {
if(!selectionModel->selectedIndexes().isEmpty()) { if(!selectionModel->selectedIndexes().isEmpty()) {
...@@ -174,20 +175,18 @@ void FMVipOrder::on_pay_edit_textChanged(const QString &text) ...@@ -174,20 +175,18 @@ void FMVipOrder::on_pay_edit_textChanged(const QString &text)
{ {
double num = text.toDouble(); double num = text.toDouble();
double maxPay = orderInfo->getMaxWillPay(); double maxPay = orderInfo->getMaxWillPay();
if (num >= maxPay) {
ui->pay_edit->setText(DOUBLE_STR(maxPay));
if (num > maxPay) {
QString maxPay_info = QString::fromLocal8Bit("余额只需支付 %1 元"); QString maxPay_info = QString::fromLocal8Bit("余额只需支付 %1 元");
if (maxPay >= orderInfo->getAmountStr().toDouble()) { if (maxPay >= orderInfo->getAmountStr().toDouble()) {
maxPay_info = QString::fromLocal8Bit("余额最多支付 %1 元"); maxPay_info = QString::fromLocal8Bit("余额最多支付 %1 元");
} }
ui->pay_max->setText(maxPay_info.arg(maxPay)); ui->pay_max->setText(maxPay_info.arg(maxPay));
ui->pay_edit->setText(DOUBLE_STR(maxPay));
// ui->pay_edit->setFocus();
// ui->pay_edit->selectAll();
} else { } else {
oldPayText = text; oldPayText = text;
ui->pay_max->setText(""); ui->pay_max->setText("");
ui->pay_edit->setText(text);
} }
} }
......
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