コード例 #1
0
ファイル: site.py プロジェクト: yyt030/quanduoduo
def tickets_detail():
    """券 详情页面"""
    openid = session.get("openid")
    user_agent = request.headers.get('User-Agent')
    print user_agent
    # 如果操作是在微信网页端进行,要获取openid
    if 'MicroMessenger' in user_agent:
        if not openid:
            code = request.args.get("code")
            if not code:
                print "not code"
                return redirect(WeixinHelper.oauth2(request.url))
            else:
                wechat_login_fun(code)

    tickets_id = request.args.get('tid', 0, type=int)
    print "ticket_id", tickets_id
    ticket = GetTicketRecord.query.get(tickets_id)
    now = datetime.date(datetime.now())
    if ticket:
        expire_date = datetime.date(ticket.create_at) + timedelta(days=ticket.discount.usable)
        isexpire = (now - expire_date).days
        print '-' * 10, isexpire
    else:
        expire_date = ""
        isexpire = True
    shops = ticket.discount.shops
    return render_template('mobile/my_tickets_detail.html', nav=2, ticket=ticket, discount=ticket.discount,
                           shops=shops, expire_date=expire_date, isexpire=isexpire)
コード例 #2
0
ファイル: site.py プロジェクト: yyt030/quanduoduo
def find():
    openid = session.get("openid")
    access_token = session.get('access_token')
    user_agent = request.headers.get('User-Agent')
    print user_agent
    # 如果操作是在微信网页端进行,要获取openid
    if 'MicroMessenger' in user_agent:
        if not openid:
            code = request.args.get("code")
            if not code:
                print "not code"
                return redirect(WeixinHelper.oauth2(request.url))
            else:
                wechat_login_fun(code)

    industry1 = request.args.get("industry1", None)
    industry2 = request.args.get('industry2', None)
    district1 = request.args.get('district1', None)
    sortrank1 = request.args.get('sortrank1', None)
    page = request.args.get('page', 0, type=int)
    query = request.args.get("query", "")

    if query:
        discounts = Discount.query.join(Brand).filter(Brand.name.like('%{0}%'.format(query)))
        return render_template('mobile/search_result.html', discounts=discounts)

    # 拼装查询条件
    discounts = Discount.query.filter(Discount.is_re == 1)
    if industry1 != u'全部分类':
        if industry1:  # 品牌大类1
            discounts = discounts.filter(Discount.brand.has(Brand.industry_1 == industry1))
        if industry2:  # 品牌大类2
            discounts = discounts.filter(Discount.brand.has(Brand.industry_2 == industry2))
    curr_user_point = (session.get('longitude', ''), session.get('latitude', ''))
    # shop_list = []
    discount_list = []

    if district1 and session.get('longitude', ''):  # 地区
        if district1 == u'200米内':
            for discount in discounts.all():
                for shop in discount.shops.all():
                    if shop.get_distinct(curr_user_point) <= 0.2:
                        # shop_list.append(shop)
                        discount.append(shop.get_distinct(curr_user_point))
                        discount_list.append(discount)
        elif district1 == u'1千米内':
            for discount in discounts.all():
                for shop in discount.shops.all():
                    if shop.get_distinct(curr_user_point) <= 1:
                        # shop_list.append(shop)
                        discount_list.append(discount)
        elif district1 == u'5千米内':
            for discount in discounts.all():
                for shop in discount.shops.all():
                    if shop.get_distinct(curr_user_point) <= 5:
                        # shop_list.append(shop)
                        discount_list.append(discount)
        else:  # 全城范围
            pass
    else:
        discount_list = discounts.all()

    if sortrank1:  # 排序方式
        if sortrank1 == u'领取量':
            discount_list.sort(key=lambda x: x.count, reverse=True)
        elif sortrank1 == u'使用量':
            discount_list.sort(key=lambda x: x.back, reverse=True)
        else:  # 默认排序
            discount_list.sort(key=lambda x: x.create_at, reverse=True)

    discounts = discount_list

    EVENY_PAGE_NUM = current_app.config['FLASKY_PER_PAGE']
    if page:  # 加载页数
        discounts = discounts[page * EVENY_PAGE_NUM:
        (page + 1) * EVENY_PAGE_NUM]

    if industry1 or district1 or sortrank1:
        return render_template('mobile/search_result.html', discounts=discounts, industry1=industry1)

    return render_template('mobile/home.html', discounts=discounts, industry1=industry1)