use strict;

return sub
{
	my $dbh = shift;
	

	my $sth = $dbh->prepare("select s.id,o.pack_id,o.pack_title from jin_sale s inner join jin_order o on o.id=s.order_id where s.pack_id=0");
	$sth->execute;

	my $sth1 = $dbh->prepare("update jin_sale set pack_id=?,pack_title=? where id=?");

	while (my $row = $sth->fetchrow_hashref)
	{
		$sth1->execute($row->{pack_id}, $row->{pack_title}, $row->{id});
	}
	

	my $sth = $dbh->prepare(<<END_SQL);
select distinct s.id,v.step_id,st.title
from jin_funnel_visit v
inner join jin_sale s on
action='addproduct' and v.order_id!=0 and s.order_id=v.order_id and prod_id=param_id
inner join jin_funnel_step st on st.id=v.step_id
where s.funnel_step_id=0
END_SQL
	$sth->execute;

	my $sth1 = $dbh->prepare("update jin_sale set funnel_step_id=?,funnel_step_title=? where id=?");

	while (my $row = $sth->fetchrow_hashref)
	{
		$sth1->execute($row->{step_id}, $row->{title}, $row->{id});
	}
	
	return;
};
