def post(self): """ 商户列表 :return: """ merchant_list = list() merchants = MerchantInfo.query_all() all_configs = MerchantFeeConfig.query_all() all_configs = MerchantFeeConfig.filter_latest_items(all_configs) merchant_all_configs = defaultdict(list) for fee in all_configs: merchant_all_configs[fee.merchant].append(fee) for merchant in merchants: fee_configs = merchant_all_configs.get(merchant.merchant) if not fee_configs: continue withdraw_fees = [x for x in fee_configs if x.payment_way == PayTypeEnum.WITHDRAW] recharge_fees = [x for x in fee_configs if x.payment_way == PayTypeEnum.DEPOSIT] withdraw_desc = '' cost_type = None if withdraw_fees: withdraw_desc = withdraw_fees[0].value_description cost_type = withdraw_fees[0].cost_type.name merchant_list.append(dict( id=merchant.id, name=merchant.merchant.name, balance_total=merchant.balance_total, balance_available=merchant.balance_available, balance_income=merchant.balance_income, balance_frozen=merchant.balance_frozen, type=merchant.m_type.name, domains='\n'.join(MerchantDomainConfig.get_domains(merchant.merchant)), state=merchant.state.name, channel_fees=dict( withdraw=withdraw_desc, cost_type=cost_type, deposit=[ dict( desc=x.payment_method.desc, value=x.payment_method.value, rate=x.value_description, ) for x in recharge_fees ] ) )) data = dict(counts=len(merchant_list), merchants=merchant_list) return MerchantListResult(bs_data=data).as_response()
def get(self): """ 商户配置查询 :return: """ if not request.args: return ResponseSuccess(message="参数规则:?merchant=test").as_response() try: merchant = MerchantEnum.from_name(request.args['merchant']) except: return ResponseSuccess(message="请输入正确的商户名称,有效的商户名称包括:%s" % MerchantEnum.get_names()).as_response() merchant_info = MerchantInfo.query_merchant(merchant) if not merchant_info: return ResponseSuccess(message="未创建商户").as_response() bs_data = dict( balance=dict( balance_total=str(merchant_info.balance_total), balance_available=str(merchant_info.balance_available), balance_income=str(merchant_info.balance_income), balance_frozen=str(merchant_info.balance_frozen), ), merchant=merchant.name, domains=MerchantDomainConfig.get_domains(merchant), # db=DBEnum(merchant.name).get_db_name(), ) deposit_fees = MerchantFeeConfig.query_active_configs( query_fields=dict( merchant=merchant, payment_way=PayTypeEnum.DEPOSIT, )) deposit_fees = MerchantFeeConfig.filter_latest_items(deposit_fees) if not deposit_fees: return MerchantConfigDepositError(bs_data=bs_data).as_response() bs_data['deposit_fees'] = [x.short_description for x in deposit_fees] withdraw_fees = MerchantFeeConfig.query_latest_one(query_fields=dict( merchant=merchant, payment_way=PayTypeEnum.WITHDRAW, )) if not withdraw_fees: return MerchantConfigWithdrawError(bs_data=bs_data).as_response() bs_data['withdraw_fees'] = withdraw_fees.short_description channels = ChannelListHelper.get_available_channels( merchant, PayTypeEnum.DEPOSIT) bs_data['deposit_channels'] = [x.short_description for x in channels] channels = ChannelListHelper.get_available_channels( merchant, PayTypeEnum.WITHDRAW) bs_data['withdraw_channels'] = [x.short_description for x in channels] return ResponseSuccess(bs_data=bs_data).as_response()
def __merchant_config_check(self): self.path = '/health/domain/check' response = self.do_get_request(dict(x=1, y=2)) self.assertEqual(ResponseSuccess.code, response.status_code) self.assertEqual(ResponseSuccess.error_code, response.json['error_code']) data = response.json['data'] self.assertEqual(InitData.merchant.name, data['merchant']) self.assertEqual( set(MerchantDomainConfig.get_domains(InitData.merchant)), set(data['domains']))