Пример #1
0
def orderNew(request):
	code=judge(request)
	if code=="success":
		jsons=jsonFromRequest(request)
		#jsons={"username":"******","password":"******","shop_cart":[{"product_id":1,"number":3},{"product_id":2,"number":4}]}
		username=jsons['username']
		password=jsons['password']
		code=getuser(username,password)
		if code==0:
			prcart=jsons['shop_cart']
			times=getLocaltime()
			order_no=getOrder_no()
			total=0
			lists=[]
			for x in range(len(prcart)):
				products=product.objects.filter(id=prcart[x]['product_id'])
				datas=getProductdict(products[0])
				datas['price']=getprice(username,products[0].id)
				orders=order(product_id=datas['id'],original_url=datas['img_url'],original_name=datas['name'],
					original_price=datas['price'],original_info=datas['info'],status=1,username=username,number=prcart[x]['number'],
					order_no=order_no,time=times)
				orders.save()
				datas['number']=prcart[x]['number']
				lists.append(datas)
				total=total+datas['price']*prcart[x]['number']
			return responseWithJsonObject({"result":0,"order_no":order_no,"status":1,"time":times,"total":total,"product":lists})

		else:
			return getBackdata(code)
	else:
		return code
Пример #2
0
def index(request):
	code=judge(request)
	if code=="success":
		jsons=jsonFromRequest(request)
		username=jsons['username']
		password=jsons['password']
		code=getuser(username,password)
		if code==0 or (username==None or password==None):
			adURL=ad_url.objects.all()
			promotions=promotion.objects.all()
			products=product.objects.filter(id=promotions[0].product_id)
			lists=[]
			for data in adURL:
				datas={}
				datas['img_url']="http://gelange.szzbmy.com:9040/media/"+str(data.ad_path)
				datas['advertise_id']=data.id
				lists.append(datas)
			prices=[dict(price=getpricelist(i,promotions[0].product_id),level=i) for i in range(5)]
			if username==None or password==None:
				levels=0
			else:
				levels=getUserkind(username)
			return responseWithJsonObject({"user_level":levels,"result":0,"promotion":{"id":promotions[0].id,"img_url":"http://gelange.szzbmy.com:9040/media/"+str(products[0].url),"name":products[0].name,"price_list":prices,"info":products[0].info,"promotion_time":getTimestamp(str(promotions[0].time))},"ad_list":lists})
		else:
			getBackdata(code)
	else:
		return code
Пример #3
0
def adList(request):
	code=judge(request)
	if code=="success":
		jsons=jsonFromRequest(request)
		#jsons={"advertise_id":"1","username":"******","password":"******"}
		username=jsons['username']
		password=jsons['password']
		ad_id=jsons['advertise_id']
		AD=ad_list.objects.filter(ad_id=ad_id)
		lists=[]
		for ad in AD:
			products=product.objects.filter(id=ad.product_id)
			datas=getProductdict(products[0])
				#datas['price']=products[0].price
			datas['price_list']=getGrads(products[0])
			lists.append(datas)
		# if username==None or password.strip==None:
		# 	for ad in AD:
		# 		products=product.objects.filter(id=ad.product_id)
		# 		datas=getProductdict(products[0])
		# 		#datas['price']=products[0].price
		# 		datas['price']=getGrads(products)
		# 		lists.append(datas)
		# else:
		# 	for ad in AD:
		# 		products=product.objects.filter(id=ad.product_id)
		# 		datas=getProductdict(products[0])
		# 		datas['price']=getprice(username,products[0].id)
		# 		lists.append(datas)
		return responseWithJsonObject({"result":0,"product":lists})
	else:
		return code
Пример #4
0
def collections(request):
	code=judge(request)
	if code=="success":
		jsons=jsonFromRequest(request)
		#jsons={"username":"******","password":"******"}
		username=jsons['username']
		password=jsons['password']
		code=getuser(username,password)
		if code==0:
			lists=getCollection(username)
			return responseWithJsonObject({"result":0,"product":lists})		
		else:
			return getBackdata(code)
	else:
		return code
Пример #5
0
def lists(request):
	code=judge(request)
	if code=="success":
		jsons=jsonFromRequest(request)
		#jsons={"kind":1,"username":"******","password":"******"}
		username=jsons['username']
		password=jsons['password']
		code=getuser(username,password)
		if code==0 or (username==None or password==None):
			kind=jsons['kind']
			products=product.objects.filter(kind=kind)
			lists=getProductlist(products)
			return	responseWithJsonObject({"result":0,"product":lists})
		else:
			return getBackdata(code)
	else:
		return code
Пример #6
0
def search(request):
	code=judge(request)
	if code=="success":
		jsons=jsonFromRequest(request)
	#jsons={"name_id":"12","username":"******","password":"******"}
		username=jsons['username']
		password=jsons['password']
		name_id=jsons['name_id']
		code=getuser(username,password)
		if code==0 or (username==None or password==None):
			if name_id.isdigit():
				products=product.objects.filter(id=int(name_id))
			else:
				products=product.objects.filter(name__contains=name_id)
			lists=getProductlist(products)
			return responseWithJsonObject({"result":0,"product":lists})
		else:
			return getBackdata(code)
	else:
		return code
Пример #7
0
def orderConfirm(request):
	code=judge(request)
	if code=="success":
		jsons=jsonFromRequest(request)
		#jsons={"username":"******","password":"******","result":1,"order_no":"bfz3uaqctq"}
		username=jsons['username']
		password=jsons['password']
		code=getuser(username,password)
		if code==0:
			result=jsons['result']
			order_no=jsons['order_no']
			if result==1:
				order.objects.filter(order_no=order_no).update(status=2)
			if result==2:
				order.objects.filter(order_no=order_no).update(status=3)
			return responseWithJsonObject({"result":1})
		else:
			return getBackdata(code)
	else:
		return code
Пример #8
0
def orderSelect(request):
	code=judge(request)
	if code=="success":
		jsons=jsonFromRequest(request)
		#jsons={"username":"******","password":"******"}
		username=jsons['username']
		password=jsons['password']
		code=getuser(username,password)
		if code==0:
			orders=order.objects.filter(username=username)
			orderList=[]
			for r in orders:
				p=[]
				datas={}
				i=list(orders).index(r)
				while i<len(orders):
					o=orders[i]
					if (not "order_no" in datas):
						data={}
						if jude_or(orderList,o.order_no):
							datas['order_no']=o.order_no
							datas['status']=o.status
							datas['time']=getTimestamp(o.time)
							data=getData(o)
							p.append(data)
							datas['product']=p
						else:
							break
					else:
						if datas['order_no']==o.order_no:
							data=getData(o)
							p.append(data)
							datas['product']=p
					i=i+1
				if not datas=={}:
					orderList.append(datas)
			return responseWithJsonObject({"order":orderList})
		else:
			return getBackdata(code)
	else:
		return code
Пример #9
0
def removeCollection(request):
	code=judge(request)
	if code=="success":
		jsons=jsonFromRequest(request)
		#jsons={"product_id":2,"username":"******","password":"******"}
		username=jsons['username']
		password=jsons['password']
		code=getuser(username,password)
		if code==0:
			product_id=jsons['product_id']
			collections=collection.objects.filter(username=username,product_id=product_id)
			if collections:
				collection.objects.filter(username=username,product_id=product_id).delete()
				lists=getCollection(username)
				return responseWithJsonObject({"result":0,"product":lists})
			else:
				return responseWithJsonObject({"result":5})
		else:
			return getBackdata(code)
	else:
		return code