22,209
社区成员
发帖
与我相关
我的任务
分享
Declare @CustCode nvarchar(36)
Declare @Number nvarchar(36)
Declare @BeginTime nvarchar(100)
Declare @FundPrice nvarchar(36)
Declare @InterestPrice nvarchar(36)
Declare @SumPrice nvarchar(36)
Declare @RemainPrice nvarchar(36)
Declare @FundType int
select @Numday=RefundDay,
@SendNumber=RefundMsgCount,
@Time=(select CONVERT(varchar(10) , getdate(), 20)),
@NewTime=(dateadd(day,@Numday,@Time)),
@BgTime=dateadd(hour,BgHour,@Time),
@BgTime=dateadd(minute,BgMinute,@BgTime),
@EdTime=dateadd(hour,EndHour,@Time),
@EdTime=dateadd(minute,EndMinute,@EdTime),
@CorpName = CorpName,
@DiffTime=(EndHour-BgHour)*60 + (EndMinute-BgMinute)
from Bas_Config where Id=57
DECLARE MY_CUR CURSOR FOR --声明游标
select CustCode,Number,CONVERT(varchar(100),BeginTime,23),FundPrice,InterestPrice,RemainPrice,SumPrice,FundType from Pact_Plan_List
where BeginTime between convert(varchar(100), @Time,25) and
convert(varchar(100), @NewTime,25) and PlanId not in (select PlanId from Pact_Plan_Pay) and
IsShouldPay = 1 or (IsShouldPay =0 and FundType<>0)
OPEN MY_CUR --打开游标
FETCH NEXT FROM MY_CUR --获取游标的下一行
into @CustCode,@Number,@BeginTime,@FundPrice,@InterestPrice,@RemainPrice,@SumPrice,@FundType
--@CustCode,客户编码 @Number,还款期次 @BeginTime,还款时间 @FundPrice,还款本金 @InterestPrice,还款利息 @RemainPrice,剩余本金
WHILE @@FETCH_STATUS = 0 --FETCH语句执行成功
BEGIN
declare @CustName nvarchar(16) --客户名称
declare @Mobile1 nvarchar(18)--发送手机1
declare @Mobile2 nvarchar(18)--发送手机2
declare @Mobile3 nvarchar(18)--发送手机3
declare @NoteTemCenter nvarchar(1000)--短信模板
declare @SendNoteText nvarchar(1000)--短信内容
declare @SendTime nvarchar(20)--发送时间
declare @i int
select @Mobile1=Mobile1,
@Mobile2=Mobile2,
@Mobile3=Mobile3,
@CustName=CustName
from Custom where CustCode=@CustCode
select @NoteTemCenter = NoteTemCenter from Bas_NoteTem where NoteCode='WHK'
set @SendNoteText=REPLACE(@NoteTemCenter,'###客户###',@CustName)
set @SendNoteText=REPLACE(@SendNoteText,'###公司名称###',@CorpName)
set @SendNoteText=REPLACE(@SendNoteText,'###还款日期###',@BeginTime)
set @SendNoteText=REPLACE(@SendNoteText,'###还款利息###',@InterestPrice)
set @SendNoteText=REPLACE(@SendNoteText,'###还款本金###',@FundPrice)
set @SendNoteText=REPLACE(@SendNoteText,'###本期还款###',@SumPrice)
-- 0 分期付款 1一次性付款 2按揭首付 3分期首付 4部分还款 5按揭首付分期付款 6贷垫款 7按揭首付分期付款首付款
if @FundType = 0 set @SendNoteText=REPLACE(@SendNoteText,'###还款类型###','分期付款')
if @FundType = 1 set @SendNoteText=REPLACE(@SendNoteText,'###还款类型###','次性付款')
if @FundType = 2 set @SendNoteText=REPLACE(@SendNoteText,'###还款类型###','按揭首付')
if @FundType = 3 set @SendNoteText=REPLACE(@SendNoteText,'###还款类型###','分期首付')
if @FundType = 5 set @SendNoteText=REPLACE(@SendNoteText,'###还款类型###','首付欠款')
if @FundType = 6 set @SendNoteText=REPLACE(@SendNoteText,'###还款类型###','贷垫款')
if @FundType = 7 set @SendNoteText=REPLACE(@SendNoteText,'###还款类型###','首付欠款首付款')
if @FundType = 8 set @SendNoteText=REPLACE(@SendNoteText,'###还款类型###','首付欠款利息')
set @SendTime=@BgTime
set @i=0
WHILE (@i) < @SendNumber
BEGIN
set @SendTime=(dateadd(minute,@DiffTime/@SendNumber,@SendTime))
if len(@Mobile1)=11
begin
insert into Bas_Note_Send (SendNoteMobile,SendNoteText,SendTime,IsSend)VALUES (@Mobile1,@SendNoteText,@SendTime,0)
end
if len(@Mobile2)=11
begin
insert into Bas_Note_Send (SendNoteMobile,SendNoteText,SendTime,IsSend)VALUES (@Mobile2,@SendNoteText,@SendTime,0)
end
if len(@Mobile3)=11
begin
insert into Bas_Note_Send (SendNoteMobile,SendNoteText,SendTime,IsSend)VALUES (@Mobile3,@SendNoteText,@SendTime,0)
end
set @i=@i+1
END
FETCH NEXT FROM MY_CUR --获取游标的下一行
--/*@CustCode,客户编码@Number,还款期次@BeginTime,还款时间@FundPrice,还款本金@InterestPrice,还款利息@RemainPrice*/剩余本金
into @CustCode,@Number,@BeginTime,@FundPrice,@InterestPrice,@RemainPrice,@SumPrice,@FundType
END
CLOSE MY_CUR --关闭游标
DEALLOCATE MY_CUR --释放游标