def showbusiness(request): try: page = int(request.GET.get('page', 1)) pagecount = int(request.GET.get('pagecount', 10)) startdatetime=request.GET.get('startdatetime') enddatetime=request.GET.get('enddatetime') icontains=request.GET.get('icontains') except: return JsonResponse({ 'status': 'false', 'msg': '参数不正确', }) online_users=User.objects.filter(status=User.STATUS_ONLINE).filter(type=User.TYPE_BUSINESS) buss=Business.objects.filter(user_id__in=online_users) type=request.GET.get('type') if type!=None: buss=buss.filter(type=type) if icontains!=None: buss=buss.filter(name__icontains=icontains) Sell.objects.filter(goods__in=Goods.objects.filter(business__in=buss)) bus_list=[] for bus in buss: b=bus.get_data_dic() golist=Goods.objects.filter(business=bus) sells=Sell.objects.filter(goods__in=golist) if startdatetime!=None: sells=sells.filter(startdatetime__lte=startdatetime).filter(enddatetime__gte=enddatetime) goods=sells.aggregate(Min('price')) if goods['price__min']!=None: b['minprice']=goods['price__min'] bus_list.append(b) context = {'status': 'OK',} context.update(pageUtil(page,pagecount,bus_list)) return JsonResponse(context)
def showgoods(request): try: page = int(request.GET.get('page', 1)) pagecount = int(request.GET.get('pagecount', 10)) startdatetime=request.GET.get('startdatetime') enddatetime=request.GET.get('enddatetime') bus_id = request.GET.get('business_id') except: return JsonResponse({ 'status': 'false', 'msg': '参数不正确', }) goodss=Goods.objects.filter(business_id=bus_id) print('len(goodss)',len(goodss)) sells=Sell.objects.filter(goods__id__in=goodss) if startdatetime!=None: sells=sells.filter(startdatetime__lte=startdatetime).filter(enddatetime__gte=enddatetime) print('len(sells),',len(sells)) se_list=[] for se in sells: god=se.goods.getdatadic() god.update(se.getdatadic()) se_list.append(god) context={'status':"OK"} context.update(pageUtil(page,pagecount,se_list)) return JsonResponse(context)
def showrecommend(request): try: page = int(request.GET.get('page', 1)) pagecount = int(request.GET.get('pagecount', 10)) except: return JsonResponse({ 'status': 'false', 'msg': '参数不正确', }) goods_insell=Sell.objects.all().values('goods').distinct() goods_inreserve=Reserve.objects.all().values('goods').distinct() res=Reserve.objects.filter(goods__in=goods_inreserve.intersection(goods_insell)) tuijian_list=res.annotate(count=Count('goods')).values('goods', 'goods_count').distinct().order_by('-goods_count') tjgoods=[] for i in tuijian_list: tjgoods.append(i['goods']) print(tjgoods) tjgoods_list=Goods.objects.filter(id__in=tjgoods) tjgoods_list=tjgoods_list.annotate(min=Min('sell__price')) tjlist=[] for tj in tjgoods_list: tjdic={} tjdic.update(tj.getdatadic()) tjdic.update({'minprice':tj.min}) tjlist.append(tjdic) context={'status':"OK",} context.update(pageUtil(page,pagecount,tjlist)) return JsonResponse(context)
def showallvofficers(request): try: page = int(request.GET.get('page', 1)) pagecount = int(request.GET.get('pagecount', 10)) name = request.GET.get('name') except: return JsonResponse({ 'status': 'false', 'msg': '参数不正确', }) vos = Vofficer.objects.all() volist = [] for vo in vos: volist.append(vo.vuser_id) vuser = User.objects.filter(type=User.TYPE_VERIFICATION) kuser = vuser.exclude(id__in=volist) if name != None: kuser = kuser.filter(username__icontains=name) ulist = [] for user in kuser: ulist.append(user.to_dic()) context = {'status': 'OK'} context.update(pageUtil(page, pagecount, ulist)) return JsonResponse(context)
def showorders(request): try: page = int(request.GET.get('page', 1)) pagecount = int(request.GET.get('pagecount', 10)) order_status=request.GET.get('order_status') except: return JsonResponse({ 'status': 'false', 'msg': '参数不正确', }) user=request.session.get('user') orders=Order.objects.filter(business_id=user['id']).order_by('-order_time') if order_status!=None: orders=orders.filter(orderstatus=order_status) olist=[] for od in orders: odic={} odic['order_id']=od.id.hex odic['order_time']=od.order_time odic['receiver']=od.receiver odic['phone']=od.phone odic['address']=od.address odic['remarks']=od.remarks odic['orderstatus']=od.orderstatus olist.append(odic) context={ 'status':"OK" } context.update(pageUtil(page,pagecount,olist)) return JsonResponse(context)
def showsells(request): try: page = int(request.GET.get('page', 1)) pagecount = int(request.GET.get('pagecount', 10)) goods_id=request.GET.get('goods') sellout=int(request.GET.get('sellout'),0) except: return JsonResponse({ 'status': 'false', 'msg': '参数不正确', }) sslist=Sell.objects.filter(goods=goods_id) if sellout==1: sslist=sslist.filter(surplus__gt=0) elif sellout==2: sslist=sslist.filter(surplus=0) selllist = sslist.order_by('startdatetime') selist=[] for se in selllist: # if se.enddatetime!=None: # print(se.enddatetime) # print(se.enddatetime>timezone.now()) # print(timezone.now()) # if timezone.now()>se.enddatetime: # se.delete() # continue selist.append(se.getdatadic()) context={'status':'OK'} context.update(pageUtil(page,pagecount,selist)) return JsonResponse(context)
def showgoodslist(request): try: page = int(request.GET.get('page', 1)) pagecount = int(request.GET.get('pagecount', 10)) except: return JsonResponse({ 'status': 'false', 'msg': '参数不正确', }) goodslist = Goods.objects.filter(business=request.session.get('user')['id']).order_by('-name') gdlist=[] for gd in goodslist: gdlist.append(gd.getdatadic()) context={"status":"OK"} context.update(pageUtil(page,pagecount,gdlist)) return JsonResponse(context)
def showPackages(request): try: page=int(request.GET.get('page',1)) pagecount=int(request.GET.get('pagecount',10)) pkgname=request.GET.get("pkgname") except: return JsonResponse({ 'status':'false', 'msg':'参数不正确', }) context={"status":"OK"} tpks=Tpackage.objects.all() if pkgname!=None: tpks=tpks.filter(name__icontains=pkgname) tplist=[] for tpk in tpks: tplist.append(tpk.todic()) context.update(pageUtil(page, pagecount, tplist)) return JsonResponse(context)
def showorderlist(request): try: page = int(request.GET.get('page', 1)) pagecount = int(request.GET.get('pagecount', 10)) order_staus=request.GET.get("order_status") except: return JsonResponse({ 'status': 'false', 'msg': '参数不正确', }) tourist=Tourist.objects.get(sessionid=request.COOKIES.get('session_id')) ords=Order.objects.filter(tourist=tourist).order_by('-order_time',) if order_staus!=None: ords=ords.filter(orderstatus=order_staus) ordlist=[] for ord in ords: a_ord={} a_ord['order_id']=ord.id.hex a_ord['order_time']=ord.order_time a_ord['business']=ord.business.user_id.hex a_ord['business_name']=ord.business.name a_ord['totalprice']=ord.totalprice a_ord['order_status']=ord.orderstatus goods_list=[] goodss=Reserve.objects.filter(order=ord) for res in goodss: mres={} mres['name']=res.goods_name mres['price']=res.goods_price mres['count']=res.goods_count mres['pic']=res.goods_pic.url goods_list.append(mres) a_ord['good_list']=goods_list ordlist.append(a_ord) context = { 'status': 'OK', } context.update(pageUtil(page,pagecount,ordlist)) return JsonResponse(context)
def showvofficers(request): try: page = int(request.GET.get('page', 1)) pagecount = int(request.GET.get('pagecount', 10)) except: return JsonResponse({ 'status': 'false', 'msg': '参数不正确', }) vos = Vofficer.objects.filter( business_id=request.session.get('user')['id']) volist = [] for vo in vos: volist.append(vo.vuser_id) vuser = User.objects.filter(type=User.TYPE_VERIFICATION) kuser = vuser.filter(id__in=volist) ulist = [] for user in kuser: ulist.append(user.to_dic()) context = {'status': 'OK'} context.update(pageUtil(page, pagecount, ulist)) return JsonResponse(context)
def showUserList(request): try: page = int(request.GET.get('page', 1)) pagecount = int(request.GET.get('pagecount', 10)) mtype = request.GET.get("type") username = request.GET.get("username") except: return JsonResponse({ 'status': 'false', 'msg': '参数不正确', }) user_list = User.objects.filter(~Q(type=0)).order_by('username') if mtype != None and mtype == '2' or mtype == '1': user_list = user_list.filter(type=mtype) if username != None: user_list = user_list.filter(username__icontains=username) ulist = [] for user in user_list: ulist.append(user.to_dic()) context = {'status': 'OK'} context.update(pageUtil(page, pagecount, ulist)) return JsonResponse(context)