Beispiel #1
0
def index():
    resp_data = {}
    req = request.values
    page = int(req['p']) if ('p' in req and req['p']) else 1
    query = User.query

    # 混合查询关键字‘mix_kw
    if 'mix_kw' in req:
        rule = or_(User.nickname.ilike("%{0}%".format(req['mix_kw'])),
                   User.mobile.ilike("%{0}%".format(req['mix_kw'])))
        query = query.filter(rule)

    if 'status' in req and int(req['status']) > -1:
        query = query.filter(User.status == int(req['status']))

    page_params = {
        'total': query.count(),  #  总数量
        'page_size': app.config['PAGE_SIZE'],
        'page': page,  # 前端传递的页数,默认为1
        'display': app.config['PAGE_DISPLAY'],  # 展示的页数
        'url': request.full_path.replace('&p={}'.format(page), "")
    }
    pages = i_pagination(page_params)
    offset = (page - 1) * app.config['PAGE_SIZE']
    limit = page * app.config['PAGE_SIZE']

    list_ = query.order_by(User.uid.desc()).all()[offset:limit]

    resp_data['list'] = list_
    resp_data['pages'] = pages
    resp_data['search_con'] = req  # 返回从前端传递的结果
    resp_data['status_mapping'] = app.config['STATUS_MAPPING']
    return ops_render("account/index.html", resp_data)
Beispiel #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': app.config['PAGE_SIZE'],
        'page': page,
        'display': app.config['PAGE_DISPLAY'],
        'url': request.full_path.replace("&p={}".format(page), "")
    }

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

    list = query.order_by(StatDailySite.id.desc()).offset(offset).limit(
        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 ops_render("stat/index.html", resp_data)
Beispiel #3
0
def index():
    resp_data = {}
    req = request.values
    page = int(req['p']) if ('p' in req and req['p']) else 1
    query = Food.query
    if 'mix_kw' in req:
        rule = or_(Food.name.ilike("%{0}%".format(req['mix_kw'])), Food.tags.ilike("%{0}%".format(req['mix_kw'])))
        query = query.filter(rule)

    if 'status' in req and int(req['status']) > -1:
        query = query.filter(Food.status == int(req['status']))

    if 'cat_id' in req and int(req['cat_id']) > 0:
        query = query.filter(Food.cat_id == int(req['cat_id']))

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

    pages = i_pagination(page_params)
    offset = (page - 1) * app.config['PAGE_SIZE']
    list = query.order_by(Food.id.desc()).offset(offset).limit(app.config['PAGE_SIZE']).all()

    cat_mapping = get_dict_filter_field(FoodCat, FoodCat.id, "id", [])
    resp_data['list'] = list
    resp_data['pages'] = pages
    resp_data['search_con'] = req
    resp_data['status_mapping'] = app.config['STATUS_MAPPING']
    resp_data['cat_mapping'] = cat_mapping
    resp_data['current'] = 'index'
    return ops_render("food/index.html", resp_data)
Beispiel #4
0
def index():
    resp_data = {}
    req = request.values
    page = int(req['p']) if ('p' in req and req['p']) else 1
    query = Member.query

    if 'mix_kw' in req:
        query = query.filter(
            Member.nickname.ilike("%{0}%".format(req['mix_kw'])))

    if 'status' in req and int(req['status']) > -1:
        query = query.filter(Member.status == int(req['status']))

    page_params = {
        'total': query.count(),
        'page_size': app.config['PAGE_SIZE'],
        'page': page,
        'display': app.config['PAGE_DISPLAY'],
        'url': request.full_path.replace('&p={}'.format(page), '')
    }
    pages = i_pagination(page_params)
    offset = (page - 1) * app.config['PAGE_SIZE']
    list = query.order_by(Member.id.desc()).offset(offset).limit(
        app.config['PAGE_SIZE']).all()
    resp_data['list'] = list
    resp_data['pages'] = pages  # 分页参数
    resp_data['search_con'] = req
    resp_data['status_mapping'] = app.config['STATUS_MAPPING']
    resp_data['current'] = 'index'
    return ops_render("member/index.html", resp_data)
Beispiel #5
0
def set():
    resp_data = {}
    req = request.values
    page = int(req['p']) if ('p' in req and req['p']) else 1
    query = PayOrder.query.filter_by(status=1)

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

    pages = i_pagination(page_params)
    offset = (page - 1) * app.config['PAGE_SIZE']
    list = query.order_by(PayOrder.id.desc()).offset(offset).limit(
        app.config['PAGE_SIZE']).all()

    stat_info = db.session.query(PayOrder, func.sum(PayOrder.total_price).label("total")) \
        .filter(PayOrder.status == 1).first()

    app.logger.info(stat_info)
    resp_data['list'] = list
    resp_data['pages'] = pages
    resp_data['total_money'] = stat_info[1] if stat_info[1] else 0.00
    resp_data['current'] = 'account'
    return ops_render("finance/account.html", resp_data)
Beispiel #6
0
def comment():
    resp_data = {}
    req = request.args
    page = int(req['p']) if ('p' in req and req['p']) else 1
    query = MemberComments.query

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

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

    comment_list = query.order_by(
        MemberComments.id.desc()).offset(offset).limit(
            app.config['PAGE_SIZE']).all()
    data_list = []
    if comment_list:
        member_map = get_dict_filter_field(
            Member, Member.id, "id",
            select_filter_obj(comment_list, "member_id"))
        food_ids = []
        for item in comment_list:
            tmp_food_ids = (item.food_ids[1:-1]).split("_")
            tmp_food_ids = {}.fromkeys(tmp_food_ids).keys()
            food_ids = food_ids + list(tmp_food_ids)

        food_map = get_dict_filter_field(Food, Food.id, "id", food_ids)

        for item in comment_list:
            tmp_member_info = member_map[item.member_id]
            tmp_foods = []
            tmp_food_ids = (item.food_ids[1:-1]).split("_")
            for tmp_food_id in tmp_food_ids:
                tmp_food_info = food_map[int(tmp_food_id)]
                tmp_foods.append({
                    'name': tmp_food_info.name,
                })

            tmp_data = {
                "content": item.content,
                "score": item.score,
                "member_info": tmp_member_info,
                "foods": tmp_foods
            }
            data_list.append(tmp_data)
    resp_data['list'] = data_list
    resp_data['pages'] = pages
    resp_data['current'] = 'comment'

    return ops_render("member/comment.html", resp_data)
Beispiel #7
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': app.config['PAGE_SIZE'],
        'page': page,
        'display': app.config['PAGE_DISPLAY'],
        'url': request.full_path.replace("&p={}".format(page), "")
    }

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

    list = query.order_by(StatDailyFood.id.desc()).offset(offset).limit(
        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 ops_render("stat/food.html", resp_data)
Beispiel #8
0
def index():
    resp_data = {}
    req = request.values
    page = int(req['p']) if ('p' in req and req['p']) else 1

    query = PayOrder.query

    if 'status' in req and int(req['status']) > -1:
        query = query.filter(PayOrder.status == int(req['status']))

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

    pages = i_pagination(page_params)
    offset = (page - 1) * app.config['PAGE_SIZE']
    pay_list = query.order_by(PayOrder.id.desc()).offset(offset).limit(
        app.config['PAGE_SIZE']).all()
    data_list = []
    if pay_list:
        pay_order_ids = select_filter_obj(pay_list, "id")
        pay_order_items_map = get_dict_list_filter_field(
            PayOrderItem, PayOrderItem.pay_order_id, "pay_order_id",
            pay_order_ids)

        food_mapping = {}
        if pay_order_items_map:
            food_ids = []
            for item in pay_order_items_map:
                tmp_food_ids = select_filter_obj(pay_order_items_map[item],
                                                 "food_id")
                tmp_food_ids = {}.fromkeys(tmp_food_ids).keys()
                food_ids = food_ids + list(tmp_food_ids)

            # food_ids里面会有重复的,要去重
            food_mapping = get_dict_filter_field(Food, Food.id, "id", food_ids)

        for item in pay_list:
            tmp_data = {
                "id": item.id,
                "status_desc": item.status_desc,
                "order_number": item.order_number,
                "price": item.total_price,
                "pay_time": item.pay_time,
                "created_time": item.created_time.strftime("%Y%m%d%H%M%S")
            }
            tmp_foods = []
            tmp_order_items = pay_order_items_map[item.id]
            for tmp_order_item in tmp_order_items:
                tmp_food_info = food_mapping[tmp_order_item.food_id]
                tmp_foods.append({
                    'name': tmp_food_info.name,
                    'quantity': tmp_order_item.quantity
                })

            tmp_data['foods'] = tmp_foods
            data_list.append(tmp_data)

    resp_data['list'] = data_list
    resp_data['pages'] = pages
    resp_data['search_con'] = req
    resp_data['pay_status_mapping'] = app.config['PAY_STATUS_MAPPING']
    resp_data['current'] = 'index'

    return ops_render("finance/index.html", resp_data)