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,
        })
    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,
        })
Beispiel #3
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
Beispiel #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
Beispiel #5
0
def main():
    product = get_object_or_none(VipRoleSetting, code_name='experience_user')
    users = User.objects.filter(
        is_active=True,
        date_joined__gte=join_date,
        vip_roles=None,
    ).exclude(userprofile=None, )

    for old_user in users:
        self_srv = SelfService()
        self_srv.user = old_user
        self_srv.product = product
        self_srv.service_name = 'self_service'
        self_service_obj = self_srv.create_service()
        self_srv.service_id = self_service_obj.id
        self_srv.active_service()
        print 'conver user success! %s' % (old_user)
def main():
    product = get_object_or_none(VipRoleSetting, code_name='experience_user')
    users = User.objects.filter(
        is_active=True,
        date_joined__gte=join_date,
        vip_roles=None,
    ).exclude(
        userprofile=None,
    )

    for old_user in users:
        self_srv = SelfService()
        self_srv.user = old_user
        self_srv.product = product
        self_srv.service_name = 'self_service'
        self_service_obj = self_srv.create_service()
        self_srv.service_id = self_service_obj.id
        self_srv.active_service()
        print 'conver user success! %s' % (old_user)
from pin_utils.django_utils import (
    get_object_or_none
)

if __name__ == '__main__':

    active_uid_list = list(UserVip.objects.filter(is_active=True).values_list('user_id', flat=True))

    deactive_uid_list = list(set(list(UserVip.objects.select_related('user').filter(is_active=False)\
                                      .exclude(user__id__in=active_uid_list).values_list('user_id', flat=True))))

    old_user_list = User.objects.filter(id__in=deactive_uid_list)

    print 'old_user count:', len(old_user_list)

    product = get_object_or_none(VipRoleSetting, code_name='experience_user')

    for old_user in old_user_list:
        self_srv = SelfService()
        self_srv.user = old_user
        self_srv.product = product
        self_srv.service_name = 'self_service'
        self_service_obj = self_srv.create_service()
        self_srv.service_id = self_service_obj.id
        self_srv.active_service()
        print 'conver user success! %s' % (old_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
Beispiel #10
0
from users.models import (User)
from app.vip.runtime.self_service import (SelfService)
from app.vip.models import (VipRoleSetting)
from pin_utils.django_utils import (get_object_or_none)

if __name__ == '__main__':

    active_uid_list = list(
        UserVip.objects.filter(is_active=True).values_list('user_id',
                                                           flat=True))

    deactive_uid_list = list(set(list(UserVip.objects.select_related('user').filter(is_active=False)\
                                      .exclude(user__id__in=active_uid_list).values_list('user_id', flat=True))))

    old_user_list = User.objects.filter(id__in=deactive_uid_list)

    print 'old_user count:', len(old_user_list)

    product = get_object_or_none(VipRoleSetting, code_name='experience_user')

    for old_user in old_user_list:
        self_srv = SelfService()
        self_srv.user = old_user
        self_srv.product = product
        self_srv.service_name = 'self_service'
        self_service_obj = self_srv.create_service()
        self_srv.service_id = self_service_obj.id
        self_srv.active_service()
        print 'conver user success! %s' % (old_user)