ck 4 years ago
parent
commit
d4bd1d7407
3 changed files with 100 additions and 8 deletions
  1. 80 8
      data_manage/pitcher_panel.py
  2. 19 0
      handlers/PitcherPanelHandler.py
  3. 1 0
      urls.py

+ 80 - 8
data_manage/pitcher_panel.py

@@ -739,14 +739,86 @@ def get_channel_summary(channel,pitcher,page,page_size,order_by,order,state,loca
     return getLimitData(db.quchen_text,sql,page,page_size)
 
 
+def get_pitcher_trend(pitcher,start=None,end=None,page=None,page_size=None,order_by=None,order=None):
+
+    db=MysqlUtils()
+
+    op1=f" and pitcher='{pitcher}'"
+    op2 = f" and dt>='{start}' " if start else ''
+    op3 = f" and dt<='{end}' " if end else ''
+    op4 = f" order by {order_by} {order}" if order_by and order else ''
+
+    sql=f"""select dt,pitcher,
+            cost,
+            reg_amount,
+            round(reg_amount/cost,4) roi,
+            round(d7/cost,4) roi7,
+            d30 reg_amount30,
+            round(d30/cost,4) roi30,
+            total_cost cost_total, 
+            total_amount amount_total,
+            total_amount-total_cost profit_total,
+            round(total_amount/total_cost,4) roi_total,
+            CONCAT(d1,",",0,',',round(d1/cost,4)) d1,
+            CONCAT(d2-d1,",",round((d2-d1)/cost,4),',',round(d2/cost,4)) d2,
+            CONCAT(d3-d2,",",round((d3-d2)/cost,4),',',round(d3/cost,4)) d3,
+            CONCAT(d4-d3,",",round((d4-d3)/cost,4),',',round(d4/cost,4)) d4,
+            CONCAT(d5-d4,",",round((d5-d4)/cost,4),',',round(d5/cost,4)) d5,
+            CONCAT(d6-d5,",",round((d6-d5)/cost,4),',',round(d6/cost,4)) d6,
+            CONCAT(d7-d6,",",round((d7-d6)/cost,4),',',round(d7/cost,4)) d7,
+            CONCAT(d8-d7,",",round((d8-d7)/cost,4),',',round(d8/cost,4)) d8,
+            CONCAT(d9-d8,",",round((d9-d8)/cost,4),',',round(d9/cost,4)) d9,
+            CONCAT(d10-d9,",",round((d10-d9)/cost,4),',',round(d10/cost,4)) d10,
+            CONCAT(d11-d10,",",round((d11-d10)/cost,4),',',round(d11/cost,4)) d11,
+            CONCAT(d12-d11,",",round((d12-d11)/cost,4),',',round(d12/cost,4)) d12,
+            CONCAT(d13-d12,",",round((d13-d12)/cost,4),',',round(d13/cost,4)) d13,
+            CONCAT(d14-d13,",",round((d14-d13)/cost,4),',',round(d14/cost,4)) d14,
+            CONCAT(d15-d14,",",round((d15-d14)/cost,4),',',round(d15/cost,4)) d15,
+            CONCAT(d16-d15,",",round((d16-d15)/cost,4),',',round(d16/cost,4)) d16,
+            CONCAT(d17-d16,",",round((d17-d16)/cost,4),',',round(d17/cost,4)) d17,
+            CONCAT(d18-d17,",",round((d18-d17)/cost,4),',',round(d18/cost,4)) d18,
+            CONCAT(d19-d18,",",round((d19-d18)/cost,4),',',round(d19/cost,4)) d19,
+            CONCAT(d20-d19,",",round((d20-d19)/cost,4),',',round(d20/cost,4)) d20,
+            CONCAT(d21-d20,",",round((d21-d20)/cost,4),',',round(d21/cost,4)) d21,
+            CONCAT(d22-d21,",",round((d22-d21)/cost,4),',',round(d22/cost,4)) d22,
+            CONCAT(d23-d22,",",round((d23-d22)/cost,4),',',round(d23/cost,4)) d23,
+            CONCAT(d24-d23,",",round((d24-d23)/cost,4),',',round(d24/cost,4)) d24,
+            CONCAT(d25-d24,",",round((d25-d24)/cost,4),',',round(d25/cost,4)) d25,
+            CONCAT(d26-d25,",",round((d26-d25)/cost,4),',',round(d26/cost,4)) d26,
+            CONCAT(d27-d26,",",round((d27-d26)/cost,4),',',round(d27/cost,4)) d27,
+            CONCAT(d28-d27,",",round((d28-d27)/cost,4),',',round(d28/cost,4)) d28,
+            CONCAT(d29-d28,",",round((d29-d28)/cost,4),',',round(d29/cost,4)) d29,
+            CONCAT(d30-d29,",",round((d30-d29)/cost,4),',',round(d30/cost,4)) d30 
+            from dw_pitcher_trend  where 1=1 {op1} {op2} {op3} {op4}
+            """
+
+    sumSql=f"""select '总计' dt,sum(cost) cost,
+    sum(reg_amount) reg_amount,
+    round(sum(reg_amount)/sum(cost),4) roi,
+    round(sum(d7)/sum(cost),4) roi7,
+    sum(reg_amount30) reg_amount30, 
+    round(sum(d30)/sum(cost),4) roi30 
+    from ({sql}) a
+    """
+
+    data,total=getLimitSumData(db.quchen_text,sql,sumSql,page,page_size)
+
+    def parse(str):
+        li=str.split(',')
+        li[0]=round(float(li[0]),2)
+        li[1]=round(float(li[1]),4)
+        li[2]=round(float(li[2]),4)
+        return dict(zip(['amount','add','roi'],li))
+
+    for i in data:
+        for k,v in i.items():
+            if k in ['d1','d2','d3','d4','d5','d6','d7','d8','d9','d10',
+         'd11','d12','d13','d14','d15','d16','d17','d18','d19','d20','d21','d22','d23','d24','d25','d26','d27','d28','d29','d30']:
+                i[k]= parse(v)
+
+    return data,total
+
 
 if __name__ == '__main__':
-    # a=get_channel_overview('','','',1,10,'date','desc')
-    # a=get_channel_summary('','')
-    # a=get_channel_again_order_trend('龙鳞文学','2021-01-01','宋刚')
-    # a=get_channel_active('玉龙书社','2020-09-15','2020-09-20',1,10,'date','desc')
-    # a,b =get_channel_order_trend("玉龙书社",'王俊杰','2020-12-01','2020-12-12',1,5,'date','desc')
-    # print(a)
-
-    get_channels_from_user('叶静')
+    get_pitcher_trend(pitcher="陈凯")
 

+ 19 - 0
handlers/PitcherPanelHandler.py

@@ -136,6 +136,25 @@ class ChannelSummary(BaseHandler):
         self.write_json(data=data,total=total)
 
 
+class PitcherTrend(BaseHandler):
+    def post(self):
+        arg = self.get_args()
+        print(arg)
+        pitcher=arg.get('pitcher')
+        start=arg.get("start")
+        end=arg.get("end")
+        date_range=arg.get("date_range")
+        page = arg.get("page")
+        page_size = arg.get("page_size")
+        order_by = arg.get("order_by", 'total_cost')
+        order = arg.get("order", 'desc')
+        if date_range:
+            start=du.get_n_days(0)
+            end=du.get_n_days(-int(date_range)+1)
+        data,total=get_pitcher_trend(pitcher,start,end,page,page_size,order_by,order)
+        self.write_json(data=data,total=total)
+
+
 
 
 

+ 1 - 0
urls.py

@@ -12,6 +12,7 @@ urls = [
     (r'/data/channel_stat/active',ChannelActive), # 公众号激活数据
     (r'/data/channel_stat/order_trend',ChannelOrderTrend),  # 公众号趋势
     (r'/data/channel_stat/channel',ChannelSummary), # 公众号总数据
+    (r'/data/pitcher/trend',PitcherTrend), # 投手个人付费趋势
 
     # 外部接口
     (r'/api/get_yangguang_data', YgApiHandler),  # 阳光订单回调接口