Browse Source

行为列表方法

durong 5 years ago
parent
commit
b2bd43c218

+ 54 - 0
app/Http/Controllers/Behavior/BehaviorController.php

@@ -0,0 +1,54 @@
+<?php
+namespace App\Http\Controllers\Behavior;
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/10
+ * Time: 上午11:09
+ */
+use App\Http\Controllers\Controller;
+use App\Repositories\BehaviorRepository;
+use App\Transformers\Behavior\BehaviorTransformer;
+use Illuminate\Http\Request;
+use Illuminate\Validation\Rule;
+use League\Fractal\Manager;
+use League\Fractal\Pagination\IlluminatePaginatorAdapter;
+use League\Fractal\Resource\Collection;
+
+class BehaviorController extends Controller
+{
+    public function __construct(BehaviorRepository $behaviorRepository)
+    {
+        $this->behaviorRepository = $behaviorRepository;
+    }
+
+    /**
+     * 行为列表
+     */
+    public function index(Request $request)
+    {
+        $behavior_list = $this->behaviorRepository->index($request->all());
+        if ($behavior_list){
+            return $behavior_list;
+        }else{
+            return '没有找到对应行为列表';
+        }
+        $fractal = new Manager();
+        $resource = new Collection($behavior_list, new BehaviorTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($behavior_list));
+        $data = $fractal->createData($resource)->toArray();
+        $data['extra'] = [
+            'filters' => [
+                '_id',
+                'behavior_name',
+            ],
+            'columns' => [
+                '_id',
+                'behavior_name',
+            ]
+        ];
+        return $data;
+
+    }
+
+}

+ 16 - 0
app/Models/Behavior.php

@@ -0,0 +1,16 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/10
+ * Time: 11:22
+ */
+
+namespace App\Models;
+use Illuminate\Database\Eloquent\Model;
+
+class Behavior extends Model
+{
+    protected $table = 'behavior';
+    protected $guarded = [];
+}

+ 43 - 0
app/Repositories/Behavior/BehaviorRepository.php

@@ -0,0 +1,43 @@
+<?php
+namespace App\Repositories;
+use App\Models\Behavior;
+use GuzzleHttp\Client;
+use GuzzleHttp\Exception\RequestException;
+use Tymon\JWTAuth\Facades\JWTAuth;
+
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/10
+ * Time: 上午11:11
+ */
+
+class BehaviorRepository
+{
+    public function __construct(Behavior $behavior)
+    {
+        $this->behavior = $behavior;
+    }
+
+    public function index($request)
+    {
+        try {
+            $app = config('constants.VIRUS_APP_ID');
+            $signKey = [
+                'app' => config('constants.VIRUS_APP_ID')
+            ];
+            ksort($signKey);
+            $signKey = urldecode(http_build_query($signKey));
+            $sign = md5(config('constants.VIRUS_APP_SECRET') . $signKey);
+            $url = config("customer.manage_service_url") . '/virus/behaviorList';
+            $array = [
+                'json' => ['app' => $app,'sign' => $sign], 'query' => [], 'http_errors' => false, 'headers' => ['Authorization' => "Bearer " . JWTAuth::getToken()]
+            ];
+
+            return http($url, $array, 'get');
+        } catch (\Exception $e) {
+            return [];
+        }
+    }
+}
+

+ 21 - 0
app/Transformers/Behavior/BehaviorTransformer.php

@@ -0,0 +1,21 @@
+<?php
+namespace App\Transformers\Behavior;
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/10
+ * Time: 上午11:39
+ */
+use App\Models\Behavior;
+use League\Fractal\TransformerAbstract;
+
+class BehaviorTransformer extends TransformerAbstract
+{
+    public function transform(Behavior $behavior_list)
+    {
+        return [
+            '_id' => $behavior_list['_id'],
+            'behavior_name' => $behavior_list['behavior_name']
+        ];
+    }
+}

+ 5 - 0
routes/api.php

@@ -45,4 +45,9 @@ $api->version('v1', [
     $api->group(['middleware' => 'jwt.chxq_auth'], function ($api) {
 
     });
+    //行为
+    $api->group(['namespace' => 'Behavior'], function ($api) {
+        //行为列表
+        $api->get('behavior/list', 'BehaviorController@index');
+    });
 });