支持插件修改订单状态机流程
This commit is contained in:
parent
0f0ba924ce
commit
27bfe41623
|
|
@ -147,8 +147,10 @@ class StateMachineService
|
||||||
*/
|
*/
|
||||||
public function nextBackendStatuses(): array
|
public function nextBackendStatuses(): array
|
||||||
{
|
{
|
||||||
|
$machines = $this->getMachines();
|
||||||
|
|
||||||
$currentStatusCode = $this->order->status;
|
$currentStatusCode = $this->order->status;
|
||||||
$nextStatus = self::MACHINES[$currentStatusCode] ?? [];
|
$nextStatus = $machines[$currentStatusCode] ?? [];
|
||||||
|
|
||||||
if (empty($nextStatus)) {
|
if (empty($nextStatus)) {
|
||||||
return [];
|
return [];
|
||||||
|
|
@ -185,6 +187,12 @@ class StateMachineService
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
foreach ($functions as $function) {
|
foreach ($functions as $function) {
|
||||||
|
if ($function instanceof \Closure) {
|
||||||
|
$function();
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (! method_exists($this, $function)) {
|
if (! method_exists($this, $function)) {
|
||||||
throw new \Exception("{$function} not exist in StateMachine!");
|
throw new \Exception("{$function} not exist in StateMachine!");
|
||||||
}
|
}
|
||||||
|
|
@ -215,6 +223,17 @@ class StateMachineService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取状态机流程, 此处通过 filter hook 可以被外部插件修改
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private function getMachines()
|
||||||
|
{
|
||||||
|
$machines = self::MACHINES;
|
||||||
|
|
||||||
|
return hook_filter('service.state_machine.machines', $machines);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过订单当前状态以及即将变为的状态获取需要触发的事件
|
* 通过订单当前状态以及即将变为的状态获取需要触发的事件
|
||||||
*
|
*
|
||||||
|
|
@ -224,7 +243,9 @@ class StateMachineService
|
||||||
*/
|
*/
|
||||||
private function getFunctions($oldStatus, $newStatus): array
|
private function getFunctions($oldStatus, $newStatus): array
|
||||||
{
|
{
|
||||||
return self::MACHINES[$oldStatus][$newStatus] ?? [];
|
$machines = $this->getMachines();
|
||||||
|
|
||||||
|
return $machines[$oldStatus][$newStatus] ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue