示例#1
0
def dashboard():
    now = datetime.datetime.now()
    date_before_30days = now + datetime.timedelta(days=-30)
    date_from = get_format_date(date=date_before_30days, format="%Y-%m-%d")
    date_to = get_format_date(date=now, format="%Y-%m-%d")

    list = StatDailySite.query.filter(StatDailySite.date >= date_from) \
        .filter(StatDailySite.date <= date_to).order_by(StatDailySite.id.asc()) \
        .all()

    resp = {'code': 200, 'msg': '操作成功~~', 'data': {}}
    data = {
        "categories": [],
        "series": [
            {
                "name": "会员总数",
                "data": []
            },
            {
                "name": "订单总数",
                "data": []
            },
        ]
    }

    if list:
        for item in list:
            data['categories'].append(
                get_format_date(date=item.date, format="%Y-%m-%d"))
            data['series'][0]['data'].append(item.total_member_count)
            data['series'][1]['data'].append(item.total_order_count)

    resp['data'] = data
    return jsonify(resp)
示例#2
0
def index():
    now = datetime.datetime.now()
    date_before_30days = now + datetime.timedelta(days=-30)
    default_date_from = get_format_date(date=date_before_30days,
                                        format="%Y-%m-%d")
    default_date_to = get_format_date(date=now, format="%Y-%m-%d")

    resp_data = {}
    req = request.values
    page = int(req['p']) if ('p' in req and req['p']) else 1
    date_from = req['date_from'] if 'date_from' in req else default_date_from
    date_to = req['date_to'] if 'date_to' in req else default_date_to
    query = StatDailySite.query.filter(StatDailySite.date >= date_from) \
        .filter(StatDailySite.date <= date_to)

    page_params = {
        'total': query.count(),
        'page_size': current_app.config['PAGE_SIZE'],
        'page': page,
        'display': current_app.config['PAGE_DISPLAY'],
        'url': request.full_path.replace("&p={}".format(page), "")
    }

    pages = i_pagination(page_params)
    offset = (page - 1) * current_app.config['PAGE_SIZE']

    list = query.order_by(StatDailySite.id.desc()).offset(offset).limit(
        current_app.config['PAGE_SIZE']).all()
    resp_data['list'] = list
    resp_data['pages'] = pages
    resp_data['current'] = 'index'
    resp_data['search_con'] = {'date_from': date_from, 'date_to': date_to}
    return render_template("stat/index.html", **resp_data)
示例#3
0
def index():
    # current_user = g.current_user
    resp_data = {
        'data': {
            'finance': {
                'today': 0,
                'month': 0
            },
            'member': {
                'today_new': 0,
                'month_new': 0,
                'total': 0
            },
            'order': {
                'today': 0,
                'month': 0
            },
            'shared': {
                'today': 0,
                'month': 0
            },
        }
    }

    now = datetime.datetime.now()
    date_before_30days = now + datetime.timedelta(days=-30)
    date_from = get_format_date(date=date_before_30days, format="%Y-%m-%d")
    date_to = get_format_date(date=now, format="%Y-%m-%d")

    list = StatDailySite.query.filter(StatDailySite.date >= date_from)\
        .filter(StatDailySite.date <= date_to).order_by(StatDailySite.id.asc())\
        .all()
    data = resp_data['data']
    if list:

        for item in list:
            data['finance']['month'] += item.total_pay_money
            data['member']['month_new'] += item.total_new_member_count
            data['member']['total'] = item.total_member_count
            data['order']['month'] += item.total_order_count
            data['shared']['month'] += item.total_shared_count
            if get_format_date(date=item.date, format="%Y-%m-%d") == date_to:
                data['finance']['today'] = item.total_pay_money
                data['member']['today_new'] = item.total_new_member_count
                data['order']['today'] = item.total_order_count
                data['shared']['today'] = item.total_shared_count

    return render_template("index/index.html", **resp_data)
