Browse Source

fix:我的团队

super-yimizi 11 hours ago
parent
commit
4894ba1ffe

+ 182 - 59
application/api/controller/commission/Agent.php

@@ -97,6 +97,7 @@ class Agent extends Commission
 
 
     /**
     /**
      * 构造代理商身份数据(包括标题和区域信息)
      * 构造代理商身份数据(包括标题和区域信息)
+     * 优化版本:直接使用数据库中存储的名称字段,无需关联查询区域表
      * @param array $agentData 代理商数据
      * @param array $agentData 代理商数据
      * @return array
      * @return array
      */
      */
@@ -115,18 +116,14 @@ class Agent extends Commission
                 
                 
             case AgentType::PROVINCE:
             case AgentType::PROVINCE:
                 // 省级代理商:山东省代理商
                 // 省级代理商:山东省代理商
-                if (!empty($agentData['manage_province_id'])) {
-                    $provinceInfo = \app\common\model\Area::where('id', $agentData['manage_province_id'])->find();
-                    if ($provinceInfo) {
-                        $result['title'] = $provinceInfo['name'] . '代理商';
-                        $result['area_info'] = [
-                            'province_name' => $provinceInfo['name'],
-                            'province_id' => $agentData['manage_province_id']
-                        ];
-                        $result['area_text'] = $provinceInfo['name'];
-                    } else {
-                        $result['title'] = '省级代理商';
-                    }
+                $provinceName = $agentData['manage_province_name'] ?? '';
+                if (!empty($provinceName)) {
+                    $result['title'] = $provinceName . '代理商';
+                    $result['area_info'] = [
+                        'province_name' => $provinceName,
+                        'province_id' => $agentData['manage_province_id'] ?? null
+                    ];
+                    $result['area_text'] = $provinceName;
                 } else {
                 } else {
                     $result['title'] = '省级代理商';
                     $result['title'] = '省级代理商';
                 }
                 }
@@ -138,26 +135,20 @@ class Agent extends Commission
                 $areaText = [];
                 $areaText = [];
                 
                 
                 // 获取省份信息
                 // 获取省份信息
-                if (!empty($agentData['manage_province_id'])) {
-                    $provinceInfo = \app\common\model\Area::where('id', $agentData['manage_province_id'])->find();
-                    if ($provinceInfo) {
-                        $areaInfo['province_name'] = $provinceInfo['name'];
-                        $areaInfo['province_id'] = $agentData['manage_province_id'];
-                        $areaText[] = $provinceInfo['name'];
-                    }
+                $provinceName = $agentData['manage_province_name'] ?? '';
+                if (!empty($provinceName)) {
+                    $areaInfo['province_name'] = $provinceName;
+                    $areaInfo['province_id'] = $agentData['manage_province_id'] ?? null;
+                    $areaText[] = $provinceName;
                 }
                 }
                 
                 
                 // 获取城市信息
                 // 获取城市信息
-                if (!empty($agentData['manage_city_id'])) {
-                    $cityInfo = \app\common\model\Area::where('id', $agentData['manage_city_id'])->find();
-                    if ($cityInfo) {
-                        $result['title'] = $cityInfo['name'] . '代理商';
-                        $areaInfo['city_name'] = $cityInfo['name'];
-                        $areaInfo['city_id'] = $agentData['manage_city_id'];
-                        $areaText[] = $cityInfo['name'];
-                    } else {
-                        $result['title'] = '市级代理商';
-                    }
+                $cityName = $agentData['manage_city_name'] ?? '';
+                if (!empty($cityName)) {
+                    $result['title'] = $cityName . '代理商';
+                    $areaInfo['city_name'] = $cityName;
+                    $areaInfo['city_id'] = $agentData['manage_city_id'] ?? null;
+                    $areaText[] = $cityName;
                 } else {
                 } else {
                     $result['title'] = '市级代理商';
                     $result['title'] = '市级代理商';
                 }
                 }
@@ -174,36 +165,28 @@ class Agent extends Commission
                 $areaText = [];
                 $areaText = [];
                 
                 
                 // 获取省份信息
                 // 获取省份信息
