예제 #1
0
def transferMoney(debitCardNo,creditCardNo,money):
    """
    转账数据接口
    debitCardNo  借方账户  金额减少
    creditCardNo 贷方账户  金额增多
    """
    debitUserDict = getUserInfosByCarNo(debitCardNo)
    creditUserDict = getUserInfosByCarNo(creditCardNo)

    debitAccount = debitUserDict.get('money',0)
    creditAccount = creditUserDict.get('money',0)

    if decimal.Decimal(debitAccount) - decimal.Decimal(money) < 0 :
        print u"借方%s 余额不足" % (creditCardNo)
        return False

    debitNewMoney = decimal.Decimal(debitAccount) - decimal.Decimal(money)
    debitNewMoney = round(debitNewMoney,2)
    creditNewMoney = decimal.Decimal(creditAccount) + decimal.Decimal(money)
    creditNewMoney = round(creditNewMoney,2)

    if not updateData(debitCardNo,{'money':debitNewMoney}) :
        print u"更新金额失败"
        return False
    if not updateData(creditCardNo,{'money':creditNewMoney}):
        print u"更新金额失败"
        updateData(debitCardNo,{'money':debitAccount})
        return False

    flow.creditFlow(creditCardNo,abs(decimal.Decimal(money)))
    flow.debitFlow(debitCardNo,abs(decimal.Decimal(money)))

    print u"账号 %s 成功转入 %s 元,共计%s元 " % (creditCardNo,money,str(creditNewMoney))
    print u"账号 %s 成功转出 %s 元,共计%s元 " % (debitCardNo,money,str(debitNewMoney))
    return True
예제 #2
0
def transferMoney(debitCardNo, creditCardNo, money):
    """
    转账数据接口
    debitCardNo  借方账户  金额减少
    creditCardNo 贷方账户  金额增多
    """
    debitUserDict = getUserInfosByCarNo(debitCardNo)
    creditUserDict = getUserInfosByCarNo(creditCardNo)

    debitAccount = debitUserDict.get('money', 0)
    creditAccount = creditUserDict.get('money', 0)

    if decimal.Decimal(debitAccount) - decimal.Decimal(money) < 0:
        print u"借方%s 余额不足" % (creditCardNo)
        return False

    debitNewMoney = decimal.Decimal(debitAccount) - decimal.Decimal(money)
    debitNewMoney = round(debitNewMoney, 2)
    creditNewMoney = decimal.Decimal(creditAccount) + decimal.Decimal(money)
    creditNewMoney = round(creditNewMoney, 2)

    if not updateData(debitCardNo, {'money': debitNewMoney}):
        print u"更新金额失败"
        return False
    if not updateData(creditCardNo, {'money': creditNewMoney}):
        print u"更新金额失败"
        updateData(debitCardNo, {'money': debitAccount})
        return False

    flow.creditFlow(creditCardNo, abs(decimal.Decimal(money)))
    flow.debitFlow(debitCardNo, abs(decimal.Decimal(money)))

    print u"账号 %s 成功转入 %s 元,共计%s元 " % (creditCardNo, money,
                                       str(creditNewMoney))
    print u"账号 %s 成功转出 %s 元,共计%s元 " % (debitCardNo, money, str(debitNewMoney))
    return True
예제 #3
0
def updateMoney(cardNo, money):
    """
    更新账户余额
    """
    userDict = getUserInfosByCarNo(cardNo)
    oldMoney = userDict.get('money', 0)
    newMoney = decimal.Decimal(oldMoney) + decimal.Decimal(money)
    newMoney = round(decimal.Decimal(newMoney), 2)
    if newMoney < 0.00:
        print u"余额不足"
        return False

    if not updateData(cardNo, {'money': newMoney}):
        print u"更新金额失败"
        return False

    #写流水
    if decimal.Decimal(money) > 0:
        flow.creditFlow(cardNo, abs(decimal.Decimal(money)))
    else:
        flow.debitFlow(cardNo, abs(decimal.Decimal(money)))

    print u"账号 %s 成功存储 %s 元,共计%s元 " % (cardNo, money, str(newMoney))
    return True
예제 #4
0
def updateMoney(cardNo,money):
    """
    更新账户余额
    """
    userDict = getUserInfosByCarNo(cardNo)
    oldMoney = userDict.get('money',0)
    newMoney = decimal.Decimal(oldMoney)+decimal.Decimal(money)
    newMoney = round(decimal.Decimal(newMoney),2)
    if newMoney < 0.00:
        print u"余额不足"
        return False

    if not updateData(cardNo,{'money':newMoney}):
        print u"更新金额失败"
        return False

    #写流水
    if decimal.Decimal(money) > 0:
       flow.creditFlow(cardNo,abs(decimal.Decimal(money)))
    else:
       flow.debitFlow(cardNo,abs(decimal.Decimal(money)))

    print u"账号 %s 成功存储 %s 元,共计%s元 " % (cardNo,money,str(newMoney))
    return True