Commit ebede106 ebede106248cc9357259c37f88806c87c12b26ed by lemon

发行转发

1 parent 1ab2a2f0
1 <?php
2
3 namespace App\Http\Controllers\Musician;
4
5 use App\Http\Controllers\Controller;
6 use App\Http\Requests\Musician\MusicianWithdrawBillConfirmRequest;
7 use App\Http\Requests\Musician\MusicianWithdrawReceiptByNameRequest;
8 use App\Http\Requests\Musician\MusicianWithdrawReceiptByNoRequest;
9 use App\Http\Requests\Musician\MusicianWithdrawReceiptRequest;
10 use App\Http\Requests\Musician\MusicianWithdrawStatusRequest;
11 use App\Services\IssueService;
12 use App\Services\MusicianWithdrawService;
13 use App\Services\WithdrawService;
14
15 /**
16 * Class IssueController
17 * @package App\Http\Controllers\Musician
18 */
19 class IssueController extends Controller
20 {
21 /**
22 * @var
23 */
24 private $issueService;
25
26 /**
27 * @param IssueService $issueService
28 */
29 public function __construct(IssueService $issueService)
30 {
31 $this->issueService = $issueService;
32 }
33
34 /**
35 * @return \Illuminate\Http\JsonResponse
36 */
37 public function index()
38 {
39 return $this->issueService->forward();
40 }
41
42 }
...@@ -6,6 +6,7 @@ use App\Helper\AesEncrypt; ...@@ -6,6 +6,7 @@ use App\Helper\AesEncrypt;
6 use App\Helper\ErrorCode; 6 use App\Helper\ErrorCode;
7 use App\Helper\Identifier; 7 use App\Helper\Identifier;
8 use App\Helper\Response; 8 use App\Helper\Response;
9 use App\Helper\Snowflake;
9 use App\Models\Legal\Stakeholder; 10 use App\Models\Legal\Stakeholder;
10 use Closure; 11 use Closure;
11 use Illuminate\Http\Request; 12 use Illuminate\Http\Request;
...@@ -30,6 +31,9 @@ class AuthIdentifier ...@@ -30,6 +31,9 @@ class AuthIdentifier
30 */ 31 */
31 public function handle(Request $request, Closure $next) 32 public function handle(Request $request, Closure $next)
32 { 33 {
34 //增加额外属性
35 $request->attributes->add(['request_id' => Snowflake::gen(),]);
36
33 $prefix = current(explode('/', $request->path())); 37 $prefix = current(explode('/', $request->path()));
34 if (!in_array($prefix, $this->auth)) goto AUTH; 38 if (!in_array($prefix, $this->auth)) goto AUTH;
35 39
......
...@@ -33,7 +33,7 @@ class Stakeholder extends BaseModel ...@@ -33,7 +33,7 @@ class Stakeholder extends BaseModel
33 case 1: 33 case 1:
34 //个人 34 //个人
35 $stakeholder= Stakeholder::query()->join('stakeholder_detail as sd', 'stakeholders.id', '=', 'sd.stakeholder_id') 35 $stakeholder= Stakeholder::query()->join('stakeholder_detail as sd', 'stakeholders.id', '=', 'sd.stakeholder_id')
36 ->where(['stakeholders.card_no'=>$identifier->identifier])->pluck('stakeholders.id')->toArray(); 36 ->where(['stakeholders.card_no'=>$identifier->identifier, 'type'=>1])->pluck('stakeholders.id')->toArray();
37 break; 37 break;
38 case 2: 38 case 2:
39 $stakeholder = Stakeholder::query()->where(['type' => 2, 'credit_code' => $identifier->identifier])->pluck('id')->toArray(); 39 $stakeholder = Stakeholder::query()->where(['type' => 2, 'credit_code' => $identifier->identifier])->pluck('id')->toArray();
......
...@@ -38,7 +38,8 @@ class RouteServiceProvider extends ServiceProvider ...@@ -38,7 +38,8 @@ class RouteServiceProvider extends ServiceProvider
38 $this->configureRateLimiting(); 38 $this->configureRateLimiting();
39 39
40 $this->routes(function () { 40 $this->routes(function () {
41 //需授权 41
42 //音乐人
42 Route::prefix('api') 43 Route::prefix('api')
43 ->middleware('api') 44 ->middleware('api')
44 ->namespace($this->namespace . '\Musician') 45 ->namespace($this->namespace . '\Musician')
...@@ -55,7 +56,7 @@ class RouteServiceProvider extends ServiceProvider ...@@ -55,7 +56,7 @@ class RouteServiceProvider extends ServiceProvider
55 ->namespace($this->namespace) 56 ->namespace($this->namespace)
56 ->group(base_path('routes/web.php')); 57 ->group(base_path('routes/web.php'));
57 58
58 //发行接口 59 //发行接口 - 对接生态平台
59 Route::prefix('release') 60 Route::prefix('release')
60 ->namespace($this->namespace . '\Release') 61 ->namespace($this->namespace . '\Release')
61 ->group(base_path('routes/release.php')); 62 ->group(base_path('routes/release.php'));
......
1 <?php
2
3 namespace App\Services;
4
5 use App\Helper\AesEncrypt;
6 use App\Helper\ErrorCode;
7 use App\Helper\Response;
8 use GuzzleHttp\Client;
9 use Illuminate\Support\Facades\Log;
10
11 /**
12 * Class IssueService
13 * @package App\Services
14 */
15 class IssueService extends Service
16 {
17 /**
18 * 转发
19 * @return \Illuminate\Http\JsonResponse
20 */
21 public function forward()
22 {
23 $client = new Client([
24 'base_uri' => env('resource_url'),
25 'timeout' => 3.0,
26 ]);
27
28 $method = $this->request->getMethod();
29 $data = [];
30
31 try {
32
33 $params['data'] = $this->request->all();
34 $params['ext'] = [
35 'user_id' => $this->identifier->user_id,
36 'stakeholder_ids' => $this->stakeholder_ids,
37 ];
38
39 $data['json'] = ['params' => AesEncrypt::encrypt(json_encode($params))];
40 $response = $client->request($method, $this->request->getRequestUri(), $data);
41 $respArr = json_decode($response->getBody()->getContents(), true);
42 return response()->json($respArr, 200);
43 } catch (\Throwable $throwable) {
44 return Response::error(ErrorCode::SERVER_ERROR, $throwable->getMessage());
45 }
46 }
47
48
49 }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
2 2
3 namespace App\Services; 3 namespace App\Services;
4 4
5 use App\Helper\Snowflake;
5 use Carbon\Carbon; 6 use Carbon\Carbon;
6 use Illuminate\Http\Request; 7 use Illuminate\Http\Request;
7 8
...@@ -12,6 +13,16 @@ use Illuminate\Http\Request; ...@@ -12,6 +13,16 @@ use Illuminate\Http\Request;
12 class Service 13 class Service
13 { 14 {
14 /** 15 /**
16 * @var Request
17 */
18 protected $request;
19
20 /**
21 * @var mixed
22 */
23 protected $user_id;
24
25 /**
15 * @var mixed 26 * @var mixed
16 */ 27 */
17 protected $identifier; 28 protected $identifier;
......
...@@ -113,7 +113,13 @@ return [ ...@@ -113,7 +113,13 @@ return [
113 'driver' => 'daily', 113 'driver' => 'daily',
114 'path' => storage_path('logs/laravel-api.log'), 114 'path' => storage_path('logs/laravel-api.log'),
115 'level' => env('LOG_LEVEL', 'debug'), 115 'level' => env('LOG_LEVEL', 'debug'),
116 ] 116 ],
117
118 'issue' => [
119 'driver' => 'daily',
120 'path' => storage_path('logs/issue/issue.log'),
121 'level' => env('LOG_LEVEL', 'debug'),
122 ],
117 ], 123 ],
118 124
119 ]; 125 ];
......
...@@ -53,7 +53,16 @@ Route::group([], function (){ ...@@ -53,7 +53,16 @@ Route::group([], function (){
53 53
54 }); 54 });
55 55
56 //发行
57 Route::group(["prefix"=>"issue"], function (){
58 Route::any('{uri}', 'IssueController@index')->where(['uri'=>'[\w_]{1,}']);
59 });
60
61
56 //api-v2 62 //api-v2
57 Route::group(["prefix"=>"v2", "namespace"=>"V2"], function (){ 63 Route::group(["prefix"=>"v2", "namespace"=>"V2"], function (){
58 Route::get('musician_song', 'MusicianSongController@list'); 64 Route::get('musician_song', 'MusicianSongController@list');
59 }); 65 });
66
67
68
......