Esempio n. 1
0
def submit_order():
    luck = random.randint(0, 100)
    list = request.form.get('list')
    user_id = utils.get_currentt_user_id()
    shop_id = int(request.form.get('shop_id'))
    time = utils.get_now()

    #检查小组是否已经添加这个店铺
    group = Group.query.filter(Group.id == utils.get_currentt_user_group_id(),
                               Shop.id == shop_id).first()

    if group:
        #计算总价
        order_list = json.loads(list)
        total = 0.0
        for order in order_list:
            total += float(order['price']) * int(order['num'])

        order = Order(user_id, shop_id, utils.get_currentt_user_group_id(),
                      total, time, list, luck)

        db.session.add(order)
        db.session.commit()

        return jsonify(result="success", luck=luck)
    else:
        return redirect("/")
Esempio n. 2
0
def submit_order():
    luck = random.randint(0, 100)
    list = request.form.get('list')
    user_id = utils.get_currentt_user_id()
    shop_id = int(request.form.get('shop_id'))
    time = utils.get_now()

    #检查小组是否已经添加这个店铺
    group = Group.query.filter(Group.id == utils.get_currentt_user_group_id(), Shop.id == shop_id).first()

    if group:
        #计算总价
        order_list = json.loads(list)
        total = 0.0
        for order in order_list:
            total += float(order['price']) * int(order['num'])

        order = Order(user_id, shop_id, utils.get_currentt_user_group_id(), total, time, list, luck)

        db.session.add(order)
        db.session.commit()

        return jsonify(result="success", luck=luck)
    else:
        return redirect("/")
Esempio n. 3
0
def join(id):
    #已经加入小组的不能加入另外的小组
    if utils.get_currentt_user_group_id() > 0:
        return redirect('/')

    group = Group.query.filter(Group.id == id).first()

    if group:
        user = User.query.get(utils.get_currentt_user_id())
        user.group_id = id
        #新增用户数
        group.user_num += 1
        db.session.commit()
        return redirect('/?action=join_group_success')
    else:
        return redirect('/')
Esempio n. 4
0
def today():
    today_time = utils.get_now().strftime('%Y-%m-%d 00:00:00')
    orders = Order.query.filter(Order.time > today_time, Order.group_id == utils.get_currentt_user_group_id()).all()

    if len(orders) == 0:
        return render_template('today.html', all=None)

    #准备好数组进行处理
    todayOrder = {}

    #进行处理
    for order in orders:
        if str(order.shop.id) in todayOrder:
            item = todayOrder[str(order.shop.id)]
            item["orders"].append(order)
            item["total"] += order.total
            if order.luck <= item["min_luck"]:
                item["min_luck"] = order.luck
                item["min_user"] = order.user
        else:
            todayOrder[str(order.shop.id)] = {
                "min_luck": order.luck,
                "min_user": order.user,
                "total": order.total,
                "shop": order.shop,
                "orders": [order],
                "analytics": {},
                "totalNum": 0
            }
        order_text = json.loads(order.text)
        for ot in order_text:
            if ot["id"] in todayOrder[str(order.shop.id)]["analytics"]:
                todayOrder[str(order.shop.id)]["totalNum"] += ot["num"]
                todayOrder[str(order.shop.id)]["analytics"][str(ot["id"])]["num"] += ot["num"]
                todayOrder[str(order.shop.id)]["analytics"][str(ot["id"])]["total"] += (float(ot["price"]) * ot["num"])
            else:
                todayOrder[str(order.shop.id)]["analytics"][str(ot["id"])] = {
                    "id": ot["id"],
                    "name": ot["name"],
                    "num": ot["num"],
                    "price": float(ot["price"]),
                    "total": float(ot["price"]) * int(ot["num"])
                }
                todayOrder[str(order.shop.id)]["totalNum"] = ot["num"]

    return render_template('today.html', all=todayOrder)
Esempio n. 5
0
def edit_food():
    """编辑美食页面"""
    id = request.args.get('id')

    if not id:
        return redirect("/")
    else:
        id = int(id)

    #检查小组是否已经添加这个店铺
    group = Group.query.filter(Group.id == utils.get_currentt_user_group_id(), Shop.id == id).first()

    if group:
        shop = Shop.query.get(id)
        return render_template("/shop/edit_food.html", shop=shop)
    else:
        return redirect('/')