-                if (!empty($agentData['manage_province_id'])) {
-                    $provinceInfo = \app\common\model\Area::where('id', $agentData['manage_province_id'])->find();
-                    if ($provinceInfo) {
-                        $areaInfo['province_name'] = $provinceInfo['name'];
-                        $areaInfo['province_id'] = $agentData['manage_province_id'];
-                        $areaText[] = $provinceInfo['name'];
-                    }
+                $provinceName = $agentData['manage_province_name'] ?? '';
+                if (!empty($provinceName)) {
+                    $areaInfo['province_name'] = $provinceName;
+                    $areaInfo['province_id'] = $agentData['manage_province_id'] ?? null;
+                    $areaText[] = $provinceName;
                 }
                 }
                 
                 
                 // 获取城市信息
                 // 获取城市信息
-                if (!empty($agentData['manage_city_id'])) {
-                    $cityInfo = \app\common\model\Area::where('id', $agentData['manage_city_id'])->find();
-                    if ($cityInfo) {
-                        $areaInfo['city_name'] = $cityInfo['name'];
-                        $areaInfo['city_id'] = $agentData['manage_city_id'];
-                        $areaText[] = $cityInfo['name'];
-                    }
+                $cityName = $agentData['manage_city_name'] ?? '';
+                if (!empty($cityName)) {
+                    $areaInfo['city_name'] = $cityName;
+                    $areaInfo['city_id'] = $agentData['manage_city_id'] ?? null;
+                    $areaText[] = $cityName;
                 }
                 }
                 
                 
                 // 获取区域信息
                 // 获取区域信息
-                if (!empty($agentData['manage_district_id'])) {
-                    $districtInfo = \app\common\model\Area::where('id', $agentData['manage_district_id'])->find();
-                    if ($districtInfo) {
-                        $result['title'] = $districtInfo['name'] . '代理商';
-                        $areaInfo['district_name'] = $districtInfo['name'];
-                        $areaInfo['district_id'] = $agentData['manage_district_id'];
-                        $areaText[] = $districtInfo['name'];
-                    } else {
-                        $result['title'] = '区域代理商';
-                    }
+                $districtName = $agentData['manage_district_name'] ?? '';
+                if (!empty($districtName)) {
+                    $result['title'] = $districtName . '代理商';
+                    $areaInfo['district_name'] = $districtName;
+                    $areaInfo['district_id'] = $agentData['manage_district_id'] ?? null;
+                    $areaText[] = $districtName;
                 } else {
                 } else {
                     $result['title'] = '区域代理商';
                     $result['title'] = '区域代理商';
                 }
                 }
@@ -218,13 +201,15 @@ class Agent extends Commission
         return $result;
         return $result;
     }
     }
 
 
