236 lines
10 KiB
PHP
236 lines
10 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Actions\Grid\DealerBonds;
|
|
use App\Admin\Actions\Grid\DealerEditLvl;
|
|
use App\Admin\Actions\Grid\DealerEditProduct;
|
|
use App\Admin\Renderable\DealerEarningSimpleTable;
|
|
use App\Admin\Renderable\DealerSubordinateCard;
|
|
use App\Admin\Renderable\DealerUserProductLogSimpleTable;
|
|
use App\Admin\Renderable\DealerWalletLogSimpleTable;
|
|
use App\Admin\Repositories\Dealer;
|
|
use App\Enums\DealerLvl;
|
|
use App\Models\Dealer as DealerModel;
|
|
use App\Models\DealerUserProduct;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Grid\Column;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
use Dcat\Admin\Layout\Row;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Widgets\Box;
|
|
use Dcat\Admin\Widgets\Tab;
|
|
|
|
class DealerController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
$builder = Dealer::with(['user', 'userInfo', 'userInfo.inviterInfo.user', 'userInfo.realInviterInfo.user', 'wallet']);
|
|
return Grid::make($builder, function (Grid $grid) {
|
|
// $grid->column('id')->sortable();
|
|
$grid->column('user.phone')->copyable();
|
|
$grid->column('userInfo.nickname');
|
|
$grid->column('userInfo.inviterInfo.user.phone')->copyable();
|
|
$grid->column('userInfo.realInviterInfo.user.phone')->copyable();
|
|
// $grid->column('user_id');
|
|
|
|
$lvlTexts = DealerLvl::texts();
|
|
$grid->column('lvl')->display(function () {
|
|
return $this->lvl->text();
|
|
})->filter(Grid\Column\Filter\In::make($lvlTexts))->modal(function ($modal) {
|
|
// $modal->title('消费值');
|
|
return DealerSubordinateCard::make(['id'=>$this->user_id]);
|
|
})->setHeaderAttributes(['style' => 'color:#5b69bc']);
|
|
$grid->column('wallet.balance')->display(function ($value) {
|
|
return $value ?? 0;
|
|
})->prepend('¥');
|
|
$grid->column('is_sale')
|
|
->if(function () {
|
|
return Admin::user()->can('dcat.admin.dealers.update');
|
|
})
|
|
->then(function (Column $column) {
|
|
$column->switch();
|
|
})
|
|
->else(function (Column $column) {
|
|
$column->bool();
|
|
});
|
|
$grid->column('is_manager')
|
|
->if(function () {
|
|
return Admin::user()->can('dcat.admin.dealers.update');
|
|
})
|
|
->then(function (Column $column) {
|
|
$column->switch();
|
|
})
|
|
->else(function (Column $column) {
|
|
$column->bool();
|
|
});
|
|
$grid->column('bonds')->prepend('¥')->filter(
|
|
Grid\Column\Filter\Between::make()
|
|
);
|
|
// $grid->column('created_at')->sortable();
|
|
|
|
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
|
if (Admin::user()->can('dcat.admin.dealers.show')) {
|
|
$actions->append('<a style="cursor: pointer;" target="_blank" href="'.admin_route('dealers.show', ['dealer_user'=>$actions->row]).'"><i class="feather icon-eye"></i> 显示 </a>');
|
|
}
|
|
if (Admin::user()->can('dcat.admin.dealers.edit_lvl')) {
|
|
$actions->append(new DealerEditLvl());
|
|
}
|
|
if ($actions->row->lvl->value >= DealerLvl::Special->value && Admin::user()->can('dcat.admin.dealers.bonds')) {
|
|
$actions->append(new DealerBonds());
|
|
}
|
|
$actions->append((new DealerEditProduct())->setKey($actions->row->user_id));
|
|
});
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->panel();
|
|
$filter->equal('user.phone')->width(3);
|
|
$filter->equal('userInfo.inviterInfo.user.phone')->width(3);
|
|
$filter->equal('userInfo.realInviterInfo.user.phone')->width(3);
|
|
$filter->equal('userInfo.nickname')->width(4);
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return function (Row $row) use ($id) {
|
|
$row->column(5, function ($column) use ($id) {
|
|
$builder = Dealer::with(['user', 'userInfo', 'userInfo.inviterInfo.user']);
|
|
$column->row(Show::make($id, $builder, function (Show $show) {
|
|
// $show->field('id');
|
|
$show->field('user.phone');
|
|
$show->field('lvl')->as(function () {
|
|
return $this->lvl->text();
|
|
});
|
|
$show->field('is_sale')->as(function ($val) {
|
|
return $val ? '是' : '否';
|
|
});
|
|
$show->field('is_manager')->as(function ($val) {
|
|
return $val ? '是' : '否';
|
|
});
|
|
|
|
$show->divider('收款信息-银行');
|
|
$show->field('bank_user_name', '银行-收款人')->as(function () {
|
|
$payInfo = $this->pay_info;
|
|
return $payInfo['bank']['user_name'] ?? '';
|
|
});
|
|
$show->field('bank_bank_name', '银行-名称')->as(function () {
|
|
$payInfo = $this->pay_info;
|
|
return $payInfo['bank']['bank_name'] ?? '';
|
|
});
|
|
$show->field('bank_bank_number', '银行-卡号')->as(function () {
|
|
$payInfo = $this->pay_info;
|
|
return $payInfo['bank']['bank_number'] ?? '';
|
|
});
|
|
$show->field('bank_bank_description', '银行-开户行')->as(function () {
|
|
$payInfo = $this->pay_info;
|
|
return $payInfo['bank']['bank_description'] ?? '';
|
|
});
|
|
$show->divider('收款信息-支付宝');
|
|
$show->field('alipay_user_name', '支付宝-真实名称')->as(function () {
|
|
$payInfo = $this->pay_info;
|
|
return $payInfo['alipay']['user_name'] ?? '';
|
|
});
|
|
$show->field('alipay_ali_name', '支付宝-账户')->as(function () {
|
|
$payInfo = $this->pay_info;
|
|
return $payInfo['alipay']['ali_name'] ?? '';
|
|
});
|
|
$show->field('alipay_image', '支付宝-收款码')->as(function () {
|
|
$payInfo = $this->pay_info;
|
|
return $payInfo['alipay']['image'] ?? '';
|
|
})->image();
|
|
$show->divider('收款信息-微信');
|
|
$show->field('wechat_user_name', '微信-真实名称')->as(function () {
|
|
$payInfo = $this->pay_info;
|
|
return $payInfo['wechat']['user_name'] ?? '';
|
|
});
|
|
$show->field('wechat_wechat_name', '微信-ID')->as(function () {
|
|
$payInfo = $this->pay_info;
|
|
return $payInfo['wechat']['wechat_name'] ?? '';
|
|
});
|
|
$show->field('wechat_image', '微信-收款码')->as(function () {
|
|
$payInfo = $this->pay_info;
|
|
return $payInfo['wechat']['image'] ?? '';
|
|
})->image();
|
|
|
|
// $show->field('pay_info');
|
|
$show->field('created_at');
|
|
$show->panel()
|
|
->tools(function (Show\Tools $tools) use ($show) {
|
|
$tools->disableEdit();
|
|
$tools->disableDelete();
|
|
});
|
|
}));
|
|
});
|
|
$row->column(7, function ($column) use ($id) {
|
|
$dealer = DealerModel::findOrFail($id);
|
|
$tab = Tab::make();
|
|
// 资金记录
|
|
$tab->add('资金记录', new DealerEarningSimpleTable(['id'=>$dealer->user_id]));
|
|
// 剩余库存
|
|
$builder = DealerUserProduct::query();
|
|
$builder->with(['product'])->where('user_id', $dealer->user_id);
|
|
$productGrid = Grid::make($builder, function (Grid $grid) {
|
|
$grid->column('product.name', '商品名称');
|
|
$grid->column('product.cover', '商品封面')->image(80, 80);
|
|
$grid->column('stock', '库存');
|
|
$grid->column('deposit_stock', '云库存');
|
|
$grid->column('created_at', '创建时间');
|
|
$grid->column('logs', '库存记录')->display('查看')->modal(function ($modal) {
|
|
$modal->title('商品');
|
|
return DealerUserProductLogSimpleTable::make(['product_id'=>$this->product_id, 'id'=> $this->user_id]);
|
|
});
|
|
// $grid->withBorder();
|
|
$grid->model()->orderBy('created_at', 'desc');
|
|
$grid->disableRefreshButton();
|
|
$grid->disableActions();
|
|
$grid->disablePagination();
|
|
});
|
|
|
|
$tab->add('剩余库存', $productGrid);
|
|
|
|
$tab->add('余额记录', new DealerWalletLogSimpleTable(['id'=>$dealer->user_id]));
|
|
// $tab->add('升级记录', '');
|
|
// 上级列表
|
|
// $tab->add('上级列表', '');
|
|
$column->row(Box::make('用户记录', $tab));
|
|
});
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new Dealer(), function (Form $form) {
|
|
$form->display('id');
|
|
// $form->text('user_id');
|
|
// $form->text('lvl');
|
|
$form->text('is_sale');
|
|
$form->text('is_manager');
|
|
// $form->text('pay_info');
|
|
|
|
$form->display('created_at');
|
|
$form->display('updated_at');
|
|
});
|
|
}
|
|
}
|