IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_check_weixinbind]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_check_weixinbind]
GO
-- =============================================      
-- Author:  郑华建  
-- Create date: 2018年1月8日 15点46分  
-- Description: 检测微信的绑定情况,如果查找到了用户信息则,则返回cu_id,并写登录日志
-- 此处会返回一个result字段,
--如果返回0 表示找了的用户,并且用户可以正常登录,     
--1 表示没有找到用户
--2 表示此用户不允许登录
-- =============================================      
CREATE PROCEDURE [dbo].[mps_check_weixinbind] 
@appid varchar(128),
@openid  varchar(128)
AS      
BEGIN      
 -- SET NOCOUNT ON added to prevent extra result sets from      
 -- interfering with SELECT statements.      
 SET NOCOUNT ON;        
 declare @cuid int      
 declare @identity varchar(256)=@appid+'|'+@openid
 declare @errorinfo varchar(512)=''
 declare @result int = 1
 --验证绑定情况
 select @cuid=cu_id from mps_login       
 where cu_qyh=@identity       
 or cu_gzh1=@identity       
 or cu_gzh2=@identity       
 or cu_gzh3=@identity       
 or cu_gzh4=@identity       
 or cu_gzh5=@identity       
 or cu_ding=@identity; 
 --判断是否找到了用户
 if @result is not null
 begin
set @result=0
 end
 --验证是否具有登录该公众号的权限
 if(@cuid is not null and  not exists(select 1 from mps_login where charindex(@appid,cu_loginscope)>0))
 begin
set @result=2
set @errorinfo='该用户不允许登录此平台'
 end
  select @result result,@cuid cu_id,@errorinfo errorinfo
END