Ejemplo n.º 1
0
def get_card_num_operations(request):
    """
    微众卡操作记录页面
    """
    card_id = request.GET.get('card_id', '')
    w_card = WeizoomCard.objects.filter(weizoom_card_id=card_id)
    card_operations = WeizoomCardOperationLog.objects.filter(
        card_id=w_card[0].id).order_by('-created_at')
    cur_card_operations = []
    for cur_card_operation in card_operations:
        cur_weizoom_card = JsonResponse()
        cur_weizoom_card.operater_name = cur_card_operation.operater_name
        cur_weizoom_card.operate_log = cur_card_operation.operate_log
        cur_weizoom_card.created_at = cur_card_operation.created_at.strftime(
            '%Y-%m-%d %H:%M:%S')
        cur_weizoom_card.remark = cur_card_operation.remark
        cur_weizoom_card.activated_to = cur_card_operation.activated_to
        cur_weizoom_card.department = cur_card_operation.department
        cur_card_operations.append(cur_weizoom_card)
    response = create_response(200)
    response.data.items = cur_card_operations
    return response.get_response()
Ejemplo n.º 2
0
def get_weizoom_cards(request):
    """
	卡列表
	"""
    count_per_page = int(100)
    cur_page = int(request.GET.get('page', '1'))
    weizoom_card_rule_id = int(request.GET.get('weizoom_card_rule_id', '-1'))
    weizoom_cards = WeizoomCard.objects.filter(
        weizoom_card_rule_id=weizoom_card_rule_id)
    weizoomcardpermission = WeiZoomCardPermission.objects.filter(
        user_id=request.user.id)
    can_active_card = 0
    can_stop_card = 0
    can_view_card_details = 0
    if weizoomcardpermission:
        can_active_card = weizoomcardpermission[0].can_active_card
        can_stop_card = weizoomcardpermission[0].can_stop_card
        can_view_card_details = weizoomcardpermission[0].can_view_card_details

    #获得已经过期的微众卡id
    today = datetime.today()
    card_ids_need_expire = []
    for card in weizoom_cards:
        #记录过期并且是未使用的微众卡id
        if card.expired_time < today:
            card_ids_need_expire.append(card.id)
    if len(card_ids_need_expire) > 0:
        WeizoomCard.objects.filter(id__in=card_ids_need_expire).update(
            is_expired=True)
    # weizoom_cards = WeizoomCard.objects.filter(weizoom_card_rule_id=weizoom_card_rule_id)
    filter_value = request.GET.get('filter_value', '')
    card_number = _get_cardNumber_value(filter_value)
    cardStatus = _get_status_value(filter_value)
    try:
        if card_number != -1:
            weizoom_cards = weizoom_cards.filter(
                weizoom_card_id__contains=str(card_number))
        if cardStatus != -1:
            weizoom_cards = weizoom_cards.filter(status=cardStatus)
    except:
        pass

    #卡号区间查询
    card_num_min = request.GET.get('card_num_min', '')
    card_num_max = request.GET.get('card_num_max', '')

    if card_num_min or card_num_max:
        weizoom_card_id_set = set(
            [int(c.weizoom_card_id) for c in weizoom_cards])

        if card_num_min and card_num_max:
            min_num = int(card_num_min)
            max_num = int(card_num_max)
            search_set = set(range(min_num, max_num + 1))
        elif card_num_max:
            search_set = set([int(card_num_max)])
        elif card_num_min:
            search_set = set([int(card_num_min)])
        else:
            search_set = set([])
        result_set = search_set & weizoom_card_id_set
        result_list = list(result_set)

        if len(result_list) > 0:
            filter_cards_id_list = []
            for card_num in result_list:
                filter_cards_id_list.append(u'%07d' % card_num)
            weizoom_cards = weizoom_cards.filter(
                weizoom_card_id__in=filter_cards_id_list)
        if len(result_list) == 0:
            weizoom_cards = []

    pageinfo, weizoom_cards = paginator.paginate(
        weizoom_cards,
        cur_page,
        count_per_page,
        query_string=request.META['QUERY_STRING'])

    weizoom_card_rule = WeizoomCardRule.objects.filter(id=weizoom_card_rule_id)
    rule_id2rule = {rule.id: rule for rule in weizoom_card_rule}
    card_recharge = WeizoomCardRecharge.objects.all()
    id2recharge_money = {}
    for card in card_recharge:
        if card.card_id not in id2recharge_money:
            id2recharge_money[card.card_id] = card.recharge_money
        else:
            id2recharge_money[card.card_id] += card.recharge_money
    cur_weizoom_cards = []
    for c in weizoom_cards:
        cur_weizoom_card = JsonResponse()
        cur_weizoom_card.id = c.id
        cur_weizoom_card.status = c.status
        cur_weizoom_card.weizoom_card_id = c.weizoom_card_id
        cur_weizoom_card.password = c.password
        cur_weizoom_card.active_card_user_id = c.active_card_user_id  #激活卡用户的id
        cur_weizoom_card.user_id = request.user.id  #当前用户的id
        cur_weizoom_card.money = '%.2f' % c.money  # 余额

        rule_money = 0.0 if c.weizoom_card_rule_id not in rule_id2rule else rule_id2rule[
            c.weizoom_card_rule_id].money
        money = '%.2f' % c.money  # 余额
        recharge_money = 0 if c.id not in id2recharge_money else id2recharge_money[
            c.id]
        total_money = '%.2f' % (float(rule_money) + recharge_money)  #总额
        used_money = '%.2f' % (float(total_money) - float(money))  #已使用金额

        if c.activated_at:
            cur_weizoom_card.activated_at = c.activated_at.strftime(
                '%Y-%m-%d %H:%M:%S')
        else:
            cur_weizoom_card.activated_at = ''
        valid_time_from = '' if c.weizoom_card_rule_id not in rule_id2rule else rule_id2rule[
            c.weizoom_card_rule_id].valid_time_from
        valid_time_to = '' if c.weizoom_card_rule_id not in rule_id2rule else rule_id2rule[
            c.weizoom_card_rule_id].valid_time_to
        cur_weizoom_card.total_money = total_money  #总额
        cur_weizoom_card.used_money = used_money  #已使用金额
        cur_weizoom_card.remark = c.remark
        cur_weizoom_card.activated_to = c.activated_to
        cur_weizoom_card.department = c.department
        cur_weizoom_card.valid_time_from = datetime.strftime(
            valid_time_from, '%Y-%m-%d %H:%M')
        cur_weizoom_card.valid_time_to = datetime.strftime(
            c.expired_time, '%Y-%m-%d %H:%M')
        cur_weizoom_card.is_expired = c.is_expired
        if (c.is_expired and cardStatus == -1) or not c.is_expired:
            cur_weizoom_cards.append(cur_weizoom_card)
        else:
            pageinfo.object_count -= 1

    response = create_response(200)
    response.data.items = cur_weizoom_cards
    response.data.sortAttr = request.GET.get('sort_attr', '-created_at')
    response.data.pageinfo = paginator.to_dict(pageinfo)
    response.data.can_active_card = can_active_card
    response.data.can_stop_card = can_stop_card
    response.data.can_view_card_details = can_view_card_details
    return response.get_response()