Commit f32854e9 authored by hj's avatar hj

更新提交

parent 9c84835d
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Http\Controllers\V1;
use App\Services\CustomerService;
use App\Exceptions\ServerRunTimeException;
use App\Services\AuthService;
use App\Services\YyBao\CustomersService;
use App\Support\Traits\Helpers;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Http\Request;
use Jiannei\Response\Laravel\Support\Facades\Response;
use Jiannei\Response\Laravel\Support\Traits\ExceptionTrait;
use Laravel\Lumen\Routing\Controller as BaseController;
use OpenApi\Annotations\Info;
use OpenApi\Annotations\Schema;
use OpenApi\Annotations\Server;
use OpenApi\Annotations\Property;
use OpenApi\Annotations\SecurityScheme;
use OpenApi\Annotations\Schema;
/**
*
* @Info(
* version="1.0",
* title="罗恩开放平台 API接口文档"
* title="研易宝"
* )
*
* @Schema(
......@@ -46,11 +38,24 @@ use OpenApi\Annotations\SecurityScheme;
* )
*
*/
abstract class Controller extends BaseController
{
use ExceptionTrait;
use Helpers, ExceptionTrait;
public function getRequestRulesInputs(Request $request): array
{
$inputs = $request->request->all();
$rules = $request->rules();
foreach($inputs as $key => $in){
if(!empty($rules) && !in_array($key,array_keys($rules))){
unset($inputs[$key]);
}
$inputs[$key] = $this->stripHtml($in);
}
$inputs['platform_source'] = current($this->getUriPath());
return $inputs;
}
/**
* request 参数验证
......@@ -76,26 +81,36 @@ abstract class Controller extends BaseController
return true;
}
protected function returnErrorExecptionResponse(\Exception $exception, string $message = '')
public function getGuardName()
{
if($exception->getCode() == 500 || $exception->getCode() == 502){
return Response::fail($exception->getMessage(),200);
}
return Response::fail($message == '' ? $exception->getMessage() : $message,200);
return app()->request->headers->get('guardName');
}
protected function checkCustomerType($customerCode,$type)
protected function returnErrorExecptionResponse(\Exception $exception, string $message = ''): \Illuminate\Http\JsonResponse
{
$customer = app(CustomerService::class)->getPlatformCustomer(['cus_number' => $customerCode, 'cus_type' => $type]);
if($customer){
if($customer['cus_type'] != $type){
switch($type){
case 'bh' : $this->returnErrorExecptionResponse(new AuthenticationException('不是百化用户,无法访问该类型接口'));break;
case 'rhawn' : $this->returnErrorExecptionResponse(new AuthenticationException('不是罗恩用户,无法访问该类型接口'));break;
case 'chemsite' : $this->returnErrorExecptionResponse(new AuthenticationException('不是chemsite用户,无法访问该类型接口'));break;
default : $this->returnErrorExecptionResponse(new AuthenticationException('用户类型未知'));
if($exception instanceof AuthenticationException){
return Response::fail($exception->getMessage(),401);
}
if($exception->getCode() == 500 || $exception->getCode() == 0){
return Response::fail($exception->getMessage(),500);
}else{
return Response::fail($message == '' ? $exception->getMessage() : $message,$exception->getCode());
}
}
public function setService($service)
{
$this->service = $service;
}
public function getService()
{
return $this->service;
}
public function getUriPath()
{
$urls = explode('/',app()->request->url);
return array_values(array_filter($urls));
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment