Перейти к содержанию

get_price_credits_from_template

Сигнатура: get_price_credits_from_template("p_tier" "text", "p_resolution" "text", "p_ratio" "text", "p_duration" integer, "p_fps" integer DEFAULT 24) RETURNS numeric
Язык: sql
Security: DEFINER

Тело функции

declare
  usd numeric;
  credits_per_usd int;
begin
  select price_usd into usd
  from public.seedance_price_templates
  where lower(tier)=lower(p_tier)
    and lower(resolution)=lower(p_resolution)
    and ratio=p_ratio
    and fps = coalesce(p_fps,24)
    and duration = p_duration
  limit 1;

  if usd is null then
    raise exception 'PRICE_TEMPLATE_NOT_FOUND %/%/%/%', p_tier, p_resolution, p_ratio, p_duration;
  end if;

  select coalesce( (value_json->>'value')::int, 50 )
    into credits_per_usd
  from app_config
  where key='credits_per_usd';

  return round(usd * credits_per_usd, 2);  -- напр. 0.09 * 50 = 4.5
end;