v2board/app/Services/OrderService.php

42 lines
797 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:16:55 +08:00
public function cancel():bool
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();
2020-03-17 20:16:55 +08:00
return false;
2020-03-17 20:00:46 +08:00
}
if ($order->balance_amount) {
$userService = new UserService();
if (!$userService->addBalance($order->user_id, $order->balance_amount)) {
DB::rollBack();
2020-03-17 20:16:55 +08:00
return false;
2020-03-17 20:00:46 +08:00
}
}
DB::commit();
2020-03-17 20:16:55 +08:00
return true;
2020-03-17 19:00:33 +08:00
}
2020-04-09 13:35:27 +08:00
public function create()
{
}
2020-03-17 19:00:33 +08:00
}