创建版本

This commit is contained in:
2021-02-22 12:17:00 +08:00
commit af555f49c3
2332 changed files with 369202 additions and 0 deletions
@@ -0,0 +1,248 @@
<?php namespace Gdoo\Workflow\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;
use Gdoo\Model\Models\Run;
use Gdoo\Model\Models\RunLog;
use Gdoo\Model\Models\RunStep;
use Gdoo\Model\Models\Step;
use Gdoo\Model\Models\Template;
use Gdoo\Workflow\Models\BillCategory;
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,
],
'category_name' => [
'field' => 'category_name',
'headerName' => '类别',
'sortable' => true,
'suppressMenu' => true,
'cellClass' => 'text-center',
'form_type' => 'text',
'width' => 120,
],
'code' => [
'field' => 'code',
'headerName' => '编码',
'sortable' => true,
'suppressMenu' => true,
'cellClass' => 'text-center',
'form_type' => 'text',
'width' => 100,
],
'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_bill_category', 'model_bill_category.id', '=', 'model_bill.category_id')
->selectRaw('
model_bill.*,
model_bill.id as master_id,
model_bill_category.name as category_name
')
->where('model_bill.type', 1)
->orderBy('model_bill.id', 'desc')
->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']);
$row['sn_rule'] = $row['sn_prefix'].$row['sn_rule'].($row['sn_length'] > 0 ? $row['sn_length'] : '');
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());
}
// 流程设置为1
$gets['audit_type'] = 1;
$gets['type'] = 1;
$bill = Bill::findOrNew($gets['id']);
$bill->fill($gets);
$bill->save();
return $this->json('恭喜你,操作成功。', true);
}
$bill_id = Request::get('id');
$bill = Bill::find($bill_id);
$categorys = BillCategory::get();
return $this->render([
'bill' => $bill,
'categorys' => $categorys,
'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,209 @@
<?php namespace Gdoo\Workflow\Controllers;
use Request;
use DB;
use Validator;
use Gdoo\Workflow\Models\BillCategory;
use Gdoo\Model\Grid;
use Gdoo\Index\Controllers\DefaultController;
use Gdoo\Model\Models\Bill;
class CategoryController extends DefaultController
{
// 流程类别
public function indexAction()
{
$header = [
'master_name' => '流程类别',
'simple_search_form' => 1,
'table' => 'model_bill_category',
'master_table' => 'model_bill_category',
'create_btn' => 1,
];
$search = search_form([
'advanced' => '',
], [
['form_type' => 'text', 'name' => '名称', 'field' => 'model_bill_category.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,
],
'remark' => [
'field' => 'remark',
'headerName' => '备注',
'sortable' => true,
'suppressMenu' => true,
'cellClass' => 'text-left',
'form_type' => 'text',
'width' => 0,
],
'sort' => [
'field' => 'sort',
'headerName' => '排序',
'sortable' => true,
'suppressMenu' => true,
'cellClass' => 'text-center',
'form_type' => 'text',
'width' => 60,
],
'updated_dt' => [
'field' => 'updated_dt',
'headerName' => '操作时间',
'sortable' => true,
'suppressMenu' => true,
'cellClass' => 'text-center',
'form_type' => 'text',
'width' => 60,
],
'id' => [
'field' => 'id',
'headerName' => 'ID',
'sortable' => true,
'suppressMenu' => true,
'cellClass' => 'text-center',
'form_type' => 'text',
'width' => 40,
],
'actions' => [
'headerName' => '',
'cellRenderer' => 'actionCellRenderer',
'options' => [[
'name' => '编辑',
'action' => 'edit',
'display' => $this->access['edit'],
]],
'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 = BillCategory::orderBy('sort', 'desc')
->selectRaw("*, id as master_id")
->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']);
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',
];
$v = Validator::make($gets, $rules);
if ($v->fails()) {
return $this->json($v->errors()->first());
}
$category = BillCategory::findOrNew($gets['id']);
$category->fill($gets);
$category->save();
return $this->json('恭喜你,操作成功。', true);
}
$category_id = Request::get('id');
$category = BillCategory::find($category_id);
return $this->render([
'category' => $category,
], 'create');
}
public function editAction()
{
return $this->createAction();
}
public function storeAction()
{
return $this->editAction();
}
// 删除流程类别
public function deleteAction()
{
if (Request::method() == 'POST') {
$id = Request::get('id');
if (empty($id)) {
return $this->json('最少选择一行记录。');
}
$count = Bill::whereIn('category_id', $id)->count();
if ($count > 0) {
return $this->json('此类别存在工作数据,无法删除。');
}
BillCategory::whereIn('id', $id)->delete();
return $this->json('恭喜你,操作成功。', true);
}
}
}
@@ -0,0 +1,88 @@
<?php namespace Gdoo\Workflow\Controllers;
use DB;
use Request;
use Gdoo\Workflow\Models\Workflow;
use Gdoo\Workflow\Models\WorkflowCategory;
use Gdoo\Index\Controllers\DefaultController;
class DesignController extends DefaultController
{
public function indexAction()
{
$search = search_form([
'referer' => 1
], [
['text','work.title','流程名称'],
['text','work.id','流程编号'],
['category','work.category_id','流程类别'],
]);
$query = $search['query'];
$model = Workflow::query();
foreach ($search['where'] as $where) {
if ($where['active']) {
$model->search($where);
}
}
$rows = $model->paginate()->appends($query);
$counts = DB::table('work_process')
->selectRaw('work_id,count(id) as count')
->groupBy('work_id')
->pluck('count', 'work_id');
$categorys = WorkflowCategory::get()->keyBy('id');
return $this->display(array(
'rows' => $rows,
'counts' => $counts,
'categorys' => $categorys,
'search' => $search,
));
}
public function addAction()
{
$gets = Request::all();
$model = Workflow::findOrNew($gets['id']);
if (Request::method() == 'POST') {
if (empty($gets['title'])) {
return $this->error('流程名称必须填写。');
}
$model->fill($gets)->save();
return $this->success('index', '工作流程保存成功。');
}
$row = Workflow::find($gets['id']);
$category = WorkflowCategory::get();
return $this->display(array(
'row' => $row,
'category' => $category,
));
}
public function processAction()
{
$this->view->set(array(
'row' => $row,
));
return $this->display();
}
// 删除流程
public function deleteAction()
{
$id = Request::get('id', 0);
if ($id > 0) {
// 此处应该删除所有的有关的文件
Workflow::where('id', $id)->delete();
return $this->success('index', '工作流删除成功。');
}
}
}
@@ -0,0 +1,90 @@
<?php namespace Gdoo\Workflow\Controllers;
use Request;
use DB;
use Gdoo\Workflow\Models\Workflow;
use Gdoo\Index\Controllers\DefaultController;
class FormController extends DefaultController
{
public $permission = ['view'];
// 表单设计
public function indexAction()
{
if ($post = $this->post()) {
unset($post['count_item']);
$work_id = $post['work_id'];
unset($post['work_id']);
$post['template'] = $_POST['template'];
DB::table('work')->where('id', $work_id)->update($post);
Workflow::cacheForm($work_id);
return $this->json('流程节点添加成功', true);
}
$workId = Request::get('work_id');
$row = DB::table('work')->where('id', $workId)->first();
return $this->display([
'row' => $row,
]);
}
// 查看步骤信息
public function viewAction()
{
$review = Request::get('review');
$workId = Request::get('id');
$work = DB::table('work as w')
->LeftJoin('work_step as s', 'w.id', '=', 's.work_id')
->where('s.number', 1)
->where('w.id', $workId)
->first(['w.template_short','w.title as work_title','w.id','s.work_id','w.type as work_type','s.field as field_write','s.field_check','s.field_secret','s.field_auto']);
$work['opflag'] = 1;
// $work['printflag'] = 1;
$work['step_id'] = $stepId;
$work['id'] = $work['work_id'];
$workFlow = array(
'workId' => (int)$work['work_id'],
'stepNumber' => 1,
'stepId' => $work['step_id'],
'workType' => $work['work_type']
);
$form = Workflow::parseForm($work['template_short'], $work);
$work['js'] = json_encode($workFlow);
$views = [
'work' => $work,
'template' => $form['template'],
'jsonload' => $form['jsonload'],
'js' => $form['js'],
];
if ($review == true) {
return $this->render($views, 'review');
} else {
return $this->display($views, 'view');
}
}
// 表单计数
public function countAction()
{
$workId = Request::get('work_id');
if ($workId > 0) {
DB::table('work')->where('id', $workId)->increment('count');
$row = DB::table('work')->where('id', $workId)->first();
return $row['count'];
}
}
}
@@ -0,0 +1,81 @@
<?php namespace Gdoo\Workflow\Controllers;
use Request;
use Gdoo\Workflow\Models\Process;
use Gdoo\Workflow\Models\ProcessData;
use Gdoo\Index\Controllers\DefaultController;
class MonitorController extends DefaultController
{
public $permission = [];
public function indexAction()
{
}
// 监控流程汇总
public function summaryAction()
{
$search = search_form([], [
['text','user.name','主办人'],
['department','user.department_id','主办人部门'],
['role','user.role_id','主办人角色'],
]);
$query = $search['query'];
$model = Process::LeftJoin('work_process_data', 'work_process.id', '=', 'work_process_data.process_id')
->LeftJoin('work', 'work.id', '=', 'work_process.work_id')
->LeftJoin('user', 'user.id', '=', 'work_process_data.user_id')
->where('work_process.end_time', 0)
->where('work_process.state', 1)
->where('work_process_data.flag', 1)
->where('work.state', 1)
->where('user.status', 1);
foreach ($search['where'] as $where) {
if ($where['active']) {
$model->search($where);
}
}
$rows = $model->get(['user.name', 'work_process_data.*']);
$items = [];
foreach ($rows as $row) {
$user_id = $row['user_id'];
$time = time() - $row['add_time'];
// 大于三十天
if ($time > 2592000) {
$items[$user_id]['c'] ++;
// 大于三天
} elseif ($time > 259200) {
$items[$user_id]['b'] ++;
// 大于一天
} elseif ($time > 86400) {
$items[$user_id]['a'] ++;
}
$items[$user_id]['total'] ++;
$items[$user_id]['name'] = $row->user->name ? $row->user->name : $user_id;
$items[$user_id]['user_id'] = $user_id;
}
$rows = [];
foreach ($items as $user_id => $item) {
$rows[] = $item;
}
return $this->display([
'rows' => $rows,
'search' => $search,
]);
}
}
@@ -0,0 +1,337 @@
<?php namespace Gdoo\Workflow\Controllers;
use DB;
use Request;
use Gdoo\Workflow\Models\Workflow;
use Gdoo\Index\Controllers\DefaultController;
class StepController extends DefaultController
{
public $permission = ['dialog'];
// 步骤列表
public function indexAction()
{
$work_id = Request::get('work_id');
if (Request::method() == 'POST') {
$rows = DB::table('work_step')
->where('work_id', $work_id)
->orderBy('id', 'asc')
->get();
$data['total'] = sizeof($rows);
$data['rows'] = $rows;
exit(json_encode($data));
}
$work = DB::table('work')->where('id', $work_id)->first();
return $this->display([
'work_id' => $work_id,
'work' => $work,
]);
}
// 添加步骤和克隆步骤
public function addAction()
{
if (Request::method() == 'POST') {
$gets = Request::all();
// 是克隆步骤
if ($gets['id'] > 0) {
$step = DB::table('work_step')->where('id', $gets['id'])->first();
unset($step['id'], $step['join']);
}
$count = DB::table('work_step')->where('work_id', $gets['work_id'])->count();
$step['work_id'] = $gets['work_id'];
$step['number'] = $count + 1;
$step['title'] = '新建步骤'.$step['number'];
DB::table('work_step')->insert($step);
return $this->json('流程节点添加成功', true);
}
}
// 步骤条件设置
public function editAction()
{
if (Request::method() == 'POST') {
$post = Request::all();
// 验证字段组合
if ($post['check']) {
$field_check = array();
$post['check'] = array_filter($post['check']);
foreach ($post['check'] as $k => $v) {
$field_check[] = $v.'='.$post['check_select'][$k];
}
$post['field_check'] = join(',', $field_check);
}
// 组合自动选人规则
if ($post['select_user_type'] > 0) {
$select_keys = array(
7 => 'select_field_user',
8 => 'select_process_user'
);
$select_key = $select_keys[$post['select_user_type']];
if ($select_key) {
$post['select_user_sign'] = $post[$select_key];
}
}
// checkbox 选项处理
$post['last'] = empty($post['last']) ? 0 : 1;
$post['deny'] = empty($post['deny']) ? 0 : 1;
$post['print'] = empty($post['print']) ? 0 : 1;
// 通知人类型
$post['notification_type'] = empty($post['notification_type']) ? '' : json_encode($post['notification_type']);
$post['notification_text'] = array_filter($post['notification_text']);
$post['notification_text'] = empty($post['notification_text']) ? '' : json_encode($post['notification_text']);
// 写字段
$post['field'] = join(',', (array)$post['write']);
// 保密字段
$post['field_secret'] = join(',', (array)$post['secret']);
// 宏字段
$post['field_auto'] = join(',', (array)$post['micro']);
// 条件转入组合
if (is_array($post['conditions'])) {
foreach ($post['conditions'] as $step_id => $condition) {
// 检查条件是否是空的
$data['condition'] = $condition == 'empty' ? '' : join("\n", (array)$condition);
DB::table('work_step')->where('id', $step_id)->update($data);
}
}
unset(
$post['select_process_user'],
$post['select_field_user'],
$post['check_select'],
$post['conditions'],
$post['check'],
$post['write'],
$post['secret'],
$post['micro']
);
DB::table('work_step')->where('id', $post['id'])->update($post);
return $this->json('流程节点设置保存成功', true);
}
$id = (int)Request::get('id');
$tabs['selected'] = Request::get('tab');
// 子表步骤
$row = DB::table('work_step')->where('id', $id)->first();
$row['joinArray'] = explode(',', $row['join']);
// 当前工作全部步骤节点
$rows = DB::table('work_step')->where('work_id', $row['work_id'])->get();
$rows = array_by($rows);
// 取得工作流主表信息
$fields = Workflow::getFormData($row['work_id']);
$_fields = [];
foreach ($fields as $key => $value) {
if ($value['class'] == 'listview') {
$titles = explode('`', $value['lv_title']);
foreach ($titles as $index => $title) {
if ($title) {
$_value = $value;
$_value['itemid'] = $_value['itemid'].'_'.$index;
$_value['title'] = $value['title'].'['.$title.']';
$_value['desc'] = $this->getFieldDescription($_value);
$_fields[$key.'_'.$index] = $_value;
}
}
} else {
$value['desc'] = $this->getFieldDescription($value);
$_fields[$key] = $value;
}
}
$fields = $_fields;
$field_write = explode(",", $row['field']);
$field_secret = explode(",", $row['field_secret']);
$field_check = explode(",", $row['field_check']);
$field_auto = explode(",", $row['field_auto']);
$field_select = array();
if ($row['field_check']) {
$checkarr = $checkarr2 = $check = array();
foreach ($field_check as $k => $v) {
if ($v) {
$part = explode("=", $v);
$checkarr[] = $part[0];
$checkarr2[] = $part[1];
}
}
}
// 取得字段名称的id号
foreach ($fields as $k => $v) {
if (in_array($v['title'], $field_write)) {
$field_select['write'][] = $v['itemid'];
}
if (in_array($v['title'], $field_auto)) {
$field_select['auto'][] = $v['itemid'];
}
if (is_array($checkarr) && in_array($v['title'], $checkarr)) {
$field_select['check'][$v['itemid']] = array_shift($checkarr2);
}
if (in_array($v['title'], $field_secret)) {
$field_select['secret'][] = $v['itemid'];
}
if ($v['class'] != "sign") {
$item_name_all[] = $v['title'];
}
}
if (strstr($row['field'], "[attach@]")) {
$field_select['write'][] = "attach";
}
$field_select['write'] = join(',', (array)$field_select['write']);
$field_select['auto'] = join(',', (array)$field_select['auto']);
$field_select['secret'] = join(',', (array)$field_select['secret']);
if (is_array($field_select['check'])) {
$field_select['check'] = json_encode($field_select['check']);
}
$row['notification_type'] = json_decode($row['notification_type'], true);
$row['notification_text'] = json_decode($row['notification_text'], true);
return $this->render([
'row' => $row,
'rows' => $rows,
'tabs' => $tabs,
'fields' => $fields,
'field_select'=> $field_select,
]);
}
public function getFieldDescription($v)
{
// 步骤字段类型匹配
$desc = '';
switch ($v['tag']) {
case "input":
if ($v['type'] == "text") {
if ($v['class'] == "auto") {
$desc .= "宏控件:";
}
$desc .= '单行文本';
} elseif ($v['type'] == "checkbox") {
$desc = '复选按钮';
} elseif ($v['class'] == "date") {
$desc = '日历控件';
} elseif ($v['class'] == "calc") {
$desc = '计算控件';
} elseif ($v['class'] == "user") {
$desc = '用户控件';
}
break;
case "textarea":
$desc = '多行文本';
if ($v['rich'] == 1) {
$desc .= ":富文本";
}
break;
case "select":
if ($v['class'] == "auto") {
$desc .= "宏控件:";
}
$desc .= '下拉菜单';
break;
case "button":
if ($v['class'] == "data") {
$desc = $lang['DataSelectControl'];
} elseif ($v['class'] == "fetch") {
$desc = $lang['DataGetControl'];
break;
}
break;
case "img":
if ($v['class'] == "radio") {
$desc = '单选按钮';
} elseif ($v['class'] == "sign") {
$desc = '签章控件';
} elseif ($v['class'] == "listview") {
$desc = '列表控件';
} elseif ($v['class'] == "progressbar") {
$desc = $lang['progressbar'];
} elseif ($v['class'] == "imgupload") {
$desc = '图片上传控件';
} elseif ($v['class'] == "qrcode") {
$desc = '二维码控件';
}
break;
default:
$desc = "";
}
return $desc;
}
// 查看步骤信息
public function viewAction()
{
$gets = Request::all();
$row = DB::table('work_step')->where('id', $gets['id'])->first();
return $this->json($row, true);
}
// 表单计数
public function itemAction()
{
$id = Request::get('id');
$row = DB::table('work_form')->where('id', $id)->first();
return $row['max_item'] + 1;
}
// 保存步骤
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']]);
DB::table('work_step')->where('id', $position['id'])->update($position);
}
return $this->json('流程节点添加成功', true);
}
}
public function dialogAction()
{
$gets = Request::all();
// 返回json
if (Request::ajax()) {
$rows = [];
if ($gets['work_id']) {
$rows = DB::table('work_step')->where('work_id', $gets['work_id'])->get(['id','title']);
}
return $this->json($rows);
}
}
// 删除步骤
public function deleteAction()
{
if (Request::method() == 'POST') {
$id = Request::get('id');
DB::table('work_step')->where('id', $id)->delete();
return $this->json('工作流删除成功。', true);
}
}
}
@@ -0,0 +1,262 @@
<?php namespace Gdoo\Workflow\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;
class TemplateController extends DefaultController
{
public $permission = ['create', 'create2'];
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;
}
$_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];
}
$template['tpl'] = json_encode($views, JSON_UNESCAPED_UNICODE);
$template['type'] = explode(',', $template['type']);
$template['client'] = explode(',', $template['client']);
return $this->display([
'template' => $template,
'model' => $model,
'bill_id' => $bill_id,
'models' => $models,
'types' => $types,
]);
}
public function create2Action()
{
$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('恭喜你,操作成功。', 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']);
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,76 @@
<?php namespace Gdoo\Workflow\Controllers;
use DB;
use Auth;
use Request;
use Gdoo\Index\Controllers\DefaultController;
use Gdoo\User\Models\User;
class WidgetController extends DefaultController
{
public $permission = ['index'];
public function indexAction()
{
if (Request::method() == 'POST') {
$rows = [];
$json['total'] = sizeof($rows);
$json['data'] = $rows;
return response()->json($json);
}
return $this->render();
}
public function efficiencyAction()
{
if (Request::method() == 'POST') {
$model = DB::table('work_process')->LeftJoin('work_process_data', 'work_process.id', '=', 'work_process_data.process_id')
->LeftJoin('work', 'work.id', '=', 'work_process.work_id')
->LeftJoin('user', 'user.id', '=', 'work_process_data.user_id')
->where('work_process.end_time', 0)
->where('work_process.state', 1)
->where('work_process_data.flag', 1)
->where('work.state', 1)
->where('user.status', 1);
// 权限列表
$users = User::authoriseAccess();
if ($users) {
$model->whereIn('work_process_data.user_id', $users);
}
$res = $model->get(['work_process_data.*', 'user.name']);
$sets = [];
foreach ($res as $row) {
$time = time() - $row['add_time'];
// 大于三十天
if ($time > 2592000) {
$sets[$row['user_id']]['c'] ++;
$sets[$row['user_id']]['count'] ++;
// 大于三天
} elseif ($time > 259200) {
$sets[$row['user_id']]['b'] ++;
$sets[$row['user_id']]['count'] ++;
// 大于一天
} elseif ($time > 86400) {
//$sets[$row['user_id']]['a'] ++;
}
$sets[$row['user_id']]['user'] = $row['name'];
}
$rows = [];
foreach ($sets as $set) {
if($set['count']) {
$rows[] = $set;
}
}
$json['total'] = sizeof($rows);
$json['data'] = $rows;
return $this->json($rows, true);
}
return $this->render();
}
}
File diff suppressed because it is too large Load Diff