ソースを参照

新增推荐用户

zhangchangchun 5 年 前
コミット
f3db4e60e9
共有5 個のファイルを変更した148 個の追加0 個の削除を含む
  1. 54 0
      app/Http/Controllers/V2/Controller.php
  2. 24 0
      app/Http/Controllers/V2/MemberGroupController.php
  3. 53 0
      app/Repositories/MemberGroupRepository.php
  4. 15 0
      app/Traits/UserTrait.php
  5. 2 0
      routes/api.php

+ 54 - 0
app/Http/Controllers/V2/Controller.php

@@ -0,0 +1,54 @@
+<?php
+
+namespace App\Http\Controllers\V2;
+
+use Dingo\Api\Routing\Helpers;
+use Illuminate\Routing\Controller as BaseController;
+
+class Controller extends BaseController
+{
+    use Helpers;
+    public function jsonSuccess($data = [], $msg = "成功")
+    {
+        $response = array(
+            'code' => 0,
+            'msg' => $msg,
+            'data' => []
+        );
+        if ($data) {
+            if (is_array($data)) {
+                //带有分页格式转换
+                if (isset($data['meta'])) {
+                    // 更改元数据格式,全部包含在data下
+                    $temp = array(
+                        'data' => array(
+                            'data' => $data['data'],
+                            'pagination' => $data['meta']['pagination']
+                        )
+                    );
+                    $response = array_merge($response, $temp);
+                } elseif (isset($data['data'])) {
+                    $response = array_merge($response, $data);
+                } else {
+                    $temp = array(
+                        'data' => $data
+                    );
+                    $response = array_merge($response, $temp);
+                }
+            } else {
+                $response['data'] = $data;
+            }
+        }
+        return $response;
+    }
+
+    public function jsonError($msg)
+    {
+        $response = array(
+            'code' => 1,
+            'msg' => $msg,
+            'data' => ""
+        );
+        return $response;
+    }
+}

+ 24 - 0
app/Http/Controllers/V2/MemberGroupController.php

@@ -0,0 +1,24 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-06-20
+ * Time: 14:18
+ */
+
+namespace App\Http\Controllers\V2;
+
+
+use App\Repositories\MemberGroupRepository;
+use Illuminate\Support\Facades\Request;
+use Illuminate\Support\Facades\Validator;
+
+class MemberGroupController extends Controller {
+    public function __construct(MemberGroupRepository $memberGroupRepository) {
+        $this->memberGroupRepository = $memberGroupRepository;
+    }
+    //获取推荐用户列表
+    public function memberList(Request $request){
+       return $this->memberGroupRepository->isSuggestMember();
+    }
+}

+ 53 - 0
app/Repositories/MemberGroupRepository.php

@@ -0,0 +1,53 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-06-20
+ * Time: 14:23
+ */
+
+namespace App\Repositories;
+
+
+use App\Models\MemberGroup;
+use App\Models\MemberGroupInfo;
+use App\Traits\UserTrait;
+
+class MemberGroupRepository {
+    use UserTrait;
+    public function __construct(MemberGroup $memberGroup,MemberGroupInfo $memberGroupInfo) {
+        $this->memberGroup = $memberGroup;
+        $this->memberGroupInfo = $memberGroupInfo;
+    }
+
+    /**
+     * @param $request
+     * @return array
+     * 获取推荐用户
+     */
+    public function isSuggestMember(){
+       $group = $this->memberGroup->where('is_suggest',1)->first();
+       if($group){
+           $groupInfo = $this->memberGroupInfo
+               ->where('member_group_id',$group->id)
+               ->orderBy('sort')
+               ->select('uid','sort')
+               ->get();
+           if($groupInfo){
+               $array  = $groupInfo->toArray();
+               $userData = [];
+               foreach ($array as $key=>$value){
+                   $userData[] = $value['uid'];
+               }
+               //请求用户接口获取用户信息
+               $uids = implode(',',$userData);
+               $data = $this->getMemberSortIdList($uids);
+               if($data){
+                   return jsonSuccess($data);
+               }
+               return jsonSuccess();
+           }
+       }
+       return jsonSuccess();
+    }
+}

+ 15 - 0
app/Traits/UserTrait.php

@@ -81,4 +81,19 @@ trait UserTrait
         }
 
     }
+    //获取推荐用户根据id排序
+    public function getMemberSortIdList($ids) {
+        try {
+            $sign = generateSign([], config('customer.app_secret'));
+            $url = config("customer.app_service_url").'/v2/member/memberSortIdList';
+            //$url = 'http://localhost:8080/v2/member/memberSortIdList';
+            $array = [
+                'json' => ['sign' => $sign, 'uids' => $ids], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
+            ];
+            return http($url,$array,'get');
+        } catch (\Exception $e) {
+            return [];
+        }
+
+    }
 }

+ 2 - 0
routes/api.php

@@ -45,6 +45,8 @@ $api->version('v1', [
             $api->get('/floor/index', 'FloorController@index');
             //获取楼层信息
             $api->get('/floor/info', 'FloorController@info');
+            //获取推荐用户组内容
+            $api->get('memberList', 'MemberGroupController@memberList');
         });
     });
 });