def get(self, request, username):

        user_query = User.objects.filter(
            username=username,
            vip_roles=None,
        ).exclude(
            userprofile=None,
        )

        if not user_query:
            return JsonResponse({
                'status': 'error',
                'data': '用户数据有误',
            })

        user = user_query[0]
        user.is_active = True
        user.save()

        experience_service = VipRoleUtils.get_experience_vip()
        srv_meta = {
            'service_name': 'self_service',
            'product': experience_service,
            'user': user,
        }
        experience_srv = SelfService(**srv_meta)
        srv = experience_srv.create_service()
        ret = experience_srv.active_service() if srv else False

        return JsonResponse({
            'status': 'ok',
            'data': '操作成功',
            'ret': ret,
        })
Example #2
0
    def get(self, request, username):

        user_query = User.objects.filter(
            username=username,
            vip_roles=None,
        ).exclude(userprofile=None, )

        if not user_query:
            return JsonResponse({
                'status': 'error',
                'data': '用户数据有误',
            })

        user = user_query[0]
        user.is_active = True
        user.save()

        experience_service = VipRoleUtils.get_experience_vip()
        srv_meta = {
            'service_name': 'self_service',
            'product': experience_service,
            'user': user,
        }
        experience_srv = SelfService(**srv_meta)
        srv = experience_srv.create_service()
        ret = experience_srv.active_service() if srv else False

        return JsonResponse({
            'status': 'ok',
            'data': '操作成功',
            'ret': ret,
        })
Example #3
0
    def set_experience_user(cls, user):
        '''
        将用户设置成体验用户
        如果用户有正在使用的自助套餐,将正在使用的自助套餐失效,将用户设置成体验用户
        '''

        # 失效用户当前正在使用的套餐
        user_vip_query = UserVip.objects.select_related(
            'user',
            'vip_role',
        ).filter(
            user=user,
            is_active=True,
        ).exclude(
            vip_role__code_name='experience_user',
        )

        if user_vip_query:
            user_vip = user_vip_query[0]
            user_vip.custom_feed = 0
            user_vip.custom_point = 0
            user_vip.is_active = False
            user_vip.save()
            point_utils.deduction_self_point(user, user_vip)

        PackageUtils.expire_uservip_package(user)

        # 体验用户生效
        experience_vip_query = UserVip.objects.select_related(
            'user',
            'vip_role',
        ).filter(
            vip_role__code_name='experience_user',
            user=user,
        )
        if experience_vip_query:
            experience_vip = experience_vip_query[0]
        else:
            experience_service = VipRoleUtils.get_experience_vip()
            experience_vip = UserVip(
                user=user,
                vip_role=experience_service,
                apply_status='success',
            )

        experience_vip.is_active = True
        experience_vip.expire_time
        experience_vip.expire_time += relativedelta(
            months=3
        )
        experience_vip.custom_feed = 0
        experience_vip.custom_point = 0
        experience_vip.save()
        PackageUtils.set_uservip_pkg_feed(experience_vip)

        return experience_vip
Example #4
0
 def active_experience_service(self, user):
     experience_service = VipRoleUtils.get_experience_vip()
     srv_meta = {
         'service_name': 'self_service',
         'product': experience_service,
         'user': user,
     }
     experience_srv = SelfService(**srv_meta)
     srv = experience_srv.create_service()
     ret = experience_srv.active_service() if srv else False
     return ret
Example #5
0
 def active_experience_service(self, user):
     experience_service = VipRoleUtils.get_experience_vip()
     srv_meta = {
         'service_name': 'self_service',
         'product': experience_service,
         'user': user,
     }
     experience_srv = SelfService(**srv_meta)
     srv = experience_srv.create_service()
     ret = experience_srv.active_service() if srv else False
     return ret
def set_experience_vip(uservip):
    custom_feed = uservip.custom_feed
    custom_point = uservip.custom_point
    active_time = uservip.active_time
    expire_time = uservip.expire_time
    user = uservip.user

    experience_user_query = UserVip.objects.filter(
        vip_role__code_name='experience_user',
        user=user,
    )
    if experience_user_query:
        experience_user = experience_user_query[0]
        experience_user.custom_feed = custom_feed
        experience_user.custom_point = custom_point
        experience_user.active_time = active_time
        experience_user.expire_time = expire_time
        experience_user.is_active = True
    else:
        experience_service = VipRoleUtils.get_experience_vip()
        experience_user = UserVip(
            vip_role=experience_service,
            custom_feed=custom_feed,
            custom_point=custom_point,
            user=user,
            is_active=True,
            active_time=active_time,
            expire_time=expire_time,
        )

    uservip.is_active = False
    uservip.custom_point = 0
    uservip.custom_feed = 0

    with transaction.atomic():
        experience_user.save()
        uservip.save()
    return experience_user
