mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-14 19:40:53 +08:00
feat: enhance plugin management
- Add command support for plugin management - Optimize plugin management page layout - Add email copy functionality for users - Convert payment methods and Telegram Bot to plugin system
This commit is contained in:
@@ -9,16 +9,18 @@ use App\Services\PaymentService;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
public function getPaymentMethods()
|
||||
{
|
||||
$methods = [];
|
||||
foreach (glob(base_path('app//Payments') . '/*.php') as $file) {
|
||||
array_push($methods, pathinfo($file)['filename']);
|
||||
}
|
||||
return $this->success($methods);
|
||||
|
||||
$pluginMethods = PaymentService::getAllPaymentMethodNames();
|
||||
$methods = array_merge($methods, $pluginMethods);
|
||||
|
||||
return $this->success(array_unique($methods));
|
||||
}
|
||||
|
||||
public function fetch()
|
||||
@@ -37,23 +39,29 @@ class PaymentController extends Controller
|
||||
|
||||
public function getPaymentForm(Request $request)
|
||||
{
|
||||
$paymentService = new PaymentService($request->input('payment'), $request->input('id'));
|
||||
return $this->success(collect($paymentService->form())->values());
|
||||
try {
|
||||
$paymentService = new PaymentService($request->input('payment'), $request->input('id'));
|
||||
return $this->success(collect($paymentService->form()));
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail([400, '支付方式不存在或未启用']);
|
||||
}
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
$payment = Payment::find($request->input('id'));
|
||||
if (!$payment) return $this->fail([400202 ,'支付方式不存在']);
|
||||
if (!$payment)
|
||||
return $this->fail([400202, '支付方式不存在']);
|
||||
$payment->enable = !$payment->enable;
|
||||
if (!$payment->save()) return $this->fail([500 ,'保存失败']);
|
||||
if (!$payment->save())
|
||||
return $this->fail([500, '保存失败']);
|
||||
return $this->success(true);
|
||||
}
|
||||
|
||||
public function save(Request $request)
|
||||
{
|
||||
if (!admin_setting('app_url')) {
|
||||
return $this->fail([400 ,'请在站点配置中配置站点地址']);
|
||||
return $this->fail([400, '请在站点配置中配置站点地址']);
|
||||
}
|
||||
$params = $request->validate([
|
||||
'name' => 'required',
|
||||
@@ -73,18 +81,19 @@ class PaymentController extends Controller
|
||||
]);
|
||||
if ($request->input('id')) {
|
||||
$payment = Payment::find($request->input('id'));
|
||||
if (!$payment) return $this->fail([400202 ,'支付方式不存在']);
|
||||
if (!$payment)
|
||||
return $this->fail([400202, '支付方式不存在']);
|
||||
try {
|
||||
$payment->update($params);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error($e);
|
||||
return $this->fail([500 ,'保存失败']);
|
||||
Log::error($e);
|
||||
return $this->fail([500, '保存失败']);
|
||||
}
|
||||
return $this->success(true);
|
||||
}
|
||||
$params['uuid'] = Helper::randomChar(8);
|
||||
if (!Payment::create($params)) {
|
||||
return $this->fail([500 ,'保存失败']);
|
||||
return $this->fail([500, '保存失败']);
|
||||
}
|
||||
return $this->success(true);
|
||||
}
|
||||
@@ -92,7 +101,8 @@ class PaymentController extends Controller
|
||||
public function drop(Request $request)
|
||||
{
|
||||
$payment = Payment::find($request->input('id'));
|
||||
if (!$payment) return $this->fail([400202 ,'支付方式不存在']);
|
||||
if (!$payment)
|
||||
return $this->fail([400202, '支付方式不存在']);
|
||||
return $this->success($payment->delete());
|
||||
}
|
||||
|
||||
@@ -105,7 +115,7 @@ class PaymentController extends Controller
|
||||
'ids.required' => '参数有误',
|
||||
'ids.array' => '参数有误'
|
||||
]);
|
||||
try{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
foreach ($request->input('ids') as $k => $v) {
|
||||
if (!Payment::find($v)->update(['sort' => $k + 1])) {
|
||||
@@ -113,11 +123,11 @@ class PaymentController extends Controller
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
}catch(\Exception $e){
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return $this->fail([500 ,'保存失败']);
|
||||
return $this->fail([500, '保存失败']);
|
||||
}
|
||||
|
||||
|
||||
return $this->success(true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user