首页 > 其他 > 详细

销售统计功能

时间:2018-11-20 22:31:42      阅读:30      评论:0      收藏:0      [点我收藏+]

标签:list   quest   以及   sel   request   spa   contex   elf   cts   

 1 class TongJiView(View):
 2 
 3     def get(self,request):
 4 
 5         date = request.GET.get("date","today")
 6         if hasattr(self,date):
 7             context = getattr(self,date)()
 8 
 9         return render(request,"customer/tongji.html",context)
10 
11     def today(self):
12         today = datetime.datetime.now().date()
13         customer_list = Customer.objects.filter(deal_date=today)
14 
15         # 查询每一个销售的名字以及今天对应的成单量
16         ret = UserInfo.objects.filter(depart_id=2,customers__deal_date=today).annotate(c=Count("customers")).values_list("username","c")
17         ret = [[item[0], item[1]] for item in ret]
18         return {"customer_list":customer_list,"ret":ret,"today":today}
19 
20     def zuotian(self):
21         today = datetime.datetime.now().date()
22         zuotian = datetime.datetime.now().date() - datetime.timedelta(days=1)
23         customer_list = Customer.objects.filter(deal_date=zuotian)
24 
25         # 查询每一个销售的名字以及昨天对应的成单量
26         ret = UserInfo.objects.filter(
27             depart_id=2,customers__deal_date=zuotian).annotate(c=Count("customers")).values_list("username","c")
28         ret = [[item[0], item[1]] for item in ret]
29         return {"customer_list":customer_list,"ret":ret,"today":today}
30 
31     def week(self):
32         today = datetime.datetime.now().date()
33         week = datetime.datetime.now().date() - datetime.timedelta(weeks=1)
34         customer_list = Customer.objects.filter(deal_date__gte=week,deal_date__lte=today)
35 
36         # 查询每一个销售的名字以及一周对应的成单量
37         ret = UserInfo.objects.filter(depart_id=2,customers__deal_date__gte=week,
38                                       customers__deal_date__lte=today).annotate(c=Count("customers")).values_list("username",
39                                                                                                              "c")
40         ret = [[item[0], item[1]] for item in ret]
41         return {"customer_list":customer_list,"ret":ret,"today":today}
42 
43     def month(self):
44         today = datetime.datetime.now().date()
45         month = datetime.datetime.now().date() - datetime.timedelta(weeks=4)
46         customer_list = Customer.objects.filter(deal_date__gte=month, deal_date__lte=today)
47 
48         # 查询每一个销售的名字以及一周对应的成单量
49         ret = UserInfo.objects.filter(depart_id=2, customers__deal_date__gte=month,
50                                       customers__deal_date__lte=today).annotate(c=Count("customers")).values_list("username",
51                                                                                                              "c")
52         ret = [[item[0],item[1]] for item in ret]
53         return {"customer_list": customer_list,"ret":ret,"today":today}

升级版本

 1 class TongJiView(View):
 2 
 3     def get(self,request):
 4 
 5         date = request.GET.get("date","today")
 6 
 7         today = datetime.datetime.now().date()
 8         delta1 = datetime.timedelta(days=1)
 9         delta2 = datetime.timedelta(weeks=1)
10         delta3 = datetime.timedelta(weeks=4)
11 
12         condition = {
13             "today":[{"deal_date":today},{"depart_id":2,"customers__deal_date":today}],
14             "zuotian":[{"deal_date":today-delta1},{"depart_id":2,"customers__deal_date":today-delta1}],
15             "week":[{"deal_date":today-delta2},{"depart_id":2,"customers__deal_date__gte":today-delta2,"customers__deal_date__lte":today}],
16             "month":[{"deal_date":today-delta3},{"depart_id":2,"customers__deal_date__gte":today-delta3,"customers__deal_date__lte":today}],
17         }
18 
19         customer_list = Customer.objects.filter(**condition.get(date)[0])
20         ret = UserInfo.objects.filter(**condition.get(date)[1]).annotate(c=Count("customers")).values_list("username",
21                                                                                                          "c")
22         ret = [[item[0], item[1]] for item in ret]
23         return render(request, "customer/tongji.html", {"customer_list": customer_list,"ret":ret,"today":today})

 

销售统计功能

标签:list   quest   以及   sel   request   spa   contex   elf   cts   

原文:https://www.cnblogs.com/qq849784670/p/9991933.html

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号