searchChannelUrl
===
SELECT @pageTag(){
        b.id,a.fescod,a.fesname,a.orderchannel,a.channelname,a.url,b.shorturl, a.channelid,
        date_format(b.inserttime, '%Y-%m-%d %H:%i:%S') inserttime, 
        date_format(b.updatetime, '%Y-%m-%d %H:%i:%S') updatetime
@}
from (
	select a3.orderchannel,a3.channelname,a1.fescod, a3.id channelid,
				 concat(a2.url,'?fes=', lower(conv(a1.fescod,10,32)),'&sou=',lower(conv(a3.orderchannel,10,32))) url,a2.fesname
	  from tb_ordercenter_fes_chan a1, tb_ordercenter_festival a2, tb_ordercenter_channel a3
	 where a1.fescod=a2.fescod and a1.channelid=a3.id
) a 
left join tb_channel_url b on a.fescod=b.fescod and a.orderchannel=b.orderchannel
where 1=1
@if(!isEmpty(fescod)){
    and a.fescod like #fescod#
@}
@if(!isEmpty(fesname)){
    and a.fesname like #'%'+fesname+'%'#
@}
@if(!isEmpty(orderchannel)){
    and a.orderchannel like #orderchannel#
@}
@if(!isEmpty(channelname)){
    and a.channelname like #'%'+channelname+'%'#
@}
@if(!isEmpty(productid)){
    and a.fescod in (select fescod from tb_ordercenter_product where productid like #'%'+productid+'%'#)
@}
@if(!isEmpty(productname)){
    and a.fescod in (select fescod from tb_ordercenter_product where productname like #'%'+productname+'%'#)
@}
@if(!isEmpty(url)){
    and a.url like #'%'+url+'%'#
@}
@if(!isEmpty(shorturl)){
    and a.shorturl like #'%'+shorturl+'%'#
@}
order by CONVERT(a.fescod, signed)

findChannelUrlById
===
select a.id, a.fescod, a.fesname, orderchannel, channelname, shorturl, url
from tb_channel_url a
where id=#id#

findByFesAndChannel
===
select b.id, a.fescod, a.fesname, a.orderchannel, a.channelname, b.shorturl, b.url
from (
	select a3.orderchannel,a3.channelname,a1.fescod, a3.id channelid,
				 concat(a2.url,'?fes=', lower(conv(a1.fescod,10,32)),'&sou=',lower(conv(a3.orderchannel,10,32))) url,a2.fesname
	  from tb_ordercenter_fes_chan a1, tb_ordercenter_festival a2, tb_ordercenter_channel a3
	 where a1.fescod=a2.fescod and a1.channelid=a3.id
) a 
left join tb_channel_url b on a.fescod=b.fescod and a.orderchannel=b.orderchannel
where a.fescod=#fescod#
  and a.orderchannel=#orderchannel#
  
findByFesAndChannelByFescod
===
select id, fescod, channelid
from tb_ordercenter_fes_chan a
where a.fescod=#fescod#

saveChannelFestival
===
insert into tb_ordercenter_fes_chan(id, fescod, channelid, promocode)
select max(id) + 1, #fescod#, #channelid#, #fescod#
from tb_ordercenter_fes_chan

saveParityChannelFestival
===
insert into tb_ordercenter_fes_chan(id, fescod, channelid, promocode)
select max(id) + 1, #paritycode#, #channelid#, #fescod#
from tb_ordercenter_fes_chan

saveChannelUrl
===
insert into tb_channel_url(id, fescod, fesname, orderchannel, channelname, url)
select max(id)+1, #fescod#, #fesname#, #orderchannel#, #channelname#, #url#
  from tb_channel_url

updateChannelFestival
===
update tb_ordercenter_fes_chan 
   set fescod=#fescod#,
       channelid=#channelid#
 where channelid=#channelid# and fescod=#fescod# 

updateParityChannelFestival
===
update tb_ordercenter_fes_chan 
   set fescod=#paritycode#,
       channelid=#channelid#
 where channelid=#channelid# and promocode=#fescod# 

updateChannelUrl
===
update tb_channel_url
   set fescod=#fescod#,
       fesname=#fesname#,
       orderchannel=#orderchannel#,
       channelname=#channelname#,
       shorturl=#shorturl#,
       url=#url#
 where id=#id#

deleteChannelUrlById
===
delete from tb_channel_url 
where id=#id#

deleteChannelFestival
===
delete from tb_ordercenter_fes_chan 
 where channelid=#channelid# and fescod=#fescod# 

deleteParityChannelFestival
===
delete from tb_ordercenter_fes_chan 
 where channelid=#channelid# 
   and promocode=#fescod# 
   and (fescod=#fescod# or fescod=#paritycode#)
 
## 删除平价活动的配置
deleteByPromofescod
===
delete from tb_ordercenter_fes_chan 
 where fescod!=#promocode#
   and promocode=#promocode#
