diff --git a/modules/EcommerceFinance/Repositories/GoodsProfitAfsRepository.php b/modules/EcommerceFinance/Repositories/GoodsProfitAfsRepository.php index 780b1776..214a822b 100644 --- a/modules/EcommerceFinance/Repositories/GoodsProfitAfsRepository.php +++ b/modules/EcommerceFinance/Repositories/GoodsProfitAfsRepository.php @@ -101,7 +101,7 @@ class GoodsProfitAfsRepository $query = $this->filtered($filters, $columns)->select($select); if ($orderColumn !== null) { - $query->orderByDesc($orderColumn); + $query->orderByRaw("STR_TO_DATE(REPLACE(`{$orderColumn}`, '/', '-'), '%Y-%m-%d %H:%i:%s') desc"); } $records = $query->orderByDesc('id')->forPage($page, $limit + 1)->get(); @@ -143,12 +143,17 @@ class GoodsProfitAfsRepository $sku = trim((string) ($filters['sku_id'] ?? '')); $shops = array_values(array_filter((array) ($filters['shop_names'] ?? []), static fn ($v) => trim((string) $v) !== '')); - if ($from !== '' && isset($columns['order_time'])) { - $query->where($columns['order_time'], '>=', $from . ' 00:00:00'); - } + // 原表的订单时间是字符串(如 2026/8/23 14:58:51,不补零),不能直接和 ISO 日期做字符串比较。 + if (($from !== '' || $to !== '') && isset($columns['order_time'])) { + $expression = "STR_TO_DATE(REPLACE(`{$columns['order_time']}`, '/', '-'), '%Y-%m-%d %H:%i:%s')"; - if ($to !== '' && isset($columns['order_time'])) { - $query->where($columns['order_time'], '<=', $to . ' 23:59:59'); + if ($from !== '') { + $query->whereRaw($expression . ' >= ?', [$from . ' 00:00:00']); + } + + if ($to !== '') { + $query->whereRaw($expression . ' <= ?', [$to . ' 23:59:59']); + } } if ($shops !== [] && isset($columns['shop_name'])) {