示例#4
0
def food():
    now = datetime.datetime.now()
    date_before_30days = now + datetime.timedelta(days=-30)
    default_date_from = get_format_date(date=date_before_30days,
                                        format="%Y-%m-%d")
    default_date_to = get_format_date(date=now, format="%Y-%m-%d")

    resp_data = {}
    req = request.values
    page = int(req['p']) if ('p' in req and req['p']) else 1
    date_from = req['date_from'] if 'date_from' in req else default_date_from
    date_to = req['date_to'] if 'date_to' in req else default_date_to
    query = StatDailyFood.query.filter(StatDailyFood.date >= date_from) \
        .filter(StatDailyFood.date <= date_to)

    page_params = {
        'total': query.count(),
        'page_size': current_app.config['PAGE_SIZE'],
        'page': page,
        'display': current_app.config['PAGE_DISPLAY'],
        'url': request.full_path.replace("&p={}".format(page), "")
    }

    pages = i_pagination(page_params)
    offset = (page - 1) * current_app.config['PAGE_SIZE']

    list = query.order_by(StatDailyFood.id.desc()).offset(offset).limit(
        current_app.config['PAGE_SIZE']).all()
    date_list = []
    if list:
        food_map = get_dict_filter_field(Food, Food.id, "id",
                                         select_filter_obj(list, "food_id"))
        for item in list:
            tmp_food_info = food_map[
                item.food_id] if item.food_id in food_map else {}
            tmp_data = {
                "date": item.date,
                "total_count": item.total_count,
                "total_pay_money": item.total_pay_money,
                'food_info': tmp_food_info
            }
            date_list.append(tmp_data)

    resp_data['list'] = date_list
    resp_data['pages'] = pages
    resp_data['current'] = 'food'
    resp_data['search_con'] = {'date_from': date_from, 'date_to': date_to}
    return render_template("stat/food.html", **resp_data)
示例#5
0
    def run(self, params):
        act = params['act'] if 'act' in params else ''
        date = params['param'][0] if params['param'] and len(params['param']) else \
            get_format_date(format="%Y-%m-%d")
        if not act:
            return

        date_from = date + " 00:00:00"
        date_to = date + " 23:59:59"
        func_params = {
            'act': act,
            'date': date,
            'date_from': date_from,
            'date_to': date_to
        }
        if act == "member":
            self.stat_member(func_params)
        elif act == "food":
            self.stat_food(func_params)
        elif act == "site":
            self.stat_site(func_params)
        elif act == "test":
            self.test()

        app.logger.info("it's over~~")
        return
示例#6
0
def finance():
    now = datetime.datetime.now()
    date_before_30days = now + datetime.timedelta(days=-30)
    date_from = get_format_date(date=date_before_30days, format="%Y-%m-%d")
    date_to = get_format_date(date=now, format="%Y-%m-%d")

    list = StatDailySite.query.filter(StatDailySite.date >= date_from) \
        .filter(StatDailySite.date <= date_to).order_by(StatDailySite.id.asc()) \
        .all()

    resp = {'code': 200, 'msg': '操作成功~~', 'data': {}}
    data = {"categories": [], "series": [{"name": "日营收报表", "data": []}]}

    if list:
        for item in list:
            data['categories'].append(
                get_format_date(date=item.date, format="%Y-%m-%d"))
            data['series'][0]['data'].append(float(item.total_pay_money))

    resp['data'] = data
    return jsonify(resp)
示例#7
0
    def run(self, params):
        now = datetime.datetime.now()
        date_before_30min = now + datetime.timedelta(minutes=-30)
        list = PayOrder.query.filter_by(status=-8).\
            filter(PayOrder.created_time <= get_format_date(date=date_before_30min)).all()
        if not list:
            app.logger.info("no data~~")
            return

        pay_target = PayService()
        for item in list:
            pay_target.close_order(pay_order_id=item.id)
        app.logger.info("it's over~~")
示例#8
0
 def test_food(self, date):
     from app.models.food.food import Food
     list = Food.query.all()
     if list:
         for item in list:
             model = FoodSaleChangeLog()
             model.food_id = item.id
             model.quantity = random.randint(1, 10)
             model.price = model.quantity * item.price
             model.member_id = 1
             model.created_time = date + " " + get_format_date(
                 format="%H:%M:%S")
             with db.auto_commit():
                 db.session.add(model)
示例#9
0
 def test(self):
     import datetime
     now = datetime.datetime.now()
     for i in reversed(range(1, 30)):
         date_before = now + datetime.timedelta(days=-i)
         date = get_format_date(date=date_before, format="%Y-%m-%d")
         tmp_params = {
             'act': 'test',
             'date': date,
             'date_from': date + " 00:00:00",
             'date_to': date + " 23:59:59"
         }
         self.test_food(date)
         self.stat_food(tmp_params)
         self.stat_member(tmp_params)
         self.stat_site(tmp_params)