...
|
...
|
@@ -22,19 +22,137 @@ func NewOrderRepository(transactionContext *transaction.TransactionContext) (*Or |
|
|
}
|
|
|
return &OrderRepository{transactionContext: transactionContext}, nil
|
|
|
}
|
|
|
func (reponsitory OrderRepository) transformPgModelToDomainModel(adminuserModel *models.Order) (domain.Order, error) {
|
|
|
result := domain.Order{}
|
|
|
|
|
|
func (reponsitory OrderRepository) transformPgModelToDomainModel(orderModel *models.Order) (domain.Order, error) {
|
|
|
result := domain.Order{
|
|
|
Id: orderModel.Id,
|
|
|
OrderType: orderModel.OrderType,
|
|
|
OrderCode: orderModel.OrderCode,
|
|
|
OrderName: orderModel.OrderName,
|
|
|
OrderStatus: orderModel.OrderStatus,
|
|
|
OrderCount: orderModel.OrderCount,
|
|
|
OrderActualCount: orderModel.OrderActualCount,
|
|
|
OrderAmount: orderModel.OrderAmount,
|
|
|
OrderActualAmount: orderModel.OrderActualAmount,
|
|
|
OrderPaymentAmount: orderModel.OrderPaymentAmount,
|
|
|
OrderRegionInfo: orderModel.OrderRegionInfo,
|
|
|
Buyer: orderModel.Buyer,
|
|
|
PartnerInfo: &domain.Partner{
|
|
|
Id: orderModel.PartnerId,
|
|
|
},
|
|
|
PartnerBonusPercent: orderModel.PartnerBonusPercent,
|
|
|
SalesmanBonusPercent: orderModel.SalesmanBonusPercent,
|
|
|
LastViewTime: orderModel.LastViewTime,
|
|
|
UpdateAt: orderModel.UpdateAt,
|
|
|
CreateAt: orderModel.CreateAt,
|
|
|
}
|
|
|
return result, nil
|
|
|
}
|
|
|
|
|
|
func (repository OrderRepository) Save(orderInfo *domain.Order) error {
|
|
|
return nil
|
|
|
var (
|
|
|
err error
|
|
|
tx = repository.transactionContext.PgTx
|
|
|
)
|
|
|
m := &models.Order{
|
|
|
Id: orderInfo.Id,
|
|
|
OrderType: orderInfo.OrderType,
|
|
|
OrderCode: orderInfo.OrderCode,
|
|
|
OrderName: orderInfo.OrderName,
|
|
|
OrderStatus: orderInfo.OrderStatus,
|
|
|
OrderCount: orderInfo.OrderCount,
|
|
|
OrderActualCount: orderInfo.OrderActualCount,
|
|
|
OrderAmount: orderInfo.OrderAmount,
|
|
|
OrderActualAmount: orderInfo.OrderActualAmount,
|
|
|
OrderPaymentAmount: orderInfo.OrderPaymentAmount,
|
|
|
OrderRegionInfo: orderInfo.OrderRegionInfo,
|
|
|
Buyer: orderInfo.Buyer,
|
|
|
PartnerId: orderInfo.PartnerInfo.Id,
|
|
|
PartnerBonusPercent: orderInfo.PartnerBonusPercent,
|
|
|
SalesmanBonusPercent: orderInfo.SalesmanBonusPercent,
|
|
|
CreateAt: orderInfo.CreateAt,
|
|
|
UpdateAt: orderInfo.UpdateAt,
|
|
|
LastViewTime: orderInfo.LastViewTime,
|
|
|
}
|
|
|
if m.Id == 0 {
|
|
|
err = tx.Insert(m)
|
|
|
orderInfo.Id = m.Id
|
|
|
} else {
|
|
|
err = tx.Update(m)
|
|
|
}
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
func (repository OrderRepository) Find() (*domain.Order, error) {
|
|
|
return nil, nil
|
|
|
func (repository OrderRepository) Find(queryOption domain.OrderFindQuery) ([]domain.Order, error) {
|
|
|
db := repository.transactionContext.PgDd
|
|
|
orderModels := []models.Order{}
|
|
|
query := db.Model(&orderModels)
|
|
|
|
|
|
if queryOption.PartnerId > 0 {
|
|
|
query = query.Where("order.partner_id=?", queryOption.PartnerId)
|
|
|
}
|
|
|
if len(queryOption.OrderCode) > 0 {
|
|
|
query = query.Where("order.order_code like ?", "%"+queryOption.OrderCode+"%")
|
|
|
}
|
|
|
if queryOption.Offset > -1 {
|
|
|
query = query.Offset(queryOption.Offset)
|
|
|
}
|
|
|
if queryOption.Limit > 0 {
|
|
|
query = query.Limit(queryOption.Limit)
|
|
|
} else {
|
|
|
query = query.Limit(20)
|
|
|
}
|
|
|
var (
|
|
|
err error
|
|
|
ordersReturn = make([]domain.Order, 0)
|
|
|
)
|
|
|
query = query.Order("order.id DESC ")
|
|
|
err = query.Select()
|
|
|
if err != nil {
|
|
|
return ordersReturn, err
|
|
|
}
|
|
|
for i := range orderModels {
|
|
|
domainOrder, err := repository.transformPgModelToDomainModel(&orderModels[i])
|
|
|
if err != nil {
|
|
|
return ordersReturn, err
|
|
|
}
|
|
|
ordersReturn = append(ordersReturn, domainOrder)
|
|
|
}
|
|
|
return ordersReturn, nil
|
|
|
}
|
|
|
|
|
|
func (repository OrderRepository) CountAll(queryOption domain.OrderFindQuery) (int, error) {
|
|
|
db := repository.transactionContext.PgDd
|
|
|
orderModels := []models.Order{}
|
|
|
query := db.Model(&orderModels)
|
|
|
if queryOption.PartnerId > 0 {
|
|
|
query = query.Where("order.partner_id=?", queryOption.PartnerId)
|
|
|
}
|
|
|
if len(queryOption.OrderCode) > 0 {
|
|
|
query = query.Where("order.order_code like ?", "%"+queryOption.OrderCode+"%")
|
|
|
}
|
|
|
var (
|
|
|
err error
|
|
|
)
|
|
|
cnt, err := query.Count()
|
|
|
if err != nil {
|
|
|
return cnt, err
|
|
|
}
|
|
|
return 0, nil
|
|
|
}
|
|
|
|
|
|
func (repository OrderRepository) FindOne() ([]domain.Order, error) {
|
|
|
return nil, nil
|
|
|
func (repository OrderRepository) FindOne(qureyOptions domain.OrderFindOneQuery) (*domain.Order, error) {
|
|
|
var (
|
|
|
err error
|
|
|
tx = repository.transactionContext.PgTx
|
|
|
)
|
|
|
m := new(models.Order)
|
|
|
err = tx.Model(m).
|
|
|
Where("id=?", qureyOptions.OrderId).
|
|
|
First()
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
result, err := repository.transformPgModelToDomainModel(m)
|
|
|
return &result, err
|
|
|
} |
...
|
...
|
|