Commit c5eeb0e9 by NitefullWind

1. 实现获取订单中可退款支付列表。

parent 985d4ae6
#include "item.h"
#include "database.h"
namespace DB {
Item::Item()
......@@ -123,21 +123,34 @@ void Order::setRefunded(bool refunded)
_refunded = refunded;
}
PayList &Order::payList()
LazyPayList &Order::payList()
{
return _payList;
}
const PayList &Order::payList() const
const LazyPayList &Order::payList() const
{
return _payList;
}
void Order::setPayList(const PayList &payList)
void Order::setPayList(const LazyPayList &payList)
{
_payList = payList;
}
PayList Order::getCanRefundPatList()
{
PayList canRefundPays;
for(LazyPayList::iterator it(_payList.begin()); it!=_payList.end(); it++) {
QLazySharedPointer<Pay>& lsp(*it);
auto sp = lsp.load();
if(sp->payAmount() > sp->refundAmount()) {
canRefundPays.append(sp);
}
}
return canRefundPays;
}
QLazySharedPointer<StoreInfo> &Order::storeInfo()
{
return _storeInfo;
......
......@@ -24,7 +24,8 @@ class Order;
class Pay;
class StoreInfo;
typedef QList<QLazySharedPointer<Pay> > PayList;
typedef QList<QLazySharedPointer<Pay> > LazyPayList;
typedef QList<QSharedPointer<Pay> > PayList;
// 可为空
#pragma db value(int) null
......@@ -81,9 +82,11 @@ public:
bool refunded() const;
void setRefunded(bool refunded);
PayList &payList();
const PayList &payList() const;
void setPayList(const PayList &payList);
LazyPayList &payList();
const LazyPayList &payList() const;
void setPayList(const LazyPayList &payList);
PayList getCanRefundPatList();
QLazySharedPointer<StoreInfo> &storeInfo();
const QLazySharedPointer<StoreInfo> &storeInfo() const;
......@@ -112,7 +115,7 @@ private:
bool _refunded;
#pragma db inverse(_order)
PayList _payList;
LazyPayList _payList;
#pragma db not_null
QLazySharedPointer<StoreInfo> _storeInfo;
......
......@@ -168,11 +168,11 @@ void TaskFinal::packageServerReq()
DBSP()->reload<Order>(_order);
// 从数据库读取支付信息
PayList payList = _order->payList();
LazyPayList payList = _order->payList();
// 转成服务端需要的payArray
QJsonArray payArray;
for (PayList::const_iterator it = payList.constBegin(); it!=payList.constEnd(); it++) {
for (LazyPayList::const_iterator it = payList.constBegin(); it!=payList.constEnd(); it++) {
QJsonObject payObj;
payObj[ServerProps(PosProps.Amount)] = it->load()->payAmount();
payObj[ServerProps(PosProps.TransId)] = it->load()->transId();
......
......@@ -44,7 +44,7 @@ void TaskQRRefund::packagePOSReq()
}
QSharedPointer<Pay> refundPay;
PayList pays = _order->payList();
LazyPayList pays = _order->payList();
foreach (auto payLazyPointer, pays) {
//! WARNING: 临时的找第三方支付的方法
if(payLazyPointer.load()->transId() != orderId) {
......
......@@ -103,4 +103,46 @@ TEST_F(TestDBQuery, T_GetLastStoreInfo)
EXPECT_EQ(newLastSi->businessDate(), newSi.businessDate());
}
TEST_F(TestDBQuery, GetCanRefund)
{
try {
odb::transaction t(DBSP()->begin());
QSharedPointer<StoreInfo> storeInfo(new StoreInfo);
storeInfo->setStoreId("99999");
DBSP()->persist(storeInfo);
ASSERT_NE(storeInfo->id(), 1);
QSharedPointer<Order> order(new Order());
order->setOrderAmount(500);
order->setPaidAmount(350);
order->setStoreInfo(storeInfo);
DBSP()->persist(order);
ASSERT_NE(order->id(), 1);
// 插入5个支付,其中一个已经全部退款
for(int i=0; i<5; i++) {
QSharedPointer<Pay> pay(new Pay());
pay->setOrder(order);
pay->setPayAmount(100);
if(i==0) {
pay->setRefundAmount(100);
} else if(i==1) {
pay->setRefundAmount(50);
}
DBSP()->persist(pay);
ASSERT_NE(pay->id(), 1);
}
DBSP()->reload(order);
ASSERT_EQ(order->payList().size(), 5);
PayList pays = order->getCanRefundPatList();
ASSERT_EQ(pays.size(), 4);
EXPECT_EQ(pays.first()->refundAmount(), 50);
t.commit();
} catch (const odb::exception& e) {
FAIL() << "Exception: " << e.what() << std::endl;
}
}
#endif // TST_DB_QUERY_H
......@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 49
#define VER_BUILD 50
//! Convert version numbers to string
#define _STR(S) #S
......
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