add balance payment

This commit is contained in:
Tokumeikoi 2020-03-17 20:16:55 +08:00
parent 3075f0d411
commit 6fba0b6dab
3 changed files with 20 additions and 5 deletions

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Admin;
use App\Http\Requests\Admin\OrderUpdate;
use App\Services\OrderService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Order;
@ -48,7 +49,7 @@ class OrderController extends Controller
public function update(OrderUpdate $request)
{
$updateData = $request->only([
$params = $request->only([
'status',
'commission_status'
]);
@ -59,8 +60,18 @@ class OrderController extends Controller
abort(500, '订单不存在');
}
if ((int)$params['status'] === 2) {
$orderService = new OrderService($order);
if (!$orderService->cancel()) {
abort(500, '更新失败');
}
return response([
'data' => true
]);
}
try {
$order->update($updateData);
$order->update($params);
} catch (\Exception $e) {
abort(500, '更新失败');
}

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Http\Requests\User\OrderSave;
use App\Services\OrderService;
use App\Services\UserService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
@ -395,8 +396,8 @@ class OrderController extends Controller
if ($order->status !== 0) {
abort(500, '只可以取消待支付订单');
}
$order->status = 2;
if (!$order->save()) {
$orderService = new OrderService($order);
if (!$orderService->cancel()) {
abort(500, '取消失败');
}
return response([

View File

@ -14,20 +14,23 @@ class OrderService
$this->order = $order;
}
public function cancel():void
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;
}
}