コード例 #1
0
 def get_queryset(self):
     manager = UserMerchantModelManager(user=self.request.user)
     merchant_status = self.request.query_params.get('merchant_status')
     if not merchant_status:
         return manager.get_auditor_merchants()
     if merchant_status == 'reviewing':
         merchant_status = config.MERCHANT_STATUS.REVIEWING
     if merchant_status == 'using':
         merchant_status = config.MERCHANT_STATUS.USING
     return manager.get_auditor_merchants(merchant_status)
コード例 #2
0
 def test_get_all_status_merchant_num(self):
     marketer = self.factory.create_marketer()
     self.factory.create_merchant(number=5,
                                  inviter=marketer,
                                  status=MERCHANT_STATUS.USING)
     self.factory.create_merchant(number=4,
                                  inviter=marketer,
                                  status=MERCHANT_STATUS.REVIEWING)
     self.factory.create_merchant(number=3,
                                  inviter=marketer,
                                  status=MERCHANT_STATUS.REJECTED)
     manager = UserMerchantModelManager(user=marketer)
     res = manager.get_invited_merchant_num()
     self.assertEqual(res.get('reviewing_merchants_num'), 4 + 3)
     self.assertEqual(res.get('using_merchants_num'), 5)
コード例 #3
0
 def test_audit_merchant(self):
     marketer = self.factory.create_marketer(name='this marketer')
     to_using_merchant = self.factory.create_merchant(
         name='to_using_merchant', status=MERCHANT_STATUS.REVIEWING)
     to_reject_merchant = self.factory.create_merchant(
         name='to_reject_merchant', status=MERCHANT_STATUS.REVIEWING)
     manager = UserMerchantModelManager(user=marketer)
     to_using_merchant = manager.audit_merchant(
         merchant_instance=to_using_merchant,
         to_status=MERCHANT_STATUS.USING)
     to_reject_merchant = manager.audit_merchant(
         merchant_instance=to_reject_merchant,
         to_status=MERCHANT_STATUS.REJECTED,
         audit_info='audit_info')
     audit_info = to_reject_merchant.merchantmarketership_set.all(
     ).order_by('-audit_datetime').first()
     pass
コード例 #4
0
    def test_get_auditor_merchant(self):

        # 创建地址
        area1 = self.factory.create_area()
        area2 = self.factory.create_area()
        area3 = self.factory.create_area()

        # 为管理员添加工作区域
        marketer = self.factory.create_marketer()
        marketer.working_areas.add(area1, area2)

        # 添加管理员非工作区域但审核过的商铺
        # using_merchant1 = self.factory.create_merchant(status=MERCHANT_STATUS.USING, area=area3)
        # using_merchant2 = self.factory.create_merchant(status=MERCHANT_STATUS.USING, area=area3)
        # using_merchant3 = self.factory.create_merchant(status=MERCHANT_STATUS.USING, area=area3)
        # self.factory.create_merchant_marketer_ship(marketer=marketer, merchant=using_merchant1)
        # self.factory.create_merchant_marketer_ship(marketer=marketer, merchant=using_merchant2)
        # self.factory.create_merchant_marketer_ship(marketer=marketer, merchant=using_merchant3)

        # 添加管理员工作区域待审核商铺
        reviewing_merchant1 = self.factory.create_merchant(
            status=MERCHANT_STATUS.REVIEWING, area=area1)
        reviewing_merchant2 = self.factory.create_merchant(
            status=MERCHANT_STATUS.REVIEWING, area=area2)

        # 添加非管理员工作区域商铺
        self.factory.create_merchant(area=area3)

        # 添加管理员工作区域已审核商铺
        using_merchant = self.factory.create_merchant(
            status=MERCHANT_STATUS.USING, area=area1)

        # 预期查询结果
        # merchant_set = {using_merchant1, using_merchant2, using_merchant3, reviewing_merchant1, reviewing_merchant2}
        merchant_set = {
            using_merchant, reviewing_merchant1, reviewing_merchant2
        }
        manager = UserMerchantModelManager(user=marketer)
        res = manager.get_auditor_merchants()

        # 实际查询结果
        res_set = set()
        for item in res:
            res_set.add(item)
        self.assertEqual(merchant_set, res_set)
コード例 #5
0
 def get_inviting_info(self, unionid):
     user = self.has_unionid(unionid)
     if not user:
         return None
     merchant_manager = UserMerchantModelManager(user=user)
     invited_merchants = merchant_manager.get_invited_merchant_num()
     using_invited_merchants_num = invited_merchants.get(
         'using_merchants_num')
     reviewing_invited_merchants_num = invited_merchants.get(
         'reviewing_merchants_num')
     transaction_manager = UserTransactionModelManager(user=user)
     user_share_transactions = transaction_manager.get_user_transactions(
         content_type='payment')
     if user_share_transactions:
         total_bonus = sum([
             transaction.amount for transaction in user_share_transactions
         ])
     else:
         total_bonus = 0
     account_manager = UserAccountModelManager(user=user)
     user_withdrawable_balance = account_manager.get_withdrawable_balance()
     return dict(
         user_name=user.name,
         user_phone=user.phone,
         user_type=user.inviter_type,
         using_invited_merchants_num=using_invited_merchants_num,
         reviewing_invited_merchants_num=reviewing_invited_merchants_num,
         total_bonus=total_bonus,
         user_withdrawable_balance=user_withdrawable_balance['wechat']
         ['balance'] + user_withdrawable_balance['alipay']['balance'],
         alipay_withdraw_balance=user_withdrawable_balance['alipay']
         ['balance'],
         wechat_withdraw_balance=user_withdrawable_balance['wechat']
         ['balance'],
         alipay_id=user.alipay_id,
         avatar=user.wechat_avatar_url,
     )
コード例 #6
0
 def get_queryset(self):
     manager = UserMerchantModelManager(self.request.user)
     return manager.get_to_be_audit_merchant()
コード例 #7
0
 def update(self, instance, validated_data):
     manager = UserMerchantModelManager(user=self.context['request'].user)
     return manager.audit_merchant(merchant_instance=instance, to_status=validated_data.get('status', ''),
                                   audit_info=validated_data.get('audit_info', ''))