Esempio n. 1
0
def get_prize(request):
    webapp_user = request.webapp_user
    lottery_id = int(request.GET['lottery_id'])
    prize_position = int(request.GET.get('prize_position', 0))
    try:
        lottery = Lottery.objects.get(id=lottery_id)
    except:
        raise Http404(u"该活动信息不存在")

    member = request.member

    if not member:
        raise Http404(u"会员信息不存在")

    relations = LotteryHasPrize.objects.filter(lottery=lottery)
    prize_ids = [r.prize_id for r in relations]
    prizes = Prize.objects.filter(id__in=prize_ids)

    #定义奖项:
    if lottery.can_repeat:
        play_times = lottery.daily_play_count
    else:
        play_times = 1

    #根据发奖规则发奖
    prize = _get_prize(lottery, member, prizes)

    response = create_response(200)

    prize = __record_prize(webapp_user, lottery, member, prize, prize_position)

    if prize:
        cur_prize = JsonResponse()
        cur_prize.name = prize.name
        cur_prize.id = prize.id
        cur_prize.level = prize.level
        response.data.prize = cur_prize
    else:
        response.data.prize = None

    cur_member = JsonResponse()
    cur_member.integral = webapp_user.integral_info['count']
    response.data.member = cur_member

    return response.get_response()
Esempio n. 2
0
def get_order(request):
    id = request.GET.get('id')
    order = Order.objects.get(id=id)
    order_has_products = OrderHasProduct.objects.filter(order=order)

    number = 0
    cur_order = JsonResponse()
    for order_has_product in order_has_products:
        number += order_has_product.number

    cur_order.number = number
    cur_order.statu = get_order_status_text(order.status)
    cur_order.express_company_name = get_name_by_value(
        order.express_company_name)
    cur_order.type = order.type
    cur_order.express_number = order.express_number
    cur_order.leader_name = order.leader_name
    cur_order.integral = order.integral
    cur_order.bill_type = order.bill_type
    cur_order.bill = order.bill
    cur_order.order_id = order.order_id
    cur_order.final_price = '%.2f' % order.final_price
    cur_order.postage = '%.2f' % order.postage
    cur_order.ship_name = order.ship_name
    cur_order.ship_tel = order.ship_tel
    cur_order.area = regional_util.get_str_value_by_string_ids(order.area)
    cur_order.ship_address = order.ship_address
    cur_order.customer_message = order.customer_message
    cur_order.created_at = __data_format(order.created_at)
    cur_order.action = get_order_actions(order)
    cur_order.reason = order.reason
    #关联的优惠券
    coupon = order.get_coupon()
    if coupon:
        cur_coupon = JsonResponse()
        cur_coupon.coupon_id = coupon.coupon_id
        cur_coupon.coupon_rule_name = coupon.coupon_rule.name
        cur_coupon.money = str(coupon.money)
        cur_order.coupon = cur_coupon
    else:
        cur_order.coupon = None

    products = mall_api.get_order_products(order)
    #商品
    cur_product_json = []
    for product in products:
        cur_product = JsonResponse()
        cur_product.name = product['name']
        cur_product.count = product['count']
        cur_product.total_price = product['total_price']
        cur_product.thumbnails_url = product['thumbnails_url']
        cur_product.is_deleted = product['is_deleted']
        properties = product['custom_model_properties']
        if properties:
            for product_property in properties:
                cur_product.property_name = product_property['name']
                cur_product.property_value = product_property['property_value']

        cur_product_json.append(cur_product)

    response = create_response(200)
    response.data.order = cur_order
    response.data.products = cur_product_json
    return response.get_jsonp_response(request)