mirror of
https://github.com/v2board/v2board.git
synced 2025-01-25 23:49:09 +08:00
add balance payment
This commit is contained in:
parent
3075f0d411
commit
6fba0b6dab
@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Http\Requests\Admin\OrderUpdate;
|
use App\Http\Requests\Admin\OrderUpdate;
|
||||||
|
use App\Services\OrderService;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Order;
|
use App\Models\Order;
|
||||||
@ -48,7 +49,7 @@ class OrderController extends Controller
|
|||||||
|
|
||||||
public function update(OrderUpdate $request)
|
public function update(OrderUpdate $request)
|
||||||
{
|
{
|
||||||
$updateData = $request->only([
|
$params = $request->only([
|
||||||
'status',
|
'status',
|
||||||
'commission_status'
|
'commission_status'
|
||||||
]);
|
]);
|
||||||
@ -59,8 +60,18 @@ class OrderController extends Controller
|
|||||||
abort(500, '订单不存在');
|
abort(500, '订单不存在');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((int)$params['status'] === 2) {
|
||||||
|
$orderService = new OrderService($order);
|
||||||
|
if (!$orderService->cancel()) {
|
||||||
|
abort(500, '更新失败');
|
||||||
|
}
|
||||||
|
return response([
|
||||||
|
'data' => true
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$order->update($updateData);
|
$order->update($params);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
abort(500, '更新失败');
|
abort(500, '更新失败');
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ namespace App\Http\Controllers\User;
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\User\OrderSave;
|
use App\Http\Requests\User\OrderSave;
|
||||||
|
use App\Services\OrderService;
|
||||||
use App\Services\UserService;
|
use App\Services\UserService;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
@ -395,8 +396,8 @@ class OrderController extends Controller
|
|||||||
if ($order->status !== 0) {
|
if ($order->status !== 0) {
|
||||||
abort(500, '只可以取消待支付订单');
|
abort(500, '只可以取消待支付订单');
|
||||||
}
|
}
|
||||||
$order->status = 2;
|
$orderService = new OrderService($order);
|
||||||
if (!$order->save()) {
|
if (!$orderService->cancel()) {
|
||||||
abort(500, '取消失败');
|
abort(500, '取消失败');
|
||||||
}
|
}
|
||||||
return response([
|
return response([
|
||||||
|
@ -14,20 +14,23 @@ class OrderService
|
|||||||
$this->order = $order;
|
$this->order = $order;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cancel():void
|
public function cancel():bool
|
||||||
{
|
{
|
||||||
$order = $this->order;
|
$order = $this->order;
|
||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
$order->status = 2;
|
$order->status = 2;
|
||||||
if (!$order->save()) {
|
if (!$order->save()) {
|
||||||
DB::rollBack();
|
DB::rollBack();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if ($order->balance_amount) {
|
if ($order->balance_amount) {
|
||||||
$userService = new UserService();
|
$userService = new UserService();
|
||||||
if (!$userService->addBalance($order->user_id, $order->balance_amount)) {
|
if (!$userService->addBalance($order->user_id, $order->balance_amount)) {
|
||||||
DB::rollBack();
|
DB::rollBack();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DB::commit();
|
DB::commit();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user