Exemple #1
0
    def GET(self):
        req = protocol.QueryBalance_Req(web.input())
        resp = protocol.QueryBalance_Resp()

        if req.userid == 0:
            account = db_helper.query_anonymous_account(req.device_id)
            if account is None:
                logger.info('no such account!! %s' % req.device_id)
                resp.rtn = BillingError.E_NO_SUCH_ACCOUNT
            else:
                resp.balance = account.money
                resp.income = account.money
                resp.outgo = 0
                resp.offerwall_income = account.offerwall_income
                resp.shared_income = 0
        else:
            account = db_helper.query_billing_account(req.userid)
            if account is None:
                logger.info('no such account!! %d' % req.userid)
                resp.rtn = BillingError.E_NO_SUCH_ACCOUNT
            else:
                resp.balance = account.money - account.freeze
                resp.income = account.income
                resp.outgo = account.outgo + account.freeze
                resp.offerwall_income = account.offerwall_income
                resp.shared_income = account.shared_income

        return resp.dump_json()
    def GET(self):
        req  = protocol.QueryBalance_Req(web.input())
        resp = protocol.QueryBalance_Resp()

        if req.userid == 0:
            account = db_helper.query_anonymous_account(req.device_id)
            if account is None:
                logger.info('no such account!! %s' %req.device_id)
                resp.rtn = BillingError.E_NO_SUCH_ACCOUNT
            else:
                resp.balance = account.money
                resp.income = account.money
                resp.outgo = 0
                resp.shared_income = 0
        else:
            account = db_helper.query_billing_account(req.userid)
            if account is None:
                logger.info('no such account!! %d' %req.userid)
                resp.rtn = BillingError.E_NO_SUCH_ACCOUNT
            else:
                resp.balance = account.money - account.freeze
                resp.income = account.income
                resp.outgo = account.outgo + account.freeze
                resp.shared_income = account.shared_income
            
        return resp.dump_json()
Exemple #3
0
    def POST(self):
        req = protocol.ActivateAccount_Req(web.input())
        resp = protocol.ActivateAccount_Resp()

        #userid不能为0
        if req.userid == 0:
            resp.rtn = BillingError.E_INVALID_ACCOUNT
            return resp.dump_json()

        #确认是否已存在billing_account
#        account = db_helper.query_billing_account(req.userid)
#        if account is not None:
#            logger.error('billing account already exists! userid: %d' %req.userid)
#            resp.rtn = BillingError.E_INVALID_ACCOUNT
#            return resp.dump_json()

#确认是否存在anonymous_account
        account = db_helper.query_anonymous_account(req.device_id)
        if account is None:
            logger.error('account not exists!! device_id: %s' % req.device_id)
            resp.rtn = BillingError.E_NO_SUCH_ACCOUNT
            return resp.dump_json()
        elif account.flag != 0:
            logger.error('account already activated, device_id: %s' %
                         req.device_id)
            resp.rtn = BillingError.E_INVALID_ACCOUNT
            return resp.dump_json()

        #进行帐号激活
        db_helper.activate_billing_account(req.userid, account)

        #查询账户余额
        account = db_helper.query_billing_account(req.userid)
        if account is None:
            logger.error('no such account!! %d' % req.userid)
            resp.rtn = BillingError.E_NO_SUCH_ACCOUNT
        else:
            resp.balance = account.money - account.freeze
            resp.income = account.income
            resp.outgo = account.outgo + account.freeze
            resp.shared_income = account.shared_income

        return resp.dump_json()
    def POST(self):
        req  = protocol.ActivateAccount_Req(web.input())
        resp = protocol.ActivateAccount_Resp()

        #userid不能为0
        if req.userid == 0:
            resp.rtn = BillingError.E_INVALID_ACCOUNT
            return resp.dump_json()

        #确认是否已存在billing_account
#        account = db_helper.query_billing_account(req.userid)
#        if account is not None:
#            logger.error('billing account already exists! userid: %d' %req.userid)
#            resp.rtn = BillingError.E_INVALID_ACCOUNT
#            return resp.dump_json()
            
        #确认是否存在anonymous_account
        account = db_helper.query_anonymous_account(req.device_id)
        if account is None:
            logger.error('account not exists!! device_id: %s' %req.device_id)
            resp.rtn = BillingError.E_NO_SUCH_ACCOUNT
            return resp.dump_json()
        elif account.flag != 0:
            logger.error('account already activated, device_id: %s' %req.device_id)
            resp.rtn = BillingError.E_INVALID_ACCOUNT
            return resp.dump_json()
            
        #进行帐号激活
        db_helper.activate_billing_account(req.userid, account)

        #查询账户余额
        account = db_helper.query_billing_account(req.userid)
        if account is None:
            logger.error('no such account!! %d' %req.userid)
            resp.rtn = BillingError.E_NO_SUCH_ACCOUNT
        else:
            resp.balance = account.money - account.freeze
            resp.income = account.income
            resp.outgo = account.outgo + account.freeze
            resp.shared_income = account.shared_income

        return resp.dump_json()