def get_orders(request): ''' 获取订单列表 # sidx 排序字段 # sord 排序 asc/desc # page 页码 # rows 页容量 # keywords 搜索关键字 ''' page = int(request.GET.get('page', 1)) pagesize = int(request.GET.get('rows', 15)) keyword = request.GET.get('keywords') orders = Order.objects.filter(seller_id=request.user.id) if keyword: orders = orders.filter(id__contains=keyword) # 按订单号查询 count = orders.count() # orders = orders.order_by('-add_time')[(page - 1) * pagesize:page * pagesize] result = [order.to_dict() for order in list(orders)] paged_result.set(page, pagesize, count, result) return JsonResponse(paged_result.to_dict())
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())
def get_customers(request): ''' 获取买家列表 ''' page = int(request.GET.get('page', 1)) pagesize = int(request.GET.get('rows', 15)) keyword = request.GET.get('keywords') customers = Customer.objects.filter(seller_id=request.user.id) if keyword: customers = customers.filter(tags__contains=keyword) # 按标签查询 count = customers.count() # 总数 customers = customers.order_by('-add_time')[(page - 1) * pagesize:page * pagesize] result = [item.to_dict() for item in list(customers)] paged_result.set(page, pagesize, count, result) return JsonResponse(paged_result.to_dict())
def get_walletbills(request): '''获取账单列表''' page = int(request.GET.get('page', 1)) pagesize = int(request.GET.get('rows', 15)) keyword = request.GET.get('keywords') bills = FWalletBill.objects.filter(user_id=request.user.id) # if keyword: # bills = bills.filter(billtype__contains=keyword) # 按账单类型查询 count = bills.count() # bills = bills.order_by('-add_time')[(page - 1) * pagesize:page * pagesize] result = [bill.to_dict() for bill in list(bills)] paged_result.set(page, pagesize, count, result) return JsonResponse(paged_result.to_dict())
def get_cashbacktasks(request): ''' 获取任务列表 ''' page = int(request.GET.get('page', 1)) pagesize = int(request.GET.get('rows', 15)) keyword = request.GET.get('keywords') tasks = CashbackTask.objects.filter(seller_id=request.user.id) if keyword: tasks = tasks.filter(name__contains=keyword) # 按名称查询 count = tasks.count() # 总数 tasks = tasks.order_by('-add_time')[(page - 1) * pagesize:page * pagesize] result = [item.to_dict() for item in list(tasks)] paged_result.set(page, pagesize, count, result) return JsonResponse(paged_result.to_dict())
def get_shops(request): ''' 获取店铺列表 ''' page = int(request.GET.get('page', 1)) pagesize = int(request.GET.get('rows', 15)) keyword = request.GET.get('keywords') shops = Shop.objects.filter(seller_id=request.user.id) if keyword: shops = shops.filter(shopname__contains=keyword) # 按店铺名称查询 count = shops.count() # 总数 shops = shops.order_by('-add_time')[(page - 1) * pagesize:page * pagesize] result = [item.to_dict() for item in list(shops)] paged_result.set(page, pagesize, count, result) return JsonResponse(paged_result.to_dict())
def get_goods(request): ''' 获取商品表 ''' page = int(request.GET.get('page', 1)) pagesize = int(request.GET.get('rows', 15)) keyword = request.GET.get('keywords') goods = Goods.objects.filter(seller_id=request.user.id) if keyword: goods = goods.filter(name__contains=keyword) # 按商品名称查询 count = goods.count() # 总数 goods = goods.order_by('-add_time')[(page - 1) * pagesize:page * pagesize] result = [item.to_dict() for item in list(goods)] paged_result.set(page, pagesize, count, result) return JsonResponse(paged_result.to_dict())
def get_account_transfers(request): '''获取充值、提现列表''' page = int(request.GET.get('page', 1)) pagesize = int(request.GET.get('rows', 15)) keyword = request.GET.get('keywords') audits = FAccountTransferAudits.objects.filter(seller_id=request.user.id) # if keyword: # orders = bills.filter(id__contains=keyword) # 按订单号查询 count = audits.count() # audits = audits.order_by('-add_time')[(page - 1) * pagesize:page * pagesize] result = [audit.to_dict() for audit in list(audits)] paged_result.set(page, pagesize, count, result) return JsonResponse(paged_result.to_dict())
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())