6
0
Fork 0
jiqu-library-server/app/Admin/Renderable/QuotaV1SendLogTable.php

59 lines
2.2 KiB
PHP

<?php
namespace App\Admin\Renderable;
use App\Models\QuotaV1SendLog;
use Dcat\Admin\Grid;
class QuotaV1SendLogTable extends Grid
{
public static function grid(int $jobId = null)
{
$builder = QuotaV1SendLog::with(['user']);
$grid = parent::make($builder, function (Grid $grid) {
$grid->column('user.phone', '手机号');
$grid->column('amount', '分红金额')->display(function ($value) {
return bcdiv($value, 100, 2);
})->prepend('¥');
$grid->column('status', '状态')->using(QuotaV1SendLog::$statusText)->dot([
0=>'warning',
1=>'success',
]);
$grid->column('created_at', '发放时间')->sortable();
$grid->model()->orderBy('created_at', 'desc');
$grid->filter(function (Grid\Filter $filter) {
$filter->panel();
$filter->equal('user.phone', '手机号')->width(3);
});
$grid->disableActions();
$grid->disableCreateButton();
});
if ($jobId) {
$grid->model()->where('job_id', $jobId);
}
$grid->header(function ($collection) use ($grid) {
$query = QuotaV1SendLog::query();
// 拿到表格筛选 where 条件数组进行遍历
$grid->model()->getQueries()->unique()->each(function ($value) use (&$query) {
if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) {
return;
}
$query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []);
});
// 查出统计数据
$receivedAmount = (clone $query)->where('status', QuotaV1SendLog::STATUS_SUCCESS)->sum('amount');
$failedAmount = (clone $query)->where('status', QuotaV1SendLog::STATUS_FAILED)->sum('amount');
$totalAmount = (clone $query)->sum('amount');
// 自定义组件
return "<div style='padding: 10px;'>已领取:".bcdiv($receivedAmount, 100, 2).' 元 | 未领取:'.bcdiv($failedAmount, 100, 2).' 元 | 共计:'.bcdiv($totalAmount, 100, 2).' 元</div>';
});
return $grid;
}
}