Ejemplo n.º 1
0
def get_groupon_customer_reviews():
    groupon_id = request.args.get("groupon_id")
    if not groupon_id:
        ret = ret_dict("3000")
        return jsonify(ret)
    page_count = request.args.get("page_count", 20)
    page_num = request.args.get("page", 1)
    index_start = (page_num - 1) * 20
    index_end = index_start + page_count
    statics_data = CustomerReviews.get_statics_data(groupon_id)
    groupon = Groupon.get_groupon(groupon_id)
    reviews = groupon.customer_reviews[index_start:index_end]
    ret = ret_dict("0000")
    data = {
        "vagScore": statics_data["avg_score"],
        "reviewsCount": statics_data["reviews_count"],
        "pageCount": page_count,
        "page": page_num,
        "sum": len(reviews),
        "reviewList": [
            {
                "userID": review.user.id,
                "nickname": review.user.wechat_nickname,
                "score": review.score,
                "content": review.content,
                "uuid": review.user.headimg_url,
            }
            for review in reviews
        ],
    }

    return jsonify(dict(ret, **data))
Ejemplo n.º 2
0
def get_groupon_detail():
    """
    获取团购详情
    :return:
    """
    groupon_id = request.args.get("groupon_id")
    groupon = Groupon.get_groupon(groupon_id)
    product = groupon.product
    product_imgas = product.images
    ret = ret_dict()
    if not groupon:
        ret = ret_dict("3000")
        ret["retMsg"] = "找不到团购详情"
    else:
        info = {
            "status": groupon.groupon_status,
            "title": groupon.title,
            "price": groupon.groupon_price,
            "originPrice": product.orginal_price,
            "endTime": groupon.end_time,
            "shipWay": groupon.ship_way,
            "shipping_fee": groupon.shipping_fee,
            "count": groupon.sold_count,
            "product_content": product.content,
            "product_imgs": [{"img_url": img.img_url, "img_order": img.order} for img in product.images],
            "uuid": groupon.profile_img,
        }
    ret = dict(ret, **info)
    return jsonify(ret)
Ejemplo n.º 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)