+    
+
 
 
     // 我的团队
     // 我的团队
     public function team()
     public function team()
     {
     {
         $params = $this->request->param();
         $params = $this->request->param();
         
         
-        // 使用验证器验证分页参数:page, page_size
+        // 使用验证器验证分页参数:page, page_size, time_filter, start_date, end_date
         $validate = new \app\api\validate\Agent();
         $validate = new \app\api\validate\Agent();
         if (!$validate->scene('team')->check($params)) {
         if (!$validate->scene('team')->check($params)) {
             $this->error($validate->getError());
             $this->error($validate->getError());
@@ -232,17 +217,155 @@ class Agent extends Commission
         
         
         $agentId = $this->service->user->id;
         $agentId = $this->service->user->id;
         
         
-        // 获取验证后的分页参数
+        // 获取验证后的参数
         $pageSize = isset($params['page_size']) ? (int)$params['page_size'] : 8;
         $pageSize = isset($params['page_size']) ? (int)$params['page_size'] : 8;
+        $timeFilter = isset($params['time_filter']) ? $params['time_filter'] : 'all';
+        $startDate = isset($params['start_date']) ? $params['start_date'] : '';
+        $endDate = isset($params['end_date']) ? $params['end_date'] : '';
+
+        // 构建查询条件
+        $query = UserModel::where('parent_user_id', $agentId)
+            ->where('status', 1);
+
+        // 根据时间筛选参数添加时间条件
+        if ($timeFilter !== 'all') {
+            $timeConditions = $this->getTimeFilterConditions($timeFilter, $startDate, $endDate);
+            if ($timeConditions) {
+                $query->where('bind_time', '>=', $timeConditions['start_time']);
+                if (isset($timeConditions['end_time'])) {
+                    $query->where('bind_time', '<=', $timeConditions['end_time']);
+                }
+            }
+        }
 
 
-        $data = UserModel::where('parent_user_id', $agentId)
-            ->where('status', 'normal')
+        $data = $query->field('id,username,nickname,avatar,mobile,bind_time,commission,order_count,total_consume,status,parent_user_id')
             ->with(['agent' => function ($query) {
             ->with(['agent' => function ($query) {
-                return $query->with('level_info');
+                return $query->with('level_info')->field('user_id,agent_type,child_user_count_all,child_order_money_all');
             }])
             }])
             ->paginate($pageSize);
             ->paginate($pageSize);
 
 
-        $this->success("", $data);
+        // 将分页对象转换为数组进行处理
+        $paginateData = $data->toArray();
+        
+        // 为代理商成员添加身份标题和统计数据
+        $this->addAgentIdentityTitle($paginateData['data']);
+        
+        // 获取当前代理商信息
+        $currentAgent = $this->service->agent;
+        
+        // 重新构造返回数据
+        $result = [
+            'total' => $paginateData['total'],
+            'per_page' => $paginateData['per_page'],
+            'current_page' => $paginateData['current_page'],
+            'last_page' => $paginateData['last_page'],
+            'list' => $paginateData['data'],
+            'agent_info' => [
+                'child_user_count_all' => intval($currentAgent['child_user_count_all'] ?? 0),
+                'child_order_money_all' => BcMath::format($currentAgent['child_order_money_all'] ?? '0.00')
+            ]
+        ];
+
+        $this->success("", $result);
+    }
+
+    /**
+     * 为团队成员添加身份标题和统计数据(统一处理所有用户)
+     * @param array $teamMembers 团队成员数据数组的引用
+     * @return void
+     */
+    private function addAgentIdentityTitle(&$teamMembers)
+    {
+        if (empty($teamMembers)) {
+            return;
+        }
+
+        foreach ($teamMembers as &$member) {
+            //处理头像
+            $member['avatar'] = !empty($member['avatar']) ? cdnurl($member['avatar']) : '';
+            
+            //格式化绑定时间
+            $member['bind_time_text'] = !empty($member['bind_time']) ? date('Y-m-d', $member['bind_time']) : '';
+            
+            if (!empty($member['agent'])) {
+                // 代理商用户:构造具体的代理商身份标题
+                $identityData = $this->buildAgentIdentityData($member['agent']);
+                $member['agent_identity_title'] = $identityData['title'];
+                
+                // 添加代理商统计数据
+                $member['order_count'] = intval($member['agent']['child_user_count_all'] ?? 0);
+                $member['total_consume'] = BcMath::format($member['agent']['child_order_money_all'] ?? '0.00');
+            } else {
+                // 普通用户:统一设置为"普通用户"
+                $member['agent_identity_title'] = '普通用户';
+                
+                // 添加普通用户统计数据
+                $member['order_count'] = intval($member['order_count'] ?? 0);
+                $member['total_consume'] = BcMath::format($member['total_consume'] ?? '0.00');
+            }
+        }
+    }
+
+
+
+    /**
+     * 获取时间筛选条件
+     * @param string $timeFilter 时间筛选类型
+     * @param string $startDate 开始日期 (Y-m-d格式,用于自定义时间段)
+     * @param string $endDate 结束日期 (Y-m-d格式,用于自定义时间段)
+     * @return array|null 返回包含开始时间和结束时间的数组
+     */
+    private function getTimeFilterConditions($timeFilter, $startDate = '', $endDate = '')
+    {
+        $currentTime = time();
+        
+        switch ($timeFilter) {
+            case 'recent_7_days':
+                return [
+                    'start_time' => $currentTime - 7 * 24 * 3600,
+                ];
+                
+            case 'recent_30_days':
+                return [
+                    'start_time' => $currentTime - 30 * 24 * 3600,
+                ];
+                
+            case 'recent_90_days':
+                return [
+                    'start_time' => $currentTime - 90 * 24 * 3600,
+                ];
+                
+            case 'current_year':
+                // 当前年份的开始时间
+                $yearStart = strtotime(date('Y-01-01 00:00:00'));
+                // 当前年份的结束时间
+                $yearEnd = strtotime(date('Y-12-31 23:59:59'));
+                return [
+                    'start_time' => $yearStart,
+                    'end_time' => $yearEnd,
+                ];
+                
+            case 'custom':
+                // 自定义时间段
+                if (empty($startDate) || empty($endDate)) {
+                    return null;
+                }
+                
+                $startTime = strtotime($startDate . ' 00:00:00');
+                $endTime = strtotime($endDate . ' 23:59:59');
+                
+                if ($startTime === false || $endTime === false || $startTime > $endTime) {
+                    return null;
+                }
+                
+                return [
+                    'start_time' => $startTime,
+                    'end_time' => $endTime,
+                ];
+                
+            default:
+                return null;
+        }
     }
     }
 
 
     // 佣金转余额/提现
     // 佣金转余额/提现

+ 2 - 2
application/api/controller/commission/AgentApply.php

@@ -66,8 +66,7 @@ class AgentApply extends Base
                 $this->error($validate->getError());
                 $this->error($validate->getError());
             }            
             }            
             $service = new AgentApplyService();
             $service = new AgentApplyService();
-            $apply = $service->submitApply($user->id, $data);
-            
+            $apply = $service->submitApply($user->id, $data);           
             
             
             if ($apply->status == ApplyModel::STATUS_APPROVED) {
             if ($apply->status == ApplyModel::STATUS_APPROVED) {
                 $this->success('申请提交成功,您已成为代理商!', $apply);
                 $this->success('申请提交成功,您已成为代理商!', $apply);
@@ -144,6 +143,7 @@ class AgentApply extends Base
             }         
             }         
             // 更新用户的上级关系
             // 更新用户的上级关系
             $user->parent_user_id = $parentAgent->user_id;
             $user->parent_user_id = $parentAgent->user_id;
+            $user->bind_time = time();
             $user->save();
             $user->save();
             
             
             // 从请求头获取platform参数(与生成二维码接口保持一致)
             // 从请求头获取platform参数(与生成二维码接口保持一致)

+ 10 - 1
application/api/validate/Agent.php

@@ -9,6 +9,9 @@ class Agent extends Validate
     protected $rule = [
     protected $rule = [
         'page' => 'integer|egt:1',
         'page' => 'integer|egt:1',
         'page_size' => 'integer|between:1,100',
         'page_size' => 'integer|between:1,100',
+        'time_filter' => 'in:all,recent_7_days,recent_30_days,recent_90_days,current_year,custom',
+        'start_date' => 'date|requireIf:time_filter,custom',
+        'end_date' => 'date|requireIf:time_filter,custom|afterWith:start_date',
     ];
     ];
 
 
     protected $message = [
     protected $message = [
@@ -16,9 +19,15 @@ class Agent extends Validate
         'page.egt' => '页码必须大于等于1',
         'page.egt' => '页码必须大于等于1',
         'page_size.integer' => '分页大小必须为整数',
         'page_size.integer' => '分页大小必须为整数',
         'page_size.between' => '分页大小必须在1-100之间',
         'page_size.between' => '分页大小必须在1-100之间',
+        'time_filter.in' => '时间筛选参数无效,必须为:all、recent_7_days、recent_30_days、recent_90_days、current_year、custom中的一个',
+        'start_date.date' => '开始日期格式不正确',
+        'start_date.requireIf' => '选择自定义时间段时,开始日期不能为空',
+        'end_date.date' => '结束日期格式不正确',
+        'end_date.requireIf' => '选择自定义时间段时,结束日期不能为空',
+        'end_date.afterWith' => '结束日期必须大于等于开始日期',
     ];
     ];
 
 
     protected $scene = [
     protected $scene = [
-        'team' => ['page', 'page_size'],
+        'team' => ['page', 'page_size', 'time_filter', 'start_date', 'end_date'],
     ];
     ];
 }
 }

+ 0 - 1
application/common.php

@@ -112,7 +112,6 @@ if (!function_exists('get_sn')) {
 
 
 
 
 
 
-
 if (!function_exists('format_log_error')) {
 if (!function_exists('format_log_error')) {
     /**
     /**
      * 格式化记录日志,重要地方使用
      * 格式化记录日志,重要地方使用

+ 62 - 5
application/common/Service/Commission/AgentApply.php

@@ -62,22 +62,40 @@ class AgentApply
             $apply->agent_type = $identity->agent_type; // 从身份配置获取代理商类型
             $apply->agent_type = $identity->agent_type; // 从身份配置获取代理商类型
             $apply->status = ApplyModel::STATUS_PENDING; // 设置初始状态为待审核
             $apply->status = ApplyModel::STATUS_PENDING; // 设置初始状态为待审核
             
             
-            // 地区信息 - 根据代理商类型设置需要的地区字段
+            // 地区信息 - 根据代理商类型设置需要的地区字段并查询名称
             $requiredFields = AgentType::getRequiredAreaFields($identity->agent_type);
             $requiredFields = AgentType::getRequiredAreaFields($identity->agent_type);
             
             
             if (in_array('province_id', $requiredFields)) {
             if (in_array('province_id', $requiredFields)) {
                 $apply->province_id = $data['province_id'] ?? null;
                 $apply->province_id = $data['province_id'] ?? null;
-                $apply->province_name = $data['province_name'] ?? '';
+                // 主动查询省份名称
+                if (!empty($data['province_id'])) {
+                    $province = Area::where('id', $data['province_id'])->where('level', 1)->find();
+                    $apply->province_name = $province ? $province->name : '';
+                } else {
+                    $apply->province_name = '';
+                }
             }
             }
             
             
             if (in_array('city_id', $requiredFields)) {
             if (in_array('city_id', $requiredFields)) {
                 $apply->city_id = $data['city_id'] ?? null;
                 $apply->city_id = $data['city_id'] ?? null;
-                $apply->city_name = $data['city_name'] ?? '';
+                // 主动查询城市名称
+                if (!empty($data['city_id'])) {
+                    $city = Area::where('id', $data['city_id'])->where('level', 2)->find();
+                    $apply->city_name = $city ? $city->name : '';
+                } else {
+                    $apply->city_name = '';
+                }
             }
             }
             
             
             if (in_array('district_id', $requiredFields)) {
             if (in_array('district_id', $requiredFields)) {
                 $apply->district_id = $data['district_id'] ?? null;
                 $apply->district_id = $data['district_id'] ?? null;
-                $apply->district_name = $data['district_name'] ?? '';
+                // 主动查询区域名称
+                if (!empty($data['district_id'])) {
+                    $district = Area::where('id', $data['district_id'])->where('level', 3)->find();
+                    $apply->district_name = $district ? $district->name : '';
+                } else {
+                    $apply->district_name = '';
+                }
             }
             }
 
 
             // 根据申请类型填充对应字段
             // 根据申请类型填充对应字段
@@ -280,37 +298,76 @@ class AgentApply
         $agent->status = AgentModel::AGENT_STATUS_NORMAL;
         $agent->status = AgentModel::AGENT_STATUS_NORMAL;
         $agent->become_time = time();
         $agent->become_time = time();
 
 
-        // 如果是区域代理商(省级、市级、区域级),设置管辖区域
+        // 如果是区域代理商(省级、市级、区域级),设置管辖区域(包括ID和名称)
         if (AgentType::isRegionalAgent($apply->agent_type)) {
         if (AgentType::isRegionalAgent($apply->agent_type)) {
             // 根据代理商类型设置对应的管辖区域
             // 根据代理商类型设置对应的管辖区域
             if ($apply->agent_type == AgentType::PROVINCE && !empty($apply->province_id)) {
             if ($apply->agent_type == AgentType::PROVINCE && !empty($apply->province_id)) {
                 $agent->manage_province_id = $apply->province_id;
                 $agent->manage_province_id = $apply->province_id;
+                $agent->manage_province_name = $apply->province_name;
             } elseif ($apply->agent_type == AgentType::CITY) {
             } elseif ($apply->agent_type == AgentType::CITY) {
                 if (!empty($apply->province_id)) {
                 if (!empty($apply->province_id)) {
                     $agent->manage_province_id = $apply->province_id;
                     $agent->manage_province_id = $apply->province_id;
+                    $agent->manage_province_name = $apply->province_name;
                 }
                 }
                 if (!empty($apply->city_id)) {
                 if (!empty($apply->city_id)) {
                     $agent->manage_city_id = $apply->city_id;
                     $agent->manage_city_id = $apply->city_id;
+                    $agent->manage_city_name = $apply->city_name;
                 }
                 }
             } elseif ($apply->agent_type == AgentType::DISTRICT) {
             } elseif ($apply->agent_type == AgentType::DISTRICT) {
                 if (!empty($apply->province_id)) {
                 if (!empty($apply->province_id)) {
                     $agent->manage_province_id = $apply->province_id;
                     $agent->manage_province_id = $apply->province_id;
+                    $agent->manage_province_name = $apply->province_name;
                 }
                 }
                 if (!empty($apply->city_id)) {
                 if (!empty($apply->city_id)) {
                     $agent->manage_city_id = $apply->city_id;
                     $agent->manage_city_id = $apply->city_id;
+                    $agent->manage_city_name = $apply->city_name;
                 }
                 }
                 if (!empty($apply->district_id)) {
                 if (!empty($apply->district_id)) {
                     $agent->manage_district_id = $apply->district_id;
                     $agent->manage_district_id = $apply->district_id;
+                    $agent->manage_district_name = $apply->district_name;
                 }
                 }
             }
             }
         }
         }
 
 
+        // 生成唯一邀请码
+        $agent->invite_code = $this->generateInviteCode();
+
         $agent->save();
         $agent->save();
 
 
         return $agent;
         return $agent;
     }
     }
 
 
     /**
     /**
+     * 生成唯一邀请码
+     * @return string
+     */
+    private function generateInviteCode()
+    {
+        $maxAttempts = 3; // 最大尝试次数
+        $attempts = 0;
+        
+        do {
+            // 使用通用的generate_code方法生成基础码
+            $letters = 'ABCDEFGHJKLMNPQRSTUVWXYZ3456789';
+            $shuffleStr = str_shuffle($letters);
+            $code = substr($shuffleStr, 0, 6);
+            
+            // 检查代理商表中是否已存在
+            $exists = AgentModel::where('invite_code', $code)->find();
+            $attempts++;
+            
+            if (!$exists) {
+                return $code;
+            }
+        } while ($attempts < $maxAttempts);
+        
+        // 如果3次尝试都失败,使用时间戳后缀确保唯一性
+        $fallbackLetters = 'ABCDEFGHJKLMNPQRSTUVWXYZ3456789';
+        $fallbackCode = substr(str_shuffle($fallbackLetters), 0, 4) . substr(time(), -2);
+        return $fallbackCode;
+    }
+
+    /**
      * 获取用户的申请记录
      * 获取用户的申请记录
      */
      */
     public function getUserApply($userId)
     public function getUserApply($userId)

+ 5 - 5
application/common/Service/Withdraw.php

@@ -116,11 +116,11 @@ class Withdraw
                 'total_count' => $totalCount,
                 'total_count' => $totalCount,
                 'total_amount' => $totalAmount,
                 'total_amount' => $totalAmount,
                 'total_charge_amount' => $totalChargeAmount,  
                 'total_charge_amount' => $totalChargeAmount,  
-                'total_actual_amount' => $totalActualAmount,
-                'filter_info' => [
-                    'year_month' => isset($params['year_month']) ? $params['year_month'] : null,
-                    'status' => isset($params['status']) ? (int)$params['status'] : null,
-                ]
+                'total_actual_amount' => $totalActualAmount,               
+            ],
+            'filter_info' => [
+                'year_month' => isset($params['year_month']) ? $params['year_month'] : null,
+                'status' => isset($params['status']) ? (int)$params['status'] : null,
             ]
             ]
         ];
         ];
 
 

+ 8 - 16
application/common/model/User.php

@@ -18,27 +18,11 @@ class User extends Model
     protected $createTime = 'createtime';
     protected $createTime = 'createtime';
     protected $updateTime = 'updatetime';
     protected $updateTime = 'updatetime';
     protected $deleteTime = 'deletetime';
     protected $deleteTime = 'deletetime';
-    // 追加属性
-    protected $append = [
-        'url',
-    ];
 
 
     public static function init()
     public static function init()
     {
     {
         parent::init();
         parent::init();
     }
     }
-
-    /**
-     * 获取个人URL
-     * @param string $value
-     * @param array  $data
-     * @return string
-     */
-    public function getUrlAttr($value, $data)
-    {
-        return "/u/" . $data['id'];
-    }
-
     /**
     /**
      * 关联上级用户
      * 关联上级用户
      */
      */
@@ -96,4 +80,12 @@ class User extends Model
     {
     {
         return $this->belongsTo('app\\common\\model\\UserGroup', 'group_id', 'id', [], 'LEFT')->setEagerlyType(0);
         return $this->belongsTo('app\\common\\model\\UserGroup', 'group_id', 'id', [], 'LEFT')->setEagerlyType(0);
     }
     }
+
+    /**
+     * 关联分销商信息
+     */
+    public function agent()
+    {
+        return $this->hasOne('app\\common\\model\\commission\\Agent', 'user_id', 'id');
+    }
 }
 }