From 6af77903cc86c01836875c9e0bbd2770de329810 Mon Sep 17 00:00:00 2001 From: renshen <1005457301@qq.com> Date: Wed, 21 Oct 2026 22:22:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=A9=E6=B6=A6=E9=95=9C?= =?UTF-8?q?=E5=83=8F=EF=BC=9A=E8=AE=A2=E5=8D=95=E6=97=B6=E9=97=B4=E6=8C=89?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=97=A5=E6=9C=9F=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=90=8E=E5=86=8D=E7=AD=9B=E9=80=89=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/GoodsProfitAfsRepository.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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'])) { -- 2.47.2