def case_withdraw(self, data, login_data, db: HandleMysql): """ 账户提现业务场景 :param data: 提现接口所需参数 :param login_data: 登录响应结果提取 :param db: 数据库连接对象 :return: """ # 替换数据 data = self.template(data, {'member_id': login_data['member_id'], 'mobile_phone': login_data['mobile_phone']}) # logger.info(f'替换后的数据:{data}') if data['sql']: # 充值前账户余额 try: before_balance: Decimal = db.get_one(data['sql'])[0] except Exception as e: logger.error('报错了') logger.exception(e) raise e # logger.info(f'充值前账户余额:{before_balance}') withdraw_response = self.withdraw_api(data['member_id'], data['amount'], login_data['token']) res = withdraw_response.json() # 充值后账户余额 after_balance: Decimal = db.get_one(data['sql'])[0] # logger.info(f'充值后账户余额:{after_balance}') withdraw: Decimal = before_balance - after_balance # logger.info(f'提现后,数据库金额变化差值:{withdraw}') res['withdraw'] = withdraw else: recharge_response = self.recharge_api(data['member_id'], data['amount'], login_data['token']) res = recharge_response.json() return res
def case_withdraw(self, data, login_data, db: HandleMysql): """ 账户提现业务场景 :param data: 提现接口所需参数 :param login_data: 登录响应结果提取 :param db: 数据库连接对象 :return: """ # 替换数据 data = self.template(data, {'member_id': login_data['member_id'], 'mobile_phone': login_data['mobile_phone']}) if data['sql']: # 充值前账户余额 before_balance: Decimal = db.get_one(data['sql'])[0] withdraw_response = self.withdraw_api(data['member_id'], data['amount'], login_data['token']) res = withdraw_response.json() # 充值后账户余额 after_balance: Decimal = db.get_one(data['sql'])[0] withdraw: Decimal = before_balance - after_balance res['withdraw'] = withdraw else: recharge_response = self.recharge_api(data['member_id'], data['amount'], login_data['token']) res = recharge_response.json() return res
def case_audit(self, data, login_data, db: HandleMysql = None): data = self.template(data, {'member_id': login_data['member_id']}) # 添加项目 add_loan_res = self.add_loan_api(**data['add_loan_json'], token=login_data['token']).json() loan_id = jsonpath(add_loan_res, '$..id')[0] # 审核 audit_res = self.audit_loan_api(loan_id, data['audit_json']['approved_or_not']).json() audit_res['loan_id'] = loan_id if 'again' in data.keys(): audit_res = self.audit_loan_api(loan_id, data['audit_json']['approved_or_not']).json() if 'sql' in data.keys() and data['sql']: data = self.template(data, {'loan_id': loan_id}) status = db.get_one(data['sql'])[0] audit_res['status'] = status return audit_res