master
parent
b78f8b01e0
commit
4d6f37fab9
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Models\Orders;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ChangeOrderStatus
|
||||
{
|
||||
public function __invoke(Orders $order)
|
||||
{
|
||||
if ($order->status != request()->from_status) {
|
||||
throw new \Exception("订单状态不匹配");
|
||||
}
|
||||
|
||||
$availableToStatus = [];
|
||||
switch ($order->status) {
|
||||
case Orders::STATUS_FINISHED:
|
||||
$availableToStatus = [Orders::STATUS_ONGOING];
|
||||
break;
|
||||
default:
|
||||
//do nothing
|
||||
}
|
||||
if (!in_array(request()->to_status, $availableToStatus)) {
|
||||
throw new \Exception("订单状态不匹配");
|
||||
}
|
||||
|
||||
$order->update([
|
||||
"status" => request()->to_status
|
||||
]);
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue