belongsTo('app\common\model\User', 'user_id', 'id')->setEagerlyType(0); } /** * 获取统计数据 * @param $userId * @return int[] */ public function getUserTotal($userId,$status='',$time=[]){ $data = [ ]; $where = [ 'parent_id'=>$userId ]; if($status){ $where['status'] = $status; } if($time){ $where['createtime'] = ['BETWEEN',[$time['start'], $time['end']]]; } $data['count'] = self::where($where)->count(); //下级数量 $data['normal'] = self::where($where)->where(['status'=>1])->count(); //正常数量 $data['hidden'] = self::where($where)->where(['status'=>0])->count(); //解绑数量 return $data; } }