WokerTask/app/adminapi/controller/FlowController.php

88 lines
3.2 KiB
PHP

<?php
declare (strict_types=1);
namespace app\adminapi\controller;
use think\facade\Db;
class FlowController extends BaseAdminController
{
public function index()
{
[$page, $limit] = $this->getPage();
$type = get_config('approve.type');
$query = Db::name('Flow');
$list = $query->field('f.*,a.name as username,t.title as flow_cate')
->alias('f')
->join('Admin a', 'a.id = f.admin_id', 'left')
->join('FlowType t', 't.id = f.flow_cate', 'left')
->page($page, $limit)->select()->toArray();
$count = $query->count();
foreach ($list as $key => &$value) {
$department = Db::name('Department')->where('id', 'in', $value['department_ids'])->column('title');
$value['department'] = implode(',', $department);
if ($value['department'] == '') {
$value['department'] = '全公司';
}
foreach ($type as $k => $val) {
if ($value['type'] == $val['id']) {
$value['type_name'] = $val['title'];
}
}
}
return $this->success('success', ['count' => $count, 'data' => $list]);
}
//添加新增/编辑
public function create()
{
$param = get_params();
$param['copy_to'] = empty($param['copy_to']) ? [] : $param['copy_to'];
$param['flow_detail'] = empty($param['flow_detail']) ? [] : $param['flow_detail'];
if ($param['flow_detail']['type'] == 1 || $param['flow_detail']['type'] == 3) {
foreach ($param['flow_detail']['step'] as $key => $step) {
if ($param['flow_detail']['type'] == 1 && $step['type'] < 3) {
continue;
}
if (empty($step['user'])) {
return $this->fail('第' . ($key + 1) . '行的指定人未选择');
}
}
}
$param['flow_detail'] = json_encode($param['flow_detail'], JSON_UNESCAPED_UNICODE);
$param['copy_to'] = json_encode($param['copy_to'], JSON_UNESCAPED_UNICODE);
if ($param['id'] > 0) {
$param['update_time'] = time();
Db::name('Flow')->strict(false)->field(true)->update($param);
} else {
$param['admin_id'] = $this->adminId;
$param['create_time'] = time();
$mid = Db::name('Flow')->strict(false)->field(true)->insertGetId($param);
}
return $this->success('保存成功', [], 1, 1);
}
public function view($id)
{
$info = Db::name('Flow')->find($id);
$info['copy_to'] = json_decode($info['copy_to'], true);
$info['flow_detail'] = json_decode($info['flow_detail'], true);
return $this->data($info);
}
//禁用/启用
public function status()
{
$param = get_params();
$param['update_time'] = time();
$res = Db::name('Flow')->where('id', $param['id'])->strict(false)->field('status,update_time')->update($param);
if ($res !== false) {
return $this->success('保存成功', [], 1, 1);
} else {
return $this->fail('操作失败');
}
}
}