• 统计当天下单量


    class PlatformData(View):
        def get(self, request):
            r = dict()
            r["errno"] = 1
            r["order_total_num"] = OrderModel.objects.all().count()
            r["product_total_num"] = ProductModel.objects.all().count()
            r["success_order"] = OrderModel.objects.filter(state=2).count()
            r["cancel_order"] = OrderModel.objects.filter(state=4).count()
            r["nopay_order"] = OrderModel.objects.filter(state=1).count()
            r["trade_amount"] = serializer(RechargeModel.objects.all().aggregate(Sum("amount")))
            return HttpResponse(json.dumps(r))
    
    
    class DailyAmount(View):
        def get(self, request):
            daily_list = []
            for i in range(0, 31):
                dtime = datetime.datetime.today() - datetime.timedelta(days=i)
                daily_dict = {}
                dailyAmount = serializer(
                    RechargeModel.objects.filter(trade_no__month=dtime.month, trade_no__day=dtime.day).aggregate(
                        damount=Sum('amount')))
                amount = dailyAmount.pop('damount')
                timestamp = time.mktime(dtime.timetuple())
                daily_dict[timestamp] = amount
                daily_list.append(daily_dict)
            return HttpResponse(json.dumps(daily_list))
    
    
    class TayAmount(View):
        def get(self, request):
            today = datetime.datetime.today().day
            tomonth = datetime.datetime.today().month
            tAmount = serializer(RechargeModel.objects.filter(trade_no__month=tomonth, trade_no__day=today).
                                 aggregate(todayAmount=Sum('amount')))
            yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
            tomonth = yesterday.month
            today = yesterday.day
            yAmount = serializer(
                RechargeModel.objects.filter(trade_no__month=tomonth, trade_no__day=today).values(
                    'amount').aggregate(yesterdayAmount=Sum('amount')))
            tAmount.update(yAmount)
            return HttpResponse(json.dumps(tAmount))
    
    
    class DailyNum(View):
        def get(self, request):
            daily_list = []
            r = dict()
            for i in range(0, 31):
                dtime = datetime.datetime.today() - datetime.timedelta(days=i)
                daily_dict = {}
                dailyNum = serializer(
                    OrderModel.objects.filter(date_created__month=dtime.month, date_created__day=dtime.day).count())
                timestamp = time.mktime(dtime.timetuple())
                daily_dict[int(timestamp)] = dailyNum
                daily_list.append(daily_dict)
            r["errno"] = 1
            r["daily_list"] = daily_list
            return HttpResponse(json.dumps(r))
    
    
    class TayNum(View):
        def get(self, request):
            today = datetime.datetime.today().day
            tomonth = datetime.datetime.today().month
            tCount = serializer(OrderModel.objects.filter(date_created__month=tomonth, date_created__day=today).count())
            yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
            tomonth = yesterday.month
            today = yesterday.day
            yCount = serializer(
                OrderModel.objects.filter(date_created__month=tomonth, date_created__day=today).count())
            r = dict()
            r['errno'] = 1
            r['todayNum'] = tCount
            r['yesterdayNum'] = yCount
            return HttpResponse(json.dumps(r))
    

      

    models 

    date_created = models.DateTimeField(default=timezone.now, verbose_name='订单创建时间')
    

    views

    orderAmount = serializer(
            OrderModel.objects.values(time=TruncDay('date_created')).annotate(num=Count('id')))  (查出来是字典的格式,time是key对应时间戳,num是key对应的是数量)
    

      

  • 相关阅读:
    luogu_1659【题解】manacher 啦啦队排练
    manacher算法
    luogu_4503【题解】企鹅QQ 哈希
    luogu_3966【题解】单词 AC自动机
    字符串 AC自动机
    luogu_3275【题解】糖果 差分约束
    luogu_4568 飞行路线 分层图
    luogu_4551【题解】最长异或路径 trie树
    luogu_1041【题解】搜索 传染病控制
    [题解/模板]扫描线
  • 原文地址:https://www.cnblogs.com/sunkai1993/p/7543544.html
Copyright © 2020-2023  润新知