Esempio n. 6
0
def edit_food():
    """编辑美食页面"""
    id = request.args.get('id')

    if not id:
        return redirect("/")
    else:
        id = int(id)

    #检查小组是否已经添加这个店铺
    group = Group.query.filter(Group.id == utils.get_currentt_user_group_id(),
                               Shop.id == id).first()

    if group:
        shop = Shop.query.get(id)
        return render_template("/shop/edit_food.html", shop=shop)
    else:
        return redirect('/')
Esempio n. 7
0
def shop_fav():
    shop_id = request.form['shop_id']
    group_id = utils.get_currentt_user_group_id()

    if group_id:
        result = Group.query.filter(Group.shops.any(id=shop_id)).first()
        group = Group.query.filter(Group.id == group_id, Shop.id == shop_id).first()
        shop = Shop.query.get(shop_id)

        if result:
            group.shops.remove(shop)
            stat = 0
        else:
            group.shops.append(shop)
            stat = 1

        db.session.commit()

        return '{"msg":"success", "stat":' + str(stat) + '}'
    else:
        return redirect("/")
Esempio n. 8
0
def add():
    """添加店铺页面"""
    if request.method == "GET":
        return render_template('/shop/add.html')
    elif request.method == "POST":
        if utils.get_currentt_user_group_id():
            name = request.form['name']
            tel = request.form['tel']
            address = request.form['address']
            city_id = utils.get_currentt_user_group().city_id

            if not name or not tel or not address or not city_id:
                return redirect("/action=add_shop_fail")

            shop = Shop(name, address, tel, city_id, utils.get_currentt_user_id())
            utils.get_currentt_user_group().shops.append(shop)
            db.session.add(shop)
            db.session.commit()

            return redirect(url_for('shop.edit_food', id=shop.id))
        else:
            return redirect("/")
Esempio n. 9
0
def shop_fav():
    shop_id = request.form['shop_id']
    group_id = utils.get_currentt_user_group_id()

    if group_id:
        result = Group.query.filter(Group.shops.any(id=shop_id)).first()
        group = Group.query.filter(Group.id == group_id,
                                   Shop.id == shop_id).first()
        shop = Shop.query.get(shop_id)

        if result:
            group.shops.remove(shop)
            stat = 0
        else:
            group.shops.append(shop)
            stat = 1

        db.session.commit()

        return '{"msg":"success", "stat":' + str(stat) + '}'
    else:
        return redirect("/")
Esempio n. 10
0
def new():
    if request.method == "GET":
        cities = City.query.all()
        return render_template("/group/new.html", cities=cities)
    elif request.method == "POST":
        #已经加入小组的不能再创建小组
        if utils.get_currentt_user_group_id() > 0:
            return redirect('/')

        name = request.form["name"]
        descrip = request.form["descrip"]
        address = request.form["address"]

        if not name or not descrip or not address:
            return redirect('/?action=create_group_fail')

        group = Group(name, descrip, address, request.form['city'], utils.get_currentt_user_id())
        group.users = [utils.get_current_user()]

        db.session.add(group)
        db.session.commit()

        return redirect('/?action=create_group_success')
Esempio n. 11
0
def add():
    """添加店铺页面"""
    if request.method == "GET":
        return render_template('/shop/add.html')
    elif request.method == "POST":
        if utils.get_currentt_user_group_id():
            name = request.form['name']
            tel = request.form['tel']
            address = request.form['address']
            city_id = utils.get_currentt_user_group().city_id

            if not name or not tel or not address or not city_id:
                return redirect("/action=add_shop_fail")

            shop = Shop(name, address, tel, city_id,
                        utils.get_currentt_user_id())
            utils.get_currentt_user_group().shops.append(shop)
            db.session.add(shop)
            db.session.commit()

            return redirect(url_for('shop.edit_food', id=shop.id))
        else:
            return redirect("/")
Esempio n. 12
0
def index():
    if utils.get_currentt_user_group_id():
        shops = Group.query.get(utils.get_currentt_user_group_id()).shops
    else:
        shops = None
    return render_template('index.html', shops=shops)
Esempio n. 13
0
def shop_fav_list():
    group = Group.query.get(utils.get_currentt_user_group_id())
    return jsonify(msg="success", shops=[i.serialize for i in group.shops])
Esempio n. 14
0
def shop_fav_list():
    group = Group.query.get(utils.get_currentt_user_group_id())
    return jsonify(msg="success", shops=[i.serialize for i in group.shops])