"("+str(c.ancestor_id)+","+str(r[0])+",now(),"+str(c.id)+","+str(channelpromotions_id)+") on conflict(company_id) do update set points = (EXCLUDED.points + a.points) "
s="SELECT * from (SELECT * from (select '发货所得'::text as act,case contenttype_id when 19 then '收货确认' when '320' then '宴会申请' else'未知' end, "+ \
"to_char(tm,'yyyy-mm-dd HH24:MI:SS'),jsonb_array_elements(parent_points )->> 'points' as points , jsonb_array_elements(parent_points )->> 'company_fr_id'as company_fr_id from "+ \
" logistics.company_bonuspointslog where parent_points @>'[{\"company_fr_id\":"+str(
cid)+"}]' ) a where a.company_fr_id = '"+str(cid)+"' "+ \
" union SELECT '收货所得'::text as act, case contenttype_id when 19 then '收货确认' when '320' then '宴会申请' else'未知' end, "+ \
"to_char(tm,'yyyy-mm-dd HH24:MI:SS'),cast(self_points as TEXT) points,cast(company_id as TEXT) from logistics.company_bonuspointslog where company_id = "+str(
cid)+" and self_points is not null and self_points> 0 )m "+\
"left outer join (SELECT name ,id from company_company )z on z.id = m.company_fr_id::int"
sDt=" and (dt BETWEEN'"+dt_fr+"'and '"+dt_to+"') "
#查询是否有积分信息
s="SELECT b.name,b.point_ratio,a.points,a.ancestor_id FROM (select points,channelpromotions_id,ancestor_id from company_bonuspoints where company_id = "+str(comapny_id)+")A "+\
"left outer join (select id,point_ratio,name from sales_channelpromotions )B "+\
s="SELECT * from (select (select name from sales_channelpromotions where id = channelpromotions_id),case contenttype_id when 19 then '收货确认' when '320' then '宴会申请' else'未知' end, "+ \
"to_char(tm,'yyyy-mm-dd HH24:MI:SS'),jsonb_array_elements(parent_points )->> 'points' as points , jsonb_array_elements(parent_points )->> 'company_fr_id'as company_fr_id from "+ \
" logistics.company_bonuspointslog where parent_points @>'[{\"company_fr_id\":"+str(
comapny_id)+"}]' "+sDt+") a where a.company_fr_id = '"+str(comapny_id)+"' "+ \
" union SELECT (select name from sales_channelpromotions where id = channelpromotions_id),case contenttype_id when 19 then '收货确认' when '320' then '宴会申请' else'未知' end, "+ \
"to_char(tm,'yyyy-mm-dd HH24:MI:SS'),cast(self_points as TEXT) points,cast(company_id as TEXT) from logistics.company_bonuspointslog where company_id = "+str(
comapny_id)+" and self_points is not null and self_points> 0 "+sDt