126 lines
4.0 KiB
PHP
126 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Repositories\DealerPurchaseLog;
|
|
use App\Admin\Widgets\InfoBox;
|
|
use App\Models\DealerPurchaseLog as DealerPurchaseLogModel;
|
|
use App\Models\User;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
use Dcat\Admin\Layout\Row;
|
|
use Dcat\Admin\Show;
|
|
use Illuminate\Support\Facades\Request;
|
|
|
|
class DealerPurchaseLogController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
Admin::style(
|
|
<<<CSS
|
|
.card-header {
|
|
margin-top: 1.5rem !important;
|
|
margin-bottom: -1rem !important;
|
|
}
|
|
CSS
|
|
);
|
|
|
|
$builder = DealerPurchaseLog::with(['user', 'order']);
|
|
return Grid::make($builder, function (Grid $grid) {
|
|
$phone = Request::input('user_phone', '');
|
|
// dd($phone);
|
|
if ($phone) {
|
|
$user = User::where('phone', $phone)->first();
|
|
if ($user) {
|
|
$grid->model()->where('path', 'like', '%-'.$user->id.'-%');
|
|
}
|
|
}
|
|
$grid->model()->orderBy('id', 'desc');//默认ID倒叙
|
|
$grid->column('id')->sortable();
|
|
$grid->column('user.phone', '手机号')->copyable();
|
|
$grid->column('lvl', '等级')->display(function () {
|
|
return $this->lvl->text();
|
|
});
|
|
$grid->column('order.sn', '订单编号');
|
|
$grid->column('total_amount');
|
|
$grid->column('remark');
|
|
$grid->column('order_completed_at', '结算时间')->sortable();
|
|
$grid->column('created_at')->sortable();
|
|
|
|
$grid->header(function ($collection) use ($grid) {
|
|
return tap(new Row(), function ($row) use ($grid) {
|
|
$query = DealerPurchaseLogModel::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'] ?? []);
|
|
});
|
|
|
|
$row->column(3, new InfoBox('进货业绩', (clone $query)->sum('total_amount'), 'fa fa-cny'));
|
|
});
|
|
});
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->panel(false);
|
|
$filter->equal('user_phone', '手机号')->ignore()->width(3);
|
|
$filter->between('order_completed_at', '结算时间')->dateTime()->width(7);
|
|
|
|
// $filter->equal('user.phone', '手机号')->width(3);
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new DealerPurchaseLog(), function (Show $show) {
|
|
$show->field('id');
|
|
$show->field('user_id');
|
|
$show->field('order_id');
|
|
$show->field('lvl');
|
|
$show->field('total_amount');
|
|
$show->field('remark');
|
|
$show->field('order_completed_at');
|
|
$show->field('created_at');
|
|
$show->field('updated_at');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new DealerPurchaseLog(), function (Form $form) {
|
|
$form->display('id');
|
|
$form->text('user_id');
|
|
$form->text('order_id');
|
|
$form->text('lvl');
|
|
$form->text('total_amount');
|
|
$form->text('remark');
|
|
$form->text('order_completed_at');
|
|
|
|
$form->display('created_at');
|
|
$form->display('updated_at');
|
|
});
|
|
}
|
|
}
|