Пример #1
0
def get_sms(request):
    ''' 获取推送消息列表 '''

    page = int(request.GET.get('page', 1))
    pagesize = int(request.GET.get('rows', 15))
    keyword = request.GET.get('keywords')

    sms = Sendsms.objects.filter(seller_id=request.user.id)
    # if keyword:
    #     cashbacks = cashbacks.filter(tags__contains=keyword)  # 按标签查询
    count = sms.count()  # 总数
    sms = sms.order_by('-add_time')[(page - 1) * pagesize:page * pagesize]
    sms = list(sms)

    result = []
    customer_ids = [item.customer_id for item in sms]
    customers = Customer.objects.filter(id__in=customer_ids).values(
        'id', 'username')

    for item in sms:
        customer_name = safe_dict_value(
            list(filter(lambda m: m['id'] == item.customer_id, customers)),
            'username')
        result.append(item.to_dict(customer_name))

    paged_result.set(page, pagesize, count, result)
    return JsonResponse(paged_result.to_dict())
Пример #2
0
def get_cashbacks(request):
    ''' 获取返现列表 '''

    page = int(request.GET.get('page', 1))
    pagesize = int(request.GET.get('rows', 15))
    keyword = request.GET.get('keywords')

    cashbacks = Cashback.objects.filter(seller_id=request.user.id)
    # if keyword:
    #     cashbacks = cashbacks.filter(tags__contains=keyword)  # 按标签查询
    count = cashbacks.count()  # 总数
    cashbacks = cashbacks.order_by('-add_time')[(page - 1) * pagesize:page *
                                                pagesize]
    cashbacks = list(cashbacks)

    customer_ids = []
    task_ids = []
    result = []
    for cashback in cashbacks:
        task_ids.append(cashback.task_id)
        customer_ids.append(cashback.customer_id)

    tasks = CashbackTask.objects.filter(id__in=task_ids).values('id', 'name')
    customers = Customer.objects.filter(id__in=customer_ids).values(
        'id', 'username')

    for cashback in cashbacks:
        task_name = safe_dict_value(
            list(filter(lambda m: m['id'] == cashback.task_id, tasks)), 'name')
        customer_name = safe_dict_value(
            list(filter(lambda m: m['id'] == cashback.customer_id, customers)),
            'username')
        result.append(cashback.to_dict(task_name, customer_name))

    paged_result.set(page, pagesize, count, result)
    return JsonResponse(paged_result.to_dict())
Пример #3
0
 def get_customername(self, cashback):
     customers = Customer.objects.filter(id=cashback.customer_id).values(
         'id', 'username')
     return safe_dict_value(
         list(filter(lambda m: m['id'] == cashback.customer_id, customers)),
         'username')
Пример #4
0
 def get_taskname(self, cashback):
     tasks = CashbackTask.objects.filter(id=cashback.task_id).values(
         'id', 'name')
     return safe_dict_value(
         list(filter(lambda m: m['id'] == cashback.task_id, tasks)), 'name')