def amt_prepay(mch_prepay, mch_accnt, amount, Type):
     """准备金计算"""
     amt = SqlSave.select_remain_amt(mch_prepay)  # 根据商户号查询余额
     set = SqlSave.select_settled_amt(mch_accnt)  # 查询结算余额
     set_amt = ((0, ), ) if int(set[0][0]) <= 0 else set
     fix_amount = SqlSave.select_fix_poundage()  # 查询手续费
     if Type:
         result_amt = int(amt[0][0]) - (int(amount) - int(set_amt[0][0]) -
                                        int(fix_amount))
         return result_amt
     return amt[0][0]
 def amt_mch_accnt(mch, amount, Type):
     """子商户或分润计算  fix 是否有手续费,type是否为预期结果"""
     amt = SqlSave.select_remain_amt(mch)
     set_amt = SqlSave.select_settled_amt(mch)
     if Type:
         result_amt = int(amt[0][0]) - int(amount)
         result_set_amt = int(set_amt[0][0]) - int(amount)
         if int(set_amt[0][0]) <= 0:
             return result_amt, set_amt[0][0]
         if int(result_set_amt) < 0:
             return result_amt, 0
         return result_amt, result_set_amt
     return amt[0][0], set_amt[0][0]
 def amt_mch_profit(mch, amount, Type):
     """分润商户增加手续费计算"""
     amt = SqlSave.select_remain_amt(mch)
     set_amt = SqlSave.select_settled_amt(mch)
     fix_amount = SqlSave.select_fix_poundage()  # 查询手续费
     if Type:
         result_amt = int(amt[0][0]) + int(fix_amount)
         result_set_amt = int(set_amt[0][0]) + int(fix_amount)
         print('查询出来的amt::%s' % amt)
         print('查询出来的可结算余额::%s' % set_amt)
         print('传入的提现金额::%s' % amount)
         print('子商户或分润计算 amt+amount%s' % result_amt)
         return result_amt, result_set_amt
     return amt[0][0], set_amt[0][0]