gpt4 book ai didi

php - 按日期和余额排序银行移动

转载 作者:行者123 更新时间:2023-11-29 05:49:31 25 4
gpt4 key购买 nike

我有一个包含银行变动的表格,我正在从 csv 和 json 文件中导入这些变动,每个变动旁边都有一个金额和一个余额。

+------------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| cuenta_banco_id | int(11) | NO | | NULL | |
| referencia | varchar(191) | NO | | NULL | |
| monto | decimal(10,2) | NO | | NULL | |
| saldo | decimal(10,2) | NO | | NULL | |
| type | int(11) | NO | | NULL | |
| user_id | int(11) | NO | | NULL | |
| fecha_movimiento | datetime | NO | | NULL | |
| created_at | timestamp | YES | | NULL | |
| updated_at | timestamp | YES | | NULL | |
+------------------+------------------+------+-----+---------+----------------+
10 rows in set (0.08 sec)

{
"Date": "22/04/2019",
"Operation": "MC",
"Reference": "15",
"Description": "TRANSF. VIA INTERNET ",
"Amount": "10000.00",
"Balance": "1869255.04"
}

文件正在完全导入数据库,问题是我需要在显示数据时正确排序

我需要按日期降序显示变动,但也需要正确显示余额。

我需要的例子:

enter image description here

这就是我获得运动的方式:

+------+-----------------+-------------+------------+-----------+------+---------+---------------------+---------------------+---------------------+
| id | cuenta_banco_id | referencia | monto | saldo | type | user_id | fecha_movimiento | created_at | updated_at |
+------+-----------------+-------------+------------+-----------+------+---------+---------------------+---------------------+---------------------+
| 3367 | 4 | 2297353555 | 10000.00 | 665445.90 | 0 | 1 | 2019-04-20 23:59:59 | 2019-04-20 18:15:33 | 2019-04-20 18:15:33 |
| 3366 | 4 | 2297322435 | 11000.00 | 655445.90 | 0 | 1 | 2019-04-20 23:59:59 | 2019-04-20 18:15:33 | 2019-04-20 18:15:33 |
| 3398 | 4 | 2297751229 | 11000.00 | 651695.90 | 0 | 1 | 2019-04-20 23:59:59 | 2019-04-20 18:15:34 | 2019-04-20 18:15:34 |
| 3362 | 4 | 2297311718 | 12000.00 | 651445.90 | 0 | 1 | 2019-04-20 23:59:59 | 2019-04-20 18:15:33 | 2019-04-20 18:15:33 |
| 3343 | 4 | 2296877327 | 10000.00 | 649845.90 | 0 | 1 | 2019-04-20 23:59:59 | 2019-04-20 18:15:33 | 2019-04-20 18:15:33 |
| 3365 | 4 | 2297317974 | -525000.00 | 644445.90 | 0 | 1 | 2019-04-20 23:59:59 | 2019-04-20 18:15:33 | 2019-04-20 18:15:33 |
| 3431 | 4 | 2298293430 | 13000.00 | 643195.90 | 0 | 1 | 2019-04-20 23:59:59 | 2019-04-20 18:15:35 | 2019-04-20 18:15:35 |
| 3397 | 4 | 2297748073 | 15900.00 | 640695.90 | 0 | 1 | 2019-04-20 23:59:59 | 2019-04-20 18:15:34 | 2019-04-20 18:15:34 |
| 3342 | 4 | 2296823905 | 30000.00 | 639845.90 | 0 | 1 | 2019-04-20 23:59:59 | 2019-04-20 18:15:33 | 2019-04-20 18:15:33 |
| 3361 | 4 | 64665863950 | 500000.00 | 639445.90 | 0 | 1 | 2019-04-20 23:59:59 | 2019-04-20 18:15:33 | 2019-04-20 18:15:33 |
+------+-----------------+-------------+------------+-----------+------+---------+---------------------+---------------------+---------------------+
10 rows in set (0.00 sec)

字段 cuenta_banco_id 标识拥有 movements 的银行,但不同银行的 movements 之间没有关系。

这是在 Laravel 5.7 和 MySQL 5.7.23 上,我使用的查询是:

$movimientos = Movimiento::query();
$movimientos->where('cuenta_banco_id', $request->banco);
$movimientos->whereBetween(DB::raw('date(fecha_movimiento)'), [$start->startOfDay()->format('Y-m-d H:i:s'), $end->endOfDay()->format('Y-m-d H:i:s')]);
$movimientos->with('recargas', 'banks', 'recargas.transactions', 'movimientos_detalles', 'recargas.transactions.siteuser');
$movimientos->orderBy('created_at', 'DESC');
$movimientos = $movimientos->paginate(50);

我怎样才能达到我的需要?

最佳答案

据我了解,您的交易纯粹是根据时间排序的(即,transaction_date DESC,然后是 created_time ASC)。并且由于你在银行ID上使用了where子句,我们这里只查看单个银行的交易(我不清楚它是否涵盖所有用户的交易。如果是这样,我们需要在申请前按用户划分订购方式)。假设“fecha_movimiento”捕获交易日期,“id”捕获交易顺序,您可以尝试这样的操作:

$movimientos->orderBy(DB::raw('date(fecha_movimiento)'), 'DESC')
->orderBy('id','ASC');

关于php - 按日期和余额排序银行移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55779086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com