Exemplo n.º 1
0
def modifyMyDetailInfo(request):
    """
    修改我的信息 接口
    :param request:
    :return:
    """
    user_service.modifyMyDetailInfo('abc','mingzi','女','1998-10-11','1212312','*****@*****.**','中关村南大街')
    context = user_service.getMyDetailInfo('abc')
    return render(request, 'DiningServer/userInfoPage.html', context)
Exemplo n.º 2
0
def getMyDetailInfoPage(request):
    """
    获取我的相信信息接口
    :param request:
    :return:
    """
    # 获取userid
    # 使用ensure_ascii = False   否则的话中文会只显示编码 不显示汉字
    context = user_service.getMyDetailInfo('abc')
    print(context)
    return render(request, 'DiningServer/userInfoPage.html', context)
Exemplo n.º 3
0
def gotoOrderPage(request):
    """
    点击去下单 跳转到的页面
    :param request:
    :return:
    """
    user = user_service.getMyDetailInfo('abc')
    meals = meal_service.getMealsAndCount(request.POST)
    count = 0
    sum = 0
    print(meals)
    buy_meals = meals['meal_list']
    print(buy_meals)
    # 获取sum和count
    for meal in buy_meals:
        print(meal)
        count += int(meal['buy_count'])
        sum += int(meal['buy_count']) * float(meal['meal_price'])
    times = time_service.getTimeOption()
    print(count, sum)
    context = {'meals':meals, 'user':user, 'times': times, 'count': count, 'sum':sum}
    print(context)
    return render(request, 'DiningServer/shopping.html', context)
Exemplo n.º 4
0
def createOrder(request):
	"""
	创建订单接口
	:param request:
	:return:
	"""
	openid = request.session.get('openid','openiddefault')
	user = user_service.getMyDetailInfo(openid)

	if not user['username'] or not user['phone'] or not user['user_location']:
		return HttpResponseRedirect("/DiningServer/modifyMyDetailInfo/")

	if request.method == 'GET':
		bill_id = request.GET.get('bill_id',None)
		sum = request.GET.get('sum',None)
	else:
		bill_id = request.POST.get('bill_id',None)
		sum = request.POST.get('sum',None)
	
	print('bill_id in create:',bill_id)
	print('sum in create:',sum)
	try:
		bill = TblBill.objects.filter(id=bill_id)[0]
	except:
		return render_to_response('DiningServer/404.html')

	if request.method == 'POST':
		print('POST send_time:',request.POST.get('send_time',''))
		# bill.bill_content = request.POST.get('remarks','')
		bill.ensure_send_time = request.POST.get('send_time','')
		bill.save()
		
	# (yuan,fen) = str('%.2f' % float(sum)).split('.')
	(yuan,fen) = str('%.2f' % float(bill.all_fee)).split('.')
	print(yuan,fen)

	body = 'Xiangeqing WeiDao'    #'家家长沙米粉'.encode('utf-8','xmlcharrefreplace').decode('latin1')
	out_trade_no = str(bill_id).replace('-','')
	total_fee = int(yuan)*100 + int(fen)
	spbill_create_ip = request.META.get('REMOTE_ADDR', "120.25.151.185")
	notify_url = 'http://xiangeqwd.9xi.com/notifyPay/'

	openid = request.session.get('openid','openiddefault')
	print('openid in createOrder:',openid)
	pay_response = weixin_service.callOrderAPI(request,body,out_trade_no,total_fee,spbill_create_ip,notify_url,openid)
	try:
		prepay_id = pay_response.get('prepay_id','')
	except:
		prepay_id = 'wx201603021557412c3168e0b20043476737'
	js_params = weixin_service.genJsAPIParams(prepay_id)

	TblBill.objects.filter(id=bill_id).update(prepay_id=prepay_id)

	context = {
			'bill_id':bill_id,
			'sum':sum,
			'all_fee':bill.all_fee,

			'prepay_id':prepay_id,
			'appId':WC_PAY_APPID,
			'openid':openid,
			'nonceStr':js_params.get('nonceStr',''),
			'timeStamp':js_params.get('timeStamp',''),
			'package':"prepay_id=%s" % prepay_id,
			'signType':js_params.get('signType',''),
			'paySign':js_params.get('paySign',''),
			}

	return render_to_response("DiningServer/createOrder.html", context,context_instance=RequestContext(request))
Exemplo n.º 5
0
def gotoOrderPage(request):
	"""
	点击去下单 跳转到的页面
	:param request:
	:return:
	"""
	openid = request.session.get('openid','openiddefault')
	print('openid in shopping:',openid)
	user = user_service.getMyDetailInfo(openid)
	
	house_id = request.session.get('house_id','houseiddefault')

	bill = order_service.createOrder(request)
	time_now = time.strftime(SERVER_TIME_FORMAT, time.localtime(time.time()))
	meals = meal_service.getMealsAndCount(request.POST)

	count = 0
	sum = 0
	buy_meals = meals['meal_list']
	for meal in buy_meals:
		print('meal in buy_meal:\n',meal)
		count += int(meal['buy_count'])
		sum += int(meal['buy_count']) * float(meal['meal_price'])

		# 保存订单中的商品
		bill_meal = TblBillMeal()
		bill_meal.id = uuid4()
		bill_meal.meal_id = meal['meal_id']
		bill_meal.bill_id = bill.id
		bill_meal.house_id = bill.house_id
		bill_meal.openid = bill.openid
		bill_meal.user_id = user['id']

		bill_meal.add_time = time_now
		bill_meal.meal_name = meal['meal_name']
		bill_meal.meal_url = meal['avatar_url']
		bill_meal.meal_price = float(meal['meal_price'])
		bill_meal.buy_count = int(meal['buy_count'])
		bill_meal.save()

		try:
			meal_in_house = TblMealInHouse.objects.filter(house_id=house_id,meal_id=meal['meals_id'])[0]
			meal_in_house.sold_count += int(meal['buy_count'])
			meal_in_house.save()
		except:
			pass

	print("count:",count)
	print("sum:",sum)
	print("bill_id:",bill.id)
	print("order Done!!!")

	delivery_fee = float(0.01)
	# delivery_fee = order_service.getDeliveryFee(request, sum)
	total_fee = sum + delivery_fee
	times = time_service.getTimeOption()

	context = {'meals':meals, 'user':user, 'times': times, 'count': count, 'sum':sum, 'delivery_fee':delivery_fee, 'total_fee':total_fee, 'bill_id':bill.id}

	# touser = openid
	# template_id = 'HRECa6Gb9oRqcHS-G7krnT5_bqBsOgYJsKwga52O0xE'
	# url = ''

	# tpl_msg_data.accept_data['keyword1']['value'] = '家家长沙米粉'
	# tpl_msg_data.accept_data['keyword2']['value'] = str(time_now)
	# tpl_msg_data.accept_data['keyword3']['value'] = '详情见商家小票'
	# tpl_msg_data.accept_data['keyword4']['value'] = all_fee
	# data = tpl_msg_data.accept_data

	# weixin_service.sendTplMsg(request, touser, template_id, url, data)

	return render(request, 'DiningServer/shopping.html', context)