修改审批
This commit is contained in:
@@ -3,7 +3,7 @@ namespace app\admin\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\admin\service\ApprovalFlowsService;
|
||||
use app\common\service\ApprovalFlowsService;
|
||||
|
||||
class ApprovalFlowsController extends BaseController
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ namespace app\admin\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\admin\service\ApprovalInstancesService;
|
||||
use app\common\service\ApprovalInstancesService;
|
||||
|
||||
class ApprovalInstancesController extends BaseController
|
||||
{
|
||||
|
||||
@@ -3,8 +3,7 @@ namespace app\admin\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\admin\service\ApprovalRecordsService;
|
||||
use app\admin\service\SysDictService;
|
||||
use app\common\service\ApprovalRecordsService;
|
||||
use app\common\model\SysDictItem;
|
||||
use support\Request;
|
||||
|
||||
@@ -31,16 +30,16 @@ class ApprovalRecordsController extends BaseController
|
||||
foreach ($data['records'] as $key => &$record) {
|
||||
$result = [
|
||||
'id' => $record['id'],
|
||||
'flows_name' => $record['approvalInstance']['flows']['name'],
|
||||
'flows_name' => $record['instance']['flows']['name'],
|
||||
|
||||
'instance_id' => $record['instance_id'],
|
||||
|
||||
'biz_id' => $record['approvalInstance']['biz_id'],
|
||||
'biz_desc' => '备货单【'.$record['approvalInstance']['bizInfo']['order_no'].'】',
|
||||
'biz_type' => $record['approvalInstance']['flow_type'],
|
||||
'biz_id' => $record['instance']['biz_id'],
|
||||
'biz_desc' => '备货单【'.$record['instance']['bizInfo']['order_no'].'】',
|
||||
'biz_type' => $record['instance']['flow_type'],
|
||||
|
||||
'initiator_name' => $record['approvalInstance']['initiator']['name'],
|
||||
'initiator_avatar' => $record['approvalInstance']['initiator']['avatar'],
|
||||
'initiator_name' => $record['instance']['initiator']['name'],
|
||||
'initiator_avatar' => $record['instance']['initiator']['avatar'],
|
||||
|
||||
'approver_name' => $record['approver']['name'],
|
||||
'approver_avatar' => $record['approver']['avatar'],
|
||||
@@ -53,8 +52,8 @@ class ApprovalRecordsController extends BaseController
|
||||
'comment' => $record['comment'],
|
||||
'approved_at' => $record['approved_at'],
|
||||
|
||||
'finished_at' => $record['approvalInstance']['finished_at'],
|
||||
'deadline_at' => $record['approvalInstance']['deadline_at'],
|
||||
'finished_at' => $record['instance']['finished_at'],
|
||||
'deadline_at' => $record['instance']['deadline_at'],
|
||||
|
||||
'created_at' => $record['created_at']
|
||||
];
|
||||
@@ -87,4 +86,57 @@ class ApprovalRecordsController extends BaseController
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function todo(Request $request)
|
||||
{
|
||||
try {
|
||||
$raw = $this->service->serviceList($request, 'todo');
|
||||
$data = $this->transformData($raw, method_exists($this, 'todoFormat')
|
||||
? [$this, 'todoFormat']
|
||||
: null);
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected function todoFormat($data)
|
||||
{
|
||||
if (isset($data['records']) && count($data['records']) > 0) {
|
||||
foreach ($data['records'] as $key => &$record) {
|
||||
$result = [
|
||||
'id' => $record['id'],
|
||||
'flows_name' => $record['instance']['flows']['name'],
|
||||
|
||||
'instance_id' => $record['instance_id'],
|
||||
|
||||
'biz_id' => $record['instance']['biz_id'],
|
||||
'biz_desc' => '备货单号【'.$record['instance']['bizInfo']['order_no'].'】',
|
||||
'biz_type' => $record['instance']['flow_type'],
|
||||
|
||||
'initiator_name' => $record['instance']['initiator']['name'],
|
||||
'initiator_avatar' => $record['instance']['initiator']['avatar'],
|
||||
|
||||
'approver_name' => $record['approver']['name'],
|
||||
'approver_avatar' => $record['approver']['avatar'],
|
||||
|
||||
'step_index' => $record['step_index'],
|
||||
'action' => $record['action'],
|
||||
'action_desc' => SysDictItem::where('item_value', $record['action'])->where('status', 1)->value('item_label'),
|
||||
'status' => $record['status'],
|
||||
'status_desc' => SysDictItem::where('item_value', $record['status'])->where('status', 1)->value('item_label'),
|
||||
'comment' => $record['comment'],
|
||||
'approved_at' => $record['approved_at'],
|
||||
|
||||
'finished_at' => $record['instance']['finished_at'],
|
||||
'deadline_at' => $record['instance']['deadline_at'],
|
||||
|
||||
'created_at' => $record['created_at']
|
||||
];
|
||||
$record = $result;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\traits\crud\CrudLogicTrait;
|
||||
use app\admin\model\ApprovalFlows;
|
||||
|
||||
class ApprovalFlowsLogic
|
||||
{
|
||||
use CrudLogicTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = ApprovalFlows::class;
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\traits\crud\CrudLogicTrait;
|
||||
use app\admin\model\ApprovalInstances;
|
||||
|
||||
class ApprovalInstancesLogic
|
||||
{
|
||||
use CrudLogicTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = ApprovalInstances::class;
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\traits\crud\CrudLogicTrait;
|
||||
use app\admin\model\ApprovalRecords;
|
||||
|
||||
class ApprovalRecordsLogic
|
||||
{
|
||||
use CrudLogicTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = ApprovalRecords::class;
|
||||
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
class ApprovalFlows extends Model
|
||||
{
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'mysql';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'approval_flows';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
protected $fillable = ['id', 'name', 'type', 'steps', 'is_active', 'timeout_hours', 'timeout_action', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
|
||||
protected $casts = [
|
||||
'steps' => 'array',
|
||||
];
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
use app\common\model\StockOrders;
|
||||
use app\common\model\User;
|
||||
use support\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class ApprovalInstances extends Model
|
||||
{
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'mysql';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'approval_instances';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
// protected $fillable = ['id', 'flow_type', 'biz_id', 'biz_type', 'form_data', 'initiator_id', 'status', 'current_step', 'finished_at', 'deadline_at', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
|
||||
protected $fillable = [
|
||||
'flow_type',
|
||||
'biz_id',
|
||||
'biz_type',
|
||||
'form_data',
|
||||
'initiator_id',
|
||||
'status',
|
||||
'current_step',
|
||||
'finished_at',
|
||||
'deadline_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'form_data' => 'array', // 自动转换 JSON 字段为数组
|
||||
'finished_at' => 'datetime',
|
||||
'deadline_at' => 'datetime',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* 一个审批实例可以有多个审批记录
|
||||
*/
|
||||
public function approvalRecords(): HasMany
|
||||
{
|
||||
return $this->hasMany(ApprovalRecords::class, 'instance_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前步骤的所有审批记录(pending 状态)
|
||||
*/
|
||||
public function currentStepRecords()
|
||||
{
|
||||
return $this->approvalRecords()
|
||||
->where('step_index', $this->current_step)
|
||||
->where('status', 'pending');
|
||||
}
|
||||
|
||||
public function flows()
|
||||
{
|
||||
return $this->belongsTo(ApprovalFlows::class, 'flow_type', 'type');
|
||||
}
|
||||
|
||||
public function initiator()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'initiator_id', 'id');
|
||||
}
|
||||
|
||||
|
||||
public function bizInfo()
|
||||
{
|
||||
return $this->hasOne(StockOrders::class, 'id', 'biz_id');
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
use app\common\model\User;
|
||||
use support\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ApprovalRecords extends Model
|
||||
{
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'mysql';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'approval_records';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
// protected $fillable = ['id', 'instance_id', 'approver_id', 'step_index', 'action', 'status', 'comment', 'approved_at', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
|
||||
protected $fillable = [
|
||||
'instance_id',
|
||||
'approver_id',
|
||||
'step_index',
|
||||
'action',
|
||||
'status',
|
||||
'comment',
|
||||
'approved_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'approved_at' => 'datetime',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* 一条审批记录属于一个审批实例
|
||||
*/
|
||||
public function approvalInstance(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ApprovalInstances::class, 'instance_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联审批人
|
||||
*/
|
||||
public function approver()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'approver_id');
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\admin\validate\ApprovalFlowsValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\admin\model\ApprovalFlows;
|
||||
use support\Request;
|
||||
|
||||
class ApprovalFlowsService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = ApprovalFlows::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = ApprovalFlowsValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
|
||||
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
|
||||
{
|
||||
$p = $request->all();
|
||||
|
||||
$config = [];
|
||||
$config['model'] = $this->modelClass;
|
||||
switch ($scene) {
|
||||
case 'index':
|
||||
$config['order']['id'] = 'desc';
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
case 'update':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\admin\validate\ApprovalInstancesValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\admin\model\ApprovalInstances;
|
||||
|
||||
class ApprovalInstancesService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = ApprovalInstances::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = ApprovalInstancesValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\admin\validate\ApprovalRecordsValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\admin\model\ApprovalRecords;
|
||||
use support\Request;
|
||||
|
||||
class ApprovalRecordsService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = ApprovalRecords::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = ApprovalRecordsValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
|
||||
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
|
||||
{
|
||||
$p = $request->all();
|
||||
|
||||
$config = [];
|
||||
$config['model'] = $this->modelClass;
|
||||
switch ($scene) {
|
||||
case 'index':
|
||||
$config['order']['id'] = 'desc';
|
||||
|
||||
$config['with'] = [
|
||||
'approvalInstance',
|
||||
'approver',
|
||||
'approvalInstance.flows',
|
||||
'approvalInstance.initiator',
|
||||
'approvalInstance.bizInfo'
|
||||
];
|
||||
|
||||
// $config['dataLimit']['type'] = 'relation';
|
||||
// $config['dataLimit']['userId'] = $request->user->uid;
|
||||
// $config['dataLimit']['userField'] = 'approver_id';
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
case 'update':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'logs':
|
||||
$config['where']['instance_id'] = $p['instance_id'];
|
||||
$config['order']['id'] = 'desc';
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
public function serviceApprove(Request $request)
|
||||
{
|
||||
$param = $request->all();
|
||||
$appro = new \app\common\utils\approval\service\ApprovalFlowService();
|
||||
return $appro->approve($param['instance_id'], $request->user->uid, $param['action'], $param['comment']);
|
||||
}
|
||||
|
||||
|
||||
public function serviceLogs(Request $request)
|
||||
{
|
||||
$config = $this->buildQueryConfig($request, 'logs');
|
||||
$item = $this->logicListAll($config);
|
||||
return $this->postProcess('Logs', $item);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class ApprovalFlowsValidate extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class ApprovalInstancesValidate extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class ApprovalRecordsValidate extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user