def set_experience_vip(uservip):
    custom_feed = uservip.custom_feed
    custom_point = uservip.custom_point
    active_time = uservip.active_time
    expire_time = uservip.expire_time
    user = uservip.user

    experience_user_query = UserVip.objects.filter(
        vip_role__code_name='experience_user',
        user=user,
    )
    if experience_user_query:
        experience_user = experience_user_query[0]
        experience_user.custom_feed = custom_feed
        experience_user.custom_point = custom_point
        experience_user.active_time = active_time
        experience_user.expire_time = expire_time
        experience_user.is_active = True
    else:
        experience_service = VipRoleUtils.get_experience_vip()
        experience_user = UserVip(
            vip_role=experience_service,
            custom_feed=custom_feed,
            custom_point=custom_point,
            user=user,
            is_active=True,
            active_time=active_time,
            expire_time=expire_time,
        )

    uservip.is_active = False
    uservip.custom_point = 0
    uservip.custom_feed = 0

    with transaction.atomic():
        experience_user.save()
        uservip.save()
    return experience_user
def trans_advance_user():
    vip_a = VipRoleSetting.objects.get(code_name='experience_user')

    UserVip.objects.filter(
        is_active=True,
        user__username__in=username_list,
    ).update(
        vip_role=vip_a
    )

    manual_service = list(PackageItem.objects.all(
    ).values_list(
        'id',
        'price',
    ))
    manual_mapper = {
        i[1]: i[0]
        for i in manual_service
    }

    user_list = User.objects.filter(
        username__in=username_list,
        manual_roles=None,
    )

    experience_service = VipRoleUtils.get_experience_vip()

    for i in user_list:
        user = i
        username = i.username
        user_price = users_mapper.get(username, {}).get('price', 0)
        if not user_price:
            print 'user %s is valid, no price' % username

        pid = manual_mapper.get(user_price, 0)
        if not pid:
            print 'user %s price %s is valid, valid price' % (username, user_price)

        start_time = str2datetime(users_mapper.get(username, {}).get('start_time', ''))
        end_time = str2datetime(users_mapper.get(username, {}).get('end_time', ''))

        with transaction.atomic():
            if not user.vip_roles.filter(is_active=True).exists():
                srv_meta = {
                    'service_name': 'self_service',
                    'product': experience_service,
                    'user': user,
                }
                experience_srv = SelfService(**srv_meta)
                experience_srv.create_service()
                experience_srv.active_service()

            order = OrderManage.create_order(
                user,
                pid,
                'manual_service',
                1,
                'offline',
            )
            OrderManage.paid_order(order.order_id, user)

            UserManualService.objects.filter(
                user=user,
                is_active=True,
            ).update(
                active_time=start_time,
                expire_time=end_time,
            )
            print 'trans %s success' % username
def trans_advance_user():
    vip_a = VipRoleSetting.objects.get(code_name='experience_user')

    UserVip.objects.filter(
        is_active=True,
        user__username__in=username_list,
    ).update(vip_role=vip_a)

    manual_service = list(PackageItem.objects.all().values_list(
        'id',
        'price',
    ))
    manual_mapper = {i[1]: i[0] for i in manual_service}

    user_list = User.objects.filter(
        username__in=username_list,
        manual_roles=None,
    )

    experience_service = VipRoleUtils.get_experience_vip()

    for i in user_list:
        user = i
        username = i.username
        user_price = users_mapper.get(username, {}).get('price', 0)
        if not user_price:
            print 'user %s is valid, no price' % username

        pid = manual_mapper.get(user_price, 0)
        if not pid:
            print 'user %s price %s is valid, valid price' % (username,
                                                              user_price)

        start_time = str2datetime(
            users_mapper.get(username, {}).get('start_time', ''))
        end_time = str2datetime(
            users_mapper.get(username, {}).get('end_time', ''))

        with transaction.atomic():
            if not user.vip_roles.filter(is_active=True).exists():
                srv_meta = {
                    'service_name': 'self_service',
                    'product': experience_service,
                    'user': user,
                }
                experience_srv = SelfService(**srv_meta)
                experience_srv.create_service()
                experience_srv.active_service()

            order = OrderManage.create_order(
                user,
                pid,
                'manual_service',
                1,
                'offline',
            )
            OrderManage.paid_order(order.order_id, user)

            UserManualService.objects.filter(
                user=user,
                is_active=True,
            ).update(
                active_time=start_time,
                expire_time=end_time,
            )
            print 'trans %s success' % username