コード例 #1
0
    def __create_merchant_info(self):
        # 创建商户TEST
        merchant = MerchantInfo.create_merchant(MerchantEnum.TEST, MerchantTypeEnum.TEST)
        self.assertEqual(merchant.id, 1)
        self.assertEqual(merchant.merchant, MerchantEnum.TEST)
        self.assertEqual(merchant.m_type, MerchantTypeEnum.TEST)
        self.assertEqual(merchant.state, AccountStateEnum.ACTIVE)

        # 创建商户QF2
        merchant = MerchantInfo.create_merchant(MerchantEnum.QF2, MerchantTypeEnum.NORMAL)
        self.assertEqual(merchant.id, 2)
        self.assertEqual(merchant.merchant, MerchantEnum.QF2)
        self.assertEqual(merchant.m_type, MerchantTypeEnum.NORMAL)
        self.assertEqual(merchant.state, AccountStateEnum.ACTIVE)

        # 创建商户QF3
        merchant = MerchantInfo.create_merchant(MerchantEnum.QF3, MerchantTypeEnum.NORMAL)
        self.assertEqual(merchant.id, 3)
        self.assertEqual(merchant.merchant, MerchantEnum.QF3)
        self.assertEqual(merchant.m_type, MerchantTypeEnum.NORMAL)
        self.assertEqual(merchant.state, AccountStateEnum.ACTIVE)

        # 应该有3个商户
        all_merchant = list(MerchantInfo.query_all())
        self.assertEqual(len(all_merchant), 3)

        # 删除TEST商户
        MerchantInfo.delete_merchant(MerchantEnum.TEST)

        # 还有2个商户
        all_merchant = list(MerchantInfo.query_all())
        self.assertEqual(len(all_merchant), 2)

        # 查不到TEST商户
        merchant = MerchantInfo.query_merchant(MerchantEnum.TEST)
        self.assertIsNone(merchant)

        # 再次添加TEST商户
        merchant = MerchantInfo.create_merchant(MerchantEnum.TEST, MerchantTypeEnum.TEST)
        self.assertEqual(merchant.id, 4)
        self.assertEqual(merchant.merchant, MerchantEnum.TEST)
        self.assertEqual(merchant.m_type, MerchantTypeEnum.TEST)
        self.assertEqual(merchant.state, AccountStateEnum.ACTIVE)

        # 又有3个商户
        all_merchant = list(MerchantInfo.query_all())
        self.assertEqual(len(all_merchant), 3)
コード例 #2
0
    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()