feat: add article and production modules
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\produce\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use plugin\produce\app\model\StatusTransition;
|
||||
|
||||
class StatusTransitionDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return StatusTransition::class;
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['trigger_event', 'description'];
|
||||
}
|
||||
|
||||
public function selectList(
|
||||
array $where,
|
||||
string|array $field = '*',
|
||||
int $page = 0,
|
||||
int $limit = 0,
|
||||
string $order = '',
|
||||
array $with = [],
|
||||
bool $search = false,
|
||||
?array $withoutScopes = null
|
||||
): ?Collection {
|
||||
$with = array_unique(array_merge($with, ['step', 'fromStatus', 'toStatus']));
|
||||
$order = $order ?: 'priority desc, sort asc, id desc';
|
||||
|
||||
return parent::selectList($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
|
||||
}
|
||||
|
||||
public function handleSearch(array $where, bool $isPage = true): Builder
|
||||
{
|
||||
$query = parent::handleSearch($where, $isPage);
|
||||
|
||||
if (($where['step_id'] ?? '') !== '') {
|
||||
$query->where('step_id', $where['step_id']);
|
||||
}
|
||||
|
||||
if (($where['from_status_id'] ?? '') !== '') {
|
||||
$query->where('from_status_id', $where['from_status_id']);
|
||||
}
|
||||
|
||||
if (($where['to_status_id'] ?? '') !== '') {
|
||||
$query->where('to_status_id', $where['to_status_id']);
|
||||
}
|
||||
|
||||
if (($where['trigger_event'] ?? '') !== '') {
|
||||
$query->where('trigger_event', $where['trigger_event']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getAutoTransitionsByStep(int|string $stepId, int|string $fromStatusId): array
|
||||
{
|
||||
return $this->getModel()::query()
|
||||
->where('step_id', $stepId)
|
||||
->where('from_status_id', $fromStatusId)
|
||||
->where('auto_trigger', 1)
|
||||
->where('status', 1)
|
||||
->orderBy('priority', 'desc')
|
||||
->orderBy('sort', 'asc')
|
||||
->with(['toStatus:id,status_name'])
|
||||
->get()
|
||||
->map(function ($item) {
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'step_id' => $item->step_id,
|
||||
'from_status_id' => $item->from_status_id,
|
||||
'to_status_id' => $item->to_status_id,
|
||||
'to_status_name' => $item->toStatus->status_name ?? '',
|
||||
'trigger_event' => $item->trigger_event,
|
||||
'event_config' => $item->event_config,
|
||||
'priority' => $item->priority,
|
||||
];
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public function getAutoTransitions(int|string $stepId, int|string $fromStatusId, string $triggerEvent): array
|
||||
{
|
||||
return $this->getModel()::query()
|
||||
->where('step_id', $stepId)
|
||||
->where('from_status_id', $fromStatusId)
|
||||
->where('trigger_event', $triggerEvent)
|
||||
->where('auto_trigger', 1)
|
||||
->where('status', 1)
|
||||
->orderBy('priority', 'desc')
|
||||
->orderBy('sort', 'asc')
|
||||
->with(['toStatus:id,status_name'])
|
||||
->get()
|
||||
->map(function ($item) {
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'step_id' => $item->step_id,
|
||||
'from_status_id' => $item->from_status_id,
|
||||
'to_status_id' => $item->to_status_id,
|
||||
'to_status_name' => $item->toStatus->status_name ?? '',
|
||||
'trigger_event' => $item->trigger_event,
|
||||
'event_config' => $item->event_config,
|
||||
'priority' => $item->priority,
|
||||
];
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user