作者 陈志颖

refactor:优化分红订单查询

@@ -24,6 +24,8 @@ type ListDividendsIncentivesEstimateQuery struct { @@ -24,6 +24,8 @@ type ListDividendsIncentivesEstimateQuery struct {
24 UserId int64 `cname:"用户ID" json:"userId"` 24 UserId int64 `cname:"用户ID" json:"userId"`
25 // 用户基础数据id 25 // 用户基础数据id
26 UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId"` 26 UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId"`
  27 + // 分红状态
  28 + OrderGoodDividendsStatus int32 `cname:"分红状态" json:"orderGoodDividendsStatus,omitempty"`
27 } 29 }
28 30
29 func (listDividendsIncentivesEstimateQuery *ListDividendsIncentivesEstimateQuery) Valid(validation *validation.Validation) { 31 func (listDividendsIncentivesEstimateQuery *ListDividendsIncentivesEstimateQuery) Valid(validation *validation.Validation) {
@@ -28,6 +28,8 @@ type SearchDividendsIncentivesEstimateQuery struct { @@ -28,6 +28,8 @@ type SearchDividendsIncentivesEstimateQuery struct {
28 PageNumber int64 `cname:"页码" json:"pageNumber,omitempty"` 28 PageNumber int64 `cname:"页码" json:"pageNumber,omitempty"`
29 // 页面大小 29 // 页面大小
30 PageSize int64 `cname:"页面大小" json:"pageSize,omitempty"` 30 PageSize int64 `cname:"页面大小" json:"pageSize,omitempty"`
  31 + // 分红状态
  32 + OrderGoodDividendsStatus int32 `cname:"分红状态" json:"orderGoodDividendsStatus,omitempty"`
31 } 33 }
32 34
33 func (searchDividendsIncentivesEstimateQuery *SearchDividendsIncentivesEstimateQuery) Valid(validation *validation.Validation) { 35 func (searchDividendsIncentivesEstimateQuery *SearchDividendsIncentivesEstimateQuery) Valid(validation *validation.Validation) {
@@ -68,6 +68,7 @@ func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentive @@ -68,6 +68,7 @@ func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentive
68 } 68 }
69 69
70 // 获取订单产品 70 // 获取订单产品
  71 + listDividendsIncentivesEstimateQuery.OrderGoodDividendsStatus = int32(1)
71 if count, orderGoods, err := orderGoodRepository.Find(tool_funs.SimpleStructToMap(listDividendsIncentivesEstimateQuery)); err != nil { 72 if count, orderGoods, err := orderGoodRepository.Find(tool_funs.SimpleStructToMap(listDividendsIncentivesEstimateQuery)); err != nil {
72 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 73 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
73 } else { 74 } else {
@@ -77,8 +78,8 @@ func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentive @@ -77,8 +78,8 @@ func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentive
77 if orderGood.DividendsOrderNumber != "" { // 查询分红订单 78 if orderGood.DividendsOrderNumber != "" { // 查询分红订单
78 dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{ 79 dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{
79 "dividendsOrderNumber": orderGood.DividendsOrderNumber, 80 "dividendsOrderNumber": orderGood.DividendsOrderNumber,
80 - "companyId": orderGood.CompanyId,  
81 - "orgId": orderGood.OrgId, 81 + "companyId": listDividendsIncentivesEstimateQuery.CompanyId,
  82 + "orgId": listDividendsIncentivesEstimateQuery.OrgId,
82 }) 83 })
83 if err != nil { 84 if err != nil {
84 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 85 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -92,8 +93,8 @@ func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentive @@ -92,8 +93,8 @@ func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentive
92 dividendsIncentivesEstimateDtos = append(dividendsIncentivesEstimateDtos, dividendsIncentivesEstimateDto) 93 dividendsIncentivesEstimateDtos = append(dividendsIncentivesEstimateDtos, dividendsIncentivesEstimateDto)
93 } else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单 94 } else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单
94 dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{ 95 dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{
95 - "companyId": orderGood.CompanyId,  
96 - "orgId": orderGood.OrgId, 96 + "companyId": listDividendsIncentivesEstimateQuery.CompanyId,
  97 + "orgId": listDividendsIncentivesEstimateQuery.OrgId,
97 "dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber, 98 "dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber,
98 }) 99 })
99 if err != nil { 100 if err != nil {
@@ -1283,6 +1284,7 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti @@ -1283,6 +1284,7 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti
1283 } 1284 }
1284 1285
1285 // 获取订单产品 1286 // 获取订单产品
  1287 + searchDividendsIncentivesEstimateQuery.OrderGoodDividendsStatus = int32(1) // 查询带分红的产品
1286 if count, orderGoods, err := orderGoodRepository.Find(tool_funs.SimpleStructToMap(searchDividendsIncentivesEstimateQuery)); err != nil { 1288 if count, orderGoods, err := orderGoodRepository.Find(tool_funs.SimpleStructToMap(searchDividendsIncentivesEstimateQuery)); err != nil {
1287 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1289 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1288 } else { 1290 } else {
@@ -1292,14 +1294,16 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti @@ -1292,14 +1294,16 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti
1292 if orderGood.DividendsOrderNumber != "" { // 查询分红订单 1294 if orderGood.DividendsOrderNumber != "" { // 查询分红订单
1293 dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{ 1295 dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{
1294 "dividendsOrderNumber": orderGood.DividendsOrderNumber, 1296 "dividendsOrderNumber": orderGood.DividendsOrderNumber,
1295 - "companyId": orderGood.CompanyId,  
1296 - "orgId": orderGood.OrgId, 1297 + "companyId": searchDividendsIncentivesEstimateQuery.CompanyId,
  1298 + "orgId": searchDividendsIncentivesEstimateQuery.OrgId,
1297 }) 1299 })
1298 if err != nil { 1300 if err != nil {
1299 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1301 + continue
  1302 + //return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1300 } 1303 }
1301 if dividendsOrder == nil { 1304 if dividendsOrder == nil {
1302 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsOrderNumber)) 1305 + continue
  1306 + //return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsOrderNumber))
1303 } 1307 }
1304 if err := dividendsIncentivesEstimateDto.LoadDto(orderGood, dividendsOrder.DividendsOrderNumber, dividendsOrder.DividendsOriginalOrderNum, dividendsOrder.CustomerName, dividendsOrder.Region.RegionName, dividendsOrder.OrderTime); err != nil { 1308 if err := dividendsIncentivesEstimateDto.LoadDto(orderGood, dividendsOrder.DividendsOrderNumber, dividendsOrder.DividendsOriginalOrderNum, dividendsOrder.CustomerName, dividendsOrder.Region.RegionName, dividendsOrder.OrderTime); err != nil {
1305 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1309 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -1308,14 +1312,16 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti @@ -1308,14 +1312,16 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti
1308 } else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单 1312 } else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单
1309 dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{ 1313 dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{
1310 "dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber, 1314 "dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber,
1311 - "companyId": orderGood.CompanyId,  
1312 - "orgId": orderGood.OrgId, 1315 + "companyId": searchDividendsIncentivesEstimateQuery.CompanyId,
  1316 + "orgId": searchDividendsIncentivesEstimateQuery.OrgId,
1313 }) 1317 })
1314 if err != nil { 1318 if err != nil {
1315 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1319 + continue
  1320 + //return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1316 } 1321 }
1317 if dividendsReturnedOrder == nil { 1322 if dividendsReturnedOrder == nil {
1318 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber)) 1323 + continue
  1324 + //return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber))
1319 } 1325 }
1320 if err := dividendsIncentivesEstimateDto.LoadDto(orderGood, dividendsReturnedOrder.DividendsReturnedOrderNumber, dividendsReturnedOrder.OriginalOrderNum, dividendsReturnedOrder.DividendsReturnedCustomerName, dividendsReturnedOrder.Region.RegionName, dividendsReturnedOrder.OrderTime); err != nil { 1326 if err := dividendsIncentivesEstimateDto.LoadDto(orderGood, dividendsReturnedOrder.DividendsReturnedOrderNumber, dividendsReturnedOrder.OriginalOrderNum, dividendsReturnedOrder.DividendsReturnedCustomerName, dividendsReturnedOrder.Region.RegionName, dividendsReturnedOrder.OrderTime); err != nil {
1321 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1327 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -203,6 +203,9 @@ func (repository *OrderGoodRepository) Find(queryOptions map[string]interface{}) @@ -203,6 +203,9 @@ func (repository *OrderGoodRepository) Find(queryOptions map[string]interface{})
203 return q, nil 203 return q, nil
204 }) 204 })
205 } 205 }
  206 + if orderGoodDividendsStatus, ok := queryOptions["orderGoodDividendsStatus"]; ok && orderGoodDividendsStatus.(int32) != 0 {
  207 + query.Where("order_good_dividends_status = ?", orderGoodDividendsStatus)
  208 + }
206 if orderGoodIds, ok := queryOptions["orderGoodIds"]; ok && len(orderGoodIds.([]int64)) > 0 { 209 if orderGoodIds, ok := queryOptions["orderGoodIds"]; ok && len(orderGoodIds.([]int64)) > 0 {
207 query.Where("order_good_id IN (?)", pg.In(orderGoodIds)) 210 query.Where("order_good_id IN (?)", pg.In(orderGoodIds))
208 } 211 }