Exemplo n.º 1
0
    def post(self):
        user_id = self.current_user_id
        password = self.get_argument('password', '')
        account = self.get_argument('account', '')
        name = self.get_argument('name', '')
        price = self.get_argument('price', '')

        if user_password_verify(user_id, password):
            a = pay_account_new(user_id, account, name, CID_PAY_ALIPAY)
            try:
                price = float(price)
            except ValueError:
                error = '金额输入错误'
            else:
                price_min = 0.05
                price_max = bank.get(user_id) / 100.

                if price > price_max:
                    error = '提现超出余额'
                elif price < price_min:
                    error = '提现下限为 %s 元' % price_min
                else:
                    t = withdraw_new(price, user_id, CID_PAY_ALIPAY)
                    return self.redirect('/money/drawed/%s' % t.id)
        else:
            error = '密码有误'

        self.render(
            price=price,
            account=account,
            name=name,
            error=error,
        )
Exemplo n.º 2
0
    def post(self):
        user_id = self.current_user_id
        password = self.get_argument('password', '')
        account = self.get_argument('account', '')
        name = self.get_argument('name', '')
        price = self.get_argument('price', '')

        if user_password_verify(user_id, password):
            a = pay_account_new(user_id, account, name, CID_PAY_ALIPAY)
            try:
                price = float(price)
            except ValueError:
                error = '金额输入错误'
            else:
                price_min = 0.05
                price_max = bank.get(user_id) / 100.

                if price > price_max:
                    error = '提现超出余额'
                elif price < price_min:
                    error = '提现下限为 %s 元' % price_min
                else:
                    t = withdraw_new(price, user_id, CID_PAY_ALIPAY)
                    return self.redirect('/money/drawed/%s' % t.id)
        else:
            error = '密码有误'

        self.render(
            price=price,
            account=account,
            name=name,
            error=error,
        )
Exemplo n.º 3
0
 def cent_need(self):
     event = self.event
     current_user_id = self.current_user_id
     cent = event.cent
     bank_cent = bank.get(current_user_id)
     if bank_cent >= cent:
         return 0
     elif bank_cent > 0:
         return cent - bank_cent
     return cent
Exemplo n.º 4
0
 def cent_need(self):
     event = self.event
     current_user_id = self.current_user_id
     cent = event.cent
     bank_cent = bank.get(current_user_id)
     if bank_cent >= cent:
         return 0
     elif bank_cent > 0:
         return cent - bank_cent
     return cent
Exemplo n.º 5
0
    def post(self):
        current_user = self.current_user
        zsite = self.zsite
        request = self.request
        errtip = Errtip()
        zsite_id = self.zsite_id

        url, title = self._arguments()
        amount = self.get_argument('amount', 0)
        alipay_account = self.get_argument('alipay_account', '')

        if not amount:
            errtip.amount = '请输入金额'
        else:
            try:
                amount = float(amount)
            except ValueError:
                errtip.amount = '%s 不是有效的金额'%amount
            else:
                if amount <= 0:
                    errtip.amount = '金额须大于零'
                elif amount >= 9999999:
                    errtip.amount = '金额超出上限'
                else:
                    amount_cent = amount * 100

        if not current_user:
            mail = self.get_argument('mail', '')
            if not mail:
                errtip.mail = '请输入联系邮箱'
            elif not EMAIL_VALID.match(mail):
                errtip.mail = '邮箱无效'
            else:
                user = user_by_mail(mail)
                self.set_cookie('E', mail.strip().lower())
                if not user:
                    user = user_new_by_mail(mail)
                elif user.state >= ZSITE_STATE_APPLY:
                    return self.redirect(
                              '/auth/login?next=%s'%request.uri
                           )
                current_user = user

        if current_user and not errtip:
            subject = '%s 向 %s 捐赠 %.2f 元' % (current_user.name, zsite.name, amount)
            current_user_id = current_user.id
            balance_cent = bank.get(current_user_id)

            def _pay_new(state):
                return pay_new(amount, current_user_id, zsite_id, CID_TRADE_PAY, state).id


            txt = self.get_argument('txt', None)
            secret = self.get_argument('secret', None)

            message = {}

            if title:
                message['title'] = title
            if url:
                message['url'] = url
            if txt:
                message['txt'] = txt
                if secret:
                    message['secret'] = secret




            if balance_cent >= amount_cent:
                o_id = _pay_new(TRADE_STATE_FINISH)
                if message:
                    trade_log.set(o_id, dumps(message))
                pay_notice(o_id)

                return self.redirect('%s/pay/result/%s'%(SITE_HTTP, o_id))
            elif balance_cent > 0:
                subject += '(余额支付 %.2f 元)' % (balance_cent/100.0)
                o_id = _pay_new(TRADE_STATE_NEW)
                amount_cent -= balance_cent
            else:
                o_id = _pay_new(TRADE_STATE_NEW)

            trade_log.set(o_id, dumps(message))

            return_url = '%s/money/alipay_sync' % SITE_HTTP
            notify_url = '%s/money/alipay_async' % RPC_HTTP

            alipay_url = alipay_payurl_with_tax(
                current_user_id,
                amount_cent/100.0,
                return_url,
                notify_url,
                subject,
                alipay_account,
                o_id
            )

            return self.redirect(alipay_url)

        self.render(
            url=url, title=title,
            amount=amount,
            errtip=errtip,
            alipay_account=alipay_account
        )
