107 lines
2.3 KiB
PHP
107 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace app\crm\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 = true;
|
|
|
|
|
|
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');
|
|
}
|
|
} |