wesmiler 2 месяцев назад
Родитель
Сommit
d32cb7f762
1 измененных файлов с 10 добавлено и 14 удалено
  1. 10 14
      app/Services/Api/MemberService.php

+ 10 - 14
app/Services/Api/MemberService.php

@@ -297,12 +297,12 @@ class MemberService extends BaseService
             return $info;
         }
 
-        $defaultField = ['id', 'user_type', 'realname', 'mobile','is_auth', 'nickname','company','position','department', 'balance', 'code', 'openid','create_time', 'status', 'avatar'];
+        $defaultField = ['id', 'user_type', 'realname', 'mobile','is_auth', 'nickname','company','position','department','parent_id', 'balance', 'code', 'openid','create_time', 'status', 'avatar'];
         $field = $field ? $field : $defaultField;
         if (is_array($where)) {
-            $info = $this->model->with(['account'])->where(['mark' => 1])->where($where)->select($field)->first();
+            $info = $this->model->with(['account','parent'])->where(['mark' => 1])->where($where)->select($field)->first();
         } else {
-            $info = $this->model->with(['account'])->where(['mark' => 1])->where(['id' => (int)$where])->select($field)->first();
+            $info = $this->model->with(['account','parent'])->where(['mark' => 1])->where(['id' => (int)$where])->select($field)->first();
         }
 
         $info = $info ? $info->toArray() : [];
@@ -325,17 +325,13 @@ class MemberService extends BaseService
             }
 
             if($type == 'center'){
-                $info['uppers'] = [
-                    ['id'=>1,'name'=>'11','avatar'=>get_image_url('/images/member/logo.png')],
-                    ['id'=>2,'name'=>'11','avatar'=>get_image_url('/images/member/logo.png')],
-                ];
-                $info['users'] = [
-                    ['id'=>1,'name'=>'11','avatar'=>get_image_url('/images/member/logo.png')],
-                    ['id'=>2,'name'=>'11','avatar'=>get_image_url('/images/member/logo.png')],
-                    ['id'=>3,'name'=>'11','avatar'=>get_image_url('/images/member/logo.png')],
-                ];
-                $info['upper_count'] = 2;
-                $info['user_count'] = 3;
+                $info['uppers'] = $info['parent']?[$info['parent']]:[];
+                $info['upper_count'] = $info['parent']?1: 0;
+                $query = $this->model->where(['parent_id'=>$info['id'],'mark'=>1])->select(['id','avatar','nickname','status']);
+                $query1 = clone $query;
+                $info['user_count'] = $query1->count('id');
+                $info['users'] = $query->limit(3)->get();
+
             }
 
             RedisService::set($cacheKey, $info, rand(30, 60));