update: order manual

This commit is contained in:
tokumeikoi 2021-08-28 15:11:59 +09:00
parent 23462e2753
commit c95d374cc0
5 changed files with 61 additions and 68 deletions

View File

@ -63,10 +63,45 @@ class OrderController extends Controller
]); ]);
} }
public function paid(Request $request)
{
$order = Order::where('trade_no', $request->input('trade_no'))
->first();
if (!$order) {
abort(500, '订单不存在');
}
if ($order->status !== 0) abort(500, '只能对待支付的订单进行操作');
$orderService = new OrderService($order);
if (!$orderService->paid('manual_operation')) {
abort(500, '更新失败');
}
return response([
'data' => true
]);
}
public function cancel(Request $request)
{
$order = Order::where('trade_no', $request->input('trade_no'))
->first();
if (!$order) {
abort(500, '订单不存在');
}
if ($order->status !== 0) abort(500, '只能对待支付的订单进行操作');
$orderService = new OrderService($order);
if (!$orderService->cancel()) {
abort(500, '更新失败');
}
return response([
'data' => true
]);
}
public function update(OrderUpdate $request) public function update(OrderUpdate $request)
{ {
$params = $request->only([ $params = $request->only([
'status',
'commission_status' 'commission_status'
]); ]);
@ -76,27 +111,6 @@ class OrderController extends Controller
abort(500, '订单不存在'); abort(500, '订单不存在');
} }
if (isset($params['status'])) {
$orderService = new OrderService($order);
switch ((int)$params['status']) {
case 1: {
if (!$orderService->success(time())) {
abort(500, '更新失败');
}
break;
}
case 2: {
if (!$orderService->cancel()) {
abort(500, '更新失败');
}
break;
}
}
return response([
'data' => true
]);
}
try { try {
$order->update($params); $order->update($params);
} catch (\Exception $e) { } catch (\Exception $e) {
@ -108,26 +122,6 @@ class OrderController extends Controller
]); ]);
} }
public function repair(Request $request)
{
if (empty($request->input('trade_no'))) {
abort(500, '参数错误');
}
$order = Order::where('trade_no', $request->input('trade_no'))
->where('status', 0)
->first();
if (!$order) {
abort(500, '订单不存在或订单已支付');
}
$order->status = 1;
if (!$order->save()) {
abort(500, '保存失败');
}
return response([
'data' => true
]);
}
public function assign(OrderAssign $request) public function assign(OrderAssign $request)
{ {
$plan = Plan::find($request->input('plan_id')); $plan = Plan::find($request->input('plan_id'));

View File

@ -34,7 +34,7 @@ class PaymentController extends Controller
} }
if ($order->status === 1) return true; if ($order->status === 1) return true;
$orderService = new OrderService($order); $orderService = new OrderService($order);
if (!$orderService->success($callbackNo)) { if (!$orderService->paid($callbackNo)) {
return false; return false;
} }
$telegramService = new TelegramService(); $telegramService = new TelegramService();

View File

@ -63,9 +63,10 @@ class AdminRoute
}); });
// Order // Order
$router->get ('/order/fetch', 'Admin\\OrderController@fetch'); $router->get ('/order/fetch', 'Admin\\OrderController@fetch');
$router->post('/order/repair', 'Admin\\OrderController@repair');
$router->post('/order/update', 'Admin\\OrderController@update'); $router->post('/order/update', 'Admin\\OrderController@update');
$router->post('/order/assign', 'Admin\\OrderController@assign'); $router->post('/order/assign', 'Admin\\OrderController@assign');
$router->post('/order/paid', 'Admin\\OrderController@paid');
$router->post('/order/cancel', 'Admin\\OrderController@cancel');
// User // User
$router->get ('/user/fetch', 'Admin\\UserController@fetch'); $router->get ('/user/fetch', 'Admin\\UserController@fetch');
$router->post('/user/update', 'Admin\\UserController@update'); $router->post('/user/update', 'Admin\\UserController@update');

View File

@ -81,25 +81,6 @@ class OrderService
DB::commit(); DB::commit();
} }
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 setOrderType(User $user) public function setOrderType(User $user)
{ {
@ -232,18 +213,35 @@ class OrderService
$order->surplus_order_ids = array_column($orders->toArray(), 'id'); $order->surplus_order_ids = array_column($orders->toArray(), 'id');
} }
public function success(string $callbackNo) public function paid(string $callbackNo)
{ {
$order = $this->order; $order = $this->order;
if ($order->status !== 0) { if ($order->status !== 0) return true;
return true;
}
$order->status = 1; $order->status = 1;
$order->paid_at = time(); $order->paid_at = time();
$order->callback_no = $callbackNo; $order->callback_no = $callbackNo;
return $order->save(); return $order->save();
} }
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;
}
private function buyByResetTraffic() private function buyByResetTraffic()
{ {

File diff suppressed because one or more lines are too long