Дано: Имеем три транка, все многоканальные по три линии на каждом. Есть оплаченные минуты на месяц - 3000 по городу, 150 на моб.
Задача: равномерно использовать каждый номер, подсчитывать наши оплаченные минуты и блокировать звонки через данные номер по их окончанию, перекидывать звонок на следующий номер.
Моё (моё и напарника, который разбирается в mysql): Создаём два макроса, один на город, другой на моб. Запросом в mysql делаем выборку по количеству использованных минут в каждом номере и создаём для каждого переменную, после чего присваиваем наш лимит, после которого номер должен блокироваться. Далее сравниваем переменные с минутами и находим наименьший транк. После чего происходит звонок, который ограничен нашим оставшимся лимитом. Ну, я думаю, что при просмотре макроса и так будет всё понятно. Выкладываю макрос на городские, там запрос в mysql по сложнее.
PRIME_BBCODE_SPOILER_SHOW PRIME_BBCODE_SPOILER: macros
exten => s,1,MYSQL(Connect connid localhost asterisk asterisk asteriskcdrdb)
same => n,MYSQL(Query resultid ${connid} select (SELECT coalesce(SUM(billsec),0) FROM cdr WHERE dstchannel LIKE '%1out%' and calldate BETWEEN DATE_FORMAT(NOW(),'%Y-%m-01') AND LAST_DAY(NOW()) + INTERVAL 1 DAY and LENGTH(dst)<>9)+(SELECT coalesce(SUM(billsec),0) FROM cdr WHERE dstchannel LIKE '%1out%' and calldate BETWEEN DATE_FORMAT(NOW(),'%Y-%m-01') AND LAST_DAY(NOW()) + INTERVAL 1 DAY and mid(dst,1,2) not in (39, 50, 63, 66, 67, 68, 91, 92, 93, 94, 95, 96, 97, 98, 99) and LENGTH(dst)=9) from cdr limit 1)
same => n,MYSQL(Fetch fetchid ${resultid} channal1)
same => n,MYSQL(Clear ${resultid})
same => n,MYSQL(Query resultid ${connid} select (SELECT coalesce(SUM(billsec),0) FROM cdr WHERE dstchannel LIKE '%2out%' and calldate BETWEEN DATE_FORMAT(NOW(),'%Y-%m-01') AND LAST_DAY(NOW()) + INTERVAL 1 DAY and LENGTH(dst)<>9)+(SELECT coalesce(SUM(billsec),0) FROM cdr WHERE dstchannel LIKE '%2out%' and calldate BETWEEN DATE_FORMAT(NOW(),'%Y-%m-01') AND LAST_DAY(NOW()) + INTERVAL 1 DAY and mid(dst,1,2) not in (39, 50, 63, 66, 67, 68, 91, 92, 93, 94, 95, 96, 97, 98, 99) and LENGTH(dst)=9) from cdr limit 1)
same => n,MYSQL(Fetch fetchid ${resultid} channal2)
same => n,MYSQL(Clear ${resultid})
same => n,MYSQL(Query resultid ${connid} select (SELECT coalesce(SUM(billsec),0) FROM cdr WHERE dstchannel LIKE '%3out%' and calldate BETWEEN DATE_FORMAT(NOW(),'%Y-%m-01') AND LAST_DAY(NOW()) + INTERVAL 1 DAY and LENGTH(dst)<>9)+(SELECT coalesce(SUM(billsec),0) FROM cdr WHERE dstchannel LIKE '%3out%' and calldate BETWEEN DATE_FORMAT(NOW(),'%Y-%m-01') AND LAST_DAY(NOW()) + INTERVAL 1 DAY and mid(dst,1,2) not in (39, 50, 63, 66, 67, 68, 91, 92, 93, 94, 95, 96, 97, 98, 99) and LENGTH(dst)=9) from cdr limit 1)
same => n,MYSQL(Fetch fetchid ${resultid} channal3)
same => n,MYSQL(Clear ${resultid})
same => n,MYSQL(Disconnect ${connid})
same => n,Set(porog=180000)
same => n,GotoIf($[${channal1} <= ${channal2}]?step1:step2)
same => n(step1),GotoIf($[${channal1} <= ${channal3}]?channal1:step2)
same => n(step2),GotoIf($[${channal2} <= ${channal3}]?channal2:channal3)
same => n(channal1),Set(trank=ukr_sip_1out) ;16
same => n,GotoIf($[${channal1}>${porog}]?finish)
same => n,Set(limit=$[${porog} - ${channal1}])
same => n,Goto(27)
same => n(channal2),Set(trank=ukr_sip_2out)
same => n,GotoIf($[${channal2}>${porog}]?finish)
same => n,Set(limit=$[${porog} - ${channal2}])
same => n,Goto(27)
same => n(channal3),Set(trank=ukr_sip_3out)
same => n,GotoIf($[${channal3}>${porog}]?finish)
same => n,Set(limit=$[${porog} - ${channal3}])
same => n,GotoIf($[${limit}<=600]?Playback:dial) ;27
same => n(Playback),Playback(anna)
same => n(dial),Dial(SIP/${trank}/${ARG1},,S(${limit})tTr)
same => n,GotoIf($[${DIALSTATUS}=CONGESTION]?next1)
same => n,GotoIf($[${DIALSTATUS}=BUSY]?finish)
same => n(next1),GotoIf($[${trank}=ukr_sip_1out]?channal2:next2)
same => n(next2),GotoIf($[${trank}=ukr_sip_2out]?channal3:channal1)
same => n(finish),Hangup
exten => h,1,MYSQL(Clear ${resultid})
same => n,MYSQL(Disconnect ${connid})
same => n,MYSQL(Query resultid ${connid} select (SELECT coalesce(SUM(billsec),0) FROM cdr WHERE dstchannel LIKE '%1out%' and calldate BETWEEN DATE_FORMAT(NOW(),'%Y-%m-01') AND LAST_DAY(NOW()) + INTERVAL 1 DAY and LENGTH(dst)<>9)+(SELECT coalesce(SUM(billsec),0) FROM cdr WHERE dstchannel LIKE '%1out%' and calldate BETWEEN DATE_FORMAT(NOW(),'%Y-%m-01') AND LAST_DAY(NOW()) + INTERVAL 1 DAY and mid(dst,1,2) not in (39, 50, 63, 66, 67, 68, 91, 92, 93, 94, 95, 96, 97, 98, 99) and LENGTH(dst)=9) from cdr limit 1)
same => n,MYSQL(Fetch fetchid ${resultid} channal1)
same => n,MYSQL(Clear ${resultid})
same => n,MYSQL(Query resultid ${connid} select (SELECT coalesce(SUM(billsec),0) FROM cdr WHERE dstchannel LIKE '%2out%' and calldate BETWEEN DATE_FORMAT(NOW(),'%Y-%m-01') AND LAST_DAY(NOW()) + INTERVAL 1 DAY and LENGTH(dst)<>9)+(SELECT coalesce(SUM(billsec),0) FROM cdr WHERE dstchannel LIKE '%2out%' and calldate BETWEEN DATE_FORMAT(NOW(),'%Y-%m-01') AND LAST_DAY(NOW()) + INTERVAL 1 DAY and mid(dst,1,2) not in (39, 50, 63, 66, 67, 68, 91, 92, 93, 94, 95, 96, 97, 98, 99) and LENGTH(dst)=9) from cdr limit 1)
same => n,MYSQL(Fetch fetchid ${resultid} channal2)
same => n,MYSQL(Clear ${resultid})
same => n,MYSQL(Query resultid ${connid} select (SELECT coalesce(SUM(billsec),0) FROM cdr WHERE dstchannel LIKE '%3out%' and calldate BETWEEN DATE_FORMAT(NOW(),'%Y-%m-01') AND LAST_DAY(NOW()) + INTERVAL 1 DAY and LENGTH(dst)<>9)+(SELECT coalesce(SUM(billsec),0) FROM cdr WHERE dstchannel LIKE '%3out%' and calldate BETWEEN DATE_FORMAT(NOW(),'%Y-%m-01') AND LAST_DAY(NOW()) + INTERVAL 1 DAY and mid(dst,1,2) not in (39, 50, 63, 66, 67, 68, 91, 92, 93, 94, 95, 96, 97, 98, 99) and LENGTH(dst)=9) from cdr limit 1)
same => n,MYSQL(Fetch fetchid ${resultid} channal3)
same => n,MYSQL(Clear ${resultid})
same => n,MYSQL(Disconnect ${connid})
same => n,Set(porog=180000)
same => n,GotoIf($[${channal1} <= ${channal2}]?step1:step2)
same => n(step1),GotoIf($[${channal1} <= ${channal3}]?channal1:step2)
same => n(step2),GotoIf($[${channal2} <= ${channal3}]?channal2:channal3)
same => n(channal1),Set(trank=ukr_sip_1out) ;16
same => n,GotoIf($[${channal1}>${porog}]?finish)
same => n,Set(limit=$[${porog} - ${channal1}])
same => n,Goto(27)
same => n(channal2),Set(trank=ukr_sip_2out)
same => n,GotoIf($[${channal2}>${porog}]?finish)
same => n,Set(limit=$[${porog} - ${channal2}])
same => n,Goto(27)
same => n(channal3),Set(trank=ukr_sip_3out)
same => n,GotoIf($[${channal3}>${porog}]?finish)
same => n,Set(limit=$[${porog} - ${channal3}])
same => n,GotoIf($[${limit}<=600]?Playback:dial) ;27
same => n(Playback),Playback(anna)
same => n(dial),Dial(SIP/${trank}/${ARG1},,S(${limit})tTr)
same => n,GotoIf($[${DIALSTATUS}=CONGESTION]?next1)
same => n,GotoIf($[${DIALSTATUS}=BUSY]?finish)
same => n(next1),GotoIf($[${trank}=ukr_sip_1out]?channal2:next2)
same => n(next2),GotoIf($[${trank}=ukr_sip_2out]?channal3:channal1)
same => n(finish),Hangup
exten => h,1,MYSQL(Clear ${resultid})
same => n,MYSQL(Disconnect ${connid})