update: add payment show

This commit is contained in:
tokumeikoi 2022-03-18 02:49:51 +08:00
parent 6a2125794b
commit 791ba463c3
3 changed files with 27 additions and 16 deletions

View File

@ -46,12 +46,23 @@ class PaymentController extends Controller
]); ]);
} }
public function show(Request $request)
{
$payment = Payment::find($request->input('id'));
if (!$payment) abort(500, '支付方式不存在');
$payment->enable = !$payment->enable;
if (!$payment->save()) abort(500, '保存失败');
return response([
'data' => true
]);
}
public function save(Request $request) public function save(Request $request)
{ {
if (!config('v2board.app_url')) { if (!config('v2board.app_url')) {
abort(500, '请在站点配置中配置站点地址'); abort(500, '请在站点配置中配置站点地址');
} }
$validateRules = [ $params = $request->validate([
'name' => 'required', 'name' => 'required',
'icon' => 'nullable', 'icon' => 'nullable',
'payment' => 'required', 'payment' => 'required',
@ -59,20 +70,7 @@ class PaymentController extends Controller
'notify_domain' => 'nullable|url', 'notify_domain' => 'nullable|url',
'handling_fee_fixed' => 'nullable|integer', 'handling_fee_fixed' => 'nullable|integer',
'handling_fee_percent' => 'nullable|numeric|between:0.1,100' 'handling_fee_percent' => 'nullable|numeric|between:0.1,100'
]; ], [
if ($request->input('id')) {
$payment = Payment::find($request->input('id'));
if (!$payment) abort(500, '支付方式不存在');
try {
$payment->update($request->only(array_keys($validateRules)));
} catch (\Exception $e) {
abort(500, $e->getMessage());
}
return response([
'data' => true
]);
}
$params = $request->validate($validateRules, [
'name.required' => '显示名称不能为空', 'name.required' => '显示名称不能为空',
'payment.required' => '网关参数不能为空', 'payment.required' => '网关参数不能为空',
'config.required' => '配置参数不能为空', 'config.required' => '配置参数不能为空',
@ -80,6 +78,18 @@ class PaymentController extends Controller
'handling_fee_fixed.integer' => '固定手续费格式有误', 'handling_fee_fixed.integer' => '固定手续费格式有误',
'handling_fee_percent.between' => '百分比手续费范围须在0.1-100之间' 'handling_fee_percent.between' => '百分比手续费范围须在0.1-100之间'
]); ]);
if ($request->input('id')) {
$payment = Payment::find($request->input('id'));
if (!$payment) abort(500, '支付方式不存在');
try {
$payment->update($params);
} catch (\Exception $e) {
abort(500, $e->getMessage());
}
return response([
'data' => true
]);
}
$params['uuid'] = Helper::randomChar(8); $params['uuid'] = Helper::randomChar(8);
if (!Payment::create($params)) { if (!Payment::create($params)) {
abort(500, '保存失败'); abort(500, '保存失败');

View File

@ -111,6 +111,7 @@ class AdminRoute
$router->post('/payment/getPaymentForm', 'Admin\\PaymentController@getPaymentForm'); $router->post('/payment/getPaymentForm', 'Admin\\PaymentController@getPaymentForm');
$router->post('/payment/save', 'Admin\\PaymentController@save'); $router->post('/payment/save', 'Admin\\PaymentController@save');
$router->post('/payment/drop', 'Admin\\PaymentController@drop'); $router->post('/payment/drop', 'Admin\\PaymentController@drop');
$router->post('/payment/show', 'Admin\\PaymentController@show');
// System // System
$router->get ('/system/getStatus', 'Admin\\SystemController@getStatus'); $router->get ('/system/getStatus', 'Admin\\SystemController@getStatus');
}); });

File diff suppressed because one or more lines are too long