Example #1
0
def get_groupon_orders():
    args = request.args
    status = args.get("status")
    page = args.get("page", 1)
    page_count = args.get("page_count", 20)

    openid = get_current_user_openid()
    current_user = User.get_user_by_openid(openid)
    if not current_user:
        ret = ret_dict("3000")
        return jsonify(ret)
    orders = GrouponOrder.get_orders_by_status_user(status, current_user.id, page, page_count)
    ret = ret_dict("0000")
    ret["orderList"] = [
        {
            "title": order.groupon_title,
            "count": order.count,
            "totalFee": order.total_fee,
            "shippingFee": order.groupon.shipping_fee,
            "status": order.order_status,
            "orderID": order.id,
        }
        for order in orders
    ]
    return jsonify(ret)
Example #2
0
def get_groupon_order_by_id():
    order_id = request.args.get("order_id")
    order = GrouponOrder.get_groupon_order_by_id(order_id)
    ret = ret_dict("0000")
    if not order:
        ret["orderDetail"] = None
        return jsonify(ret)
    ret["orderDetail"] = {
        "title": order.groupon_title,
        "count": order.count,
        "totalFee": order.total_fee,
        "shippingFee": order.groupon.shipping_fee,
        "status": order.order_status,
        "orderID": order.id,
    }
    return jsonify(ret)
Example #3
0
def commit_groupon_order():
    """
    穿件团购订单
    :return:
    """
    args = request.args
    groupon_id = args.get("groupon_id")
    count = args.get("count")
    address = args.get("address")
    name = args.get("name")
    phone = args.get("phone")
    openid = get_current_user_openid()
    current_user = User.get_user_by_openid(openid)
    user_area = current_user.residential_area
    groupon = Groupon.get_groupon(groupon_id=groupon_id)
    product = groupon.product
    if not current_user:
        return jsonify(ret_dict("1000"))
    if not groupon:
        return jsonify(ret_dict("3000"))
    if not user_area:
        ret = {"retCode": "3000", "retMsg": "无法确定用户在哪个地区:用户id:" + str(current_user.id)}
        return jsonify(ret)
    if not product:
        ret = {"retCode": "5000", "retMsg": "没有关联的产品,请确认团购信息正确,groupon_id" + str(groupon.id)}
        return jsonify(ret)
    groupon_order = GrouponOrder()
    groupon_order.groupon_id = groupon_id
    groupon_order.user_id = current_user.id
    groupon_order.residential_area_id = user_area.id
    groupon_order.create_time = time.time()
    groupon_order.order_status = DefaultConfig.GROUPON_ORDER_STATUS_NEW
    groupon_order.user_phone = phone
    groupon_order.user_name = name
    groupon_order.groupon_title = groupon.title
    groupon_order.groupon_price = groupon.groupon_price
    groupon_order.product_title = product.title
    groupon_order.product_type = product.category
    groupon_order.area_name = user_area.area_name
    groupon_order.area_province = user_area.province.area_name
    groupon_order.area_city = user_area.city.area_name
    groupon_order.area_zone = user_area.zone.area_name
    groupon_order.area_stree = user_area.stree
    groupon_order.count = count
    groupon_order.total_fee = count * groupon.groupon_price + groupon.shipping_fee
    db.session.add(groupon_order)
    try:
        db.session.commit()
        order_id = groupon_order.id
        # 更新groupon的sold_count
        groupon.sold_count += 1
    except IntegrityError, ex:
        ret = {"retCode": "5000", "retMsg": "外键依赖错误:" + ex.message}
        return jsonify(ret)