创建版本
This commit is contained in:
@@ -0,0 +1,272 @@
|
||||
<?php namespace Gdoo\Model\Controllers;
|
||||
|
||||
use DB;
|
||||
use Auth;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Grid;
|
||||
|
||||
use Gdoo\Model\Models\Bill;
|
||||
use Gdoo\Model\Models\Model;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class BillController extends DefaultController
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
$header = [
|
||||
'master_name' => '单据',
|
||||
'simple_search_form' => 1,
|
||||
'table' => 'model_bill',
|
||||
'master_table' => 'model_bill',
|
||||
'create_btn' => 1,
|
||||
];
|
||||
|
||||
$search = search_form([
|
||||
'advanced' => '',
|
||||
], [
|
||||
['form_type' => 'text', 'name' => '名称', 'field' => 'model_bill.name', 'value' => '', 'options' => []],
|
||||
], 'model');
|
||||
|
||||
$header['cols'] = [
|
||||
'checkbox' => [
|
||||
'width' => 40,
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
'checkboxSelection' => true,
|
||||
'headerCheckboxSelection' => true,
|
||||
],
|
||||
'sequence_sn' => [
|
||||
'width' => 60,
|
||||
'headerName' => '序号',
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'resizable' => false,
|
||||
'editable' => false,
|
||||
'type' => 'sn',
|
||||
'filter' => false,
|
||||
],
|
||||
'name' => [
|
||||
'field' => 'name',
|
||||
'headerName' => '名称',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-left',
|
||||
'form_type' => 'text',
|
||||
'width' => 100,
|
||||
],
|
||||
'code' => [
|
||||
'field' => 'code',
|
||||
'headerName' => '编码',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 100,
|
||||
],
|
||||
'uri' => [
|
||||
'field' => 'uri',
|
||||
'headerName' => '路径',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-left',
|
||||
'form_type' => 'text',
|
||||
'width' => 140,
|
||||
],
|
||||
'model_name' => [
|
||||
'field' => 'model_name',
|
||||
'headerName' => '主模型',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 120,
|
||||
],
|
||||
'audit_type_name' => [
|
||||
'field' => 'audit_type_name',
|
||||
'headerName' => '审核类型',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 80,
|
||||
],
|
||||
'sn_rule' => [
|
||||
'field' => 'sn_rule',
|
||||
'headerName' => '编号规则',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 80,
|
||||
],
|
||||
'updated_dt' => [
|
||||
'field' => 'updated_dt',
|
||||
'headerName' => '操作时间',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 80,
|
||||
],
|
||||
'id' => [
|
||||
'field' => 'id',
|
||||
'headerName' => 'ID',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 40,
|
||||
],
|
||||
'actions' => [
|
||||
'headerName' => '',
|
||||
'cellRenderer' => 'actionCellRenderer',
|
||||
'options' => [[
|
||||
'name' => '视图',
|
||||
'action' => 'view',
|
||||
'display' => 1,
|
||||
],[
|
||||
'name' => '流程',
|
||||
'action' => 'flow',
|
||||
'display' => 1,
|
||||
],[
|
||||
'name' => '权限',
|
||||
'action' => 'permission',
|
||||
'display' => 1,
|
||||
],[
|
||||
'name' => '编辑',
|
||||
'action' => 'edit',
|
||||
'display' => $this->access['edit'],
|
||||
]],
|
||||
'width' => 160,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressSizeToFit' => true,
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
],
|
||||
];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
|
||||
$model = Bill::leftJoin('model', 'model.id', '=', 'model_bill.model_id')
|
||||
->selectRaw('model_bill.*,model_bill.id as master_id, model.[table] as model_table,model.name as model_name')
|
||||
->orderBy('model_bill.id', 'desc')
|
||||
->where('model_bill.type', 0)
|
||||
->setBy($header);
|
||||
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
|
||||
$rows->transform(function($row) {
|
||||
$row['updated_dt'] = format_datetime($row['updated_at']);
|
||||
|
||||
if ($row['audit_type'] == 0) {
|
||||
$row['audit_type_name'] = '无';
|
||||
}
|
||||
elseif($row['audit_type'] == 1) {
|
||||
$row['audit_type_name'] = '固定流程';
|
||||
}
|
||||
elseif($row['audit_type'] == 2) {
|
||||
$row['audit_type_name'] = '自由流程';
|
||||
}
|
||||
elseif($row['audit_type'] == 3) {
|
||||
$row['audit_type_name'] = '审核';
|
||||
}
|
||||
$row['sn_rule'] = $row['sn_prefix'].$row['sn_rule'].($row['sn_length'] > 0 ? $row['sn_length'] : '');
|
||||
$row['model_name'] = $row['model_name'].'('.$row['model_table'].')';
|
||||
return $row;
|
||||
});
|
||||
return $rows;
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
|
||||
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['search_form'] = $search;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
// 配置权限
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
public function createAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
$rules = [
|
||||
'name' => 'required',
|
||||
'code' => 'required|unique:model_bill,code,'.$gets['id'],
|
||||
];
|
||||
$v = Validator::make($gets, $rules);
|
||||
|
||||
if ($v->fails()) {
|
||||
return $this->json($v->errors()->first());
|
||||
}
|
||||
|
||||
// 单据设置为0
|
||||
$gets['type'] = 0;
|
||||
|
||||
$bill = Bill::findOrNew($gets['id']);
|
||||
$bill->fill($gets);
|
||||
$bill->save();
|
||||
return $this->json('恭喜你,操作成功。', true);
|
||||
}
|
||||
|
||||
$bill_id = Request::get('id');
|
||||
$bill = Bill::find($bill_id);
|
||||
$models = Model::where('parent_id', 0)->get();
|
||||
|
||||
return $this->render([
|
||||
'bill' => $bill,
|
||||
'models' => $models,
|
||||
'bill_id' => $bill_id,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
public function storeAction()
|
||||
{
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
public function deleteAction()
|
||||
{
|
||||
$ids = (array)Request::get('id');
|
||||
if (count($ids) > 0) {
|
||||
Bill::whereIn('id', $ids)->delete();
|
||||
/*
|
||||
Step::whereIn('bill_id', $ids)->delete();
|
||||
Run::whereIn('bill_id', $ids)->delete();
|
||||
RunLog::whereIn('bill_id', $ids)->delete();
|
||||
RunStep::whereIn('bill_id', $ids)->delete();
|
||||
Template::whereIn('bill_id', $ids)->delete();
|
||||
*/
|
||||
return $this->json('恭喜你,操作成功。', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,431 @@
|
||||
<?php namespace Gdoo\Model\Controllers;
|
||||
|
||||
use DB;
|
||||
use Auth;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use App\Support\Module;
|
||||
|
||||
use Gdoo\Model\Models\Model;
|
||||
use Gdoo\Model\Models\Field;
|
||||
use Gdoo\Model\Form;
|
||||
|
||||
use Gdoo\Model\Services\FlowService;
|
||||
use Gdoo\Model\Services\FieldService;
|
||||
use Gdoo\Model\Services\ModuleService;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
use Gdoo\System\Models\Option;
|
||||
|
||||
class FieldController extends DefaultController
|
||||
{
|
||||
public $permission = ['getColumns', 'getEnums'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$model_id = Request::get('model_id');
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$sorts = Request::get('sort');
|
||||
$i = 0;
|
||||
foreach ($sorts as $id) {
|
||||
Field::where('id', $id)->update(['sort' => $i]);
|
||||
$i ++;
|
||||
}
|
||||
return $this->json('恭喜你,操作成功。', true);
|
||||
}
|
||||
|
||||
$master = Model::with(['fields' => function ($q) {
|
||||
$q->orderBy('sort', 'asc')
|
||||
->orderBy('id', 'asc');
|
||||
}])->find($model_id);
|
||||
|
||||
$sublist = Model::with(['fields' => function ($q) {
|
||||
$q->orderBy('sort', 'asc')
|
||||
->orderBy('id', 'asc');
|
||||
}])->where('parent_id', $master->id)->get();
|
||||
|
||||
$models = DB::table('model')->where('parent_id', 0)->orderBy('lft', 'asc')->get();
|
||||
$model = Model::find($model_id);
|
||||
|
||||
$sets = $models->keyBy('table');
|
||||
|
||||
return $this->display([
|
||||
'master' => $master,
|
||||
'sublist' => $sublist,
|
||||
'model_id' => $model_id,
|
||||
'model' => $model,
|
||||
'models' => $models,
|
||||
'sets' => $sets,
|
||||
]);
|
||||
}
|
||||
|
||||
public function createAction()
|
||||
{
|
||||
$model_id = (int)Request::get('model_id');
|
||||
$id = (int)Request::get('id');
|
||||
|
||||
$row = Field::find($id);
|
||||
$model = Model::find($model_id);
|
||||
|
||||
$templates = [];
|
||||
|
||||
switch ($this->dbType) {
|
||||
case 'sqlsrv':
|
||||
$templates = [
|
||||
'BIGINT' => ['type' => 'bigint', 'length' => '', 'default' => 'NULL'],
|
||||
'INT' => ['type' => 'int', 'length' => '', 'default' => 'NULL'],
|
||||
'MEDIUMINT' => ['type' => 'int', 'length' => '', 'default' => 'NULL'],
|
||||
'SMALLINT' => ['type' => 'smallint', 'length' => '', 'default' => 'NULL'],
|
||||
'TINYINT' => ['type' => 'tinyint', 'length' => '', 'default' => 'NULL', ],
|
||||
'DECIMAL' => ['type' => 'decimal', 'length' => '20,2', 'default' => 'NULL'],
|
||||
'DATE' => ['type' => 'date', 'length' => '', 'default' => 'NULL'],
|
||||
'DATETIME' => ['type' => 'datetime', 'length' => '', 'default' => 'NULL'],
|
||||
'NCHAR' => ['type' => 'nchar', 'length' => '50', 'default' => 'NULL'],
|
||||
'NVARCHAR' => ['type' => 'nvarchar', 'length' => '255', 'default' => 'NULL'],
|
||||
'NVARCHAR(MAX)' => ['type' => 'nvarchar(max)', 'length' => '', 'default' => 'NULL'],
|
||||
'VARCHAR' => ['type' => 'nvarchar', 'length' => '255', 'default' => 'NULL'],
|
||||
'TEXT' => ['type' => 'nvarchar(max)', 'length' => '', 'default' => 'NULL']
|
||||
];
|
||||
break;
|
||||
case 'mysql':
|
||||
$templates = [
|
||||
'BIGINT' => ['type' => 'bigint', 'length' => '20', 'default' => 'NULL'],
|
||||
'INT' => ['type' => 'integer', 'length' => '11', 'default' => 'NULL'],
|
||||
'SMALLINT' => ['type' => 'smallint', 'length' => '5', 'default' => 'NULL'],
|
||||
'TINYINT' => ['type' => 'smallint', 'length' => '3', 'default' => 'NULL'],
|
||||
'DECIMAL' => ['type' => 'decimal', 'length' => '20,2', 'default' => 'NULL'],
|
||||
'DATE' => ['type' => 'date', 'length' => '', 'default' => 'NULL'],
|
||||
'DATETIME' => ['type' => 'datetime', 'length' => '', 'default' => 'NULL'],
|
||||
'TIME' => ['type' => 'time', 'length' => '', 'default' => 'NULL'],
|
||||
'CHAR' => ['type' => 'char', 'length' => '50', 'default' => 'NULL'],
|
||||
'VARCHAR' => ['type' => 'varchar', 'length' => '255', 'default' => 'NULL'],
|
||||
'TEXT' => ['type' => 'text', 'length' => '', 'default' => 'NULL']
|
||||
];
|
||||
break;
|
||||
}
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
|
||||
$gets = Request::all();
|
||||
|
||||
$rules = [
|
||||
'name' => 'required',
|
||||
'field' => 'required|unique:model_field,field,'.$id.',id,model_id,'.$model_id,
|
||||
'form_type' => 'required',
|
||||
];
|
||||
|
||||
if ($gets['validate']) {
|
||||
$gets['validate'] = join('|', $gets['validate']);
|
||||
}
|
||||
|
||||
$v = Validator::make($gets, $rules);
|
||||
if ($v->fails()) {
|
||||
return $this->json(join('<br>',$v->errors()->all()));
|
||||
}
|
||||
|
||||
if (trim($gets['type'])) {
|
||||
$type = $templates[$gets['type']]['type'];
|
||||
$table = $model->getAttribute('table');
|
||||
$sql = [];
|
||||
|
||||
try {
|
||||
$columns = DB::select('select column_name as column_name from information_schema.columns where table_name=?', [$table]);
|
||||
$columns = array_by($columns, 'column_name');
|
||||
|
||||
switch ($this->dbType) {
|
||||
case 'sqlsrv':
|
||||
if ($gets['id'] > 0 && isset($columns[$row['field']])) {
|
||||
|
||||
// 修改字段名
|
||||
if ($row['field'] != $gets['field']) {
|
||||
$sql[] = "EXEC sp_rename '{$table}.{$row['field']}', '{$gets['field']}', 'column'";
|
||||
|
||||
// 删除旧索引
|
||||
if ($row['index']) {
|
||||
if ($row['index'] == 'PRIMARY') {
|
||||
$index = "pk_{$table}_{$row['field']}";
|
||||
} else {
|
||||
$index = "idx_{$table}_{$row['field']}";
|
||||
}
|
||||
$sql[] = "if exists (select 1 from sys.indexes where object_id = object_id(N'{$table}') and name = '{$index}')
|
||||
begin
|
||||
drop index {$index} on {$table}
|
||||
end";
|
||||
}
|
||||
|
||||
// 添加新索引
|
||||
if ($gets['index']) {
|
||||
if ($gets['index'] == 'INDEX') {
|
||||
$sql[] = "create INDEX idx_{$table}_{$gets['field']} on $table({$gets['field']})";
|
||||
} else if($gets['index'] == 'UNIQUE') {
|
||||
$sql[] = "create UNIQUE INDEX idx_{$table}_{$gets['field']} on $table({$gets['field']})";
|
||||
} else if($gets['index'] == 'PRIMARY') {
|
||||
$sql[] = "create PRIMARY KEY INDEX pk_{$table}_{$gets['field']} on $table({$gets['field']})";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 修改字段类型
|
||||
if ($row['type'] != $gets['type'] || $row['not_null'] != $gets['not_null'] || $row['length'] != $gets['length']) {
|
||||
$not_null = $gets['not_null'] == 1 ? 'not null' : 'null';
|
||||
$type = $gets['length'] == '' ? $type : $type.'('.$gets['length'].')';
|
||||
$sql[] = "alter table {$table} alter column {$gets['field']} {$type} $not_null";
|
||||
}
|
||||
|
||||
// 默认值
|
||||
if ($row['default'] != $gets['default']) {
|
||||
|
||||
// 删除旧默认值
|
||||
$sql[] = "if exists (select 1 from sysobjects as t where id = (select cdefault from syscolumns where id = object_id(N'{$table}') and name = 'df_{$table}_{$gets['field']}'))
|
||||
begin
|
||||
alter table $table drop constraint df_{$table}_{$gets['field']}
|
||||
end";
|
||||
|
||||
$default = trim($gets['default']);
|
||||
if ($gets['default'] == 'NULL') {
|
||||
$default = 'NULL';
|
||||
} else if($gets['default'] == 'Empty String') {
|
||||
$default = "''";
|
||||
}
|
||||
if ($default != '') {
|
||||
$sql[] = "alter table $table add constraint df_{$table}_{$gets['field']} default {$default} for {$gets['field']} with values";
|
||||
}
|
||||
}
|
||||
|
||||
// 修改字段注释
|
||||
if ($row['name'] != $gets['name']) {
|
||||
$sql[] = "EXECUTE sp_updateextendedproperty 'MS_Description', '{$gets['name']}', 'user', 'dbo', 'table', '{$table}', 'column', '{$gets['field']}'";
|
||||
}
|
||||
|
||||
} else {
|
||||
// 字段不存在
|
||||
if (!isset($columns[$gets['field']])) {
|
||||
|
||||
$not_null = $gets['not_null'] == 1 ? 'not null' : 'null';
|
||||
$type = $gets['length'] == '' ? $type : $type.'('.$gets['length'].')';
|
||||
|
||||
// 添加字段
|
||||
$sql[] = "alter table {$table} add {$gets['field']} {$type} $not_null";
|
||||
// 添加字段索引
|
||||
if ($gets['index']) {
|
||||
if ($gets['index'] == 'INDEX') {
|
||||
$sql[] = "create INDEX idx_{$table}_{$gets['field']} on $table({$gets['field']})";
|
||||
} else if($gets['index'] == 'UNIQUE') {
|
||||
$sql[] = "create UNIQUE INDEX idx_{$table}_{$gets['field']} on $table({$gets['field']})";
|
||||
}
|
||||
else if($gets['index'] == 'PRIMARY') {
|
||||
$sql[] = "create PRIMARY KEY INDEX pk_{$table}_{$gets['field']} on $table({$gets['field']})";
|
||||
}
|
||||
}
|
||||
|
||||
$default = trim($gets['default']);
|
||||
if ($default == '') {
|
||||
$default = '';
|
||||
} else if ($default == 'NULL') {
|
||||
$default = 'NULL';
|
||||
} else if($gets['default'] == 'Empty String') {
|
||||
$default = "''";
|
||||
}
|
||||
if ($default != '') {
|
||||
$sql[] = "alter table $table add constraint df_{$table}_{$gets['field']} default {$gets['default']} for {$gets['field']} with values";
|
||||
}
|
||||
|
||||
$sql[] = "EXECUTE sp_addextendedproperty 'MS_Description', '{$gets['name']}', 'user', 'dbo', 'table', '{$table}', 'column', '{$gets['field']}'";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'mysql':
|
||||
$type = $gets['type'].($gets['length'] == '' ? '' : '('.$gets['length'].')');
|
||||
$not_null = $gets['not_null'] == 1 ? 'not null' : 'null';
|
||||
|
||||
// 处理默认值
|
||||
$default = trim($gets['default']);
|
||||
if ($default == '' || $default == 'NULL') {
|
||||
$default = 'default NULL';
|
||||
} else if($default == 'Empty String') {
|
||||
$default = "default ''";
|
||||
} else {
|
||||
$default = "default '{$default}'";
|
||||
}
|
||||
// 处理注释
|
||||
$comment = "COMMENT '{$gets['name']}'";
|
||||
// 字段位置
|
||||
$after = '';
|
||||
|
||||
if ($gets['id'] > 0 && isset($columns[$row['field']])) {
|
||||
|
||||
// 修改字段数据
|
||||
if ($row['field'] != $gets['field'] || $row['type'] != $gets['type'] || $row['not_null'] != $gets['not_null'] || $row['length'] != $gets['length']) {
|
||||
$sql[] = "alter table {$table} change `{$row['field']}` `{$gets['field']}` $type $not_null $default $comment $after";
|
||||
}
|
||||
|
||||
// 修改字段名
|
||||
if ($row['field'] != $gets['field']) {
|
||||
// 删除旧索引
|
||||
if ($row['index']) {
|
||||
if ($row['index'] == 'PRIMARY') {
|
||||
$index = "pk_{$table}_{$row['field']}";
|
||||
} else {
|
||||
$index = "idx_{$table}_{$row['field']}";
|
||||
}
|
||||
$sql[] = "drop index {$index} on {$table}";
|
||||
}
|
||||
|
||||
// 添加新索引
|
||||
if ($gets['index']) {
|
||||
if ($gets['index'] == 'INDEX') {
|
||||
$sql[] = "alter table {$table} add index idx_{$table}_{$gets['field']} on $table({$gets['field']})";
|
||||
} else if($gets['index'] == 'UNIQUE') {
|
||||
$sql[] = "alter table {$table} add unique idx_{$table}_{$gets['field']} on $table({$gets['field']})";
|
||||
} else if($gets['index'] == 'PRIMARY') {
|
||||
$sql[] = "alter table {$table} add primary key pk_{$table}_{$gets['field']} on $table({$gets['field']})";
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 字段不存在
|
||||
if (!isset($columns[$gets['field']])) {
|
||||
// 添加字段
|
||||
$sql[] = "alter table {$table} add `{$gets['field']}` $type $not_null $default $comment $after";
|
||||
|
||||
// 添加新索引
|
||||
if ($gets['index']) {
|
||||
if ($gets['index'] == 'INDEX') {
|
||||
$sql[] = "alter table {$table} add index idx_{$table}_{$gets['field']} on $table({$gets['field']})";
|
||||
} else if($gets['index'] == 'UNIQUE') {
|
||||
$sql[] = "alter table {$table} add unique idx_{$table}_{$gets['field']} on $table({$gets['field']})";
|
||||
} else if($gets['index'] == 'PRIMARY') {
|
||||
$sql[] = "alter table {$table} add primary key pk_{$table}_{$gets['field']} on $table({$gets['field']})";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// 操作数据表
|
||||
foreach ($sql as $_sql) {
|
||||
DB::statement($_sql);
|
||||
}
|
||||
|
||||
} catch(\Exception $e) {
|
||||
return $this->json($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 写入模型数据
|
||||
$gets['setting'] = json_encode($gets['setting'], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
$model = Field::findOrNew((int)$gets['id']);
|
||||
$model->fill($gets);
|
||||
$model->save();
|
||||
|
||||
return $this->json('恭喜你,操作成功。', url('index', ['model_id' => $gets['model_id']]));
|
||||
}
|
||||
|
||||
if ($row['validate']) {
|
||||
$row['validate'] = explode('|', $row['validate']);
|
||||
}
|
||||
|
||||
if ($model['parent_id'] > 0) {
|
||||
// 获取子表目录
|
||||
$_model = DB::table('model')->where('id', $model['parent_id'])->first();
|
||||
$_models = DB::table('model')->where('parent_id', $_model['id'])->get();
|
||||
} else {
|
||||
// 获取子表目录
|
||||
$_model = DB::table('model')->where('id', $model['id'])->first();
|
||||
$_models = DB::table('model')->where('parent_id', $_model['id'])->get();
|
||||
}
|
||||
|
||||
$models[] = $_model;
|
||||
foreach ($_models as $_model) {
|
||||
$models[] = $_model;
|
||||
}
|
||||
|
||||
$row['model_id'] = $model_id;
|
||||
|
||||
$setting = json_decode($row['setting'], true);
|
||||
$row['setting'] = $setting;
|
||||
|
||||
$types = [];
|
||||
$dialogs = ModuleService::dialogs();
|
||||
foreach ($dialogs as $table => $dialog) {
|
||||
$types[] = ['table' => $table, 'name' => $dialog['name']];
|
||||
}
|
||||
|
||||
$_types = DB::table('model')->orderBy('lft')->get()->keyBy('id');
|
||||
$types = [];
|
||||
foreach ($_types as $type) {
|
||||
if ($type['parent_id']) {
|
||||
$name = $_types[$type['parent_id']]['name'].'->'.$type['name'];
|
||||
} else {
|
||||
$name = $type['name'];
|
||||
}
|
||||
$types[] = ['table' => $type['table'], 'name' => $name];
|
||||
}
|
||||
|
||||
$fields = DB::table('model_field')->where('model_id', $model_id)->get(['field', 'name']);
|
||||
|
||||
$regulars = FlowService::regulars();
|
||||
return $this->render([
|
||||
'types' => $types,
|
||||
'fields' => $fields,
|
||||
'row' => $row,
|
||||
'model' => $model,
|
||||
'models' => $models,
|
||||
'model_id' => $model_id,
|
||||
'regulars' => $regulars,
|
||||
'templates' => $templates,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字段类型
|
||||
*/
|
||||
public function typeAction()
|
||||
{
|
||||
$type = Request::get('type');
|
||||
$model_id = Request::get('model_id');
|
||||
if ($type) {
|
||||
return FieldService::{'form_'.$type}([], $model_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段关联对象
|
||||
*/
|
||||
public function getColumnsAction()
|
||||
{
|
||||
$table = Request::get('table');
|
||||
|
||||
$flow = DB::table('model')->where('table', $table)->first();
|
||||
$fields = DB::table('model_field')->where('model_id', $flow['id'])->get();
|
||||
$rows = [];
|
||||
foreach($fields as $field) {
|
||||
if ($field['data_type'] && $field['data_field']) {
|
||||
$f = $field['data_type'].'.'.$field['data_field'];
|
||||
$rows[] = ['field' => $f, 'key' => $field['field'].'.'.$field['data_link'].':'.$f, 'name' => $field['name']];
|
||||
} else {
|
||||
$rows[] = ['field' => $field['field'], 'key' => $field['field'], 'name' => $field['name']];
|
||||
}
|
||||
}
|
||||
return $this->json($rows, true);
|
||||
}
|
||||
|
||||
public function getEnumsAction()
|
||||
{
|
||||
$enums = Option::where('parent_id', 0)->orderBy('sort', 'asc')->orderBy('id', 'asc')->get();
|
||||
return response()->json($enums);
|
||||
}
|
||||
|
||||
public function deleteAction()
|
||||
{
|
||||
$model_id = Request::get('model_id');
|
||||
$id = Request::get('id');
|
||||
$id = is_array($id) ? $id : [$id];
|
||||
Field::whereIn('id', $id)->delete();
|
||||
return $this->json('恭喜你,操作成功。', url('index', ['model_id' => $model_id]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
<?php namespace Gdoo\Model\Controllers;
|
||||
|
||||
use DB;
|
||||
use Auth;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Form;
|
||||
use Gdoo\Model\Grid;
|
||||
|
||||
use Gdoo\Model\Models\Model;
|
||||
use Gdoo\Model\Models\Field;
|
||||
use Gdoo\Model\Models\Step;
|
||||
use Gdoo\Model\Models\Run;
|
||||
use Gdoo\Model\Models\RunLog;
|
||||
use Gdoo\Model\Models\RunStep;
|
||||
use Gdoo\Model\Models\Template;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class ModelController extends DefaultController
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
$header = [
|
||||
'master_name' => '模型',
|
||||
'simple_search_form' => 1,
|
||||
'table' => 'model',
|
||||
'master_table' => 'model',
|
||||
'create_btn' => 1,
|
||||
];
|
||||
|
||||
$search = search_form([
|
||||
'advanced' => '',
|
||||
], [
|
||||
['form_type' => 'text', 'name' => '名称', 'field' => 'model.name', 'value' => '', 'options' => []],
|
||||
], 'model');
|
||||
|
||||
$header['cols'] = [
|
||||
'checkbox' => [
|
||||
'width' => 40,
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
'checkboxSelection' => true,
|
||||
'headerCheckboxSelection' => true,
|
||||
],
|
||||
'sequence_sn' => [
|
||||
'width' => 60,
|
||||
'headerName' => '序号',
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'resizable' => false,
|
||||
'editable' => false,
|
||||
'type' => 'sn',
|
||||
'filter' => false,
|
||||
],
|
||||
'text' => [
|
||||
'field' => 'text',
|
||||
'headerName' => '名称',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-left',
|
||||
'form_type' => 'text',
|
||||
'width' => 100,
|
||||
],
|
||||
'user' => [
|
||||
'field' => 'table',
|
||||
'headerName' => '表名',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-left',
|
||||
'form_type' => 'text',
|
||||
'width' => 0,
|
||||
],
|
||||
'relation' => [
|
||||
'field' => 'relation',
|
||||
'headerName' => '关联外键',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 80,
|
||||
],
|
||||
'updated_dt' => [
|
||||
'field' => 'updated_dt',
|
||||
'headerName' => '操作时间',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 80,
|
||||
],
|
||||
'id' => [
|
||||
'field' => 'id',
|
||||
'headerName' => 'ID',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 40,
|
||||
],
|
||||
'actions' => [
|
||||
'headerName' => '',
|
||||
'cellRenderer' => 'actionCellRenderer',
|
||||
'options' => [[
|
||||
'name' => '字段',
|
||||
'action' => 'field',
|
||||
'display' => 1,
|
||||
],[
|
||||
'name' => '编辑',
|
||||
'action' => 'edit',
|
||||
'display' => $this->access['edit'],
|
||||
]],
|
||||
'width' => 100,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressSizeToFit' => true,
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
],
|
||||
];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = Model::setBy($header);
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
$model->orderBy('lft', 'asc');
|
||||
$model->selectRaw('*, id as master_id');
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
|
||||
$rows->transform(function($row) {
|
||||
$row['updated_dt'] = format_datetime($row['updated_at']);
|
||||
return $row;
|
||||
});
|
||||
|
||||
$items = $rows->items();
|
||||
array_nest($items);
|
||||
$rows->items($items);
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
|
||||
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['search_form'] = $search;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
// 配置权限
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
public function createAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
|
||||
$rules = [
|
||||
'name' => 'required',
|
||||
'table' => 'required|unique:model,table,'.$gets['id'],
|
||||
];
|
||||
$v = Validator::make($gets, $rules);
|
||||
|
||||
if ($v->fails()) {
|
||||
return $this->json($v->errors()->first());
|
||||
}
|
||||
|
||||
$model = Model::findOrNew($gets['id']);
|
||||
$model->fill($gets);
|
||||
$model->save();
|
||||
$model->treeRebuild();
|
||||
return $this->json('恭喜你,操作成功。', true);
|
||||
}
|
||||
|
||||
$model_id = Request::get('id');
|
||||
$model = Model::find($model_id);
|
||||
$models = Model::where('parent_id', 0)->get();
|
||||
|
||||
return $this->render([
|
||||
'model' => $model,
|
||||
'models' => $models,
|
||||
'model_id' => $model_id,
|
||||
], 'create');
|
||||
}
|
||||
|
||||
public function editAction()
|
||||
{
|
||||
return $this->createAction();
|
||||
}
|
||||
|
||||
public function storeAction()
|
||||
{
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
public function deleteAction()
|
||||
{
|
||||
$ids = (array)Request::get('id');
|
||||
if (count($ids) > 0) {
|
||||
Model::whereIn('id', $ids)->delete();
|
||||
Field::whereIn('model_id', $ids)->delete();
|
||||
return $this->json('恭喜你,操作成功。', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
<?php namespace Gdoo\Model\Controllers;
|
||||
|
||||
use DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Form;
|
||||
use Gdoo\Model\Grid;
|
||||
|
||||
use Gdoo\Model\Models\Module;
|
||||
use Gdoo\Model\Services\ModuleService;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class ModuleController extends DefaultController
|
||||
{
|
||||
public $permission = ['test', 'refresh'];
|
||||
|
||||
/**
|
||||
* 邮件设置
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$header = [
|
||||
'master_name' => '模块',
|
||||
'simple_search_form' => 1,
|
||||
'table' => 'model_module',
|
||||
'master_table' => 'model_module',
|
||||
'create_btn' => 0,
|
||||
];
|
||||
|
||||
$search = search_form([
|
||||
'advanced' => '',
|
||||
], [
|
||||
['form_type' => 'text', 'name' => '模块名称', 'field' => 'model_module.name', 'value' => '', 'options' => []],
|
||||
], 'model');
|
||||
|
||||
$query = $search['query'];
|
||||
|
||||
$header['cols'] = [
|
||||
'checkbox' => [
|
||||
'width' => 40,
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
'checkboxSelection' => true,
|
||||
'headerCheckboxSelection' => true,
|
||||
],
|
||||
'sequence_sn' => [
|
||||
'width' => 60,
|
||||
'headerName' => '序号',
|
||||
'suppressSizeToFit' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'resizable' => false,
|
||||
'editable' => false,
|
||||
'type' => 'sn',
|
||||
'filter' => false,
|
||||
],
|
||||
'name' => [
|
||||
'field' => 'name',
|
||||
'headerName' => '模块名称',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-',
|
||||
'form_type' => 'text',
|
||||
'width' => 0,
|
||||
],
|
||||
'status_name' => [
|
||||
'field' => 'status_name',
|
||||
'headerName' => '状态',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'width' => 120,
|
||||
],
|
||||
'id' => [
|
||||
'field' => 'id',
|
||||
'headerName' => 'ID',
|
||||
'sortable' => true,
|
||||
'suppressMenu' => true,
|
||||
'cellClass' => 'text-center',
|
||||
'form_type' => 'text',
|
||||
'width' => 40,
|
||||
],
|
||||
'actions' => [
|
||||
'headerName' => '',
|
||||
'cellRenderer' => 'actionCellRenderer',
|
||||
'options' => [[
|
||||
'name' => '安装',
|
||||
'action' => 'install',
|
||||
'display' => 0,
|
||||
],[
|
||||
'name' => '升级',
|
||||
'action' => 'upgrade',
|
||||
'display' => 0,
|
||||
]],
|
||||
'width' => 80,
|
||||
'cellClass' => 'text-center',
|
||||
'suppressSizeToFit' => true,
|
||||
'suppressMenu' => true,
|
||||
'sortable' => false,
|
||||
'editable' => false,
|
||||
'resizable' => false,
|
||||
'filter' => false,
|
||||
],
|
||||
];
|
||||
$query = $search['query'];
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$model = DB::table($header['table'])->setBy($header);
|
||||
foreach ($search['where'] as $where) {
|
||||
if ($where['active']) {
|
||||
$model->search($where);
|
||||
}
|
||||
}
|
||||
$model->selectRaw('*, id as master_id');
|
||||
$rows = $model->paginate($query['limit'])->appends($query);
|
||||
$rows->transform(function($row) {
|
||||
if ($row['status'] == 1) {
|
||||
$row['status_name'] = '已安装';
|
||||
} else {
|
||||
$row['status_name'] = '未安装';
|
||||
}
|
||||
return $row;
|
||||
});
|
||||
return $rows->toJson();
|
||||
}
|
||||
|
||||
$header['buttons'] = [
|
||||
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
|
||||
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['left_buttons'] = [
|
||||
['name' => '更新', 'color' => 'default', 'icon' => 'fa-refresh', 'action' => 'refresh', 'display' => 1],
|
||||
['name' => '安装', 'color' => 'default', 'icon' => 'fa-cloud-download', 'action' => 'install', 'display' => 1],
|
||||
['name' => '打包', 'color' => 'default', 'icon' => 'fa-cube', 'action' => 'package', 'display' => 1],
|
||||
];
|
||||
|
||||
$header['search_form'] = $search;
|
||||
$header['js'] = Grid::js($header);
|
||||
|
||||
// 配置权限
|
||||
return $this->display([
|
||||
'header' => $header,
|
||||
]);
|
||||
}
|
||||
|
||||
// 新建邮箱帐号
|
||||
public function createAction()
|
||||
{
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
// 编辑邮箱帐号
|
||||
public function editAction()
|
||||
{
|
||||
$id = (int)Request::get('id');
|
||||
$row = DB::table('mail')->where('id', $id)->first();
|
||||
return $this->render([
|
||||
'row' => $row,
|
||||
], 'edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
public function storeAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
$rules = [
|
||||
'name' => 'required',
|
||||
'smtp' => 'required',
|
||||
'user' => 'required',
|
||||
'password' => 'required',
|
||||
'port' => 'required',
|
||||
];
|
||||
$v = Validator::make($gets, $rules);
|
||||
if ($v->fails()) {
|
||||
return $this->json(join('<br>', $v->errors()->all()));
|
||||
|
||||
}
|
||||
if ($gets['id']) {
|
||||
DB::table('mail')->where('id', $gets['id'])->update($gets);
|
||||
} else {
|
||||
DB::table('mail')->insert($gets);
|
||||
}
|
||||
return $this->json('恭喜你,操作成功。', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function deleteAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$id = Request::get('id');
|
||||
Module::whereIn('id', $id)->delete();
|
||||
return $this->json('删除成功。', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新模块列表
|
||||
*/
|
||||
public function refreshAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$modules = ModuleService::details();
|
||||
foreach($modules as $module => $row) {
|
||||
$model = Module::firstOrNew(['module' => $module]);
|
||||
$model->name = $row['name'];
|
||||
$model->module = $module;
|
||||
$model->save();
|
||||
}
|
||||
return $this->json('模块刷新完成。', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php namespace Gdoo\Model\Controllers;
|
||||
|
||||
use DB;
|
||||
use Auth;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Models\Bill;
|
||||
use Gdoo\Model\Models\Model;
|
||||
use Gdoo\Model\Models\Field;
|
||||
use Gdoo\Model\Models\Permission;
|
||||
|
||||
use Gdoo\Model\Services\FlowService;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class PermissionController extends DefaultController
|
||||
{
|
||||
public $permission = ['index','create','delete'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$sorts = Request::get('sort');
|
||||
$i = 0;
|
||||
foreach ($sorts as $sort) {
|
||||
Permission::where('id', $sort)->update(['sort' => $i]);
|
||||
$i ++;
|
||||
}
|
||||
return $this->json('恭喜你,操作成功。', true);
|
||||
}
|
||||
|
||||
$bill_id = Request::get('bill_id');
|
||||
$rows = Permission::where('bill_id', $bill_id)
|
||||
->orderBy('sort', 'asc')
|
||||
->get();
|
||||
|
||||
return $this->display([
|
||||
'bill_id' => $bill_id,
|
||||
'rows' => $rows,
|
||||
]);
|
||||
}
|
||||
|
||||
public function createAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
|
||||
$rules = [
|
||||
'name' => 'required',
|
||||
];
|
||||
$v = Validator::make($gets, $rules);
|
||||
|
||||
$gets['data'] = json_encode($gets['data']);
|
||||
$gets['type'] = join(',', (array)$gets['type']);
|
||||
|
||||
if ($v->fails()) {
|
||||
return $this->back()->withErrors($v)->withInput();
|
||||
}
|
||||
|
||||
if ($gets['id']) {
|
||||
Permission::where('id', $gets['id'])->update($gets);
|
||||
} else {
|
||||
Permission::insert($gets);
|
||||
}
|
||||
|
||||
return $this->success('index', ['bill_id' => $gets['bill_id']], '恭喜你,操作成功。');
|
||||
}
|
||||
|
||||
$id = Request::get('id');
|
||||
$bill_id = Request::get('bill_id');
|
||||
$bill = Bill::find($bill_id);
|
||||
$permission = Permission::find($id);
|
||||
|
||||
$permission['data'] = json_decode($permission['data'], true);
|
||||
|
||||
$master = Model::with([
|
||||
'fields' => function ($q) {
|
||||
$q->orderBy('sort', 'asc')
|
||||
->orderBy('id', 'asc');
|
||||
}])
|
||||
->where('id', $bill->model_id)
|
||||
->first();
|
||||
|
||||
$sublist = Model::with(['fields' => function ($q) {
|
||||
$q->orderBy('sort', 'asc')
|
||||
->orderBy('id', 'asc');
|
||||
}])->where('parent_id', $master->id)->get();
|
||||
|
||||
$permission['bill_id'] = $bill->id;
|
||||
$permission['type'] = explode(',', $permission['type']);
|
||||
|
||||
$models = DB::table('model')->where('parent_id', 0)->orderBy('lft', 'asc')->get();
|
||||
$regulars = FlowService::regulars();
|
||||
|
||||
return $this->display([
|
||||
'permission' => $permission,
|
||||
'regulars' => $regulars,
|
||||
'bill_id' => $bill->id,
|
||||
'models' => $models,
|
||||
'master' => $master,
|
||||
'sublist' => $sublist,
|
||||
]);
|
||||
}
|
||||
|
||||
public function deleteAction()
|
||||
{
|
||||
$id = Request::get('id');
|
||||
if ($id > 0) {
|
||||
Permission::where('id', $id)->delete();
|
||||
return $this->success('index', '恭喜你,操作成功。');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,401 @@
|
||||
<?php namespace Gdoo\Model\Controllers;
|
||||
|
||||
use DB;
|
||||
use Auth;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Models\Bill;
|
||||
use Gdoo\Model\Models\Step;
|
||||
use Gdoo\Model\Models\Model;
|
||||
use Gdoo\Model\Models\Field;
|
||||
use Gdoo\Model\Models\Permission;
|
||||
|
||||
use Gdoo\Model\Services\StepService;
|
||||
use Gdoo\Model\Services\FlowService;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class StepController extends DefaultController
|
||||
{
|
||||
public $permission = ['condition', 'steps', 'index2', 'save', 'add', 'show'];
|
||||
|
||||
/**
|
||||
* 步骤列表
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
// 更新排序
|
||||
if (Request::method() == 'POST') {
|
||||
$sorts = Request::get('sort');
|
||||
StepService::setSort($sorts);
|
||||
return $this->json('恭喜你,操作成功。', true);
|
||||
}
|
||||
|
||||
$bill_id = Request::get('bill_id');
|
||||
$bill = Bill::find($bill_id);
|
||||
$rows = Step::where('bill_id', $bill_id)->orderBy('sort', 'asc')->get()->keyBy('id');
|
||||
|
||||
if ($bill->audit_type == 1) {
|
||||
// 开始结果
|
||||
$count = Step::where('bill_id', $bill_id)->whereIn('type', ['start', 'end'])->count();
|
||||
if ($count == 0) {
|
||||
Step::insert([
|
||||
'bill_id' => $bill_id,
|
||||
'name' => '开始',
|
||||
'sort' => 0,
|
||||
'type' => 'start',
|
||||
]);
|
||||
Step::insert([
|
||||
'bill_id' => $bill_id,
|
||||
'name' => '结束',
|
||||
'sort' => 255,
|
||||
'type' => 'end',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->display([
|
||||
'rows' => $rows,
|
||||
'bill_id' => $bill_id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 步骤列表
|
||||
*/
|
||||
public function index2Action()
|
||||
{
|
||||
// 更新排序
|
||||
if (Request::method() == 'POST') {
|
||||
$bill_id = Request::get('bill_id');
|
||||
$rows = Step::where('bill_id', $bill_id)->orderBy('sort', 'asc')->get()->keyBy('id')->toArray();
|
||||
$top = 100;
|
||||
$left = 0;
|
||||
foreach ($rows as &$row) {
|
||||
$row['top'] = $row['posY'];
|
||||
$row['left'] = $row['posX'];
|
||||
/*
|
||||
if ($row['type'] == 1) {
|
||||
} else {
|
||||
$left = $left + 40;
|
||||
$row['top'] = $top;
|
||||
}
|
||||
$row['left'] = $row['left'] + $left;
|
||||
if ($row['join']) {
|
||||
$joins = explode(',', $row['join']);
|
||||
$_top = count($joins) * 45;
|
||||
$_left = $left;
|
||||
foreach ($joins as $join) {
|
||||
$rows[$join]['top'] = $_top;
|
||||
$rows[$join]['left'] = $_left;
|
||||
$_top = $_top + 65;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
return $this->json($rows, true);
|
||||
}
|
||||
|
||||
$bill_id = Request::get('bill_id');
|
||||
$bill = Bill::find($bill_id);
|
||||
$rows = Step::where('bill_id', $bill_id)->orderBy('sort', 'asc')->get()->keyBy('id');
|
||||
|
||||
if ($bill->audit_type == 1) {
|
||||
// 开始结果
|
||||
$count = Step::where('bill_id', $bill_id)->whereIn('type', ['start', 'end'])->count();
|
||||
if ($count == 0) {
|
||||
Step::insert([
|
||||
'bill_id' => $bill->id,
|
||||
'name' => '开始',
|
||||
'sort' => 0,
|
||||
'type' => 'start',
|
||||
]);
|
||||
Step::insert([
|
||||
'bill_id' => $bill->id,
|
||||
'name' => '结束',
|
||||
'sort' => 255,
|
||||
'type' => 'end',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->display([
|
||||
'rows' => $rows,
|
||||
'bill' => $bill,
|
||||
'bill_id' => $bill_id,
|
||||
]);
|
||||
}
|
||||
|
||||
// 添加步骤和克隆步骤
|
||||
public function addAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
// 是克隆步骤
|
||||
if ($gets['id'] > 0) {
|
||||
$step = DB::table('model_step')->where('id', $gets['id'])->first();
|
||||
unset($step['id'], $step['join']);
|
||||
}
|
||||
$count = DB::table('model_step')->where('bill_id', $gets['bill_id'])->count();
|
||||
$step['bill_id'] = $gets['bill_id'];
|
||||
$step['name'] = '新建节点';
|
||||
DB::table('model_step')->insert($step);
|
||||
return $this->json('节点添加成功', true);
|
||||
}
|
||||
}
|
||||
|
||||
// 查看步骤信息
|
||||
public function showAction()
|
||||
{
|
||||
$gets = Request::all();
|
||||
$row = DB::table('model_step')->where('id', $gets['id'])->first();
|
||||
return $this->json($row, true);
|
||||
}
|
||||
|
||||
// 保存步骤
|
||||
public function saveAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
$_join = [];
|
||||
foreach ($gets['join'] as $join) {
|
||||
$_join[$join['id']][] = $join['target'];
|
||||
}
|
||||
foreach ($gets['position'] as $position) {
|
||||
$position['join'] = join(',', (array)$_join[$position['id']]);
|
||||
$position['posX'] = (int)$position['posX'];
|
||||
$position['posY'] = (int)$position['posY'];
|
||||
DB::table('model_step')->where('id', $position['id'])->update($position);
|
||||
}
|
||||
return $this->json('节点添加成功', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 节点条件
|
||||
*/
|
||||
public function conditionAction()
|
||||
{
|
||||
$id = Request::get('id');
|
||||
$bill_id = Request::get('bill_id');
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
$step = Step::find($id);
|
||||
$step->condition = json_encode($gets['condition'], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
$step->save();
|
||||
return $this->json('恭喜你,流程步骤操作成功。', url('step/index', ['bill_id'=>$bill_id]));
|
||||
}
|
||||
|
||||
$row = Step::findOrNew($id);
|
||||
|
||||
if (empty($row->join)) {
|
||||
return '很抱歉,此进程没有下一步节点。';
|
||||
}
|
||||
|
||||
$join = explode(',', $row->join);
|
||||
$condition = json_decode($row->condition, true);
|
||||
|
||||
$bill = Bill::find($bill_id);
|
||||
$steps = Step::where('bill_id', $bill_id)->whereIn('id', $join)->orderBy('sort', 'ASC')->get();
|
||||
$model = Model::with('fields', 'children.fields')->where('id', $bill->model_id)->first();
|
||||
|
||||
$fields = [
|
||||
['name' => '[创建人ID]', 'field' => '[start_user_id]', 'auto' => 1],
|
||||
['name' => '[创建人角色ID]', 'field' => '[start_role_id]', 'auto' => 1],
|
||||
['name' => '[创建人部门ID]', 'field' => '[start_department_id]', 'auto' => 1],
|
||||
['name' => '[创建人姓名]', 'field' => '[start_user]', 'auto' => 1],
|
||||
['name' => '[创建人职位]', 'field' => '[start_position]', 'auto' => 1],
|
||||
['name' => '[创建人组]', 'field' => '[start_group]', 'auto' => 1],
|
||||
['name' => '[创建人角色]', 'field' => '[start_role]', 'auto' => 1],
|
||||
['name' => '[创建人部门]', 'field' => '[start_department]', 'auto' => 1],
|
||||
['name' => '[经办人姓名]', 'field' => '[edit_user]', 'auto' => 1],
|
||||
['name' => '[经办人ID]', 'field' => '[edit_user_id]', 'auto' => 1],
|
||||
['name' => '[经办人角色ID]', 'field' => '[edit_role_id]', 'auto' => 1],
|
||||
['name' => '[经办人部门ID]', 'field' => '[edit_department_id]', 'auto' => 1],
|
||||
['name' => '[经办人职位]', 'field' => '[edit_position]', 'auto' => 1],
|
||||
['name' => '[经办人群组]', 'field' => '[edit_group]', 'auto' => 1],
|
||||
['name' => '[经办人角色]', 'field' => '[edit_role]', 'auto' => 1],
|
||||
['name' => '[经办人部门]', 'field' => '[edit_department]', 'auto' => 1],
|
||||
];
|
||||
|
||||
$fields = array_merge($fields, $model->fields->toArray());
|
||||
$columns[$model->table] = [
|
||||
'master' => 1,
|
||||
'name' => $model['name'],
|
||||
'data' => $fields
|
||||
];
|
||||
|
||||
foreach ($model->children as $children) {
|
||||
$columns[$children->table] = [
|
||||
'master' => 0,
|
||||
'name' => $children['name'],
|
||||
'data' => $children->fields->toArray(),
|
||||
];
|
||||
}
|
||||
|
||||
return $this->render([
|
||||
'model' => $model,
|
||||
'condition' => $condition,
|
||||
'columns' => $columns,
|
||||
'steps' => $steps,
|
||||
'row' => $row,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建步骤
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
$id = Request::get('id');
|
||||
$bill_id = Request::get('bill_id');
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
|
||||
$gets['field'] = json_encode($gets['field']);
|
||||
$gets['notify'] = json_encode($gets['notify']);
|
||||
$gets['select_org'] = (int)$gets['select_org'];
|
||||
$gets['type_value'] = (string)$gets['type_value'][$gets['type']];
|
||||
|
||||
$rules = array(
|
||||
'name' => 'required',
|
||||
);
|
||||
$v = Validator::make($gets, $rules);
|
||||
|
||||
if ($v->fails()) {
|
||||
return $this->back()->withErrors($v)->withInput();
|
||||
}
|
||||
|
||||
$flow = Step::findOrNew($gets['id']);
|
||||
$flow->fill($gets);
|
||||
$flow->save();
|
||||
|
||||
return $this->json('恭喜你,步骤操作成功。', true);
|
||||
}
|
||||
|
||||
$row = Step::findOrNew($id);
|
||||
|
||||
$row->condition = json_decode($row->condition, true);
|
||||
$row->field = json_decode($row->field, true);
|
||||
$row->notify = json_decode($row->notify, true);
|
||||
|
||||
$bill = Bill::find($bill_id);
|
||||
$steps = Step::where('bill_id', $bill_id)->orderBy('sort', 'ASC')->get();
|
||||
$permissions = Permission::where('bill_id', $bill_id)->orderBy('id', 'ASC')->get();
|
||||
|
||||
$model = Model::with('fields', 'children.fields')->where('id', $bill->model_id)->first();
|
||||
$columns[$model->table]['master'] = 1;
|
||||
$columns[$model->table]['fields'] = $model->fields;
|
||||
|
||||
foreach ($model->children as $children) {
|
||||
$columns[$children->table]['master'] = 0;
|
||||
$columns[$children->table]['fields'] = $children->fields;
|
||||
}
|
||||
|
||||
$regulars = FlowService::regulars();
|
||||
return $this->render([
|
||||
'bill' => $bill,
|
||||
'model' => $model,
|
||||
'columns' => $columns,
|
||||
'permissions' => $permissions,
|
||||
'regulars' => $regulars,
|
||||
'steps' => $steps,
|
||||
'row' => $row,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 流程移交
|
||||
*/
|
||||
public function moveAction()
|
||||
{
|
||||
$id = Request::get('id');
|
||||
$bill_id = Request::get('bill_id');
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$gets = Request::all();
|
||||
|
||||
$gets['condition'] = json_encode($gets['condition']);
|
||||
$gets['field'] = json_encode($gets['field']);
|
||||
$gets['notify'] = json_encode($gets['notify']);
|
||||
|
||||
$gets['type_value'] = (string)$gets['type_value'][$gets['type']];
|
||||
|
||||
$rules = array(
|
||||
'name' => 'required',
|
||||
'sn' => 'required|numeric|min:1',
|
||||
);
|
||||
$v = Validator::make($gets, $rules);
|
||||
|
||||
if ($v->fails()) {
|
||||
return $this->back()->withErrors($v)->withInput();
|
||||
}
|
||||
|
||||
$flow = Step::findOrNew($gets['id']);
|
||||
$flow->fill($gets);
|
||||
$flow->save();
|
||||
|
||||
return $this->success('index', ['bill_id'=>$bill_id], '恭喜你,流程步骤操作成功。');
|
||||
}
|
||||
|
||||
$row = Step::findOrNew($id);
|
||||
|
||||
$row->join = explode(',', $row->join);
|
||||
$row->condition = json_decode($row->condition, true);
|
||||
$row->field = json_decode($row->field, true);
|
||||
$row->notify = json_decode($row->notify, true);
|
||||
|
||||
$bill = Bill::find($bill_id);
|
||||
$steps = Step::where('bill_id', $bill_id)->orderBy('sort', 'ASC')->get();
|
||||
|
||||
$permissions = Permission::where('bill_id', $bill_id)->orderBy('id', 'ASC')->get();
|
||||
|
||||
$model = Model::with('fields', 'children.fields')->where('id', $bill->model_id)->first();
|
||||
$columns[$model->table]['master'] = 1;
|
||||
$columns[$model->table]['fields'] = $model->fields;
|
||||
|
||||
foreach ($model->children as $children) {
|
||||
$columns[$children->table]['master'] = 0;
|
||||
$columns[$children->table]['fields'] = $children->fields;
|
||||
}
|
||||
|
||||
return $this->render([
|
||||
'model' => $model,
|
||||
'columns' => $columns,
|
||||
'permissions' => $permissions,
|
||||
'steps' => $steps,
|
||||
'row' => $row,
|
||||
]);
|
||||
}
|
||||
|
||||
public function stepsAction()
|
||||
{
|
||||
$table = Request::get('table');
|
||||
$model = Model::where('table', $table)->first();
|
||||
|
||||
$rows = Step::where('model_id', $model->id)
|
||||
->where('type', '!=', 'end')
|
||||
->orderBy('sort', 'asc')
|
||||
->get(['id', 'name']);
|
||||
return json_encode($rows);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除步骤
|
||||
*/
|
||||
public function deleteAction()
|
||||
{
|
||||
$id = Request::get('id');
|
||||
if ($id > 0) {
|
||||
$step = Step::find($id);
|
||||
Step::where('id', $id)->delete();
|
||||
StepService::setFieldSort($step->bill_id);
|
||||
return $this->json('恭喜你,流程步骤删除成功。', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
<?php namespace Gdoo\Model\Controllers;
|
||||
|
||||
use DB;
|
||||
use Auth;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
use Gdoo\Model\Models\Model;
|
||||
use Gdoo\Model\Models\Field;
|
||||
use Gdoo\Model\Models\Template;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
use Gdoo\Model\Services\ModelService;
|
||||
use Gdoo\Model\Services\ModuleService;
|
||||
|
||||
class TemplateController extends DefaultController
|
||||
{
|
||||
public $permission = ['create', 'create2', 'create3'];
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
if (Request::method() == 'POST') {
|
||||
$sorts = Request::get('sort');
|
||||
$i = 0;
|
||||
foreach ($sorts as $sort) {
|
||||
Template::where('id', $sort)->update(['sort' => $i]);
|
||||
$i ++;
|
||||
}
|
||||
return $this->json('恭喜你,操作成功。', true);
|
||||
}
|
||||
|
||||
$bill_id = Request::get('bill_id');
|
||||
$rows = Template::where('bill_id', $bill_id)
|
||||
->orderBy('sort', 'asc')
|
||||
->get();
|
||||
|
||||
$models = DB::table('model')->where('parent_id', 0)->orderBy('lft', 'asc')->get();
|
||||
$model = Model::find($bill_id);
|
||||
|
||||
return $this->display([
|
||||
'rows' => $rows,
|
||||
'bill_id' => $bill_id,
|
||||
'models' => $models,
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
public function createAction()
|
||||
{
|
||||
$gets = Request::all();
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
$rules = [
|
||||
'name' => 'required',
|
||||
];
|
||||
$v = Validator::make($gets, $rules);
|
||||
|
||||
if ($v->fails()) {
|
||||
return $this->back()->withErrors($v)->withInput();
|
||||
}
|
||||
|
||||
$gets['type'] = join(',', (array)$gets['type']);
|
||||
$gets['client'] = join(',', (array)$gets['client']);
|
||||
$gets['tpl'] = json_encode($gets['columns'], JSON_UNESCAPED_UNICODE);
|
||||
unset($gets['columns']);
|
||||
|
||||
$model = Template::findOrNew($gets['id']);
|
||||
$model->fill($gets);
|
||||
$model->save();
|
||||
return $this->json('恭喜你,操作成功。', url('create', ['bill_id' => $gets['bill_id'], 'id' => $gets['id']]));
|
||||
}
|
||||
|
||||
$bill_id = Request::get('bill_id');
|
||||
$bill = DB::table('model_bill')->find($bill_id);
|
||||
|
||||
// 主模型
|
||||
$master_model = null;
|
||||
|
||||
// 获取全部模型
|
||||
$models = ModelService::getModelAllFields($bill['model_id']);
|
||||
$lists = [];
|
||||
foreach ($models as $model) {
|
||||
if ($model['parent_id'] == 0) {
|
||||
$master_model = $model;
|
||||
}
|
||||
foreach ($model['fields'] as $field) {
|
||||
$field['table'] = $model['table'];
|
||||
$lists[$field['id']] = $field;
|
||||
}
|
||||
}
|
||||
|
||||
$template = DB::table('model_template')->find($gets['id']);
|
||||
$tpl = $template['tpl'];
|
||||
$views = json_decode($tpl, true);
|
||||
|
||||
foreach ((array)$views as $i => $view) {
|
||||
$v1 = $view['fields'];
|
||||
foreach ($v1 as $j => $sublist) {
|
||||
$_fields = $sublist['fields'];
|
||||
if ($_fields) {
|
||||
foreach ($_fields as $k => $_field) {
|
||||
if (empty($_field['table'])) {
|
||||
$list = $lists[$_field['id']];
|
||||
$_field['table'] = $list['table'];
|
||||
unset($_field['id']);
|
||||
} else {
|
||||
$list = $models[$_field['table']]['fields'][$_field['field']];
|
||||
}
|
||||
if ($list) {
|
||||
$_field['name'] = $list['name'];
|
||||
}
|
||||
$_fields[$k] = $_field;
|
||||
|
||||
unset($models[$_field['table']]['fields'][$_field['field']]);
|
||||
}
|
||||
$v1[$j]['fields'] = $_fields;
|
||||
} else {
|
||||
if (empty($sublist['table'])) {
|
||||
$list = $lists[$sublist['id']];
|
||||
$sublist['table'] = $list['table'];
|
||||
unset($sublist['id']);
|
||||
} else {
|
||||
$sublist['table'] = $master_model['table'];
|
||||
$list = $models[$master_model['table']]['fields'][$sublist['field']];
|
||||
}
|
||||
if ($list) {
|
||||
$sublist['name'] = $list['name'];
|
||||
$sublist['field'] = $list['field'];
|
||||
}
|
||||
$v1[$j] = $sublist;
|
||||
unset($models[$sublist['table']]['fields'][$sublist['field']]);
|
||||
}
|
||||
}
|
||||
$views[$i]['fields'] = $v1;
|
||||
}
|
||||
|
||||
$template['type'] = explode(',', $template['type']);
|
||||
$template['client'] = explode(',', $template['client']);
|
||||
|
||||
return $this->display([
|
||||
'views' => $views,
|
||||
'template' => $template,
|
||||
'model' => $model,
|
||||
'master_model' => $master_model,
|
||||
'bill_id' => $bill_id,
|
||||
'models' => $models,
|
||||
]);
|
||||
}
|
||||
|
||||
public function create2Action()
|
||||
{
|
||||
$gets = Request::all();
|
||||
|
||||
if (Request::method() == 'POST') {
|
||||
|
||||
$gets['code'] = $gets['table'].$gets['code'];
|
||||
$rules = [
|
||||
'name' => 'required',
|
||||
'code' => 'required',
|
||||
];
|
||||
$v = Validator::make($gets, $rules);
|
||||
|
||||
if ($v->fails()) {
|
||||
return $this->back()->withErrors($v)->withInput();
|
||||
}
|
||||
|
||||
$gets['type'] = join(',', (array)$gets['type']);
|
||||
$gets['client'] = join(',', (array)$gets['client']);
|
||||
$gets['tpl'] = json_encode($gets['columns'], JSON_UNESCAPED_UNICODE);
|
||||
unset($gets['columns']);
|
||||
|
||||
$model = Template::findOrNew($gets['id']);
|
||||
$model->fill($gets);
|
||||
$model->save();
|
||||
return $this->json('恭喜你,操作成功。', true);
|
||||
}
|
||||
|
||||
$bill_id = Request::get('bill_id');
|
||||
$bill = DB::table('model_bill')->find($bill_id);
|
||||
$template = DB::table('model_template')->find($gets['id']);
|
||||
|
||||
$leftFields = [];
|
||||
$rightFields = [];
|
||||
$views = (array)json_decode($template['tpl'], true);
|
||||
|
||||
// 获取所有模型
|
||||
$models = array_by(ModelService::getModels($bill['model_id']), 'id');
|
||||
foreach ($views as $view) {
|
||||
if (empty($view['table'])) {
|
||||
$view['table'] = $models[$view['model_id']]['table'];
|
||||
}
|
||||
unset($view['model_id']);
|
||||
unset($view['id']);
|
||||
$rightFields[$view['table'].'.'.$view['field']] = $view;
|
||||
}
|
||||
|
||||
$model = DB::table('model')->find($bill['model_id']);
|
||||
$_fields = DB::table('model_field')->where('model_id', $model['id'])->orderBy('sort', 'asc')->get();
|
||||
foreach ($_fields as $field) {
|
||||
$field_key = $model['table'].'.'.$field['field'];
|
||||
$rightField = $rightFields[$field_key];
|
||||
if ($rightField) {
|
||||
$rightField['name'] = $field['name'];
|
||||
$rightField['table'] = $model['table'];
|
||||
$rightField['field'] = $field['field'];
|
||||
$rightFields[$field_key] = $rightField;
|
||||
continue;
|
||||
}
|
||||
$leftFields[] = ['table' => $model['table'], 'field' => $field['field'], 'name' => $field['name']];
|
||||
}
|
||||
|
||||
// 子模型
|
||||
$childrens = DB::table('model')->where('parent_id', $model['id'])->get();
|
||||
foreach ($childrens as $children) {
|
||||
$_fields = DB::table('model_field')->where('model_id', $children['id'])->orderBy('sort', 'asc')->get();
|
||||
foreach ($_fields as $field) {
|
||||
$field_key = $children['table'].'.'.$field['field'];
|
||||
$rightField = $rightFields[$field_key];
|
||||
if ($rightField) {
|
||||
$rightField['table'] = $children['table'];
|
||||
$rightField['field'] = $field['field'];
|
||||
$rightField['name'] = '['.$children['name'].']'.$field['name'];
|
||||
$rightFields[$field_key] = $rightField;
|
||||
continue;
|
||||
}
|
||||
$leftFields[] = ['table' => $children['table'], 'field' => $field['field'], 'name' => '['.$children['name'].']'.$field['name']];
|
||||
}
|
||||
}
|
||||
|
||||
$rightFields = array_values($rightFields);
|
||||
|
||||
$models = DB::table('model')->where('parent_id', 0)->orderBy('lft', 'asc')->get();
|
||||
$template['leftFields'] = $leftFields;
|
||||
$template['rightFields'] = $rightFields;
|
||||
unset($template['tpl']);
|
||||
$template['type'] = explode(',', $template['type']);
|
||||
$template['client'] = explode(',', $template['client']);
|
||||
$template['code'] = str_replace($model['table'].'_', '', $template['code']);
|
||||
|
||||
return $this->display([
|
||||
'template' => $template,
|
||||
'model' => $model,
|
||||
'bill_id' => $bill_id,
|
||||
'models' => $models,
|
||||
]);
|
||||
}
|
||||
|
||||
public function deleteAction()
|
||||
{
|
||||
$id = Request::get('id');
|
||||
if ($id > 0) {
|
||||
DB::table('model_template')->where('id', $id)->delete();
|
||||
return $this->success('index', '恭喜你,操作成功。');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php namespace Gdoo\Model\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use DB;
|
||||
use Auth;
|
||||
|
||||
use Gdoo\Index\Controllers\DefaultController;
|
||||
|
||||
class TodoController extends DefaultController
|
||||
{
|
||||
public $permission = ['widget'];
|
||||
|
||||
/**
|
||||
* 流程待办
|
||||
*/
|
||||
public function widgetAction(Request $request)
|
||||
{
|
||||
if ($request->method() == 'POST') {
|
||||
$bill_id = $request->get('bill_id');
|
||||
$model = DB::table('model_run_log')
|
||||
->leftJoin('model_run', 'model_run.id', '=', 'model_run_log.run_id')
|
||||
->leftJoin('model_bill', 'model_bill.id', '=', 'model_run.bill_id')
|
||||
->leftJoin('user as run_log_user', 'run_log_user.id', '=', 'model_run_log.created_id')
|
||||
->leftJoin('customer', 'customer.id', '=', DB::raw("model_run.partner_id and model_run.partner_type = 'customer'"))
|
||||
->leftJoin('supplier', 'supplier.id', '=', DB::raw("model_run.partner_id and model_run.partner_type = 'supplier'"))
|
||||
->where('model_run_log.updated_id', 0)
|
||||
->where('model_run_log.user_id', auth()->id())
|
||||
->orderBy('model_run.id', 'desc')
|
||||
->selectRaw("
|
||||
model_run_log.*,
|
||||
model_run.name,
|
||||
model_run.sn,
|
||||
model_run.remark,
|
||||
model_run.bill_id,
|
||||
model_run_log.[option],
|
||||
run_log_user.name as user_name,
|
||||
model_run_log.created_at,
|
||||
model_run.data_id,
|
||||
model_bill.uri as bill_uri,
|
||||
CASE WHEN partner_type = 'customer' THEN customer.name ELSE supplier.name END AS partner_name
|
||||
");
|
||||
|
||||
if ($bill_id > 0) {
|
||||
$model->where('model_run.bill_id', $bill_id);
|
||||
}
|
||||
|
||||
$rows = $model->get();
|
||||
|
||||
$rows->transform(function ($row) {
|
||||
$row['url'] = $row['bill_uri'].'/show';
|
||||
return $row;
|
||||
});
|
||||
return $this->json($rows, true);
|
||||
}
|
||||
|
||||
$selects = DB::table('model_bill')->where('audit_type', 1)->get();
|
||||
return $this->render([
|
||||
'selects' => $selects,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user