Exemplo n.º 6
0
    def post(self):
        current_user = self.current_user
        zsite = self.zsite
        request = self.request
        errtip = Errtip()
        zsite_id = self.zsite_id

        url, title = self._arguments()
        amount = self.get_argument('amount', 0)
        alipay_account = self.get_argument('alipay_account', '')

        if not amount:
            errtip.amount = '请输入金额'
        else:
            try:
                amount = float(amount)
            except ValueError:
                errtip.amount = '%s 不是有效的金额' % amount
            else:
                if amount <= 0:
                    errtip.amount = '金额须大于零'
                elif amount >= 9999999:
                    errtip.amount = '金额超出上限'
                else:
                    amount_cent = amount * 100

        if not current_user:
            mail = self.get_argument('mail', '')
            if not mail:
                errtip.mail = '请输入联系邮箱'
            elif not EMAIL_VALID.match(mail):
                errtip.mail = '邮箱无效'
            else:
                user = user_by_mail(mail)
                self.set_cookie('E', mail.strip().lower())
                if not user:
                    user = user_new_by_mail(mail)
                elif user.state >= ZSITE_STATE_APPLY:
                    return self.redirect('/auth/login?next=%s' % request.uri)
                current_user = user

        if current_user and not errtip:
            subject = '%s 向 %s 捐赠 %.2f 元' % (current_user.name, zsite.name,
                                             amount)
            current_user_id = current_user.id
            balance_cent = bank.get(current_user_id)

            def _pay_new(state):
                return pay_new(amount, current_user_id, zsite_id,
                               CID_TRADE_PAY, state).id

            txt = self.get_argument('txt', None)
            secret = self.get_argument('secret', None)

            message = {}

            if title:
                message['title'] = title
            if url:
                message['url'] = url
            if txt:
                message['txt'] = txt
                if secret:
                    message['secret'] = secret

            if balance_cent >= amount_cent:
                o_id = _pay_new(TRADE_STATE_FINISH)
                if message:
                    trade_log.set(o_id, dumps(message))
                pay_notice(o_id)

                return self.redirect('%s/pay/result/%s' % (SITE_HTTP, o_id))
            elif balance_cent > 0:
                subject += '(余额支付 %.2f 元)' % (balance_cent / 100.0)
                o_id = _pay_new(TRADE_STATE_NEW)
                amount_cent -= balance_cent
            else:
                o_id = _pay_new(TRADE_STATE_NEW)

            trade_log.set(o_id, dumps(message))

            return_url = '%s/money/alipay_sync' % SITE_HTTP
            notify_url = '%s/money/alipay_async' % RPC_HTTP

            alipay_url = alipay_payurl_with_tax(current_user_id,
                                                amount_cent / 100.0,
                                                return_url, notify_url,
                                                subject, alipay_account, o_id)

            return self.redirect(alipay_url)

        self.render(url=url,
                    title=title,
                    amount=amount,
                    errtip=errtip,
                    alipay_account=alipay_account)