YNICTE/Dao/MyBatis/Maps/Pay.xml

903 lines
58 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<sqlMap xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/tr/xmlschema-1/" namespace="">
<alias>
<!--tfile, 첨부파일 -->
<typeAlias alias="pay" type="NP.Model.Pay, NP.Model" />
<typeAlias alias="payitem" type="NP.Model.PayItem, NP.Model" />
<typeAlias alias="payitemresult" type="NP.Model.PayItemResult, NP.Model" />
<typeAlias alias="paydvr" type="NP.Model.PayDVR, NP.Model" />
<typeAlias alias="paycart" type="NP.Model.PayCart, NP.Model" />
<typeAlias alias="paytax" type="NP.Model.PayTax, NP.Model" />
<typeAlias alias="payrfd" type="NP.Model.PayRfd, NP.Model" />
</alias>
<cacheModels>
<cacheModel id="payCache" implementation="LRU" >
<flushInterval hours="1" />
<property name="CacheSize" value="1000" />
</cacheModel>
</cacheModels>
<!--<parametermaps>
</parametermaps>-->
<resultMaps>
</resultMaps>
<statements>
<insert id="pay.pay.in" parameterClass="pay">
insert into pay(ptype,ispg,isgroup,userno,username,isexam,pstatus,rstatus,refunding,paylimit,payoktime,pgkey
,orgamt,discamt,deliamt,isrefunddvr,payamt,refundamt,pplno,isbill,<include refid="sql.inc"></include>)
values (#ptype#,#ispg#,#isgroup#,#userno#,#username#,0,#pstatus#,#rstatus#,#refunding#,#paylimit#,case when #isinmoney# is not null then <include refid="sql.now"></include> else #payoktime# end,#pgkey#
,#orgamt#,#discamt#,#deliamt#,#isrefunddvr#,#payamt#,#refundamt#,#pplno#,#isbill#,<include refid="sql.inv"></include>);
<selectKey type="post" property="payno" resultClass="long">SELECT LAST_INSERT_ID()</selectKey>
</insert>
<insert id="pay.payitem.in" parameterClass="payitem">
insert into payitem (payno,ptype,pcno,itemno,userno,pstatus,rstatus,pcnt,orgamt,discamt,payamt,payamtcash,payamtcard,refundamt,refundtime,refundtimereal,refundinfo,isrebate,rbank,rbankaccnum,tbankuser,<include refid="sql.inc"></include>)
values(#payno#,#ptype#,#pcno#,#itemno#,#userno#,#pstatus#,#rstatus#,#pcnt#,#orgamt#,#discamt#,#payamt#,#payamtcash#,#payamtcard#,#refundamt#,#refundtime#,#refundtimereal#,#refundinfo#,#isrebate#,#rbank#,#rbankaccnum#,#tbankuser#,<include refid="sql.inv"></include>);
<selectKey type="post" property="pino" resultClass="long">SELECT LAST_INSERT_ID()</selectKey>
</insert>
<insert id="pay.lect.in" parameterClass="payitem">
insert into lect (cmno,payno,pino,userno,status,isready,iscomplete,orgcmno,attrate,isrebate,ispc,pcno,isjoin,fgno,ischanged,cmisno,<include refid="sql.inc"></include>)
values(#itemno#,#payno#,#pino#,#userno#,#status#,#isready#,null,null,0,0,#ispc#,#pcno#,#isjoin#,null,0,#cmisno#,<include refid="sql.inv"></include>);
<selectKey type="post" property="lectno" resultClass="long">SELECT LAST_INSERT_ID()</selectKey>
</insert>
<select id="pay.paydvrs" parameterClass="hashtable" resultClass="paydvr">
select a.*
from (
select a.payno,a.payoktime
,au.username,au.userid
,bb.bkname,c.isdvr,c.dvrcode
,c.rcvname
,count(bb.bkno) dvrcount
,row_number() over(order by <isNotNull property="orderby">$orderby$</isNotNull><isNull property="orderby">a.payoktime desc,a.payno,b.pino</isNull>) rno
,count(a.cdt) over() pagetotalcount
from pay a
inner join payitem b on b.payno=a.payno and b.ptype=2 and b.pstatus=1 and b.rstatus=0
inner join book bb on bb.bkno=b.itemno
<isNotNull property="bname">and bb.bkname like concat('%',#bkname#,'%')</isNotNull>
inner join users au on au.userno=a.userno
<isNotNull property="username">and au.username=#username#</isNotNull>
<isNotNull property="userid">and au.userid=#userid#</isNotNull>
inner join paydvr c on c.payno=a.payno
<isNotNull property="isdvr">and c.isdvr=#isdvr#</isNotNull>
<isNotNull property="isdvrcode0">and c.dvrcode is null</isNotNull>
<isNotNull property="isdvrcode1">and c.dvrcode is not null</isNotNull>
<isNotNull property="rcvname">and c.rcvname =#rcvname#</isNotNull>
where a.pstatus=1 and a.rstatus &lt; 2 and a.payoktime is not null
<isNotNull property="payokstime">and a.payoktime between #payokstime# and #payoketime#</isNotNull>
<isNotNull property="all">
and (bb.bkname like concat('%',#all#,'%') or au.username=#all# or au.userid=#all# or c.rcvname=#all#)
</isNotNull>
group by a.payno,a.payoktime
,au.username,au.userid
,bb.bkname,c.isdvr,c.dvrcode
,c.rcvname
) a
<include refid="sql.pagedynamic"></include>
order by a.rno
</select>
<update id="pay.paydvr.dvrcode" parameterClass="hashtable">
update paydvr set <include refid="sql.up"></include>
,dvrcode=#dvrcode#,codetime=<include refid="sql.now"></include>
where payno=#payno#
</update>
<select id="pay.paydvrfortalk" parameterClass="string" resultClass="paydvr">
select a.dvrcode,a.userno
,b.username,CAST(AES_DECRYPT(UNHEX(b.mobile), <include refid="sql.digest"></include>) AS char) mobile
from (
select a.dvrcode,c.userno
,count(d.bkno) dvrcount
,max(d.bkname) bkname
from paydvr a
inner join pay b on b.payno=a.payno
inner join payitem c on c.payno=b.payno and c.ptype=2
inner join book d on d.bkno=c.itemno
where a.payno in ($paynos$)
group by a.dvrcode,c.userno
) a
inner join users b on b.userno=a.userno
</select>
<select id="pay.cart.check" parameterClass="hashtable" resultClass="paycart">
select a.*
from (
select a.ptype,a.itemno,b.cname itemname
from paycart a
inner join cm b on b.cmno=a.itemno
where a.status=1 and a.ptype=0
<isNotNull property="itemno">and a.itemno=#itemno#</isNotNull>
<isNotNull property="userno">and a.userno=#userno#</isNotNull>
union all
select a.ptype,a.itemno,b.cname itemname
from paycart a
inner join cm b on b.cmno=a.itemno
where a.status=1 and a.ptype in (2,9)
<isNotNull property="itemno">and a.itemno=#itemno#</isNotNull>
<isNotNull property="userno">and a.userno=#userno#</isNotNull>
<isNotNull property="bknos">and a.itemno in (#bknos#)</isNotNull>
) a
order by a.ptype
</select>
<update id="pay.cart.in" parameterClass="paycart">
<!--update paycart set status=4 where #ptype#=0 and isgroup=0 and ptype=9 and cmno=#itemno# and status=1;
update paycart set status=4 where #ptype#=0 and isgroup=0 and ptype=0 and itemno=#itemno# and status=1;-->
insert into paycart(isgroup,ptype,itemno,isrefund,cmno,userno,pcnt,status,fgno,<include refid="sql.inc"></include>)
select 0,#ptype#,#itemno#,#isrefund#,#cmno#,#userno#,#pcnt#,#status#,#fgno#,<include refid="sql.inv"></include>
from (select 1 col1) a
left outer join paycart b on b.ptype=#ptype# and b.itemno=#itemno# and b.userno=#userno# and b.status=1
where b.pcno is null;
<isNotNull property="bknos">
insert into paycart(isgroup,ptype,itemno,isrefund,cmno,userno,pcnt,status,fgno,<include refid="sql.inc"></include>)
select #isgroup#,9,a.itemno,#isrefund#,#itemno#,#userno#,a.pcnt,#status#,null,<include refid="sql.inv"></include>
from (
<iterate property="Ds" open ="" conjunction="union all" close="">
select #Ds[].itemno# itemno,#Ds[].pcnt# pcnt
</iterate>
) a
</isNotNull>
</update>
<select id="pay.payitems.forexampay" parameterClass="hashtable" resultClass="payitem">
select 3 ptype,b.exno itemno,b.exname itemname,0 isrebate,1 pcnt
,b.outfee orgamt
,case when ua.isjoin=1 then b.outfee-b.infee else 0 end discamt
,case when ua.isjoin=1 then b.infee else b.outfee end payamt
,case when ua.isjoin=1 then b.infee else b.outfee end payamt2
,b.rstime,b.retime
from examuser a
inner join exam b on b.exno=a.exno and b.rstime &lt; now() and b.retime &gt; now()
inner join users u on u.userno=a.userno
left outer join assign ua on ua.asno=u.asno
where a.exno=#exno# and a.userno=#userno# and a.status=1 and a.pstatus=4
</select>
<select id="pay.payitems.forcertpay" parameterClass="hashtable" resultClass="payitem">
update payitem a
inner join pay b on b.payno=a.payno and b.userno=#userno# and b.pstatus=21
inner join users u on u.userno=b.userno
left outer join assign ua on ua.asno=u.asno
left outer join cm c on a.ptype=4 and c.cmno=a.itemno
left outer join book d on a.ptype=2 and d.bkno=a.itemno
set a.orgamt=case when a.ptype=4 then c.outfee else d.price * a.pcnt end
,a.discamt=case when a.ptype=4 and ua.isjoin=1 then c.outfee-c.infee else 0 end
,a.payamt=case when a.ptype=4 then case when ua.isjoin=1 then c.infee else c.outfee end else d.price * a.pcnt end
where a.payno=#payno# and a.ptype in (2,4) and a.pstatus in(21,50);
update pay a
inner join (
select a.payno,sum(b.orgamt) orgamt,sum(b.discamt) discamt,sum(b.payamt) payamt
from pay a
inner join payitem b on b.payno=a.payno
where a.payno=#payno# and a.userno=#userno# and a.pstatus=21
group by a.payno
) b on b.payno=a.payno
set a.orgamt=b.orgamt,a.discamt=b.discamt,a.payamt=b.payamt
where a.payno=#payno# and a.userno=#userno# and a.pstatus=21;
select b.ptype,b.itemno,case when b.ptype=4 then c.cname else d.bkname end itemname,b.isrebate,b.pcnt
,b.orgamt,b.discamt,b.payamt payamt2,case when b.ptype=4 then b.payamt else d.price end payamt,datediff(c.setime, c.sstime)+1 days
,c.rstime,c.retime
from pay a
inner join payitem b on b.payno=a.payno and b.ptype in(2,4) and b.pstatus in(21,50)
left outer join cm c on b.ptype=4 and c.cmno=b.itemno
left outer join book d on b.ptype=2 and d.bkno=b.itemno
inner join users u on u.userno=a.userno
left outer join assign ua on ua.asno=u.asno
where a.payno=#payno# and a.userno=#userno# and a.pstatus=21
</select>
<select id="pay.payitems.forpay" parameterClass="hashtable" resultClass="payitem">
select 0 ptype,0 itemno,'a' itemname,0 orgamt,0 discamt,0 payamt,0 days, null cshape
from (select 1 col1) a
<isNotEmpty property="cmnos0">
union all
select 0,a.cmno,a.cname,a.outfee,case when c.isjoin=1 then a.outfee-a.infee else 0 end
,case when c.isjoin=1 then a.infee else a.outfee end
,datediff(a.setime, a.sstime)+1,a.cshape
from cm a
inner join users b on b.userno=#userno#
left outer join assign c on c.asno=b.asno
where a.cmno in ($cmnos0$)
</isNotEmpty>
<isNotEmpty property="bknos">
union all
select 2,a.bkno,a.bkname,a.price,0,a.price,0,null cshape
from book a
where a.bkno in ($bknos$)
</isNotEmpty>
</select>
<select id="pay.cmcheck.forgrouppay" parameterClass="hashtable" resultClass="lect">
select a.cmno,a.cname,a.quota,a.rstime,a.retime
,b.userno,b.status,c.username
,case when #usernos# like concat('%,',b.userno,',%') then 1 else 0 end ispaied
,a.infee,a.outfee,case when ua.isjoin=1 then a.infee else a.outfee end payamt
from cm a
inner join users u on u.userno=#userno#
left outer join assign ua on ua.asno=u.asno
left outer join lect b on b.cmno=a.cmno and b.status &lt; 5 and b.ischanged=0
left outer join users c on c.userno=b.userno and c.status=1
where a.cmno=#cmno# and a.ismaster=0 and a.rstime &lt; now() and a.retime &gt; now() and a.isuse=1 and a.isdel=0
</select>
<select id="pay.cmcheck.forpay" parameterClass="hashtable" resultClass="lect">
select a.cmno,a.cname,a.quota,a.rstime,a.retime
,b.status
,a.infee,a.outfee,case when ua.isjoin=1 then a.infee else a.infee end payamt ,a.accommofee
,count(d.userno) countlect
from cm a
inner join users u on u.userno=#userno#
left outer join assign ua on ua.asno=u.asno
left outer join lect b on b.cmno=a.cmno and b.userno =#userno# and b.status &lt; 5 and b.ischanged=0
left outer join lect c on c.cmno=a.cmno and c.status in (1,2,3,4,6) and c.ischanged=0
left outer join users d on d.userno=c.userno and d.status=1
where
<isNotNull property="cmnos">a.cmno in($cmnos$)</isNotNull>
<isNotNull property="cmno">a.cmno=#cmno#</isNotNull>
and a.ismaster=0 and a.rstime &lt; now() and a.retime &gt; now() and a.isuse=1 and a.isdel=0
group by a.cmno,a.cname,a.quota,a.rstime,a.retime,a.infee,a.outfee,ua.asno
,b.status
</select>
<insert id="pay.pay.pgin" parameterClass="pay">
insert into pay(ptype,ispg,isgroup,isexam,userno,username,pstatus,rstatus
,refunding,paylimit,payoktime,pgkey,orgamt,discamt,deliamt,isrefunddvr,payamt,refundamt,isdvr,iscashrct,cashrcthp,pplno,isbill,<include refid="sql.inc"></include>)
select #ptype#,#ispg#,#isgroup#,#isexam#,a.userno,a.username,case when #ptype# = 6 then 1 else 0 end,0
,#refunding#,#paylimit#,case when #ptype# = 6 then now() else #payoktime# end,#pgkey#,#orgamt#,#discamt#,#deliamt#,#isrefunddvr#,#payamt#,#refundamt#,#isdvr#,#iscashrct#,HEX(AES_ENCRYPT(#cashrcthp#, <include refid="sql.digest"></include>)),#pplno#,#isbill#,<include refid="sql.inv"></include>
from users a
where a.userno=#userno#
<selectKey type="post" property="payno" resultClass="long">SELECT LAST_INSERT_ID()</selectKey>
</insert>
<update id="pay.payitem.pgin" parameterClass="pay">
insert into payitem (payno,ptype,pcno,itemno,userno,pstatus,rstatus
,pcnt,orgamt,discamt,payamt,payamtcash,payamtcard,refundamt,refundtime,refundtimereal,refundinfo,isrebate,rbank,rbankaccnum,tbankuser,fgno,<include refid="sql.inc"></include>)
select #payno#,a.ptype,null,a.itemno,a.userno,case when #ptype# = 6 then 1 else 0 end,0
,a.pcnt,a.orgamt,a.discamt,a.payamt,0,0,0,null,null,null,a.isrebate,a.rbank,HEX(AES_ENCRYPT(a.rbankaccnum, <include refid="sql.digest"></include>)),a.tbankuser,ifnull(b.fgno,a.fgno),<include refid="sql.inv"></include>
from (
<iterate property="PIs" open="" conjunction="union all" close=""> select #PIs[].ptype# ptype,#PIs[].itemno# itemno,#PIs[].userno# userno,#PIs[].pcnt# pcnt,#PIs[].orgamt# orgamt,#PIs[].discamt# discamt,#PIs[].payamt# payamt,#PIs[].isrebate# isrebate,#PIs[].rbank# rbank,#PIs[].rbankaccnum# rbankaccnum,#PIs[].tbankuser# tbankuser,#PIs[].fgno# fgno </iterate>
) a
left outer join paycart b on #isexam# = 2 and a.ptype=0 and b.ptype=0 and b.itemno=a.itemno and b.userno=#userno# and b.status=1 and b.ispay=1
</update>
<update id="pay.paydvr.in" parameterClass="hashtable">
delete from paydvr where payno=#payno#;
insert into paydvr (payno,dvrcode,codetime,isdvr,rcvname,telno,mobile,email,post,address1,address2,dmemo,<include refid="sql.inc"></include>)
values (#payno#,#dvrcode#,#codetime#,#isdvr#,#rcvname#
,HEX(AES_ENCRYPT(#telno#, <include refid="sql.digest"></include>))
,HEX(AES_ENCRYPT(#mobile#, <include refid="sql.digest"></include>))
,HEX(AES_ENCRYPT(#email#, <include refid="sql.digest"></include>))
,#post#,#address1#,#address2#,#dmemo#,<include refid="sql.inv"></include>)
</update>
<update id="pay.freeok" parameterClass="long">
insert into lect (cmno,payno,pino,userno,status,attrate,isrebate,ispc,isjoin,ischanged,fgno2,<include refid="sql.inc"></include>)
select b.itemno,a.payno,b.pino,case when a.isgroup=1 then b.userno else a.userno end,1,0,b.isrebate,0,case when ua.isjoin=1 then 1 else 0 end,0,b.fgno,<include refid="sql.inv"></include>
from pay a
inner join payitem b on b.payno=a.payno and b.ptype=0
inner join users u on u.userno=a.userno
left outer join assign ua on ua.asno=u.asno
where a.payno=#payno#;
</update>
<update id="pay.paydvr.save" parameterClass="hashtable">
update paydvr set <include refid="sql.up"></include>
,dvrcode=#dvrcode#,rcvname=#rcvname#,post=#post#,address1=#address1#,address2=#address2#,dmemo=#dmemo#
,codetime=case when codetime is null and #dvrcode# is not null then now() else codetime end
,telno=HEX(AES_ENCRYPT(#telno#, <include refid="sql.digest"></include>))
,mobile=HEX(AES_ENCRYPT(#mobile#, <include refid="sql.digest"></include>))
where payno=#payno#
</update>
<update id="pay.paycert.paystart" parameterClass="pay">
update pay a
inner join users b on b.userno=a.userno
set a.ptype=#ptype#,a.paylimit=#paylimit#,a.orgamt=#orgamt#,a.payamt=#payamt#,a.isbill=#isbill#
where a.payno=#payno# and a.userno=#userno# and a.pstatus=21;
update payitem a
inner join users b on b.userno=a.userno
set a.orgamt=#orgamt#,a.payamt=#payamt#
where a.payno=#payno# and a.userno=#userno# and a.pstatus=21;
</update>
<select id="pay.pay" parameterClass="hashtable" resultClass="pay">
select a.payno,a.ptype,a.isgroup,a.isexam,a.userno,a.pstatus,a.payamt,a.rstatus,a.refundamt,a.ispg,a.paylimit
,b.isready,b.isaccommodation
from pay a
left outer join pplog b on b.pplno=a.pplno
<dynamic prepend="where">
<isNotNull property="payno" prepend="and">a.payno=#payno#</isNotNull>
<isNotNull property="userno" prepend="and">a.userno=#userno#</isNotNull>
<isNotNull property="pstatus21" prepend="and">(a.pstatus=#pstatus21# or a.pstatus=21)</isNotNull>
<isNotNull property="pstatus" prepend="and">a.pstatus=#pstatus#</isNotNull>
<isNotNull property="rstatusnot" prepend="and">a.rstatus&lt;&gt;#rstatusnot#</isNotNull>
</dynamic>
</select>
<update id="pay.paylect" parameterClass="hashtable">
update pay set <include refid="sql.up"></include>
,pstatus=case when ptype=3 then 22 else 1 end
,payoktime=case when ptype=3 then null else <include refid="sql.now"></include> end
,pgkey=#pgkey#
where payno=#payno#;
insert into paydata(payno,payresult,payresultmsg,vactnum,vactbankcode,vactbankname,vactname,vactinname,cshrrcode,cshrtype,cshrauthno,cardquota,cardquotatype,cardeventcode,cardnum,iscardpoint,cardcode,cardbankcode,cardprtccode,checkflag,ocbnum,ocbappno,ocbprice,gsnum,gsremain,gsprice,unum,upoint,uprice,<include refid="sql.inc"></include>)
values (#payno#,#payresult#,#payresultmsg#,HEX(AES_ENCRYPT(#vactnum#, <include refid="sql.digest"></include>)),#vactbankcode#,#vactbankname#,#vactname#,#vactinname#,#cshrrcode#,#cshrtype#,#cshrauthno#,#cardquota#,#cardquotatype#,#cardeventcode#,HEX(AES_ENCRYPT(#cardnum#, <include refid="sql.digest"></include>)),#iscardpoint#,#cardcode#,#cardbankcode#,#cardprtccode#,#checkflag#,#ocbnum#,#ocbappno#,#ocbprice#,#gsnum#,#gsremain#,#gsprice#,#unum#,#upoint#,#uprice#,<include refid="sql.inv"></include>);
update payitem a
inner join pay b on b.payno=a.payno
set a.udt=now(),a.uno=#uno#,a.uip=#uip#
,a.pstatus=case when b.ptype=3 then 22 else 1 end
where a.payno=#payno#;
insert into lect (cmno,payno,pino,userno
,status,iscomplete,orgcmno,attrate,isrebate
,ispc,isjoin,fgno,apoint,mpoint
,fpoint,spoint,dpoint,tpoint,ischanged
,stime,etime,sip,eip,ispcs
,ispce,fgno2,cmisno,<include refid="sql.inc"></include>)
select a.itemno,a.payno,a.pino,case when b.isgroup=1 then a.userno else b.userno end
,case when b.ptype=3 then 2 else 1 end,null,null,0,a.isrebate
,0,ifnull(d.isjoin, 0),null,null,null
,null,null,null,null,0
,null,null,null,null,null
,null,a.fgno,e.cmisno,<include refid="sql.inv"></include>
from payitem a
inner join pay b on b.payno=a.payno
inner join users c on c.userno=b.userno
left outer join assign d on d.asno=c.asno
left outer join pplog e on e.pplno=b.pplno
left outer join lect f on f.payno=a.payno and f.pino=a.pino and f.status=4 and f.isready=1
where a.payno=#payno# and a.ptype=0 and f.lectno is null;
update lect a
inner join pay b on b.payno=a.payno and b.pstatus in (22,1)
inner join payitem c on c.payno=b.payno and c.itemno=a.cmno and c.pstatus=b.pstatus
set a.status=case when b.pstatus=22 then 2 else 1 end,a.uno=#uno#,a.uip=#uip#
where a.payno=#payno# and a.status=4;
<!--update examuser a
inner join pay b on b.isexam=1 and b.payno=#payno# and b.pstatus in (22,1)
inner join payitem c on c.payno=b.payno and c.ptype=3 and c.itemno=a.exno and c.pstatus=b.pstatus
set a.payno=b.payno,a.pstatus=case when b.pstatus=22 then 2 else 1 end,a.uno=#uno#,a.uip=#uip#
where a.userno=#userno# and a.status=1 and a.pstatus=4;
update paycart a
inner join pay b on b.isexam=2 and b.payno=#payno# and b.pstatus in (22,1)
inner join payitem c on c.payno=b.payno and c.ptype=case when a.ptype=9 then 2 else a.ptype end and c.itemno=a.itemno and c.pstatus=b.pstatus
set a.status=3,c.cartno=a.pcno,a.uno=#uno#,a.uip=#uip#
where a.userno=#userno# and a.status=1 and a.ispay=1;-->
</update>
<update id="pay.pay.fail" parameterClass="hashtable">
update pay set pstatus=#pstatus# where payno=#payno#;
insert into paydata(payno,payresult,payresultmsg,vactnum,vactbankcode,vactbankname,vactname,vactinname,cshrrcode,cshrtype,cshrauthno,cardquota,cardquotatype,cardeventcode,cardnum,iscardpoint,cardcode,cardbankcode,cardprtccode,checkflag,ocbnum,ocbappno,ocbprice,gsnum,gsremain,gsprice,unum,upoint,uprice,<include refid="sql.inc"></include>)
values (#payno#,#payresult#,#payresultmsg#,HEX(AES_ENCRYPT(#vactnum#, <include refid="sql.digest"></include>)),#vactbankcode#,#vactbankname#,#vactname#,#vactinname#,#cshrrcode#,#cshrtype#,#cshrauthno#,#cardquota#,#cardquotatype#,#cardeventcode#,#cardnum#,#iscardpoint#,HEX(AES_ENCRYPT(#cardnum#, <include refid="sql.digest"></include>)),#cardbankcode#,#cardprtccode#,#checkflag#,#ocbnum#,#ocbappno#,#ocbprice#,#gsnum#,#gsremain#,#gsprice#,#unum#,#upoint#,#uprice#,<include refid="sql.inv"></include>);
</update>
<update id="pay.paylect.vbankin" parameterClass="hashtable">
insert into payvbankin (payno,pgkey,inbankcode,indeal,inymd,inhms,msgseq,transseq,vacct,inamt,checkamt,isclose,typemsg,frombank,fromname,fromymd,calcymd,tranymd,transcode,korcode,cshrymd,cshrhms,cshrcode,cshrpgkey,cshramt,<include refid="sql.inc"></include>)
values (#payno#,#pgkey#,#inbankcode#,#indeal#,#inymd#,#inhms#,#msgseq#,#transseq#,#vacct#,#inamt#,#checkamt#,#isclose#,#typemsg#,#frombank#,#fromname#,#fromymd#,#calcymd#,#tranymd#,#transcode#,#korcode#,#cshrymd#,#cshrhms#,#cshrcode#,#cshrpgkey#,#cshramt#,<include refid="sql.inv"></include>);
<!--여기 입금 처리-->
update pay set <include refid="sql.up"></include>
,pstatus=1
,payoktime=<include refid="sql.now"></include>
<!--,pgkey=#pgkey#-->
where payno=#payno# and pstatus=22 <!--and pgkey=#pgkey#-->;
update payitem a
inner join pay b on b.payno=a.payno <!--and b.pgkey=#pgkey#-->
set a.udt=now(),a.uno=#uno#,a.uip=#uip#
,a.pstatus=1
where a.payno=#payno# and a.pstatus=22;
update lect a
inner join pay b on b.isexam &lt;&gt; 1 and b.payno=a.payno and b.pstatus=1 <!--and b.pgkey=#pgkey#-->
set a.udt=now(),a.uno=#uno#,a.uip=#uip#
,a.status=1
where a.payno=#payno#;
<!--update examuser a
inner join pay b on b.isexam=1 and b.payno=a.payno and b.pstatus=1 --><!--and b.pgkey=#pgkey#--><!--
set a.udt=now(),a.uno=#uno#,a.uip=#uip#
,a.pstatus=1
where a.payno=#payno#;-->
</update>
<select id="pay.payitems" parameterClass="long" resultClass="payitemresult">
select a0.payno,a0.isgroup,a0.isexam,a0.isdvr,a0.payamt tpayamt,a0.paylimit,a0.ptype,a0.udt,a0.deliamt,a0.pgkey
,ad.rcvname
,CAST(AES_DECRYPT(UNHEX(ad.mobile), <include refid="sql.digest"></include>) AS char) mobile
,CAST(AES_DECRYPT(UNHEX(ad.telno), <include refid="sql.digest"></include>) AS char) telno
,CAST(AES_DECRYPT(UNHEX(ad.email), <include refid="sql.digest"></include>) AS char) email
,ad.post,ad.address1,ad.address2
,a.ptype ptype2,a.payamt,a.pcnt,a.isrebate,a.itemno
,b.cmno,b.cshape,b.sstime,b.setime
,b1.rsno
,b2.username,cc.cname ccpositionname,b2.isassignuser
,CAST(AES_DECRYPT(UNHEX(b2.email), <include refid="sql.digest"></include>) AS char) email2
,CAST(AES_DECRYPT(UNHEX(b2.telno), <include refid="sql.digest"></include>) AS char) telno2
,b2.depart,b2.kfcfyear,b2.edus
,c.bkno
,case a.ptype when 0 then b.cname when 4 then b.cname when 2 then c.bkname when 3 then e.exname else '-' end itemname
,cg2.cgcode
,CAST(AES_DECRYPT(UNHEX(pd.vactnum), <include refid="sql.digest"></include>) AS char) vactnum,pd.vactbankname,pd.vactname
,t.lectno,t.status
,ad.isdvr isdvr2
from pay a0
left outer join paydvr ad on ad.payno=a0.payno
left outer join paydata pd on pd.payno=a0.payno
inner join payitem a on a.payno=a0.payno
left outer join cm b on a.ptype in(0,4) and b.cmno=a.itemno
left outer join lect t on t.cmno=b.cmno and t.userno=a.userno and t.status=1
left outer join cg cg1 on cg1.cgno=b.cgno
left outer join cg cg2 on cg2.cgno=cg1.pcgno
left outer join cmrs b1 on b1.cmno=b.cmno and b1.rstype=1 and b1.isdel=0
left outer join users b2 on b2.userno=a.userno
left outer join comcode cc on cc.ccode=b2.ccposition
left outer join book c on a.ptype=2 and c.bkno=a.itemno
left outer join examuser d on a.ptype=3 and d.exno=a.itemno and d.userno=a0.userno and d.payno=a0.payno
left outer join exam e on e.exno=d.exno
where a0.payno=#payno#
</select>
<insert id="pay.certpay" parameterClass="hashtable">
insert into pay(ptype,ispg,isgroup,userno,pstatus,rstatus,refunding,orgamt,discamt,deliamt,isrefunddvr,payamt,refundamt,isdvr,isexam,<include refid="sql.inc"></include>)
values (0,1,0,#userno#,51,0,0,0,0,0,0,0,0,0,0,<include refid="sql.inv"></include>)
<selectKey type="post" property="payno" resultClass="long">SELECT LAST_INSERT_ID()</selectKey>
</insert>
<update id="pay.certpayitem" parameterClass="hashtable">
insert into payitem (payno,ptype,itemno,userno,pstatus,rstatus,pcnt
,orgamt,discamt,payamt,payamtcash,payamtcard,refundamt,isrebate,fgno,<include refid="sql.inc"></include>)
values (#payno#,4,#cmno#,#userno#,51,0,1
,0,0,0,0,0,0,#isrebate#,#fgno#,<include refid="sql.inv"></include>);
insert into lect(cmno,payno,pino,userno,status,attrate,isrebate,ispc,isjoin,fgno,ischanged,fgno2,<include refid="sql.inc"></include>)
select #cmno#,#payno#,LAST_INSERT_ID(),a.userno,3,0,#isrebate#,0,b.isjoin,#fgno2#,0,#fgno#,<include refid="sql.inv"></include>
from users a
left outer join assign b on b.asno=a.asno
where a.userno=#userno#;
<isNotNull property="inquery">
<!--insert into paycertbook (payno,bkno,bcount,<include refid="sql.inc"></include>)
<iterate property="PIs" open ="" conjunction="union all" close="">
select #payno#,#PIs[].itemno#,#PIs[].pcnt#,now(),#uno#,now(),#uno#,#uip#
</iterate>-->
insert into payitem (payno,ptype,itemno,userno,pstatus,rstatus,pcnt,orgamt,discamt,payamt,payamtcash,payamtcard,refundamt,isrebate,fgno,<include refid="sql.inc"></include>)
<iterate property="PIs" open ="" conjunction="union all" close="">
select #payno#,2,#PIs[].itemno#,#userno#,50,0,#PIs[].pcnt#,0,0,0,0,0,0,0,null,now(),#uno#,now(),#uno#,#uip#
</iterate>
</isNotNull>
</update>
<select id="pay.paylect.get" parameterClass="long" resultClass="lect">
select a.fgno
,b.cshape,b.cname,b.rstime,b.retime,b.sstime,b.setime
,b2.cname certgradeccname
,c.username
,CAST(AES_DECRYPT(UNHEX(c.email), <include refid="sql.digest"></include>) AS char) email
,CAST(AES_DECRYPT(UNHEX(c.mobile), <include refid="sql.digest"></include>) AS char) mobile
,CAST(AES_DECRYPT(UNHEX(c.telno), <include refid="sql.digest"></include>) AS char) telno
,c.depart
,c2.cname ccpositionname
,d.asname
from lect a
inner join cm b on b.cmno=a.cmno
left outer join comcode b2 on b2.ccode=b.certgradecc
inner join users c on c.userno=a.userno
left outer join comcode c2 on c2.ccode=c.ccposition
left outer join assign d on d.asno=c.asno
where a.payno=#payno#
</select>
<select id="pay.mypayitems" parameterClass="hashtable" resultClass="payitem">
select a.payno,a.isgroup,a.pstatus ppstatus,a.rstatus prstatus
,b.pino,b.ptype,b.pcno,b.itemno,b.userno,b.pstatus,b.rstatus,b.isrebate
,c.cname,c.classno,c.rstime,c.retime,c.sstime,c.setime,c.cshape,c.isrefund
,cc.cname studyplacename
,d.tyear,d.tseq
,u.username
,ua.asname
,uc.cname ccpositionname
,CAST(AES_DECRYPT(UNHEX(u.email), <include refid="sql.digest"></include>) AS char) email
,case when max(e.rfdno) &gt; 0 then 1 else 0 end rfdstatus
,lect.cmisno
,cmis.estart cmiestart,cmis.eend cmieend
from pay a
inner join payitem b on b.payno=a.payno and b.ptype in (0,1,4) and b.pstatus in (1,21,22,51,55)
inner join cm c on c.cmno=b.itemno and c.rstime &lt; now() and c.retime &gt; now()
inner join term d on d.tmno=c.tmno
inner join users u on u.userno=b.userno
left outer join assign ua on ua.asno=u.asno
left outer join comcode uc on uc.ccode=u.ccposition
left outer join payrfditem e0 on e0.pino=b.pino
left outer join payrfd e on e.rfdno=e0.rfdno and e.payno=a.payno and e.rstatus=0
left outer join comcode cc on cc.ccode=c.studyplace
left outer join lect lect on lect.pino=b.pino and lect.ischanged=0
left outer join cminningscd cmis on cmis.cmisno=lect.cmisno
where a.userno=#userno# and a.pstatus in (1,21,22,51,55) and lect.status &lt; 8
group by a.payno,a.isgroup,a.pstatus,a.rstatus
,b.pino,b.ptype,b.pcno,b.itemno,b.userno,b.pstatus,b.rstatus,b.isrebate
,c.cname,c.classno,c.rstime,c.retime,c.sstime,c.setime,c.cshape
,cc.cname
,d.tyear,d.tseq
,u.username
,ua.asname
,uc.cname
,u.email
,lect.cmisno
,cmis.estart,cmis.eend
order by c.retime,a.payno,b.pino
</select>
<update id="pay.paycancel" parameterClass="hashtable">
update pay set <include refid="sql.up"></include>
,pstatus=case when pstatus=22 then 43 else 41 end
where payno=#payno# and userno=#userno# and pstatus in (51,55,21,22);
update payitem a
inner join pay b on b.payno=a.payno and b.userno=#userno# and b.pstatus in (41,43)
set a.pstatus=b.pstatus,a.uno=#uno#,a.uip=#uip#
where a.payno=#payno# and a.pstatus in (21,22);
update lect a
inner join pay b on b.payno=a.payno and b.userno=#userno# and b.pstatus in (41,43)
set a.status=9
where a.payno=#payno#;
update examuser a
inner join pay b on b.payno=a.payno and b.userno=a.userno and b.pstatus in (41,43)
set a.pstatus=9
where a.payno=#payno# and a.userno=#userno#
</update>
<update id="pay.cart.clear" parameterClass="hashtable">
update paycart set status=2,udt=now(),uno=#uno#,uip=#uip# where userno=#userno# and status=1 and date_add(cdt, interval 7 day) &lt; now();
update paycart a
inner join cm b on b.cmno=a.itemno and b.udt &gt; a.cdt
set a.status=2,a.udt=now(),a.uno=#uno#,a.uip=#uip#
where a.userno=#userno# and a.status=1 and a.ptype=0;
update paycart a
inner join book b on b.bkno=a.itemno and b.udt &gt; a.cdt
set a.status=2,a.udt=now(),a.uno=#uno#,a.uip=#uip#
where a.userno=#userno# and a.status=1 and a.ptype in (2,9);
update paycart a
left outer join cm b on b.cmno=a.itemno and b.rstime &lt; now() and b.retime &gt; now()
set a.status=2,a.udt=now(),a.uno=#uno#,a.uip=#uip#
where a.userno=#userno# and a.status=1 and a.ptype=0 and b.cmno is null;
update paycart a
left outer join paycart b on b.ptype =0 and b.userno=#userno# and b.status=1 and b.itemno=a.cmno
set a.status=2,a.udt=now(),a.uno=#uno#,a.uip=#uip#
where a.userno=#userno# and a.status=1 and a.ptype=9 and b.pcno is null
</update>
<select id="pay.carts" parameterClass="int" resultClass="paycart">
select a.pcno,a.ptype,a.itemno,a.isrefund,a.cmno,a.userno,a.pcnt,a.fgno
,case when a.ptype=0 then b.cname else c.bkname end itemname,b.cshape,b.sstime,b.setime
,case when a.ptype = 0 then case when ua.isjoin=1 then b.infee else b.outfee end else c.price end payamt
,case when a.ptype = 0 then b.outfee else c.price end orgamt
from paycart a
inner join users u on u.userno=a.userno
left outer join assign ua on ua.asno=u.asno
left outer join cm b on a.ptype=0 and b.cmno=a.itemno
left outer join book c on a.ptype in (2,9) and c.bkno=a.itemno
where a.status=1 and a.userno=#userno#
order by a.cdt desc
</select>
<update id="pay.paycart.del" parameterClass="hashtable">
update paycart a
set a.status=0,<include refid="sql.up"></include>
where a.userno=#userno# and a.status &lt;&gt;0
<isNotNull property="pcno">and a.pcno=#pcno#</isNotNull>
<isNotNull property="pcnos">and a.pcno in ($pcnos$)</isNotNull>
</update>
<update id="pay.paycart.flag" parameterClass="hashtable">
update paycart set ispay=0 where userno=#userno#;
update paycart a
set a.ispay=1
where a.userno=#userno# and a.status=1
<isNotNull property="pcno">and a.pcno=#pcno#</isNotNull>
<isNotNull property="pcnos">and a.pcno in ($pcnos$)</isNotNull>
</update>
<select id="pay.payitems.forcartpay" parameterClass="hashtable" resultClass="payitem">
select case when a.ptype = 9 then 2 else a.ptype end ptype,a.itemno,case when a.ptype=0 then b.cname else c.bkname end itemname,case when a.ptype=0 then a.isrefund else 0 end isrebate,a. pcnt
,case when a.ptype=0 then b.outfee else c.price end orgamt
,case when a.ptype=0 then case when ua.isjoin=1 then b.outfee-b.infee else 0 end else 0 end discamt
,case when a.ptype=0 then case when ua.isjoin=1 then b.infee else b.outfee end else c.price end payamt
,case when a.ptype=0 then case when ua.isjoin=1 then b.infee else b.outfee end else c.price end * a.pcnt payamt2
,b.rstime,b.retime,b.sstime,b.setime,b.cshape,datediff(b.setime, b.sstime)+1 days
from paycart a
left outer join cm b on a.ptype=0 and b.cmno=a.itemno and b.rstime &lt; now() and b.retime &gt; now()
left outer join book c on a.ptype in (2,9) and c.bkno=a.itemno
inner join users u on u.userno=a.userno
left outer join assign ua on ua.asno=u.asno
where a.userno=#userno# and a.status=1 and a.ispay=1;
</select>
<select id="pay.mypaies" parameterClass="int" resultClass="pay">
select a.payno,a.ptype,a.isexam,a.pstatus,a.rstatus,a.rstatustime,a.payamt,a.deliamt,a.isdvr,a.cdt,a.payoktime,a.refundamt,a.ispg,a.paylimit
,b.ptype piptype,b.isrebate
,c0.cshape
,case b.ptype when 0 then c0.cname when 2 then c2.bkname when 4 then c0.cname when 3 then c3.exname else '-' end itemname
,a2.dvrcode,a2.isdvr isdvr2
,a3.vactbankname,CAST(AES_DECRYPT(UNHEX(a3.vactnum), <include refid="sql.digest"></include>) AS char) vactnum
,max(r.rfdno) rfdno
from pay a
left outer join paydvr a2 on a2.payno=a.payno
left outer join paydata a3 on a3.payno=a.payno
inner join payitem b on b.payno=a.payno
left outer join cm c0 on b.ptype in (0,4) and c0.cmno=b.itemno
left outer join book c2 on b.ptype=2 and c2.bkno=b.itemno
left outer join exam c3 on b.ptype=3 and c3.exno=b.itemno
left outer join payrfditem ri on ri.pino=b.pino
left outer join payrfd r on r.rfdno=ri.rfdno and r.payno=a.payno and r.rstatus=0
where a.ptype &gt; 0 and a.userno=#userno# and a.pstatus in (1,22,41,42,43)
<isNotNull property="paytermday">and date_add(a.cdt, interval $paytermday$ day) &gt; now()</isNotNull>
<isNotNull property="paytermmonth">and date_add(a.cdt, interval $paytermmonth$ month) &gt; now()</isNotNull>
group by a.payno,a.ptype,a.isexam,a.pstatus,a.rstatus,a.rstatustime,a.payamt,a.deliamt,a.isdvr,a.cdt,a.payoktime,a.refundamt,a.ispg,a.paylimit
,b.ptype,b.isrebate
,c0.cshape
,c0.cname,c2.bkname,c3.exname
,a2.dvrcode,a2.isdvr
,a3.vactbankname,vactnum
order by a.cdt desc,a.payno
</select>
<select id="pay.mypay" parameterClass="hashtable" resultClass="pay">
select a.payno,a.ptype,a.ispg,a.isgroup,a.isexam,a.userno,a.pstatus,a.rstatus,a.rstatustime,a.refunding,a.paylimit,a.payoktime,a.isrefunddvr,a.refundamt,a.payamt,a.deliamt,a.isdvr,a.cdt,a.pgkey
,b.dvrcode,b.isdvr isdvr2,b.rcvname,b.post,b.address1,b.address2
,CAST(AES_DECRYPT(UNHEX(b.telno), <include refid="sql.digest"></include>) AS char) telno
,CAST(AES_DECRYPT(UNHEX(b.email), <include refid="sql.digest"></include>) AS char) email
,CAST(AES_DECRYPT(UNHEX(b.mobile), <include refid="sql.digest"></include>) AS char) mobile
,c.vactbankname,CAST(AES_DECRYPT(UNHEX(c.vactnum), <include refid="sql.digest"></include>) AS char) vactnum,c.vactname
from pay a
left outer join paydvr b on b.payno=a.payno
left outer join paydata c on c.payno=a.payno
where a.payno=#payno# and a.userno=#userno# and a.pstatus in (1,22,41,42,43)
</select>
<select id="pay.mypayitem" parameterClass="hashtable" resultClass="payitem">
select a.ptype,c0.cshape,a.isrebate,a.payamt,a.pcnt,a.rstatus,a.userno,a.pstatus,a.pino,c0.infee,c0.outfee,c0.rstime,c0.retime
,case a.ptype when 0 then c0.cname when 2 then c2.bkname when 4 then c0.cname when 3 then c3.exname else '-' end itemname
,c0.sstime,c0.setime,datediff(c0.setime, c0.sstime)+1 days
,u.username,uc.cname ccpositionname,u.isassignuser
,CAST(AES_DECRYPT(UNHEX(u.telno), <include refid="sql.digest"></include>) AS char) telno
,CAST(AES_DECRYPT(UNHEX(u.email), <include refid="sql.digest"></include>) AS char) email
,CAST(AES_DECRYPT(UNHEX(u.mobile), <include refid="sql.digest"></include>) AS char) mobile
,u.kfcfyear,u.edus,u.depart
,rs.rsno,t.lectno
,a2.taxno
from payitem a
left outer join paytax a3 on a3.payno = a.payno and (a3.iscancel is null or a3.iscancel &lt;&gt; 1)
left outer join paytaxitem a2 on a2.pino=a.pino and a3.taxno = a2.taxno
left outer join cm c0 on a.ptype in (0,1,4) and c0.cmno=a.itemno
left outer join book c2 on a.ptype=2 and c2.bkno=a.itemno
left outer join exam c3 on a.ptype=3 and c3.exno=a.itemno
left outer join users u on u.userno=a.userno
left outer join assign ua on ua.asno=u.asno
left outer join comcode uc on uc.ccode=u.ccposition
left outer join cmrs rs on rs.cmno=c0.cmno and rs.rstype=1 and rs.isdel=0
left outer join lect t on a.ptype in (0,1,4) and t.cmno=c0.cmno and t.payno=a.payno and t.pino=a.pino and t.userno=a.userno
where a.payno=#payno#
</select>
<select id="pay.mypayrfd" parameterClass="long" resultClass="payrfd">
select a.rfdno
from payrfd a
<dynamic prepend="where">
<isNotNull property="payno" prepend="and">a.payno=#payno#</isNotNull>
<isNotNull property="rstatus" prepend="and">a.rstatus=#rstatus#</isNotNull>
<isNotNull property="withoutrstatus" prepend="and">a.rstatus not in($withoutrstatus$)</isNotNull>
</dynamic>
</select>
<select id="pay.mypayrfdinfo" parameterClass="long" resultClass="payrfd">
select
a.rfdno,a.payno,a.rtext,a.bankname
,CAST(AES_DECRYPT(UNHEX(a.bankno), <include refid="sql.digest"></include>) AS char) bankno
,CAST(AES_DECRYPT(UNHEX(a.rphone), <include refid="sql.digest"></include>) AS char) rphone
,a.bankowner,a.isowner,a.rstatus,a.statustime,a.ramt,a.rreason,a.ruser,a.fgnor,a.fgnob,a.rback,a.cdt,a.udt,a.cno,a.uno,a.uip
from payrfd a
<dynamic prepend="where">
<isNotNull property="payno" prepend="and">a.payno=#payno#</isNotNull>
<isNotNull property="withoutrstatus" prepend="and">a.rstatus not in($withoutrstatus$)</isNotNull>
</dynamic>
order by a.cdt desc
</select>
<select id="pay.paytax.fornew" parameterClass="hashtable" resultClass="paytax">
select a.payno,a.isgroup,a.ptype,a.ispg
,ua.asname,ua.ceoname,ua.brno,ua.grno,ua.btype,ua.bkind
,am.mname manname
,CAST(AES_DECRYPT(UNHEX(am.telno), <include refid="sql.digest"></include>) AS char) telno
,CAST(AES_DECRYPT(UNHEX(am.mobile), <include refid="sql.digest"></include>) AS char) mobile
,CAST(AES_DECRYPT(UNHEX(am.email), <include refid="sql.digest"></include>) AS char) email
,sum(case when b.taxdate is not null then 0 else b.taxamt end) taxamtsum
,sum(b.taxamt) taxamt
from pay a
inner join users u on u.userno=a.userno
left outer join assign ua on ua.asno=u.asno
left outer join assignman am on am.asno=ua.asno and am.mtype=2 and am.jtype=0 and am.isdel=0
left outer join paytax b on b.payno=a.payno and (b.iscancel is null or b.iscancel &lt;&gt; 1)
where a.payno=#payno# and a.userno=#userno# and a.rstatus &lt; 2 and (a.pstatus=1 or a.pstatus=22)
group by a.payno,a.isgroup,ua.asname,ua.ceoname,ua.brno,ua.grno,ua.btype,ua.bkind,am.mname,am.telno,am.mobile,am.email
</select>
<select id="pay.paytax.fornewitem" parameterClass="hashtable" resultClass="paytax">
select a.payno,a.isgroup
,ifnull(c.taxno,0) taxno,b.pino,b.ptype,b.rstatus
,case b.ptype when 0 then c0.cname when 4 then c0.cname when 2 then c2.bkname when 3 then c3.exname else '-' end itemname
,b.pcnt,b.payamt
from pay a
inner join payitem b on b.payno=a.payno and (b.pstatus=1 or b.pstatus=22)
left outer join cm c0 on b.ptype in (0,4) and c0.cmno=b.itemno
left outer join book c2 on b.ptype=2 and c2.bkno=b.itemno
left outer join exam c3 on b.ptype=3 and c3.exno=b.itemno
left outer join paytax c4 on c4.payno = a.payno and (c4.iscancel is null or c4.iscancel &lt;&gt; 1)
left outer join paytaxitem c on c.pino=b.pino and c.taxno = c4.taxno
where a.payno=#payno# and a.userno=#userno# and a.rstatus &lt; 2 and (a.pstatus=1 or a.pstatus=22)
order by ifnull(c.taxno,0),b.pino
</select>
<insert id="pay.paytax.in" parameterClass="paytax">
insert into paytax(payno,taxamt,pcnt,asname,ceoname,brno,grno,btype,bkind,manname,telno,email,fgno,taxinfo,asaddr,isreceipt,<include refid="sql.inc"></include>)
select a.payno
,sum(b.payamt)
,sum(b.pcnt)
,#asname#,#ceoname#
,#brno#
,#grno#
,#btype#,#bkind#,#manname#
,HEX(AES_ENCRYPT(#telno#, <include refid="sql.digest"></include>))
,HEX(AES_ENCRYPT(#email#, <include refid="sql.digest"></include>))
,#fgno#,#taxinfo#,#asaddr#,#isreceipt#,<include refid="sql.inv"></include>
from pay a
inner join payitem b on b.payno=a.payno and b.pino in ($pinos$) and (a.pstatus=1 or a.pstatus=22) and a.rstatus=0
where a.payno=#payno# and a.userno=#uno# and (a.pstatus=1 or a.pstatus=22) and a.rstatus &lt; 2
group by a.payno;
<selectKey type="post" property="taxno" resultClass="long">SELECT LAST_INSERT_ID()</selectKey>
</insert>
<update id="pay.paytaxitem.in" parameterClass="paytax">
insert into paytaxitem (taxno,pino,<include refid="sql.inc"></include>)
select #taxno#,b.pino,<include refid="sql.inv"></include>
from pay a
inner join payitem b on b.payno=a.payno and b.pino in ($pinos$) and (a.pstatus=1 or a.pstatus=22) and a.rstatus=0
where a.payno=#payno# and a.userno=#uno# and (a.pstatus=1 or a.pstatus=22) and a.rstatus &lt; 2
</update>
<select id="pay.payitem.forrefund" parameterClass="hashtable" resultClass="payitem">
select distinct a.payno,b.pino,b.pstatus,b.rstatus,b.payamt,b.ptype,b.pcnt
,case b.ptype when 0 then c0.cname when 4 then c0.cname when 2 then c2.bkname when 3 then c3.exname else '-' end itemname
,case when b.ptype in (0,1,4) then
case when date_add(c0.retime, interval 1 day) &lt; now() then 1 else 0 end
else
case when b.ptype=3 then
case when date_add(c3.retime, interval 1 day) &lt; now() then 1 else 0 end
else
0
end
end ispast
,u.username
,max(d.rfdno) rfdno
,max(ifnull(case when c.rstatus=1 then -1 else c.rstatus end,-2)) rfdrstatus
from pay a
inner join payitem b on b.payno=a.payno and b.pstatus=1
left outer join users u on a.isgroup=1 and b.ptype=0 and u.userno=b.userno
left outer join cm c0 on b.ptype in (0,4) and c0.cmno=b.itemno
left outer join book c2 on b.ptype=2 and c2.bkno=b.itemno
left outer join exam c3 on b.ptype=3 and c3.exno=b.itemno
left outer join payrfditem d on d.pino=b.pino
left outer join payrfd c on c.rfdno=d.rfdno and c.payno=a.payno and c.rstatus in (0,2)
where a.payno=#payno# and a.userno=#userno# and a.pstatus=1 and a.rstatus &lt; 2
<!--and (d.rfdno is null or (d.rfdno is not null and c.rfdno is not null))-->
group by a.payno,b.pino,b.pstatus,b.rstatus,b.payamt,b.ptype,b.pcnt
,c0.cname,c2.bkname,c3.exname,c0.retime,c3.retime,u.username
order by d.rfdno,b.rstatus,ispast,b.pino
</select>
<insert id="pay.payrfd.in" parameterClass="payrfd">
delete from payrfd where payno=#payno#;
insert into payrfd(payno,rtext,bankname,bankno,bankowner,isowner,rstatus,ruser,rphone,rreason,fgnor,fgnob,ramt,<include refid="sql.inc"></include>)
select distinct #payno#,#rtext#,#bankname#
,HEX(AES_ENCRYPT(#bankno#, <include refid="sql.digest"></include>))
,#bankowner#,#isowner#,#rstatus#,#ruser#
,HEX(AES_ENCRYPT(#rphone#, <include refid="sql.digest"></include>))
,#rreason#,#fgnor#,#fgnob#,#ramt#,<include refid="sql.inv"></include>
from pay a
inner join payitem b on b.payno=a.payno and b.pino in ($pinos$) and a.pstatus=1 and a.rstatus=0
left outer join cm c0 on b.ptype in (0,4) and c0.cmno=b.itemno and ifnull(c0.retime,date_add(now(), interval 1 day)) &gt; now()
left outer join book c2 on b.ptype=2 and c2.bkno=b.itemno
left outer join exam c3 on b.ptype=3 and c3.exno=b.itemno and c3.retime &gt; now()
where a.payno=#payno# and a.userno=#uno# and a.pstatus=1 and a.rstatus &lt; 2 and (b.ptype=2 or c0.cmno is not null or c3.exno is not null);
<selectKey type="post" property="rfdno" resultClass="long">SELECT LAST_INSERT_ID()</selectKey>
</insert>
<update id="pay.payrfditem.in" parameterClass="payrfd">
insert into payrfditem (rfdno,pino,<include refid="sql.inc"></include>)
select #rfdno#,b.pino,<include refid="sql.inv"></include>
from pay a
inner join payitem b on b.payno=a.payno and b.pino in ($pinos$) and a.pstatus=1 and a.rstatus=0
left outer join cm c0 on b.ptype in (0,4) and c0.cmno=b.itemno and ifnull(c0.retime,date_add(now(), interval 1 day)) &gt; now()
left outer join book c2 on b.ptype=2 and c2.bkno=b.itemno
left outer join exam c3 on b.ptype=3 and c3.exno=b.itemno and c3.retime &gt; now()
where a.payno=#payno# and a.userno=#uno# and a.pstatus=1 and a.rstatus &lt; 2 and (b.ptype=2 or c0.cmno is not null or c3.exno is not null)
</update>
<update id="pay.payrfd.up" parameterClass="hashtable">
update payrfd
set fgnor=#fgnor#,fgnob=#fgnob#,udt=now(),uno=#uno#,uip=#uip#
where rfdno=#rfdno# and payno=#payno#
</update>
<update id="pay.payrfdcancel.up" parameterClass="hashtable">
delete from payrfditem where rfdno=#rfdno#;
update payrfd
set rstatus=#rstatus#,udt=now(),uno=#uno#,uip=#uip#
where rfdno=#rfdno# and payno=#payno#
</update>
<update id="pay.unpay" parameterClass="hashtable">
update examuser a
inner join pay b on b.payno=a.payno and b.pstatus=22 and b.ptype=3 and b.ispg=1 <!--and b.paylimit &lt; now()--> and b.isunpay is null and b.userno=a.userno
inner join payitem c on c.payno=b.payno and c.ptype=3 and c.itemno=a.exno and c.pino=a.pino
set a.pstatus=1,a.udt=now(),a.uno=#uno#,a.uip=#uip#
where a.payno=#payno# and a.pstatus=2;
update lect a
inner join pay b on b.payno=a.payno and b.pstatus=22 and b.ptype=3 and b.ispg=1 <!--and b.paylimit &lt; now()--> and b.isunpay is null
inner join payitem c on c.payno=b.payno and c.ptype in(0,4) and c.itemno=a.cmno and c.userno=a.userno and c.pino=a.pino
set a.status=1,a.udt=now(),a.uno=#uno#,a.uip=#uip#
where a.payno=#payno# and a.status=2 and a.ischanged=0;
update payitem a
inner join pay b on b.payno=a.payno and b.pstatus=22 and b.ptype=3 and b.ispg=1 <!--and b.paylimit &lt; now()--> and b.isunpay is null
set a.pstatus=1,a.udt=now(),a.uno=#uno#,a.uip=#uip#
where a.payno=#payno#;
update pay
set pstatus=1,isunpay=1,udt=now(),uno=#uno#,uip=#uip#
where payno=#payno# and pstatus=22 and ptype=3 and ispg=1 <!--and paylimit &lt; now()--> and isunpay is null;
</update>
<update id="pay.abspay" parameterClass="hashtable">
update examuser a
inner join pay b on b.payno=a.payno and b.pstatus=22 and b.ptype=3 and b.ispg=1 <!--and b.paylimit &lt; now()--> and b.isunpay is null and b.userno=a.userno
inner join payitem c on c.payno=b.payno and c.ptype=3 and c.itemno=a.exno and c.pino=a.pino
set a.pstatus=1,a.udt=now(),a.uno=#uno#,a.uip=#uip#
where a.payno=#payno# and a.pstatus=2;
update lect a
inner join pay b on b.payno=a.payno and b.pstatus=22 and b.ptype=3 and b.ispg=1 <!--and b.paylimit &lt; now()--> and b.isunpay is null
inner join payitem c on c.payno=b.payno and c.ptype in(0,4) and c.itemno=a.cmno and c.userno=a.userno and c.pino=a.pino
set a.status=1,a.udt=now(),a.uno=#uno#,a.uip=#uip#
where a.payno=#payno# and a.status=2 and a.ischanged=0;
update payitem a
inner join pay b on b.payno=a.payno and b.pstatus=22 and b.ptype=3 and b.ispg=1 <!--and b.paylimit &lt; now()--> and b.isunpay is null
set a.pstatus=1,a.udt=now(),a.uno=#uno#,a.uip=#uip#
where a.payno=#payno#;
update pay
set ptype=#ptype#,payoktime=now(),pstatus=1,isunpay=3,udt=now(),uno=#uno#,uip=#uip#
where payno=#payno# and pstatus=22 and ptype=3 and ispg=1 <!--and paylimit &lt; now()--> and isunpay is null;
</update>
<update id="pay.unpaymoney" parameterClass="hashtable">
update pay
set isunpay=2,payoktime=#payoktime#,udt=now(),uno=#uno#,uip=#uip#
where payno=#payno# and isunpay=1;
</update>
<select id="pay.pplogs" parameterClass="hashtable" resultClass="pplog">
select a.pplno,a.isready,a.cmno,a.cmisno,a.isrebate,a.rbankname,a.rbankacc,a.rbankowner,a.isaccommodation
,b.payno,b.pstatus
,a2.infee,a2.accommofee
from pplog a
inner join cm a2 on a2.cmno=a.cmno
left outer join pay b on b.pplno=a.pplno
<dynamic prepend="where">
<isNotNull property="pplno" prepend="and">a.pplno=#pplno#</isNotNull>
<isNotNull property="userno" prepend="and">a.userno=#userno#</isNotNull>
</dynamic>
</select>
<select id="pay.payresult" parameterClass="hashtable" resultClass="payitem">
select a.payno,a.payamt,a.ptype,a.pstatus
,b.itemno
from pay a
inner join payitem b on b.payno=a.payno
where a.payno=#payno# and a.userno=#userno# and a.pstatus in (1,21,22,51,55)
</select>
<select id="pay.lectready" parameterClass="int" resultClass="int">
select count(a.userno)
from lect a
where a.cmno=#cmno# and a.isready=1 and a.status=6
</select>
<select id="pay.pplogs.bypay" parameterClass="hashtable" resultClass="pplog">
select a.pplno,a.isready,a.cmno,a.cmisno,a.isrebate,a.rbankname,a.rbankacc,a.rbankowner,a.isaccommodation
,b.payno,b.pstatus
from pay b
inner join pplog a on a.pplno=b.pplno
where b.payno=#payno# and a.userno=#userno#
</select>
</statements>
</sqlMap>