Commit cfd48cd7 by shangshang.dai

Fix 1: 更改入帐逻辑为服务器错误则订单移除队列

      2: 修复合并商品SKU丢失的问题
parent a78759ae
......@@ -138,7 +138,7 @@ bool FmPlugin::GetOnDutyCashiers(QList<CashierObject> &cashiersList, QString &er
return true;
}
bool FmPlugin::DoOrderEntry(const OrderObject *orderObject, const QString &cashierId, const QString &cashierName, QString &bill_data, QString &fee_data, QString &error)
bool FmPlugin::DoOrderEntry(const OrderObject *orderObject, const QString &cashierId, const QString &cashierName, QString &bill_data, QString &fee_data, QString &error, bool& bServerFailed)
{
Q_UNUSED(cashierId)Q_UNUSED(cashierName)
......@@ -196,6 +196,7 @@ bool FmPlugin::DoOrderEntry(const OrderObject *orderObject, const QString &cashi
if(uuid.isEmpty())
{
error = recvJson["echoMessage"].toString();
bServerFailed = true;
return false;
}
recvArray.clear();
......@@ -475,6 +476,7 @@ QByteArray FmPlugin::_GetOrderEntryData(const OrderObject *orderObject, const QS
QJsonArray products;
for(int i=0; i < orderObject->proList.count(); i++)
{
qDebug() <<orderObject->order_id << i;
ProductObject *pObj = orderObject->proList.at(i);
if(!pObj->sub_products.isEmpty())
{
......@@ -489,6 +491,7 @@ QByteArray FmPlugin::_GetOrderEntryData(const OrderObject *orderObject, const QS
if(_proMap.contains(cpObj->pid))
{
Product_elemet elemet;
elemet.skuId = cpObj->pid;
elemet.qty = _proMap.value(cpObj->pid).qty + cpObj->productAmount*ratio;
elemet.ys_fee = _proMap.value(cpObj->pid).ys_fee + ys_fee;
elemet.ss_fee = _proMap.value(cpObj->pid).ss_fee + ss_fee;
......@@ -518,6 +521,7 @@ QByteArray FmPlugin::_GetOrderEntryData(const OrderObject *orderObject, const QS
if(_proMap.contains(pObj->pid))
{
Product_elemet elemet;
elemet.skuId = pObj->pid;
elemet.qty = _proMap.value(pObj->pid).qty + pObj->productAmount*ratio;
elemet.ys_fee = _proMap.value(pObj->pid).ys_fee + ys_fee;
elemet.ss_fee = _proMap.value(pObj->pid).ss_fee + ss_fee;
......
......@@ -48,7 +48,7 @@ public slots:
* 返回:是否成功
* */
bool DoOrderEntry(OrderObject const *orderObject, const QString& cashierId, const QString& cashierName,
QString& bill_data, QString& fee_data, QString& error);
QString& bill_data, QString& fee_data, QString& error, bool& bServerFailed);
/* 功能:获取库存信息
* 参数:[1]_out库存信息
......
......@@ -252,8 +252,6 @@ bool FlowControl::_PullOrder()
{
QLOG_INFO() << QString("will entry %1").arg(orderObject->order_id);
QTimer::singleShot(1000*60*60, [orderObject, this](){
//QTimer::singleShot(1000*10, [orderObject,this](){
QLOG_INFO() << QString("订单[%1]进入队列").arg(orderObject->order_id);
m_mutex.lock();
m_billList.append(orderObject);
......@@ -292,7 +290,8 @@ void FlowControl::_PostBill()
for(int i=0; i<5; i++)
{
QLOG_INFO() << QString("第%1次尝试写入订单%2").arg(i+1).arg(orderObject->order_id);
if(FmPlugin::GetInstance().DoOrderEntry(orderObject,"","",bill_data, fee_data,error))
bool bServerFailed = false;
if(FmPlugin::GetInstance().DoOrderEntry(orderObject,"","",bill_data, fee_data,error, bServerFailed))
{
QLOG_INFO() << QString("销售单数据%1 配送费数据%2").arg(bill_data,fee_data);
QLOG_INFO() << QString("_PullOrder DoOrderEntry successful %1 %2").arg(orderObject->order_id).arg(error);
......@@ -308,6 +307,15 @@ void FlowControl::_PostBill()
QLOG_INFO() << QString("销售单数据%1 配送费数据%2").arg(bill_data,fee_data);
QLOG_INFO() << QString("_PullOrder DoOrderEntry failed %1 %2").arg(orderObject->order_id, error);
this->_ReportBillEntryResult(orderObject->order_id, 0, error);
if(bServerFailed)
{
m_mutex.lock();
m_billList.removeOne(orderObject);
QLOG_INFO() << QString("订单%1移出队列").arg(orderObject->order_id);
m_mutex.unlock();
break;
}
}
QEventLoop loop;
QTimer::singleShot(1000*60, &loop, &QEventLoop::quit);
......@@ -378,83 +386,83 @@ bool FlowControl::_GetDelivers(const QString &orderId)
bool FlowControl::_ConfirmOrder(const QString &orderId, const DeliverObject &deliverObj)
{
QString error;
bool result;
QJsonObject sendJson;
QJsonObject recvJson;
sendJson = DataManger::GetInstance().GetConfirmOrderData(orderId, deliverObj.id, deliverObj.name, deliverObj.phone);
emit showAlert(AlertForm::LOADING, "正在通信......");
QLOG_INFO() << QString("[---confirm order---]. [requestData:%1]").arg(_GetJsonStr(sendJson));
result = m_procOrderSocket->Request(sendJson, recvJson, error);
QLOG_INFO() << QString("confirm order finsh. [result:%1][msg:%2][recvData:%3]")
.arg(result).arg(error, _GetJsonStr(recvJson));
if(!result)
{
emit showAlert(AlertForm::ERROR, "接单失败![网络错误]");
}else
{
if(JSON_STATUSCODE_OK != recvJson[JSON_STATUSCODE].toInt())
{
result = false;
emit showAlert(AlertForm::ERROR, QString("接单失败![%1]").arg(recvJson[JSON_MESSAGE].toString()));
}else
{
OrderObject *orderObject = m_ordersMap.value(orderId);
emit showAlert(AlertForm::LOADING, "正在录入天天饮食......");
QLOG_INFO() << QString("[---order entry begin---]");
QString orderEntryError("");
if(!FmPlugin::GetInstance().DoOrderEntry(orderObject, m_cashierObject.id, m_cashierObject.name,
m_cashierObject.shiftId, m_cashierObject.shiftName, error))
{
QString dirPath = QString("%1/orders").arg(QApplication::applicationDirPath());
QDir dir;
dir.mkdir(dirPath);
QFile file(QString("%1/%2").arg(dirPath, orderObject->order_id));
if(!file.exists())
{
file.open(QFile::WriteOnly);
file.close();
}
orderEntryError = QString("<font color=\"#FF0000\">[此单录入天天饮食失败,请务必及时在订单详情页补录]</font>");
QLOG_ERROR() << QString("order entry failed,[%1]").arg(error);
}else
{
QLOG_INFO() << QString("order entry success.");
}
QString remark(orderObject->remark), deliveryTime;
remark = remark.isEmpty()? "" : QString("[备注: %1]").arg(remark);
deliveryTime = QString("[期望送达时间: %1]").arg(orderObject->delivery_time==0? "立即送出" : QDateTime::fromTime_t(orderObject->delivery_time).toString("yyyy-MM-dd hh:mm:ss"));
emit showAlert(AlertForm::SUCCESS, QString("接单成功!%1<br/>%2<br/>%3").arg(remark).arg(deliveryTime).arg(orderEntryError));
// 通知主界面移动订单
int oldStatus = orderObject->status;
orderObject->status = recvJson[JSON_STATUS].toInt();
orderObject->status_desc = recvJson[JSON_STATUSDESC].toString();
emit changeOrderStatus(orderObject, oldStatus);
if(orderObject->status==2&&!orderObject->courier_name.isEmpty())
{
// 打印
QLOG_INFO() << QString("[---begin print---].");
orderObject->courier_name = deliverObj.name;
orderObject->courier_phone = deliverObj.phone;
if(FmPrinter::GetInstance().DoPrint(ConfigManger::GetInstance().GetPrinterName(), orderObject))
{
QLOG_INFO() << QString("print sucessful");
}else
{
QLOG_INFO() << QString("print failed");
}
}
}
}
return result;
// QString error;
// bool result;
// QJsonObject sendJson;
// QJsonObject recvJson;
// sendJson = DataManger::GetInstance().GetConfirmOrderData(orderId, deliverObj.id, deliverObj.name, deliverObj.phone);
// emit showAlert(AlertForm::LOADING, "正在通信......");
// QLOG_INFO() << QString("[---confirm order---]. [requestData:%1]").arg(_GetJsonStr(sendJson));
// result = m_procOrderSocket->Request(sendJson, recvJson, error);
// QLOG_INFO() << QString("confirm order finsh. [result:%1][msg:%2][recvData:%3]")
// .arg(result).arg(error, _GetJsonStr(recvJson));
// if(!result)
// {
// emit showAlert(AlertForm::ERROR, "接单失败![网络错误]");
// }else
// {
// if(JSON_STATUSCODE_OK != recvJson[JSON_STATUSCODE].toInt())
// {
// result = false;
// emit showAlert(AlertForm::ERROR, QString("接单失败![%1]").arg(recvJson[JSON_MESSAGE].toString()));
// }else
// {
// OrderObject *orderObject = m_ordersMap.value(orderId);
// emit showAlert(AlertForm::LOADING, "正在录入天天饮食......");
// QLOG_INFO() << QString("[---order entry begin---]");
// QString orderEntryError("");
// if(!FmPlugin::GetInstance().DoOrderEntry(orderObject, m_cashierObject.id, m_cashierObject.name,
// m_cashierObject.shiftId, m_cashierObject.shiftName, error))
// {
// QString dirPath = QString("%1/orders").arg(QApplication::applicationDirPath());
// QDir dir;
// dir.mkdir(dirPath);
// QFile file(QString("%1/%2").arg(dirPath, orderObject->order_id));
// if(!file.exists())
// {
// file.open(QFile::WriteOnly);
// file.close();
// }
// orderEntryError = QString("<font color=\"#FF0000\">[此单录入天天饮食失败,请务必及时在订单详情页补录]</font>");
// QLOG_ERROR() << QString("order entry failed,[%1]").arg(error);
// }else
// {
// QLOG_INFO() << QString("order entry success.");
// }
// QString remark(orderObject->remark), deliveryTime;
// remark = remark.isEmpty()? "" : QString("[备注: %1]").arg(remark);
// deliveryTime = QString("[期望送达时间: %1]").arg(orderObject->delivery_time==0? "立即送出" : QDateTime::fromTime_t(orderObject->delivery_time).toString("yyyy-MM-dd hh:mm:ss"));
// emit showAlert(AlertForm::SUCCESS, QString("接单成功!%1<br/>%2<br/>%3").arg(remark).arg(deliveryTime).arg(orderEntryError));
// // 通知主界面移动订单
// int oldStatus = orderObject->status;
// orderObject->status = recvJson[JSON_STATUS].toInt();
// orderObject->status_desc = recvJson[JSON_STATUSDESC].toString();
// emit changeOrderStatus(orderObject, oldStatus);
// if(orderObject->status==2&&!orderObject->courier_name.isEmpty())
// {
// // 打印
// QLOG_INFO() << QString("[---begin print---].");
// orderObject->courier_name = deliverObj.name;
// orderObject->courier_phone = deliverObj.phone;
// if(FmPrinter::GetInstance().DoPrint(ConfigManger::GetInstance().GetPrinterName(), orderObject))
// {
// QLOG_INFO() << QString("print sucessful");
// }else
// {
// QLOG_INFO() << QString("print failed");
// }
// }
// }
// }
return true;
}
bool FlowControl::_RefuseOrder(const QString &orderId, int refuseCode)
......@@ -870,24 +878,24 @@ void FlowControl::onGetOrderDetails(const QString &orderId)
void FlowControl::onReEntryOrder(const QString &orderId)
{
emit showAlert(AlertForm::LOADING, "正在补录到天天饮食......");
QLOG_INFO() << QString("[---order reEntry begin---]");
// 写入销售单
OrderObject *orderObject = m_ordersMap.value(orderId);
QString error;
if(!FmPlugin::GetInstance().DoOrderEntry(orderObject, m_cashierObject.id, m_cashierObject.name,
m_cashierObject.shiftId, m_cashierObject.shiftName, error))
{
QLOG_ERROR() << QString("order reEntry failed,[%1]").arg(error);
emit showAlert(AlertForm::ERROR, "<font color=\"#FF0000\">补录天天饮食失败,请联系管理员或者进群咨询(205821431)</font>");
}else
{
QFile file(QString("%1/orders/%2").arg(QApplication::applicationDirPath(), orderObject->order_id));
file.remove();
QLOG_INFO() << QString("order reEentry success.");
emit showAlert(AlertForm::SUCCESS, "补录天天饮食成功");
}
// emit showAlert(AlertForm::LOADING, "正在补录到天天饮食......");
// QLOG_INFO() << QString("[---order reEntry begin---]");
// // 写入销售单
// OrderObject *orderObject = m_ordersMap.value(orderId);
// QString error;
// if(!FmPlugin::GetInstance().DoOrderEntry(orderObject, m_cashierObject.id, m_cashierObject.name,
// m_cashierObject.shiftId, m_cashierObject.shiftName, error))
// {
// QLOG_ERROR() << QString("order reEntry failed,[%1]").arg(error);
// emit showAlert(AlertForm::ERROR, "<font color=\"#FF0000\">补录天天饮食失败,请联系管理员或者进群咨询(205821431)</font>");
// }else
// {
// QFile file(QString("%1/orders/%2").arg(QApplication::applicationDirPath(), orderObject->order_id));
// file.remove();
// QLOG_INFO() << QString("order reEentry success.");
// emit showAlert(AlertForm::SUCCESS, "补录天天饮食成功");
// }
}
void FlowControl::onSerachOrder(const QString &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