dm_channel_summary.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import time
  2. from model.DateUtils import DateUtils
  3. from model.DataBaseUtils import MysqlUtils,CkUtils
  4. du = DateUtils()
  5. db= MysqlUtils()
  6. ck = CkUtils()
  7. def dm_channel_summary():
  8. sql=""" SELECT channel,
  9. if(end>date_sub(now(),interval 10 day),'在投','停投') state,
  10. location,start,end,total_cost,total_amount,
  11. total_amount-total_cost profit,
  12. if(total_cost=0,0,total_amount/total_cost) roi,
  13. follow_user,
  14. if(follow_user=0,0,total_cost/follow_user) follow_per_cost,
  15. order_user,
  16. if(follow_user=0,0,order_user/follow_user) order_tran_rate,
  17. if(order_user=0,0,total_cost/order_user) order_tran_cost,
  18. pitcher,stage
  19. FROM
  20. (select
  21. channel,pitcher,stage,
  22. case when type ='vx' then 'MP' when type ='qq' then 'GDT' end location,
  23. min(if(cost>0,dt,null)) start,
  24. max(if(cost>0,dt,null)) end,
  25. sum(cost) total_cost,
  26. sum(order_amount) total_amount,
  27. sum(follow_user) follow_user,
  28. sum(reg_order_user) order_user
  29. from dw_daily_channel GROUP BY channel,type,pitcher,stage) a"""
  30. data=ck.execute(sql)
  31. db.quchen_text.executeMany("replace into dm_channel_summary values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",data)
  32. if __name__ == '__main__':
  33. dm_channel_summary()