# 销售统计功能

``` 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         # 查询每一个销售的名字以及今天对应的成单量
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(
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,
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,
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])
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})```

(0)
(0)

0条