<?php
namespace App\Admin\Controllers;
use App\ChannelLevel;
use App\Combo;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;
use Encore\Admin\Widgets\Table;
class ManageChannelLevelController extends Controller
{
use HasResourceActions;
public function index(Content $content)
{
return $content
->header('等级')
->description('列表')
->body($this->grid());
}
public function show($id, Content $content)
{
return $content
->header('等级')
->description('详情')
->body($this->detail($id));
}
public function edit($id, Content $content)
{
return $content
->header('编辑')
->description('等级')
->body($this->form()->edit($id));
}
public function create(Content $content)
{
return $content
->header('创建')
->description('等级')
->body($this->form());
}
protected function grid()
{
$grid = new Grid(new ChannelLevel);
$grid->id('Id');
$grid->name('名称');
$grid->team('团队');
$grid->agent_price('代理费');
$grid->deposit('押金');
$grid->royalty('分成(%)');
$grid->content('内容')->display(function($content){
return '查看';
})->modal('内容', function ($model) {
$values = [];
foreach ($model->content as $item){
$name = Combo::find($item['id'])->name;
$value = [
$name,
$item['channel_price'],
];
array_push($values,$value);
} return new Table(['服务', '代理价格'], $values);
});
$grid->created_at('创建日期');
return $grid;
}
protected function detail($id)
{
$show = new Show(ChannelLevel::findOrFail($id));
$show->id('Id');
$show->name('Name');
$show->team('Team');
$show->agent_price('Agent price');
$show->deposit('Deposit');
$show->content('Content');
$show->created_at('Created at');
$show->updated_at('Updated at');
return $show;
}
protected function form()
{
$form = new Form(new ChannelLevel);
$form->text('name', '名称');
$form->text('team', '团队规模');
$form->decimal('agent_price', '代理费');
$form->decimal('deposit', '押金');
$options = Combo::all()->pluck('name', 'id');
$form->number('royalty', '分成(%)')->default(0);
$form->table('content', '内容',function ($table) use ($options){
$table->select('id', '套餐id')->options($options);
$table->decimal('channel_price','代理价格');
});
return $form;
}
}