作者 陈志颖

refactor:优化分红订单查询

... ... @@ -24,6 +24,8 @@ type ListDividendsIncentivesEstimateQuery struct {
UserId int64 `cname:"用户ID" json:"userId"`
// 用户基础数据id
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId"`
// 分红状态
OrderGoodDividendsStatus int32 `cname:"分红状态" json:"orderGoodDividendsStatus,omitempty"`
}
func (listDividendsIncentivesEstimateQuery *ListDividendsIncentivesEstimateQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -28,6 +28,8 @@ type SearchDividendsIncentivesEstimateQuery struct {
PageNumber int64 `cname:"页码" json:"pageNumber,omitempty"`
// 页面大小
PageSize int64 `cname:"页面大小" json:"pageSize,omitempty"`
// 分红状态
OrderGoodDividendsStatus int32 `cname:"分红状态" json:"orderGoodDividendsStatus,omitempty"`
}
func (searchDividendsIncentivesEstimateQuery *SearchDividendsIncentivesEstimateQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -68,6 +68,7 @@ func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentive
}
// 获取订单产品
listDividendsIncentivesEstimateQuery.OrderGoodDividendsStatus = int32(1)
if count, orderGoods, err := orderGoodRepository.Find(tool_funs.SimpleStructToMap(listDividendsIncentivesEstimateQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -77,8 +78,8 @@ func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentive
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": orderGood.DividendsOrderNumber,
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
"companyId": listDividendsIncentivesEstimateQuery.CompanyId,
"orgId": listDividendsIncentivesEstimateQuery.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -92,8 +93,8 @@ func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentive
dividendsIncentivesEstimateDtos = append(dividendsIncentivesEstimateDtos, dividendsIncentivesEstimateDto)
} else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单
dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
"companyId": listDividendsIncentivesEstimateQuery.CompanyId,
"orgId": listDividendsIncentivesEstimateQuery.OrgId,
"dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber,
})
if err != nil {
... ... @@ -1283,6 +1284,7 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti
}
// 获取订单产品
searchDividendsIncentivesEstimateQuery.OrderGoodDividendsStatus = int32(1) // 查询带分红的产品
if count, orderGoods, err := orderGoodRepository.Find(tool_funs.SimpleStructToMap(searchDividendsIncentivesEstimateQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -1292,14 +1294,16 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": orderGood.DividendsOrderNumber,
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
"companyId": searchDividendsIncentivesEstimateQuery.CompanyId,
"orgId": searchDividendsIncentivesEstimateQuery.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
continue
//return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if dividendsOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsOrderNumber))
continue
//return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsOrderNumber))
}
if err := dividendsIncentivesEstimateDto.LoadDto(orderGood, dividendsOrder.DividendsOrderNumber, dividendsOrder.DividendsOriginalOrderNum, dividendsOrder.CustomerName, dividendsOrder.Region.RegionName, dividendsOrder.OrderTime); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -1308,14 +1312,16 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti
} else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单
dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{
"dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber,
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
"companyId": searchDividendsIncentivesEstimateQuery.CompanyId,
"orgId": searchDividendsIncentivesEstimateQuery.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
continue
//return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if dividendsReturnedOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber))
continue
//return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber))
}
if err := dividendsIncentivesEstimateDto.LoadDto(orderGood, dividendsReturnedOrder.DividendsReturnedOrderNumber, dividendsReturnedOrder.OriginalOrderNum, dividendsReturnedOrder.DividendsReturnedCustomerName, dividendsReturnedOrder.Region.RegionName, dividendsReturnedOrder.OrderTime); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
... ... @@ -203,6 +203,9 @@ func (repository *OrderGoodRepository) Find(queryOptions map[string]interface{})
return q, nil
})
}
if orderGoodDividendsStatus, ok := queryOptions["orderGoodDividendsStatus"]; ok && orderGoodDividendsStatus.(int32) != 0 {
query.Where("order_good_dividends_status = ?", orderGoodDividendsStatus)
}
if orderGoodIds, ok := queryOptions["orderGoodIds"]; ok && len(orderGoodIds.([]int64)) > 0 {
query.Where("order_good_id IN (?)", pg.In(orderGoodIds))
}
... ...