2026-02-24 17:57:25 +08:00
|
|
|
<?php
|
|
|
|
|
|
2026-02-25 18:09:04 +08:00
|
|
|
namespace app\model;
|
2026-02-24 17:57:25 +08:00
|
|
|
|
2026-02-25 18:15:17 +08:00
|
|
|
use support\Model;
|
2026-02-24 17:57:25 +08:00
|
|
|
|
|
|
|
|
class ApprovalNode extends Model
|
|
|
|
|
{
|
|
|
|
|
protected $table = 'approval_node';
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'flow_id',
|
|
|
|
|
'type',
|
|
|
|
|
'name',
|
|
|
|
|
'order',
|
|
|
|
|
'approvers',
|
|
|
|
|
'conditions',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'approvers' => 'array',
|
|
|
|
|
'conditions' => 'array',
|
|
|
|
|
'order' => 'integer',
|
|
|
|
|
'created_at' => 'datetime',
|
|
|
|
|
'updated_at' => 'datetime',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
2026-02-25 18:26:22 +08:00
|
|
|
* 节点类型常量(与数据库 enum 保持一致)
|
2026-02-24 17:57:25 +08:00
|
|
|
*/
|
|
|
|
|
const TYPE_APPROVER = 'approver'; // 审批人(单人)
|
|
|
|
|
const TYPE_AND_APPROVE = 'and_approve'; // 会签(需所有人通过)
|
|
|
|
|
const TYPE_OR_APPROVE = 'or_approve'; // 或签(任一人通过)
|
|
|
|
|
const TYPE_NOTIFY = 'notify'; // 抄送(通知用)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 关联流程
|
|
|
|
|
*/
|
|
|
|
|
public function flow()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(ApprovalFlow::class, 'flow_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取指定顺序的节点
|
|
|
|
|
*/
|
|
|
|
|
public function scopeByOrder($query, int $order)
|
|
|
|
|
{
|
|
|
|
|
return $query->where('order', $order);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断是否是审批节点
|
|
|
|
|
*/
|
|
|
|
|
public function isApprovalNode(): bool
|
|
|
|
|
{
|
|
|
|
|
return in_array($this->type, [
|
|
|
|
|
self::TYPE_APPROVER,
|
|
|
|
|
self::TYPE_AND_APPROVE,
|
|
|
|
|
self::TYPE_OR_APPROVE,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断是否是会签
|
|
|
|
|
*/
|
|
|
|
|
public function isAndApprove(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->type === self::TYPE_AND_APPROVE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断是否是或签
|
|
|
|
|
*/
|
|
|
|
|
public function isOrApprove(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->type === self::TYPE_OR_APPROVE;
|
|
|
|
|
}
|
2026-02-25 18:26:22 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断是否是单人审批
|
|
|
|
|
*/
|
|
|
|
|
public function isSingleApprove(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->type === self::TYPE_APPROVER;
|
|
|
|
|
}
|
2026-02-24 17:57:25 +08:00
|
|
|
}
|