v2board/app/Services/OrderService.php

34 lines
677 B
PHP
Raw Normal View History

2020-03-17 19:00:33 +08:00
<?php
namespace App\Services;
use App\Models\Order;
2020-03-17 20:00:46 +08:00
use Illuminate\Support\Facades\DB;
2020-03-17 19:00:33 +08:00
class OrderService
{
public $order;
public function __construct(Order $order)
{
$this->order = $order;
}
2020-03-17 20:00:46 +08:00
public function cancel():void
2020-03-17 19:00:33 +08:00
{
2020-03-17 20:00:46 +08:00
$order = $this->order;
DB::beginTransaction();
$order->status = 2;
if (!$order->save()) {
DB::rollBack();
}
if ($order->balance_amount) {
$userService = new UserService();
if (!$userService->addBalance($order->user_id, $order->balance_amount)) {
DB::rollBack();
}
}
DB::commit();
2020-03-17 19:00:33 +08:00
}
}