logoResponse(fn () => $service->options()); } public function saveLogo(\App\Services\Payment\RechargeChannelLogoService $service) { return $this->logoResponse(fn () => $service->save(request()->all())); } private function logoResponse(callable $callback) { try { return $this->success($callback()); } catch (ValidationException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); } catch (\Throwable $e) { \Illuminate\Support\Facades\Log::error('recharge_channel_logo_failed', ['exception' => $e]); return $this->error(HttpStatus::CUSTOM_ERROR, '充值Logo操作失败,请稍后重试'); } } public function delete(RechargeChannelConfigurationService $service) { try { $params = request()->validate(['id' => ['required', 'integer', 'min:1']]); $service->delete((int)$params['id']); return $this->success(); } catch (ValidationException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); } catch (ModelNotFoundException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, '通道不存在'); } catch (\PDOException $e) { report($e); return $this->error(HttpStatus::CUSTOM_ERROR, '删除通道失败,请稍后重试'); } catch (Exception $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage()); } } public function options(RechargeChannelConfigurationService $service) { try { $params = request()->validate([ 'data_type' => ['required', 'integer', 'in:1,2'], 'id' => ['nullable', 'integer', 'min:1'], ]); return $this->success($service->options((int)$params['data_type'], isset($params['id']) ? (int)$params['id'] : null)); } catch (ValidationException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); } catch (ModelNotFoundException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, '数据不存在'); } catch (\PDOException $e) { report($e); return $this->error(HttpStatus::CUSTOM_ERROR, '读取通道选项失败'); } catch (Exception $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage()); } } /** 充值/提现通道操作日志 */ public function logs(RechargeChannelConfigurationService $service) { try { $params = request()->validate([ 'data_type' => ['required', 'integer', 'in:1,2'], 'channel_id' => ['nullable', 'integer', 'min:1'], 'operator_name' => ['nullable', 'string', 'max:100'], 'action' => ['nullable', 'string', 'in:create,update,delete,save'], 'start_time' => ['nullable', 'date'], 'end_time' => ['nullable', 'date'], 'page' => ['nullable', 'integer', 'min:1'], 'limit' => ['nullable', 'integer', 'min:1', 'max:200'], ]); return $this->success($service->logs($params)); } catch (ValidationException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); } catch (Exception $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage()); } } //获取充值方式 public function getChannel() { $data_type = (int)request()->input('data_type', 1) === 2 ? 2 : 1; $channel = RechargeChannelModel::getChannel($data_type); return $this->success(['total' => count($channel), 'data' => $channel]); } /** * 充值通道组合列表 */ public function groupList() { try { $page = request()->input('page', 1); $limit = request()->input('limit', 15); $query = new RechargeChannelGroup(); $count = $query->count(); $list = $query ->forPage($page, $limit) ->get(); foreach($list as &$item) { $item->rechargeTypes = $item['recharge_type'] ? RechargeChannelModel::getChannel(1, $item['recharge_type']) : []; $item->withdrawTypes = $item['withdraw_type'] ? RechargeChannelModel::getChannel(2, $item['withdraw_type']) : []; } } catch (Exception $e) { return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage()); } return $this->success(['total' => $count, 'data' => $list]); } /** * 充值通道组合管理更新 */ public function updateGroup() { try { $params = request()->validate([ 'id' => ['nullable','integer'], 'name' => ['required','string'], 'recharge_type' => ['present','array'], 'withdraw_type' => ['present','array'], ]); $removed = app(RechargeChannelConfigurationService::class)->saveGroup($params); return $this->success([], $removed === [] ? '' : '保存成功,已清理失效的历史通道类型'); } catch (ValidationException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); } catch (ModelNotFoundException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, '层级不存在'); } catch (\PDOException $e) { report($e); return $this->error(HttpStatus::CUSTOM_ERROR, '保存层级失败,请稍后重试'); } catch (Exception $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage()); } } public function deleteGroup(RechargeChannelConfigurationService $service) { try { $params = request()->validate(['id' => ['required', 'integer', 'min:1']]); $service->deleteGroup((int)$params['id']); return $this->success(); } catch (ValidationException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); } catch (ModelNotFoundException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, '层级不存在'); } catch (\PDOException $e) { report($e); return $this->error(HttpStatus::CUSTOM_ERROR, '删除层级失败,请稍后重试'); } catch (Exception $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage()); } } /** * 充值通道管理列表 */ public function list() { try { $params = request()->validate([ 'page' => ['nullable', 'integer', 'min:1'], 'limit' => ['nullable', 'integer', 'min:1'], 'data_type' => ['nullable', 'integer', 'in:1,2'], 'type' => ['nullable', 'string'], 'from' => ['nullable', 'integer'], 'key' => ['nullable', 'string'], 'name' => ['nullable', 'string'], 'payment_company' => ['nullable', Rule::in(PaymentProviderCatalog::codes())], ]); $page = request()->input('page', 1); $limit = request()->input('limit', 15); // 只管理充值(1)、提现(2)通道;原活动(3)配置已停用 $query = RechargeChannelModel::query()->whereIn('data_type', [1, 2]); if (!empty($params['data_type'])) { $query = $query->where('data_type', $params['data_type']); } if (!empty($params['type'])) { $query = $query->where('type', $params['type']); } if (isset($params['from'])) { $query = $query->where('from', $params['from']); } if (!empty($params['key'])) { $query = $query->where('key', $params['key']); } if (!empty($params['name'])) { $query = $query->where('name', 'like', '%'.$params['name'].'%'); } if (!empty($params['payment_company'])) { $direction = !empty($params['data_type']) ? (int)$params['data_type'] : null; $query = $query->where('from', 1)->whereIn('data_type', [1, 2])->whereIn('type', PaymentProviderCatalog::channelTypesForProvider($params['payment_company'], $direction)); } $count = $query->count(); $companyStatuses = PaymentProviderService::statuses(); $channels = $query ->forPage($page, $limit) ->orderBy('sort', 'asc') ->orderBy('id', 'asc') ->get(); $configuredLogos = []; $logoTypes = $channels->filter(fn (RechargeChannelModel $channel) => (int)$channel->data_type === 1) ->pluck('type')->map(fn ($type) => (string)$type)->unique()->values()->all(); if ($logoTypes !== []) $configuredLogos = RechargeChannelLogoService::configured($logoTypes); $list = $channels->map(function (RechargeChannelModel $channel) use ($companyStatuses, $configuredLogos) { $row = $channel->toArray(); $dataType = (int)$row['data_type']; if (RechargeChannelLogoService::supportsDirection($dataType) && ($row['logo'] ?? '') === '' && $dataType === 1 && isset($configuredLogos[(string)$row['type']])) { $row['logo'] = (string)Util::ensureUrl($configuredLogos[(string)$row['type']]); } return $row + PaymentProviderCatalog::channelDisplay($row, $companyStatuses); }); } catch (Exception $e) { return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage()); } return $this->success(['total' => $count, 'data' => $list]); } /** * 充值通道管理更新 */ public function update(RechargeChannelConfigurationService $service) { try { $params = request()->validate([ 'id' => ['nullable','integer'], 'from' => ['nullable','integer','in:1,2,3'], 'payment_company' => ['nullable', Rule::in(PaymentProviderCatalog::codes())], 'key' => ['nullable','string','max:100'], 'name' => ['nullable','string','max:100'], 'data_type' => ['required','integer','in:1,2'], 'type' => ['required','string','max:100'], 'rate' => ['required','numeric','min:0'], 'min' => ['exclude_if:type,zfbge','nullable','numeric','min:0'], 'max' => ['exclude_if:type,zfbge','nullable','numeric','gte:min'], 'fixed' => ['nullable'], 'status' => ['nullable','integer','in:0,1'], 'sort' => ['nullable','integer','min:0'], 'logo' => ['nullable', 'string', 'max:2048'], ]); $service->save($params); return $this->success(); } catch (ValidationException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); } catch (ModelNotFoundException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, '数据不存在'); } catch (\PDOException $e) { report($e); return $this->error(HttpStatus::CUSTOM_ERROR, '保存通道失败,请稍后重试'); } catch (Exception $e) { return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage()); } } }