163 lines
5.7 KiB
PHP
163 lines
5.7 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Models\OrderProfit;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
use App\Admin\Extensions\Grid\Tools\ProfitBatchSuccess;
|
|
use App\Enums\PayWay;
|
|
use App\Models\Agent;
|
|
use Carbon\Carbon;
|
|
use Dcat\Admin\Admin;
|
|
|
|
class OrderProfitController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(OrderProfit::with(['order', 'user', 'fromUser']), function (Grid $grid) {
|
|
|
|
$grid->model()->latest('created_at');
|
|
|
|
$grid->disableViewButton(false);
|
|
|
|
$grid->column('order.sn')->link(fn() => admin_url('orders', ['id' => $this->order_id]));
|
|
$grid->column('fromUser.phone');
|
|
$grid->column('user.phone');
|
|
$grid->column('role_name');
|
|
$grid->column('growth_value');
|
|
$grid->column('ratio')->display(function ($v) {
|
|
return $v . '%';
|
|
});
|
|
$grid->column('money');
|
|
$grid->column('status')->using(OrderProfit::$statusMap)->dot(OrderProfit::$statusColor);
|
|
$grid->column('created_at');
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->panel();
|
|
$filter->like('order.sn')->width(3);
|
|
$filter->like('fromUser.phone')->width(3);
|
|
$filter->like('user.phone')->width(3);
|
|
$filter->equal('status')->select(OrderProfit::$statusMap)->width(3);
|
|
$filter->where('role_name', fn($q) => $q->role($this->input))->select(Agent::$typeMap)->width(3);
|
|
$filter->whereBetween('created_at', function ($q) {
|
|
$start = data_get($this->input, 'start');
|
|
$start = $start ? Carbon::createFromFormat('Y-m-d', $start) : null;
|
|
$end = data_get($this->input, 'end');
|
|
$end = $end ? Carbon::createFromFormat('Y-m-d', $end) : null;
|
|
if ($start) {
|
|
if ($end) {
|
|
$q->whereBetween('created_at', [$start, $end]);
|
|
}
|
|
$q->where('created_at', '>=', $start);
|
|
} else if ($end) {
|
|
$q->where('created_at', '<=', $end);
|
|
}
|
|
})->date()->width(6);
|
|
});
|
|
|
|
$grid->showRowSelector();
|
|
$grid->batchActions(function (Grid\Tools\BatchActions $batch) {
|
|
$batch->disableDelete();
|
|
if (Admin::user()->can('dcat.admin.profit.pay')) {
|
|
$batch->add(new ProfitBatchSuccess());
|
|
}
|
|
});
|
|
|
|
$grid->footer(function ($collection) use ($grid) {
|
|
$query = OrderProfit::query();
|
|
$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'] ?? []);
|
|
});
|
|
$money = number_format($query->sum('money'), 2);
|
|
return <<<HTML
|
|
<table class="table table-bordered">
|
|
<tbody>
|
|
<tr>
|
|
<td>统计</td>
|
|
<td>收益金额: $money</td>
|
|
<tr>
|
|
</tbody>
|
|
</table>
|
|
HTML;
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, OrderProfit::with(['order', 'user', 'fromUser']), function (Show $show) {
|
|
$show->field('id');
|
|
$show->field('order.sn');
|
|
$show->field('from_user.phone');
|
|
$show->field('user.phone');
|
|
$show->field('role_name');
|
|
$show->field('growth_value');
|
|
$show->field('ratio')->as(function ($v) {
|
|
return $v . '%';
|
|
});
|
|
$show->field('money');
|
|
$show->field('status')->using(OrderProfit::$statusMap)->dot(OrderProfit::$statusColor);
|
|
$show->field('paid_at');
|
|
$show->field('pay_way')->using([
|
|
PayWay::Offline->value => PayWay::Offline->text(),
|
|
PayWay::WxpayTransfer->value => PayWay::WxpayTransfer->text()
|
|
])->label();
|
|
$show->field('pay_no');
|
|
$show->field('remarks');
|
|
$show->field('created_at');
|
|
$show->field('updated_at');
|
|
|
|
$show->panel()->tools(function (Show\Tools $tools) use ($show) {
|
|
$tools->disableEdit();
|
|
$tools->disableDelete();
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new OrderProfit(), function (Form $form) {
|
|
$form->display('id');
|
|
$form->text('order_id');
|
|
$form->text('from_user_id');
|
|
$form->text('user_id');
|
|
$form->text('role');
|
|
$form->text('role_name');
|
|
$form->text('growth_value');
|
|
$form->text('ratio');
|
|
$form->text('money');
|
|
$form->text('status');
|
|
$form->field('pay_way');
|
|
$form->field('pay_no');
|
|
$form->field('paid_at');
|
|
|
|
$form->display('created_at');
|
|
$form->display('updated_at');
|
|
});
|
|
}
|
|
}
|