Ejemplo 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("/")
Ejemplo 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("/")
Ejemplo n.º 3
0
def connect_authorized(app):
    code = request.args.get('code')
    open_user = {}
    if app == "sina":
        sinaClient = SinaAPIClient(
            app_key=current_app.config.get('SINA_APP_KEY'),
            app_secret=current_app.config.get('SINA_APP_SECRET'),
            redirect_uri=current_app.config.get('SINA_CALLBACK_URL')
        )
        try:
            r = sinaClient.request_access_token(code)
            access_token = r.get("access_token")
            expires_in = r.get("expires_in")
            sinaClient.set_access_token(access_token, expires_in)
            try:
                sinaUser = sinaClient.users.show.get(uid=r.uid)
                open_user["id"] = sinaUser.id
                open_user["name"] = sinaUser.name
                open_user["access_token"] = access_token
                open_user["figureurl"] = sinaUser.profile_image_url
            except:
                return redirect('/signin')
        except:
            return redirect
    elif app == "qq":
        qqClient = QQAPIClient(
            client_id=current_app.config.get('QQ_APP_KEY'),
            client_secret=current_app.config.get('QQ_APP_SECRET'),
            redirect_uri=current_app.config.get('QQ_CALLBACK_URL')
        )
        r = qqClient.request_access_token(code)
        access_token = r.get("access_token")
        expires_in = r.get("expires_in")
        qqClient.set_access_token(access_token, expires_in)
        openid = qqClient.request_openid()
        qqClient.set_openid(openid)
        qqUser = qqClient.request_api('user/get_user_info')
        open_user["id"] = openid
        open_user["name"] = qqUser.nickname
        open_user["access_token"] = access_token
        open_user["figureurl"] = qqUser.figureurl_1

    connect = Connect.query.filter(Connect.openid == open_user["id"], Connect.app == app).first()

    if connect:
        connect.access_token = open_user["access_token"]
        db.session.commit()
        user = User.query.get(connect.user_id)
        utils.login(user)
        return redirect(url_for("frontend.index"))
    else:
        session['user'] = User(
            nickname=open_user["name"],
            name=open_user["name"],
            join=utils.get_now(),
            figureurl=open_user["figureurl"]
        )
        session['connect'] = Connect(open_user["id"], open_user["access_token"], app)
        return redirect(url_for("frontend.connect_callback", app=app))
Ejemplo 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)
Ejemplo n.º 5
0
 def __init__(self, name, descrip, address, city_id, creator_id, user_num=1, created=utils.get_now()):
     self.name = name
     self.descrip = descrip
     self.address = address
     self.city_id = city_id
     self.creator_id = creator_id
     self.user_num = user_num
     self.created = created