Commit cfd48cd7 by shangshang.dai

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

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