ck 4 anos atrás
pai
commit
0a758c2d73
2 arquivos alterados com 114 adições e 260 exclusões
  1. 111 256
      data_manage/pitcher_panel.py
  2. 3 4
      handlers/PitcherPanelHandler.py

+ 111 - 256
data_manage/pitcher_panel.py

@@ -487,238 +487,116 @@ select toDate(formatDateTime(reg_time,'%Y-%m-%d')) dt,channel,
     return li,total
 
 def get_channel_order_trend(channel,pitcher,start,end,page,page_size,order_by,order):
-    ck = CkUtils()
-
-    channel_op =f" and channel='{channel}' " if channel!='' else ''
-    if pitcher != '赞象 admin':
-        if get_channels_from_user(pitcher).__len__() == 0:
-            pitcher_op = f"  and pitcher='{pitcher}'"
-        else:
-            pitcher_op = f" and channel in {get_channels_from_user(pitcher)}"
-
-    op1 =f" and dt>='{start}' " if start else ''
-    op2=f" and dt<='{end}' " if end else ''
-
-    sql=f"""select stage,pitcher,channel,toString(dt) date,book,
-        require_roi,require_mult,
-        toDecimal32(r1*require_mult-cost,2),
-        toDecimal32(cost,2),
-        toDecimal32(reg_order_amount,2),
-        toDecimal32(reg_order_amount-cost,2),
-        roi,new_follow_user,
-        new_follow_per_cost,order_user,order_count,
-       toDecimal32(order_user_per_cost,2),
-       concat(toString(r1),',',toString(r1/cost),',', toString(a1/cost),',',toString(b1)),
-       concat(toString(a2),',',toString(r2/cost),',', toString(a2/cost),',',toString(b2)),
- concat(toString(a3),',',toString(r3/cost),',', toString(a3/cost),',',toString(b3)),
- concat(toString(a4),',',toString(r4/cost),',', toString(a4/cost),',',toString(b4)),
- concat(toString(a5),',',toString(r5/cost),',', toString(a5/cost),',',toString(b5)),
- concat(toString(a6),',',toString(r6/cost),',', toString(a6/cost),',',toString(b6)),
- concat(toString(a7),',',toString(r7/cost),',', toString(a7/cost),',',toString(b7)),
- concat(toString(a8),',',toString(r8/cost),',', toString(a8/cost),',',toString(b8)),
- concat(toString(a9),',',toString(r9/cost),',', toString(a9/cost),',',toString(b9)),
- concat(toString(a10),',',toString(r10/cost),',', toString(a10/cost),',',toString(b10)),
- concat(toString(a11),',',toString(r11/cost),',', toString(a11/cost),',',toString(b11)),
- concat(toString(a12),',',toString(r12/cost),',', toString(a12/cost),',',toString(b12)),
- concat(toString(a13),',',toString(r13/cost),',', toString(a13/cost),',',toString(b13)),
- concat(toString(a14),',',toString(r14/cost),',', toString(a14/cost),',',toString(b14)),
- concat(toString(a15),',',toString(r15/cost),',', toString(a15/cost),',',toString(b15)),
- concat(toString(a16),',',toString(r16/cost),',', toString(a16/cost),',',toString(b16)),
- concat(toString(a17),',',toString(r17/cost),',', toString(a17/cost),',',toString(b17)),
- concat(toString(a18),',',toString(r18/cost),',', toString(a18/cost),',',toString(b18)),
- concat(toString(a19),',',toString(r19/cost),',', toString(a19/cost),',',toString(b19)),
- concat(toString(a20),',',toString(r20/cost),',', toString(a20/cost),',',toString(b20)),
- concat(toString(a21),',',toString(r21/cost),',', toString(a21/cost),',',toString(b21)),
- concat(toString(a22),',',toString(r22/cost),',', toString(a22/cost),',',toString(b22)),
- concat(toString(a23),',',toString(r23/cost),',', toString(a23/cost),',',toString(b23)),
- concat(toString(a24),',',toString(r24/cost),',', toString(a24/cost),',',toString(b24)),
- concat(toString(a25),',',toString(r25/cost),',', toString(a25/cost),',',toString(b25)),
- concat(toString(a26),',',toString(r26/cost),',', toString(a26/cost),',',toString(b26)),
- concat(toString(a27),',',toString(r27/cost),',', toString(a27/cost),',',toString(b27)),
- concat(toString(a28),',',toString(r28/cost),',', toString(a28/cost),',',toString(b28)),
- concat(toString(a29),',',toString(r29/cost),',', toString(a29/cost),',',toString(b29)),
- concat(toString(a30),',',toString(r30/cost),',', toString(a30/cost),',',toString(b30)),
- concat(toString(a31),',',toString(r31/cost),',', toString(a31/cost),',',toString(b31)),
- concat(toString(a32),',',toString(r32/cost),',', toString(a32/cost),',',toString(b32)),
- concat(toString(a33),',',toString(r33/cost),',', toString(a33/cost),',',toString(b33)),
- concat(toString(a34),',',toString(r34/cost),',', toString(a34/cost),',',toString(b34)),
- concat(toString(a35),',',toString(r35/cost),',', toString(a35/cost),',',toString(b35)),
- concat(toString(a36),',',toString(r36/cost),',', toString(a36/cost),',',toString(b36)),
- concat(toString(a37),',',toString(r37/cost),',', toString(a37/cost),',',toString(b37)),
- concat(toString(a38),',',toString(r38/cost),',', toString(a38/cost),',',toString(b38)),
- concat(toString(a39),',',toString(r39/cost),',', toString(a39/cost),',',toString(b39)),
- concat(toString(a40),',',toString(r40/cost),',', toString(a40/cost),',',toString(b40)),
- concat(toString(a41),',',toString(r41/cost),',', toString(a41/cost),',',toString(b41)),
- concat(toString(a42),',',toString(r42/cost),',', toString(a42/cost),',',toString(b42)),
- concat(toString(a43),',',toString(r43/cost),',', toString(a43/cost),',',toString(b43)),
- concat(toString(a44),',',toString(r44/cost),',', toString(a44/cost),',',toString(b44)),
- concat(toString(a45),',',toString(r45/cost),',', toString(a45/cost),',',toString(b45)),
- concat(toString(a46),',',toString(r46/cost),',', toString(a46/cost),',',toString(b46)),
- concat(toString(a47),',',toString(r47/cost),',', toString(a47/cost),',',toString(b47)),
- concat(toString(a48),',',toString(r48/cost),',', toString(a48/cost),',',toString(b48)),
- concat(toString(a49),',',toString(r49/cost),',', toString(a49/cost),',',toString(b49)),
- concat(toString(a50),',',toString(r50/cost),',', toString(a50/cost),',',toString(b50)),
- concat(toString(a51),',',toString(r51/cost),',', toString(a51/cost),',',toString(b51)),
- concat(toString(a52),',',toString(r52/cost),',', toString(a52/cost),',',toString(b52)),
- concat(toString(a53),',',toString(r53/cost),',', toString(a53/cost),',',toString(b53)),
- concat(toString(a54),',',toString(r54/cost),',', toString(a54/cost),',',toString(b54)),
- concat(toString(a55),',',toString(r55/cost),',', toString(a55/cost),',',toString(b55)),
- concat(toString(a56),',',toString(r56/cost),',', toString(a56/cost),',',toString(b56)),
- concat(toString(a57),',',toString(r57/cost),',', toString(a57/cost),',',toString(b57)),
- concat(toString(a58),',',toString(r58/cost),',', toString(a58/cost),',',toString(b58)),
- concat(toString(a59),',',toString(r59/cost),',', toString(a59/cost),',',toString(b59)),
- concat(toString(a60),',',toString(r60/cost),',', toString(a60/cost),',',toString(b60)),
- concat(toString(a90),',',toString(r90/cost),',', toString(a90/cost),',',toString(b90)),
-concat(toString(a120),',',toString(r120/cost),',', toString(a120/cost),',',toString(b120)),
-concat(toString(a150),',',toString(r150/cost),',', toString(a150/cost),',',toString(b150))
-from
-              (
-select pitcher,channel,dt,book,cost,reg_order_amount,stage,
-       ifnull(require_roi,0) require_roi,ifnull(require_mult,0) require_mult,
-       if(cost=0,0,reg_order_amount/cost) roi,
-       follow_user new_follow_user,
-       if(follow_user=0,0,cost/follow_user) new_follow_per_cost,
-       reg_order_user order_user, reg_order_count order_count,
-       if(reg_order_user=0,0,cost/reg_order_user) order_user_per_cost
-       from dw_daily_channel where 1=1 {op1} {op2} {channel_op} {pitcher_op}  and cost>0) a
+    db=MysqlUtils()
+    if pitcher:
+        op1 = f" and pitcher='{pitcher}'" if get_channels_from_user(
+            pitcher).__len__() == 0 else f" and channel in {get_channels_from_user(pitcher)}"
+    else:
+        op1 = ''
+    op2 = f" and channel='{channel}'" if channel else ''
+    op3 = f" and dt>='{start}' " if start else ''
+    op4 = f" and dt<='{end}' " if end else ''
+    op5 = f" order by {order_by} {order}" if order_by and order else ''
 
-left outer join (
-select toDate(formatDateTime(reg_time,'%Y-%m-%d')) dt,channel,
-       sum(if(toDate(formatDateTime(reg_time,'%Y-%m-%d'))=date,amount,0)) as r1,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),1)>=date,amount,0)) as r2,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),2)>=date,amount,0)) as r3,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),3)>=date,amount,0)) as r4,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),4)>=date,amount,0)) as r5,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),5)>=date,amount,0)) as r6,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),6)>=date,amount,0)) as r7,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),7)>=date,amount,0)) as r8,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),8)>=date,amount,0)) as r9,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),9)>=date,amount,0)) as r10,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),10)>=date,amount,0)) as r11,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),11)>=date,amount,0)) as r12,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),12)>=date,amount,0)) as r13,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),13)>=date,amount,0)) as r14,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),14)>=date,amount,0)) as r15,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),15)>=date,amount,0)) as r16,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),16)>=date,amount,0)) as r17,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),17)>=date,amount,0)) as r18,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),18)>=date,amount,0)) as r19,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),19)>=date,amount,0)) as r20,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),20)>=date,amount,0)) as r21,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),21)>=date,amount,0)) as r22,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),22)>=date,amount,0)) as r23,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),23)>=date,amount,0)) as r24,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),24)>=date,amount,0)) as r25,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),25)>=date,amount,0)) as r26,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),26)>=date,amount,0)) as r27,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),27)>=date,amount,0)) as r28,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),28)>=date,amount,0)) as r29,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),29)>=date,amount,0)) as r30,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),30)>=date,amount,0)) as r31,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),31)>=date,amount,0)) as r32,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),32)>=date,amount,0)) as r33,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),33)>=date,amount,0)) as r34,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),34)>=date,amount,0)) as r35,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),35)>=date,amount,0)) as r36,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),36)>=date,amount,0)) as r37,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),37)>=date,amount,0)) as r38,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),38)>=date,amount,0)) as r39,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),39)>=date,amount,0)) as r40,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),40)>=date,amount,0)) as r41,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),41)>=date,amount,0)) as r42,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),42)>=date,amount,0)) as r43,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),43)>=date,amount,0)) as r44,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),44)>=date,amount,0)) as r45,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),45)>=date,amount,0)) as r46,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),46)>=date,amount,0)) as r47,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),47)>=date,amount,0)) as r48,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),48)>=date,amount,0)) as r49,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),49)>=date,amount,0)) as r50,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),50)>=date,amount,0)) as r51,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),51)>=date,amount,0)) as r52,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),52)>=date,amount,0)) as r53,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),53)>=date,amount,0)) as r54,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),54)>=date,amount,0)) as r55,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),55)>=date,amount,0)) as r56,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),56)>=date,amount,0)) as r57,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),57)>=date,amount,0)) as r58,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),58)>=date,amount,0)) as r59,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),59)>=date,amount,0)) as r60,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),89)>=date,amount,0)) as r90,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),119)>=date,amount,0)) as r120,
-       sum(if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),149)>=date,amount,0)) as r150,
-       0 a1,1 b1,
-       r2-r1 a2,if(r1=0,0,r2/r1) b2,
-r3-r2 a3,if(r1=0,0,r3/r1) b3,
-r4-r3 a4,if(r1=0,0,r4/r1) b4,
-r5-r4 a5,if(r1=0,0,r5/r1) b5,
-r6-r5 a6,if(r1=0,0,r6/r1) b6,
-r7-r6 a7,if(r1=0,0,r7/r1) b7,
-r8-r7 a8,if(r1=0,0,r8/r1) b8,
-r9-r8 a9,if(r1=0,0,r9/r1) b9,
-r10-r9 a10,if(r1=0,0,r10/r1) b10,
-r11-r10 a11,if(r1=0,0,r11/r1) b11,
-r12-r11 a12,if(r1=0,0,r12/r1) b12,
-r13-r12 a13,if(r1=0,0,r13/r1) b13,
-r14-r13 a14,if(r1=0,0,r14/r1) b14,
-r15-r14 a15,if(r1=0,0,r15/r1) b15,
-r16-r15 a16,if(r1=0,0,r16/r1) b16,
-r17-r16 a17,if(r1=0,0,r17/r1) b17,
-r18-r17 a18,if(r1=0,0,r18/r1) b18,
-r19-r18 a19,if(r1=0,0,r19/r1) b19,
-r20-r19 a20,if(r1=0,0,r20/r1) b20,
-r21-r20 a21,if(r1=0,0,r21/r1) b21,
-r22-r21 a22,if(r1=0,0,r22/r1) b22,
-r23-r22 a23,if(r1=0,0,r23/r1) b23,
-r24-r23 a24,if(r1=0,0,r24/r1) b24,
-r25-r24 a25,if(r1=0,0,r25/r1) b25,
-r26-r25 a26,if(r1=0,0,r26/r1) b26,
-r27-r26 a27,if(r1=0,0,r27/r1) b27,
-r28-r27 a28,if(r1=0,0,r28/r1) b28,
-r29-r28 a29,if(r1=0,0,r29/r1) b29,
-r30-r29 a30,if(r1=0,0,r30/r1) b30,
-r31-r30 a31,if(r1=0,0,r31/r1) b31,
-r32-r31 a32,if(r1=0,0,r32/r1) b32,
-r33-r32 a33,if(r1=0,0,r33/r1) b33,
-r34-r33 a34,if(r1=0,0,r34/r1) b34,
-r35-r34 a35,if(r1=0,0,r35/r1) b35,
-r36-r35 a36,if(r1=0,0,r36/r1) b36,
-r37-r36 a37,if(r1=0,0,r37/r1) b37,
-r38-r37 a38,if(r1=0,0,r38/r1) b38,
-r39-r38 a39,if(r1=0,0,r39/r1) b39,
-r40-r39 a40,if(r1=0,0,r40/r1) b40,
-r41-r40 a41,if(r1=0,0,r41/r1) b41,
-r42-r41 a42,if(r1=0,0,r42/r1) b42,
-r43-r42 a43,if(r1=0,0,r43/r1) b43,
-r44-r43 a44,if(r1=0,0,r44/r1) b44,
-r45-r44 a45,if(r1=0,0,r45/r1) b45,
-r46-r45 a46,if(r1=0,0,r46/r1) b46,
-r47-r46 a47,if(r1=0,0,r47/r1) b47,
-r48-r47 a48,if(r1=0,0,r48/r1) b48,
-r49-r48 a49,if(r1=0,0,r49/r1) b49,
-r50-r49 a50,if(r1=0,0,r50/r1) b50,
-r51-r50 a51,if(r1=0,0,r51/r1) b51,
-r52-r51 a52,if(r1=0,0,r52/r1) b52,
-r53-r52 a53,if(r1=0,0,r53/r1) b53,
-r54-r53 a54,if(r1=0,0,r54/r1) b54,
-r55-r54 a55,if(r1=0,0,r55/r1) b55,
-r56-r55 a56,if(r1=0,0,r56/r1) b56,
-r57-r56 a57,if(r1=0,0,r57/r1) b57,
-r58-r57 a58,if(r1=0,0,r58/r1) b58,
-r59-r58 a59,if(r1=0,0,r59/r1) b59,
-r60-r59 a60,if(r1=0,0,r60/r1) b60,
-r90-r60 a90,if(r1=0,0,r90/r1) b90,
-r120-r90 a120,if(r1=0,0,r120/r1) b120,
-r150-r120 a150,if(r1=0,0,r150/r1) b150
-from order where 1=1 {op1} {channel_op}  group by formatDateTime(reg_time,'%Y-%m-%d'),channel
-    ) b on a.dt=b.dt and a.channel=b.channel
+    sql=f"""select stage,pitcher,a.channel,a.dt date,book,
+        0 require_roi,0 require_mult,
+--         round(r1*require_mult-cost,2) expect_profit,
+        0 expect_profit,
+        cost,
+        first_order_amount first_amount,
+        reg_order_amount reg_amount,
+        reg_order_amount-cost profit,
+        follow_user new_follow_user,
+        round(reg_order_amount/cost,4) roi,
+        round(first_order_amount/cost) first_roi,
+        round(cost/follow_user,2) new_follow_per_cost,
+        reg_order_user order_user,
+       reg_order_count order_count,
+       round(cost/reg_order_user ,2) order_user_per_cost,
+       concat(da1,',',da1/cost,',', 0,',',1) d1,
+       concat(da2-da1,',',da2/cost,',', (da2-da1)/cost,',',da2/da1) d2,
+       concat(da3-da2,',',da3/cost,',', (da3-da2)/cost,',',da3/da1) d3,
+       concat(da4-da3,',',da4/cost,',', (da4-da3)/cost,',',da4/da1) d4,
+       concat(da5-da4,',',da5/cost,',', (da5-da4)/cost,',',da5/da1) d5,
+       concat(da6-da5,',',da6/cost,',', (da6-da5)/cost,',',da6/da1) d6,
+       concat(da7-da6,',',da7/cost,',', (da7-da6)/cost,',',da7/da1) d7,
+       concat(da8-da7,',',da8/cost,',', (da8-da7)/cost,',',da8/da1) d8,
+       concat(da9-da8,',',da9/cost,',', (da9-da8)/cost,',',da9/da1) d9,
+concat(da10-da9 ,',' ,da10/cost ,',', (da10-da9)/cost ,',' ,da10/da1) d10,
+concat(da11-da10 ,',' ,da11/cost ,',', (da11-da10)/cost ,',' ,da11/da1) d11,
+concat(da12-da11 ,',' ,da12/cost ,',', (da12-da11)/cost ,',' ,da12/da1) d12,
+concat(da13-da12 ,',' ,da13/cost ,',', (da13-da12)/cost ,',' ,da13/da1) d13,
+concat(da14-da13 ,',' ,da14/cost ,',', (da14-da13)/cost ,',' ,da14/da1) d14,
+concat(da15-da14 ,',' ,da15/cost ,',', (da15-da14)/cost ,',' ,da15/da1) d15,
+concat(da16-da15 ,',' ,da16/cost ,',', (da16-da15)/cost ,',' ,da16/da1) d16,
+concat(da17-da16 ,',' ,da17/cost ,',', (da17-da16)/cost ,',' ,da17/da1) d17,
+concat(da18-da17 ,',' ,da18/cost ,',', (da18-da17)/cost ,',' ,da18/da1) d18,
+concat(da19-da18 ,',' ,da19/cost ,',', (da19-da18)/cost ,',' ,da19/da1) d19,
+concat(da20-da19 ,',' ,da20/cost ,',', (da20-da19)/cost ,',' ,da20/da1) d20,
+concat(da21-da20 ,',' ,da21/cost ,',', (da21-da20)/cost ,',' ,da21/da1) d21,
+concat(da22-da21 ,',' ,da22/cost ,',', (da22-da21)/cost ,',' ,da22/da1) d22,
+concat(da23-da22 ,',' ,da23/cost ,',', (da23-da22)/cost ,',' ,da23/da1) d23,
+concat(da24-da23 ,',' ,da24/cost ,',', (da24-da23)/cost ,',' ,da24/da1) d24,
+concat(da25-da24 ,',' ,da25/cost ,',', (da25-da24)/cost ,',' ,da25/da1) d25,
+concat(da26-da25 ,',' ,da26/cost ,',', (da26-da25)/cost ,',' ,da26/da1) d26,
+concat(da27-da26 ,',' ,da27/cost ,',', (da27-da26)/cost ,',' ,da27/da1) d27,
+concat(da28-da27 ,',' ,da28/cost ,',', (da28-da27)/cost ,',' ,da28/da1) d28,
+concat(da29-da28 ,',' ,da29/cost ,',', (da29-da28)/cost ,',' ,da29/da1) d29,
+concat(da30-da29 ,',' ,da30/cost ,',', (da30-da29)/cost ,',' ,da30/da1) d30,
+concat(da31-da30 ,',' ,da31/cost ,',', (da31-da30)/cost ,',' ,da31/da1) d31,
+concat(da32-da31 ,',' ,da32/cost ,',', (da32-da31)/cost ,',' ,da32/da1) d32,
+concat(da33-da32 ,',' ,da33/cost ,',', (da33-da32)/cost ,',' ,da33/da1) d33,
+concat(da34-da33 ,',' ,da34/cost ,',', (da34-da33)/cost ,',' ,da34/da1) d34,
+concat(da35-da34 ,',' ,da35/cost ,',', (da35-da34)/cost ,',' ,da35/da1) d35,
+concat(da36-da35 ,',' ,da36/cost ,',', (da36-da35)/cost ,',' ,da36/da1) d36,
+concat(da37-da36 ,',' ,da37/cost ,',', (da37-da36)/cost ,',' ,da37/da1) d37,
+concat(da38-da37 ,',' ,da38/cost ,',', (da38-da37)/cost ,',' ,da38/da1) d38,
+concat(da39-da38 ,',' ,da39/cost ,',', (da39-da38)/cost ,',' ,da39/da1) d39,
+concat(da40-da39 ,',' ,da40/cost ,',', (da40-da39)/cost ,',' ,da40/da1) d40,
+concat(da41-da40 ,',' ,da41/cost ,',', (da41-da40)/cost ,',' ,da41/da1) d41,
+concat(da42-da41 ,',' ,da42/cost ,',', (da42-da41)/cost ,',' ,da42/da1) d42,
+concat(da43-da42 ,',' ,da43/cost ,',', (da43-da42)/cost ,',' ,da43/da1) d43,
+concat(da44-da43 ,',' ,da44/cost ,',', (da44-da43)/cost ,',' ,da44/da1) d44,
+concat(da45-da44 ,',' ,da45/cost ,',', (da45-da44)/cost ,',' ,da45/da1) d45,
+concat(da46-da45 ,',' ,da46/cost ,',', (da46-da45)/cost ,',' ,da46/da1) d46,
+concat(da47-da46 ,',' ,da47/cost ,',', (da47-da46)/cost ,',' ,da47/da1) d47,
+concat(da48-da47 ,',' ,da48/cost ,',', (da48-da47)/cost ,',' ,da48/da1) d48,
+concat(da49-da48 ,',' ,da49/cost ,',', (da49-da48)/cost ,',' ,da49/da1) d49,
+concat(da50-da49 ,',' ,da50/cost ,',', (da50-da49)/cost ,',' ,da50/da1) d50,
+concat(da51-da50 ,',' ,da51/cost ,',', (da51-da50)/cost ,',' ,da51/da1) d51,
+concat(da52-da51 ,',' ,da52/cost ,',', (da52-da51)/cost ,',' ,da52/da1) d52,
+concat(da53-da52 ,',' ,da53/cost ,',', (da53-da52)/cost ,',' ,da53/da1) d53,
+concat(da54-da53 ,',' ,da54/cost ,',', (da54-da53)/cost ,',' ,da54/da1) d54,
+concat(da55-da54 ,',' ,da55/cost ,',', (da55-da54)/cost ,',' ,da55/da1) d55,
+concat(da56-da55 ,',' ,da56/cost ,',', (da56-da55)/cost ,',' ,da56/da1) d56,
+concat(da57-da56 ,',' ,da57/cost ,',', (da57-da56)/cost ,',' ,da57/da1) d57,
+concat(da58-da57 ,',' ,da58/cost ,',', (da58-da57)/cost ,',' ,da58/da1) d58,
+concat(da59-da58 ,',' ,da59/cost ,',', (da59-da58)/cost ,',' ,da59/da1) d59,
+concat(da60-da59 ,',' ,da60/cost ,',', (da60-da59)/cost ,',' ,da60/da1) d60,
+concat(dm3-da60 ,',' ,dm3/cost ,',', (dm3-da60)/cost ,',' ,dm3/da1) m3,
+concat(dm4-dm3 ,',' ,dm4/cost ,',', (dm4-dm3)/cost ,',' ,dm4/da1) m4,
+concat(dm5-dm4 ,',' ,dm5/cost ,',', (dm5-dm4)/cost ,',' ,dm5/da1) m5 
+from ( select * from  dw_channel where 1=1 {op1} {op2} {op3} {op4}  {op5}) a
+left join  dw_channel_amount_daily b on a.channel=b.channel and a.dt=b.dt
 """
 
-    total = ck.execute(f"select count(1) from ({sql}) a")[0][0]
-    sql += f" order by {order_by} {order} limit {(page-1)*page_size},{page_size} "
+    sumsql=f"""select '总计' date,
+               sum(cost) cost,
+               sum(reg_amount)  reg_amount,
+               sum(first_amount)  first_amount,
+                sum(profit) profit,
+               sum(new_follow_user) new_follow_user,
+                sum(reg_amount)/sum(cost) roi,
+                sum(first_amount)/sum(cost) first_roi,
+                sum(cost)/sum(new_follow_user) new_follow_per_cost,
+                sum(order_user) order_user,
+                sum(order_count) order_count,
+                sum(cost)/sum(order_count) order_user_per_cost,
+                sum(expect_profit) expect_profit
+                from ({sql}) a
+                """
+    data,total,total_data=getLimitSumData(db.dm,sql,sumsql,page,page_size)
 
-    data=get_round(ck.execute(sql))
-    # print(data)
     def parse(str):
         li=str.split(',')
         li[0]=round(float(li[0]),2)
@@ -728,36 +606,13 @@ from order where 1=1 {op1} {channel_op}  group by formatDateTime(reg_time,'%Y-%m
         return dict(zip(['order','roi','add','mult'],li))
 
     for i in data:
-        for x,y in enumerate(i):
-            if x>=17:
-                i[x]=parse(y)
-    print(data)
-    key=['stage','pitcher','channel','date','book','require_roi','require_mult','expect_profit','cost','reg_amount','profit','roi','new_follow_user','new_follow_per_cost','order_user','order_count',
-         'order_user_per_cost','d1','d2','d3','d4','d5','d6','d7','d8','d9','d10','d11','d12','d13','d14','d15','d16','d17','d18',
+        for x in i:
+            if x 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','d31','d32','d33','d34','d35','d36','d37','d38',
          'd39','d40','d41','d42','d43','d44','d45','d46','d47','d48','d49','d50','d51','d52','d53','d54','d55','d56','d57','d58','d59',
-         'd60','m3','m4','m5']
-    data=get_dict_list(key,data)
-
-    cost=reg_amount=roi=new_follow_user=new_follow_per_cost=order_user=order_count=order_user_per_cost=profit=expect_profit=0
-    for i in data:
-        cost+= i['cost']
-        reg_amount+=i['reg_amount']
-        profit+=i['profit']
-        roi+=i['roi']
-        new_follow_user+=i['new_follow_user']
-        new_follow_per_cost+=i['new_follow_per_cost']
-        order_user+=i['order_user']
-        order_count+=i['order_count']
-        order_user_per_cost+=i['order_user_per_cost']
-        expect_profit+=i['expect_profit']
-    count= len(data)
-    if count==0:
-        return [],0,{}
-    total_data={'cost':round(cost,2),'reg_amount':round(reg_amount,2),'profit':round(profit,2),'expect_profit':round(expect_profit,2),'roi':round(reg_amount/cost,4), 'new_follow_user':new_follow_user,
-        'new_follow_per_cost':round(new_follow_per_cost/count,2),'order_user':order_user,'order_count':order_count,
-        'order_user_per_cost':round(order_user_per_cost/count,2),'channel':'-','date':'总计','book':'-'
-        }
+         'd60','m3','m4','m5']:
+                i[x]=parse(i[x]) if i[x] is not None else {}
+    print(data)
 
     return data,total,total_data
 

+ 3 - 4
handlers/PitcherPanelHandler.py

@@ -105,13 +105,13 @@ class ChannelOrderTrend(BaseHandler):
     def post(self):
         arg = self.get_args()
         print(arg)
-        pitcher=arg.get("pitcher",'')
-        channel = arg.get("channel", '')
+        pitcher=arg.get("pitcher")
+        channel = arg.get("channel")
         start = arg.get("start")
         end = arg.get("end")
         page = arg.get("page", 1)
         page_size = arg.get("page_size", 10)
-        order_by = arg.get("order_by", 'date')
+        order_by = arg.get("order_by", 'dt')
         order = arg.get("order", 'desc')
         if 'date_range' in list(arg.keys()):
             end = self.get_n_days(0)
@@ -119,7 +119,6 @@ class ChannelOrderTrend(BaseHandler):
         data,total,total_data=get_channel_order_trend(channel,pitcher,start,end,page,page_size,order_by,order)
         self.write_json(data=data,total=total,total_data=total_data)
 
-
 class ChannelSummary(BaseHandler):
     def post(self):
         arg = self.get_args()