IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_g_category_bizinfo_new]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_g_category_bizinfo_new]
GO
CREATE procedure [dbo].[mps_g_category_bizinfo_new](
@cmpid int,
@useruid int,
@useradmin int ,
@category nvarchar(200) ,
@mobile int =default
)
as
begin
set nocount on 
if (@mobile is null or @mobile=-999999999) set @mobile=1 
declare @biztype varchar(30) 
set @biztype = 'biz_c' 
if (charindex('/',@category)>0) set @biztype='biz_sc' 
select * from mps_template where tmp_cmpid=@cmpid and tmp_type=@biztype and tmp_objid=0 and (tmp_objid2=@useradmin or tmp_objid2=0) and tmp_caption=@category order by tmp_objid2 desc 
-- 获取有之相关的所有业务单信息
declare @c1 nvarchar(100) 
declare @c2 nvarchar(100) 
declare @i int 
set @i = CHARINDEX('/',@category) 
if (@i>0) 
begin
set @c1 = SUBSTRING(@category ,  1 , @i-1) 
set @c2 = SUBSTRING(@category ,  @i+1 , LEN(@category) - @i) 
end else 
begin
set @c1 = @category 
set @c2 = '' 
end 
declare @t table(bizid int , ok int) 
if (@c2='') 
insert into @t(bizid,ok) 
select biz_id ,0
from mps_biztype  
where biz_cmpid=@cmpid and biz_category=@c1 
else 
insert into @t(bizid,ok) 
select biz_id , 0
from mps_biztype  
        where biz_cmpid=@cmpid and biz_category=@c1 and biz_subcategory=@c2 
    
    update @t set ok=1 
    from mps_biztype_users 
    where bp_bizid=bizid and bp_cuid=@useruid and 
( bp_type='biznew')

if (@mobile=0)
select distinct biz_order,biz_id,biz_formstyle,biz_hidemenu,biz_hidemenu_mobile,biz_icon,biz_title,biz_category , biz_subcategory ,
0 as biz_comefrom , 0 biz_flag 
from mps_biztype , @t 
where biz_id=bizid and ok=1 and biz_hidemenu_mobile=1 
order by biz_order 
else if (@mobile=1)
select distinct biz_order,biz_id,biz_formstyle,biz_hidemenu,biz_hidemenu_mobile,biz_icon,biz_title,biz_category , biz_subcategory ,
0 as biz_comefrom , 0 biz_flag 
from mps_biztype , @t 
where biz_id=bizid and ok=1 and biz_hidemenu=1 
order by biz_order 
else select distinct biz_order,biz_id,biz_formstyle,biz_hidemenu,biz_hidemenu_mobile,biz_icon,biz_title,biz_category , biz_subcategory ,
0 as biz_comefrom , 0 biz_flag 
from mps_biztype , @t 
where biz_id=bizid and ok=1  
order by biz_order 



set nocount off 
end