if exists(select 1 from sysobjects where name='pr_wxsf_distribution_myteam')
  drop procedure pr_wxsf_distribution_myteam
go



CREATE procedure pr_wxsf_distribution_myteam 
@cardid nvarchar(50), --分销员卡号
@pageindex int, --页码
@pagesize int,--每页获取数量
@total int out --总行数

WITH ENCRYPTION
as
 declare @totalnum int --团队总人数
 declare @todaynum int--今日邀请
 declare @monthnum int --本月邀请
 declare @phoneNumber nvarchar(50) --手机号
 declare @newcardid  nvarchar(50) --卡号
 declare @addtime datetime
 if(@cardid is null or @cardid='')
 begin
   return 
 end
 
begin
 --团队总人数
 select @totalnum=COUNT(1) from t_rm_vip_info where father_card=@cardid
 
 --今日邀请
 select @todaynum=COUNT(1) from t_rm_vip_info where father_card=@cardid 
 and CONVERT(nvarchar(10),oper_date,120)=CONVERT(nvarchar(10),GETDATE(),120)
 
 --本月邀请
 select @monthnum=COUNT(1) from t_rm_vip_info where father_card=@cardid 
 and CONVERT(nvarchar(7),oper_date,120)=CONVERT(nvarchar(7),GETDATE(),120)
 
 --总行数
 SELECT @total=COUNT(1) from t_rm_vip_info  where father_card=@cardid
 
  select @totalnum as totalnum,@todaynum as todaynum,@monthnum as monthnum
 --明细
 
 
  SELECT IDENTITY(INT,1,1) AS rowid,T.cardid,T.mobile,T.addtime 
  INTO #temp_teble
  FROM (select card_id as cardid,oper_date as addtime,mobile 
  from t_rm_vip_info where    father_card=@cardid) T   
  
  SELECT cardid,mobile,addtime
  FROM #temp_teble
  WHERE RowId between @pageSize*(@pageIndex-1) + 1 and @pageSize*@pageIndex

 
end
go