Пример #1
0
    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')
Пример #2
0
 def test_zuser_pay(self):
     '''
     测试付款
     :return:
     '''
     res = user_pay(1, 1, 1)
     self.assertTrue(res)
     res = user_pay(10, 1, 10)
     self.assertFalse(res)
Пример #3
0
 def test_zuser_pay(self):
     '''
     测试付款
     :return:
     '''
     res = user_pay(1,1,1)
     self.assertTrue(res)
     res = user_pay(10,1,10)
     self.assertFalse(res)
Пример #4
0
    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')