This commit is contained in:
邹宗楠
2026-01-09 17:12:23 +08:00
parent 752e23e836
commit 0a8a2ef523

View File

@@ -1753,6 +1753,9 @@ func StatisticsFineFee(db *DaoDB, startTime, endTime time.Time, storeId []int) (
// StatisticsSettlement 统计京西门店结算信息
func StatisticsSettlement(db *DaoDB, storeId []int, start, end time.Time, vendorId []int, size, offset int, rank string) (pagedInfo *model.PagedInfo, err error) {
var (
fields []string
)
sql := `
SELECT
SQL_CALC_FOUND_ROWS
@@ -1821,7 +1824,7 @@ func StatisticsSettlement(db *DaoDB, storeId []int, start, end time.Time, vendor
u_operator1.name, u_operator2.name, u_operator3.name,
s.jx_brand_fee_factor, s.market_add_fee_factor, s.pay_percentage, s.package_setting `
if rank != "" {
fields := strings.Split(rank, ",")
fields = strings.Split(rank, ",")
sql += fmt.Sprintf(` ORDER BY %s %s `, fields[0], fields[1])
} else {
sql += fmt.Sprintf(`ORDER BY order_count desc`)
@@ -1856,6 +1859,21 @@ func StatisticsSettlement(db *DaoDB, storeId []int, start, end time.Time, vendor
v.Profit = v.JxIncome + v.MarketIncome + float64(v.PackageSetting)
}
}
sortWay := SortOption{}
if len(fields) != 0 {
sortWay.Field = fields[0]
switch fields[1] {
case "ASC", "asc":
sortWay.Ascending = true
case "DESC", "desc":
sortWay.Ascending = false
default:
sortWay.Ascending = false
}
}
SortSettlement(msgList, nil, sortWay)
pagedInfo = &model.PagedInfo{
TotalCount: GetLastTotalRowCount2(db, txDB),
Data: msgList,
@@ -1865,6 +1883,9 @@ func StatisticsSettlement(db *DaoDB, storeId []int, start, end time.Time, vendor
// StatisticsSettlementByCity 根据城市统计结算
func StatisticsSettlementByCity(db *DaoDB, cityCode []string, start, end time.Time, vendorId []int, size, offset int, rank string) (pagedInfo *model.PagedInfo, err error) {
var (
fields []string
)
sql := `
SELECT
SQL_CALC_FOUND_ROWS
@@ -1909,7 +1930,7 @@ func StatisticsSettlementByCity(db *DaoDB, cityCode []string, start, end time.Ti
sql += ` GROUP BY p.name,u.name, u.mobile,s.id `
if rank != "" {
fields := strings.Split(rank, ",")
fields = strings.Split(rank, ",")
sql += fmt.Sprintf(` ORDER BY %s %s `, fields[0], fields[1])
} else {
sql += fmt.Sprintf(`ORDER BY order_count desc`)
@@ -1941,9 +1962,120 @@ func StatisticsSettlementByCity(db *DaoDB, cityCode []string, start, end time.Ti
}
}
sortWay := SortOption{}
if len(fields) != 0 {
sortWay.Field = fields[0]
switch fields[1] {
case "ASC", "asc":
sortWay.Ascending = true
case "DESC", "desc":
sortWay.Ascending = false
default:
sortWay.Ascending = false
}
}
SortSettlement(nil, msgList, sortWay)
pagedInfo = &model.PagedInfo{
TotalCount: GetLastTotalRowCount2(db, txDB),
Data: msgList,
}
return pagedInfo, nil
}
// SortOption 排序选项
type SortOption struct {
Field string
Ascending bool // true 升序
//ThenBy *SortOption // 用于多级排序
}
func SortSettlement(store []*model.JxSettlementInfo, code []*model.SettlementByCityCode, option SortOption) {
if store != nil {
sort.Slice(store, func(i, j int) bool {
return compareByStore(store[i], store[j], option)
})
} else if code != nil {
sort.Slice(code, func(i, j int) bool {
return compareByCode(code[i], code[j], option)
})
}
}
func compareByStore(a, b *model.JxSettlementInfo, option SortOption) bool {
var result bool
switch option.Field {
case "order_count":
result = a.OrderCount < b.OrderCount
case "package_setting":
result = a.PackageSetting < b.PackageSetting
case "total_desired_fee":
result = a.TotalDesiredFee < b.TotalDesiredFee
case "refund_money":
result = a.RefundMoney < b.RefundMoney
case "total_shop_money":
result = a.TotalShopMoney < b.TotalShopMoney
case "platform_income":
result = a.PlatformIncome < b.PlatformIncome
case "store_income":
result = a.StoreIncome < b.StoreIncome
case "jx_income":
result = a.JxIncome < b.JxIncome
case "market_income":
result = a.MarketIncome < b.MarketIncome
default:
result = a.OrderCount < b.OrderCount
}
// 处理降序
if !option.Ascending {
result = !result
}
// 如果相等且有下一级排序,则继续比较
//if result == false && a.FirstName == b.FirstName && option.ThenBy != nil {
// return comparePeople(a, b, *option.ThenBy)
//}
return result
}
func compareByCode(a, b *model.SettlementByCityCode, option SortOption) bool {
var result bool
switch option.Field {
case "order_count":
result = a.OrderCount < b.OrderCount
case "package_setting":
result = a.PackageSetting < b.PackageSetting
case "total_desired_fee":
result = a.TotalDesiredFee < b.TotalDesiredFee
case "refund_money":
result = a.RefundMoney < b.RefundMoney
case "total_shop_money":
result = a.TotalShopMoney < b.TotalShopMoney
case "platform_income":
result = a.PlatformIncome < b.PlatformIncome
case "store_income":
result = a.StoreInCome < b.StoreInCome
case "jx_income":
result = a.JxIncome < b.JxIncome
case "market_income":
result = a.MarketIncome < b.MarketIncome
default:
result = a.OrderCount < b.OrderCount
}
// 处理降序
if !option.Ascending {
result = !result
}
// 如果相等且有下一级排序,则继续比较
//if result == false && a.FirstName == b.FirstName && option.ThenBy != nil {
// return comparePeople(a, b, *option.ThenBy)
//}
return result
}