You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
2.9 KiB
99 lines
2.9 KiB
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Repositories\LanzuAdminUserMarket;
|
|
use App\Models\AdminUsers;
|
|
use App\Models\v3\Market;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Controllers\AdminController;
|
|
|
|
class LanzuAdminUserMarketController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new LanzuAdminUserMarket(), function (Grid $grid) {
|
|
$grid->column('id')->sortable();
|
|
$grid->column('admin_user_id','用户名')->display(function (){
|
|
return AdminUsers::where('id',$this->admin_user_id)->first()->name;
|
|
});
|
|
$grid->column('market_id','关联市场')->display(function (){
|
|
return Market::where('id',$this->market_id)->first()->name;
|
|
});
|
|
$grid->column('created_at')->display(function ($time){
|
|
return date('Y-m-d H:i:s',$time);
|
|
});
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->equal('id');
|
|
|
|
});
|
|
|
|
$grid->disableViewButton();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new LanzuAdminUserMarket(), function (Show $show) {
|
|
$show->field('id');
|
|
$show->field('admin_user_id');
|
|
$show->field('market_id');
|
|
$show->field('created_at');
|
|
$show->field('updated_at');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
$this->getAdminUser();
|
|
return Form::make(new LanzuAdminUserMarket(), function (Form $form) {
|
|
$form->display('id');
|
|
if ($form->isCreating()){
|
|
$aumIds = \App\Models\LanzuAdminUserMarket::pluck('admin_user_id')->toArray();
|
|
$form->select('admin_user_id','用户名')->options($this->getAdminUser($aumIds));
|
|
}else{
|
|
$form->select('admin_user_id','用户名')->options($this->getAdminUser(null))->disable();
|
|
}
|
|
$form->select('market_id','关联市场')->options($this->getMarket());
|
|
$form->disableViewButton();
|
|
$form->disableEditingCheck();
|
|
$form->disableCreatingCheck();
|
|
$form->disableViewCheck();
|
|
});
|
|
}
|
|
|
|
public function getAdminUser($aumIds=null)
|
|
{
|
|
if ($aumIds){
|
|
$data = AdminUsers::whereNotIn('id',$aumIds)->pluck('name','id')->toArray();
|
|
}else{
|
|
$data = AdminUsers::pluck('name','id')->toArray();
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
public function getMarket()
|
|
{
|
|
$data = Market::pluck('name','id')->toArray();
|
|
return $data;
|
|
}
|
|
}
|