112 lines
3.0 KiB
PHP
112 lines
3.0 KiB
PHP
<?php namespace Gdoo\CustomerCost\Controllers;
|
|
|
|
use DB;
|
|
use Request;
|
|
use Validator;
|
|
|
|
use Gdoo\Model\Grid;
|
|
use Gdoo\Model\Form;
|
|
|
|
use Gdoo\CustomerCost\Models\Category;
|
|
|
|
use Gdoo\Index\Controllers\DefaultController;
|
|
|
|
class CategoryController extends DefaultController
|
|
{
|
|
public $permission = ['dialog'];
|
|
|
|
public function index()
|
|
{
|
|
$header = Grid::header([
|
|
'code' => 'customer_cost_category',
|
|
'referer' => 1,
|
|
'search' => ['by' => ''],
|
|
]);
|
|
|
|
$cols = $header['cols'];
|
|
|
|
$cols['actions']['options'] = [[
|
|
'name' => '编辑',
|
|
'action' => 'edit',
|
|
'display' => $this->access['edit'],
|
|
]];
|
|
|
|
$header['buttons'] = [
|
|
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
|
|
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
|
|
];
|
|
$header['cols'] = $cols;
|
|
$header['tabs'] = Category::$tabs;
|
|
|
|
$search = $header['search_form'];
|
|
$query = $search['query'];
|
|
|
|
if (Request::method() == 'POST') {
|
|
$model = DB::table($header['table'])->setBy($header);
|
|
foreach ($header['join'] as $join) {
|
|
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
|
|
}
|
|
$model->orderBy('sort', 'asc');
|
|
|
|
foreach ($search['where'] as $where) {
|
|
if ($where['active']) {
|
|
$model->search($where);
|
|
}
|
|
}
|
|
|
|
$model->select($header['select']);
|
|
$rows = $model->paginate($query['limit'])->appends($query);
|
|
return Grid::dataFilters($rows, $header);
|
|
}
|
|
|
|
return $this->display([
|
|
'header' => $header,
|
|
]);
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$id = (int)Request::get('id');
|
|
$form = Form::make(['code' => 'customer_cost_category', 'id' => $id]);
|
|
return $this->render([
|
|
'form' => $form,
|
|
], 'create');
|
|
}
|
|
|
|
public function edit()
|
|
{
|
|
return $this->create();
|
|
}
|
|
|
|
public function dialog()
|
|
{
|
|
$search = search_form([], [
|
|
['text','customer_cost_category.name','名称'],
|
|
['text','customer_cost_category.id','ID'],
|
|
]);
|
|
|
|
if (Request::method() == 'POST') {
|
|
$model = Category::orderBy('sort', 'asc');
|
|
foreach ($search['where'] as $where) {
|
|
if ($where['active']) {
|
|
$model->search($where);
|
|
}
|
|
}
|
|
$rows = $model->get(['*', 'name as text']);
|
|
return ['data' => $rows];
|
|
}
|
|
return $this->render([
|
|
'get' => Request::all()
|
|
]);
|
|
}
|
|
|
|
// 删除
|
|
public function delete()
|
|
{
|
|
if (Request::method() == 'POST') {
|
|
$ids = Request::get('id');
|
|
return Form::remove(['code' => 'customer_cost_category', 'ids' => $ids]);
|
|
}
|
|
}
|
|
}
|