133 lines
3.6 KiB
PHP
133 lines
3.6 KiB
PHP
<?php namespace Gdoo\User\Controllers;
|
|
|
|
use DB;
|
|
use Request;
|
|
use Validator;
|
|
|
|
use Gdoo\Model\Grid;
|
|
use Gdoo\Model\Form;
|
|
|
|
use Gdoo\User\Models\User;
|
|
use Gdoo\User\Models\UserPosition;
|
|
|
|
use Gdoo\Index\Controllers\DefaultController;
|
|
|
|
class PositionController extends DefaultController
|
|
{
|
|
public $permission = ['dialog'];
|
|
|
|
public function indexAction()
|
|
{
|
|
$header = Grid::header([
|
|
'code' => 'user_position',
|
|
'referer' => 1,
|
|
'search' => ['tab' => 'position'],
|
|
'trash_btn' => 0,
|
|
]);
|
|
|
|
$cols = $header['cols'];
|
|
|
|
$cols['actions']['options'] = [[
|
|
'name' => '编辑',
|
|
'action' => 'edit',
|
|
'display' => $this->access['edit'],
|
|
]];
|
|
|
|
$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($header['sort'], $header['order'])
|
|
->orderBy('id', 'desc');
|
|
|
|
foreach ($search['where'] as $where) {
|
|
if ($where['active']) {
|
|
$model->search($where);
|
|
}
|
|
}
|
|
|
|
$model->select($header['select']);
|
|
$rows = $model->paginate($query['limit'])->appends($query);
|
|
$items = Grid::dataFilters($rows, $header);
|
|
return $items->toJson();
|
|
}
|
|
|
|
$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'] = User::$tabs;
|
|
$header['js'] = Grid::js($header);
|
|
|
|
return $this->display([
|
|
'header' => $header,
|
|
]);
|
|
}
|
|
|
|
// 新建客户联系人
|
|
public function createAction()
|
|
{
|
|
$id = (int)Request::get('id');
|
|
$form = Form::make(['code' => 'user_position', 'id' => $id]);
|
|
return $this->render([
|
|
'form' => $form,
|
|
], 'create');
|
|
}
|
|
|
|
// 创建客户联系人
|
|
public function editAction()
|
|
{
|
|
return $this->createAction();
|
|
}
|
|
|
|
// 显示客户联系人
|
|
public function showAction()
|
|
{
|
|
$id = (int)Request::get('id');
|
|
$position = UserPosition::find($id);
|
|
$options = [
|
|
'table' => 'user_position',
|
|
'row' => $position,
|
|
];
|
|
$tpl = Form::show($options);
|
|
return $this->display([
|
|
'tpl' => $tpl,
|
|
]);
|
|
}
|
|
|
|
public function dialogAction()
|
|
{
|
|
$search = search_form([], [
|
|
['text','user_position.name','名称'],
|
|
['text','user_position.id','ID'],
|
|
]);
|
|
|
|
if (Request::method() == 'POST') {
|
|
$model = UserPosition::orderBy('sort', 'asc');
|
|
foreach ($search['where'] as $where) {
|
|
if ($where['active']) {
|
|
$model->search($where);
|
|
}
|
|
}
|
|
$rows = $model->get(['*', 'name as text']);
|
|
return response()->json(['data' => $rows]);
|
|
}
|
|
return $this->render([
|
|
'search' => $search,
|
|
]);
|
|
}
|
|
|
|
// 删除
|
|
public function deleteAction()
|
|
{
|
|
if (Request::method() == 'POST') {
|
|
$ids = Request::get('id');
|
|
return Form::remove(['code' => 'user_position', 'ids' => $ids]);
|
|
}
|
|
}
|
|
} |