def post(self, *args, **kwargs): product_id = self.get_argument(u"product_id") buy_count = self.get_argument(u"buyCount") user_id = self.get_secure_cookie(u"user_id") product_id = int(product_id) buy_count = int(buy_count) user_id = int(user_id) #首先获得商品的单价,再获得用户所有的支付宝账户 #print u'用户购买' accounts = get_user_accounts(user_id) #用户当前剩余金额 rem =0 product = get_product(product_id) for account in accounts: if account.balance < product.price*buy_count: pass else: by_transaction( user_id,product_id,buy_count ) user_pay(user_id,account.id,product.price*buy_count) self.redirect('/buy_history') break self.render('addAccount.html')
def get(self, *args, **kwargs): user_id = self.get_secure_cookie("user_id") user_id = int(user_id) shopping_cars = get_car(user_id) #下面语句对返回的shopping_cars 执行了预处理 #目的是为了渲染页面,保持页面的简洁 #构造了一个字典,字典的 key 是物品的id #value 为 物品的个数 tmp = dict() for shopping_car in shopping_cars: tmp[shopping_car.product_id]=( tmp[shopping_car.product_id]+1 ) if tmp.has_key(shopping_car.product_id) else 1 productsd = dict() for key in tmp: productsd[key]=get_product(key) self.render("car.html", products= tmp,productsd=productsd)
def get(self, *args, **kwargs): user_id = self.get_secure_cookie("user_id") user_id = int(user_id) shopping_cars = get_car(user_id) #下面语句对返回的shopping_cars 执行了预处理 #目的是为了渲染页面,保持页面的简洁 #构造了一个字典,字典的 key 是物品的id #value 为 物品的个数 tmp = dict() for shopping_car in shopping_cars: tmp[shopping_car.product_id] = (tmp[shopping_car.product_id] + 1) if tmp.has_key( shopping_car.product_id) else 1 productsd = dict() for key in tmp: productsd[key] = get_product(key) self.render("car.html", products=tmp, productsd=productsd)
def post(self, *args, **kwargs): product_id = self.get_argument(u"product_id") buy_count = self.get_argument(u"buyCount") user_id = self.get_secure_cookie(u"user_id") product_id = int(product_id) buy_count = int(buy_count) user_id = int(user_id) #首先获得商品的单价,再获得用户所有的支付宝账户 #print u'用户购买' accounts = get_user_accounts(user_id) #用户当前剩余金额 rem = 0 product = get_product(product_id) for account in accounts: if account.balance < product.price * buy_count: pass else: by_transaction(user_id, product_id, buy_count) user_pay(user_id, account.id, product.price * buy_count) self.redirect('/buy_history') break self.render('addAccount.html')