Commit ebede106 ebede106248cc9357259c37f88806c87c12b26ed by lemon

发行转发

1 parent 1ab2a2f0
<?php
namespace App\Http\Controllers\Musician;
use App\Http\Controllers\Controller;
use App\Http\Requests\Musician\MusicianWithdrawBillConfirmRequest;
use App\Http\Requests\Musician\MusicianWithdrawReceiptByNameRequest;
use App\Http\Requests\Musician\MusicianWithdrawReceiptByNoRequest;
use App\Http\Requests\Musician\MusicianWithdrawReceiptRequest;
use App\Http\Requests\Musician\MusicianWithdrawStatusRequest;
use App\Services\IssueService;
use App\Services\MusicianWithdrawService;
use App\Services\WithdrawService;
/**
* Class IssueController
* @package App\Http\Controllers\Musician
*/
class IssueController extends Controller
{
/**
* @var
*/
private $issueService;
/**
* @param IssueService $issueService
*/
public function __construct(IssueService $issueService)
{
$this->issueService = $issueService;
}
/**
* @return \Illuminate\Http\JsonResponse
*/
public function index()
{
return $this->issueService->forward();
}
}
......@@ -6,6 +6,7 @@ use App\Helper\AesEncrypt;
use App\Helper\ErrorCode;
use App\Helper\Identifier;
use App\Helper\Response;
use App\Helper\Snowflake;
use App\Models\Legal\Stakeholder;
use Closure;
use Illuminate\Http\Request;
......@@ -30,6 +31,9 @@ class AuthIdentifier
*/
public function handle(Request $request, Closure $next)
{
//增加额外属性
$request->attributes->add(['request_id' => Snowflake::gen(),]);
$prefix = current(explode('/', $request->path()));
if (!in_array($prefix, $this->auth)) goto AUTH;
......@@ -52,10 +56,10 @@ class AuthIdentifier
//通过身份证查询id
$stakeholder_ids = Stakeholder::stakeholderIds($identifier);
if (empty($stakeholder_ids)) return Response::error(ErrorCode::MATCH_IDENTIFIER_FAIL);
$request->attributes->add([
'identifier' => $identifier,
'stakeholder_ids' => $stakeholder_ids,
'identifier' => $identifier,
'stakeholder_ids' => $stakeholder_ids,
]);
AUTH:
......
......@@ -33,7 +33,7 @@ class Stakeholder extends BaseModel
case 1:
//个人
$stakeholder= Stakeholder::query()->join('stakeholder_detail as sd', 'stakeholders.id', '=', 'sd.stakeholder_id')
->where(['stakeholders.card_no'=>$identifier->identifier])->pluck('stakeholders.id')->toArray();
->where(['stakeholders.card_no'=>$identifier->identifier, 'type'=>1])->pluck('stakeholders.id')->toArray();
break;
case 2:
$stakeholder = Stakeholder::query()->where(['type' => 2, 'credit_code' => $identifier->identifier])->pluck('id')->toArray();
......
......@@ -38,7 +38,8 @@ class RouteServiceProvider extends ServiceProvider
$this->configureRateLimiting();
$this->routes(function () {
//需授权
//音乐人
Route::prefix('api')
->middleware('api')
->namespace($this->namespace . '\Musician')
......@@ -55,7 +56,7 @@ class RouteServiceProvider extends ServiceProvider
->namespace($this->namespace)
->group(base_path('routes/web.php'));
//发行接口
//发行接口 - 对接生态平台
Route::prefix('release')
->namespace($this->namespace . '\Release')
->group(base_path('routes/release.php'));
......
<?php
namespace App\Services;
use App\Helper\AesEncrypt;
use App\Helper\ErrorCode;
use App\Helper\Response;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Log;
/**
* Class IssueService
* @package App\Services
*/
class IssueService extends Service
{
/**
* 转发
* @return \Illuminate\Http\JsonResponse
*/
public function forward()
{
$client = new Client([
'base_uri' => env('resource_url'),
'timeout' => 3.0,
]);
$method = $this->request->getMethod();
$data = [];
try {
$params['data'] = $this->request->all();
$params['ext'] = [
'user_id' => $this->identifier->user_id,
'stakeholder_ids' => $this->stakeholder_ids,
];
$data['json'] = ['params' => AesEncrypt::encrypt(json_encode($params))];
$response = $client->request($method, $this->request->getRequestUri(), $data);
$respArr = json_decode($response->getBody()->getContents(), true);
return response()->json($respArr, 200);
} catch (\Throwable $throwable) {
return Response::error(ErrorCode::SERVER_ERROR, $throwable->getMessage());
}
}
}
......@@ -2,6 +2,7 @@
namespace App\Services;
use App\Helper\Snowflake;
use Carbon\Carbon;
use Illuminate\Http\Request;
......@@ -12,6 +13,16 @@ use Illuminate\Http\Request;
class Service
{
/**
* @var Request
*/
protected $request;
/**
* @var mixed
*/
protected $user_id;
/**
* @var mixed
*/
protected $identifier;
......
......@@ -113,7 +113,13 @@ return [
'driver' => 'daily',
'path' => storage_path('logs/laravel-api.log'),
'level' => env('LOG_LEVEL', 'debug'),
]
],
'issue' => [
'driver' => 'daily',
'path' => storage_path('logs/issue/issue.log'),
'level' => env('LOG_LEVEL', 'debug'),
],
],
];
......
......@@ -53,7 +53,16 @@ Route::group([], function (){
});
//发行
Route::group(["prefix"=>"issue"], function (){
Route::any('{uri}', 'IssueController@index')->where(['uri'=>'[\w_]{1,}']);
});
//api-v2
Route::group(["prefix"=>"v2", "namespace"=>"V2"], function (){
Route::get('musician_song', 'MusicianSongController@list');
});
......