mirror of
				https://github.com/v2board/v2board.git
				synced 2025-11-01 01:41:47 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			42 lines
		
	
	
		
			797 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			797 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Services;
 | |
| 
 | |
| use App\Models\Order;
 | |
| use Illuminate\Support\Facades\DB;
 | |
| 
 | |
| class OrderService
 | |
| {
 | |
|     public $order;
 | |
| 
 | |
|     public function __construct(Order $order)
 | |
|     {
 | |
|         $this->order = $order;
 | |
|     }
 | |
| 
 | |
|     public function cancel():bool
 | |
|     {
 | |
|         $order = $this->order;
 | |
|         DB::beginTransaction();
 | |
|         $order->status = 2;
 | |
|         if (!$order->save()) {
 | |
|             DB::rollBack();
 | |
|             return false;
 | |
|         }
 | |
|         if ($order->balance_amount) {
 | |
|             $userService = new UserService();
 | |
|             if (!$userService->addBalance($order->user_id, $order->balance_amount)) {
 | |
|                 DB::rollBack();
 | |
|                 return false;
 | |
|             }
 | |
|         }
 | |
|         DB::commit();
 | |
|         return true;
 | |
|     }
 | |
| 
 | |
|     public function create()
 | |
|     {
 | |
| 
 | |
|     }
 | |
| }
 |