Example #1
0
 def update(self, request, *args, **kwargs):
     user = self.request.user
     code = 201
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     password = self.request.data.get('password')
     password2 = self.request.data.get('password2')
     auth_code = serializer.validated_data.get('auth_code')
     original_safe_code = self.request.data.get('original_safe_code')
     safe_code = self.request.data.get('safe_code')
     safe_code2 = self.request.data.get('safe_code2')
     # tuoxie001 修改自己
     if password:
         if password == password2:
             user.set_password(password)
         elif password != password2:
             code = 400
     if auth_code:
         user.auth_code = make_auth_code()
     if original_safe_code:
         if make_md5(original_safe_code) == user.safe_code:
             if safe_code == safe_code2:
                 if safe_code:
                     print('tuoxie001修改操作密码中..........')
                     safe_code = make_md5(safe_code)
                     self.request.user.safe_code = safe_code
             else:
                 code = 400
         else:
             code = 400
     user.save()
     serializer = UserDetailSerializer(user)
     return Response(data=serializer.data, status=code)
Example #2
0
 def create(self, validated_data):
     del validated_data['password2']
     user = UserProfile.objects.create(**validated_data)
     user.set_password(validated_data['password'])
     user.uid = make_uuid_code()
     user.auth_code = make_auth_code()
     user.is_active = False
     user.save()
     return user
Example #3
0
 def create(self, request, *args, **kwargs):
     resp = {'msg': []}
     proxy_user = self.request.user
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     validated_data = serializer.validated_data
     del validated_data['password2']
     user = UserProfile.objects.create(**validated_data)
     user.set_password(validated_data['password'])
     user.uid = make_uuid_code()
     user.auth_code = make_auth_code()
     user.level = 2
     user.save()
     code = 200
     resp['msg'] = '创建成功'
     serializer = AdminUserDetailSerializer(user)
     return Response(data=serializer.data, status=code)
Example #4
0
 def update(self, request, *args, **kwargs):
     user = self.get_object()
     resp = {}
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     password = self.request.data.get('password')
     password2 = self.request.data.get('password2')
     auth_code = serializer.validated_data.get('auth_code')
     original_safe_code = self.request.data.get('original_safe_code')
     safe_code = self.request.data.get('safe_code')
     safe_code2 = self.request.data.get('safe_code2')
     code = 400
     if password:
         if password == password2:
             user.set_password(password)
             user.save()
             resp['pwd'] = '密码修改成功'
             code = 200
         elif password != password2:
             resp['pwd'] = '密码不一致'
             code = 400
     if auth_code:
         user.auth_code = make_auth_code()
         user.save()
         resp['auth_code'] = '授权码修改成功'
     if original_safe_code:
         if make_md5(original_safe_code) == user.safe_code:
             if safe_code == safe_code2:
                 if safe_code:
                     safe_code = make_md5(safe_code)
                     user.safe_code = safe_code
                     user.save()
                     resp['safe_code'] = '安全码修改成功'
                     code = 200
             else:
                 resp['safe_code'] = '安全码输入不一致'
                 code = 400
         else:
             resp['safe_code'] = '原始安全码输入不一致'
             code = 400
     return Response(data=resp, status=code)
Example #5
0
    def update(self, request, *args, **kwargs):
        resp = {'msg': []}
        code = 200
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        password = self.request.data.get('password', '')
        password2 = self.request.data.get('password2', '')
        operatepw = self.request.data.get('operatepw', '')
        notify_url = self.request.data.get('notify_url', '')
        get_proxyid = self.request.data.get('id', '')
        add_money = self.request.data.get('add_money', '')
        minus_money = self.request.data.get('minus_money', '')
        auth_code = self.request.data.get('auth_code', '')
        is_active = self.request.data.get('is_active', '')
        original_safe_code = self.request.data.get('original_safe_code', '')
        safe_code = self.request.data.get('safe_code', '')
        safe_code2 = self.request.data.get('safe_code2', '')
        proxy_id = self.request.data.get('proxy_id', '')
        service_rate = self.request.data.get('service_rate', '')
        ramark_info = self.request.data.get('remark_info', '无备注!')

        print('ramark_info', ramark_info)
        if self.request.user.is_superuser:
            if get_proxyid:
                user_queryset = UserProfile.objects.filter(id=get_proxyid)
                if user_queryset:
                    # 引入日志
                    log = MakeLogs()
                    user = user_queryset[0]
                    daili_queryset = UserProfile.objects.filter(id=user.proxy_id)
                    if daili_queryset:
                        daili_obj = daili_queryset[0]
                        if add_money:
                            user.total_money = '%.2f' % (Decimal(user.total_money) + Decimal(add_money))
                            resp['msg'].append('加款成功')
                            # 加日志
                            if not ramark_info:
                                ramark_info = '无备注!'
                            content = '用户:' + str(self.request.user.username) + ' 对 ' + str(
                                user.username) + ' 加款 ' + ' 金额 ' + str(add_money) + ' 元。' + ' 备注:' + str(ramark_info)
                            log.add_logs('3', content, self.request.user.id)
                            # 更新代理余额
                            daili_obj.total_money = '%.2f' % (Decimal(daili_obj.total_money) + Decimal(add_money))
                            daili_obj.save()
                        if minus_money:
                            if Decimal(minus_money) <= Decimal(user.total_money) and Decimal(daili_obj.total_money) >= Decimal(minus_money):
                                user.total_money = '%.2f' % (Decimal(user.total_money) - Decimal(minus_money))
                                resp['msg'].append('扣款成功')
                                # 加日志
                                if not ramark_info:
                                    ramark_info = '无备注!'
                                content = '用户:' + str(self.request.user.username) + ' 对 ' + str(
                                    user.username) + ' 扣款 ' + ' 金额 ' + str(minus_money) + ' 元。' + ' 备注:' + str(
                                    ramark_info)
                                log.add_logs('3', content, self.request.user.id)
                                # 更新代理余额
                                daili_obj.total_money = '%.2f' % (
                                            Decimal(daili_obj.total_money) - Decimal(minus_money))
                                daili_obj.save()
                            else:
                                code = 400
                                resp['msg'].append('余额不足,扣款失败')
                    else:
                        # code = 400
                        resp['msg'].append('余额处理失败,代理不存在')
                    if password == password2:
                        if password:
                            user.set_password(password)
                            resp['msg'].append('密码修改成功')

                            # 加日志
                            content = '用户:' + str(self.request.user.username) + ' 对 ' + str(user.username) + '修改密码'
                            log.add_logs('3', content, self.request.user.id)
                    else:
                        resp['msg'].append('输入密码不一致')

                    # if safe_code == safe_code2:
                    #     if password:
                    #         print('admin修改用户操作密码中..........')
                    #         user.safe_code = make_md5(safe_code)
                    #         resp['msg'].append('操作密码修改成功')
                    # else:
                    #     resp['msg'].append('操作输入密码不一致')

                    if str(is_active):
                        if is_active == 'true':
                            is_active = True
                        if is_active == 'false':
                            is_active = False
                        resp['msg'].append('用户状态修改成功')
                        user.is_active = is_active

                    if service_rate:
                        resp['msg'].append('费率修改成功')
                        old_c = user.service_rate

                        user.service_rate = float(service_rate)
                        # 加日志
                        content = '用户:' + str(self.request.user.username) + ' 对 ' + str(user.username) + ' 原费率_' + str(
                            old_c) + ' 改为_' + str(service_rate)
                        log.add_logs('3', content, self.request.user.id)
                    if notify_url:
                        user.notify_url = notify_url
                        resp['msg'].append('回调修改成功')
                    if operatepw:
                        print('operatepw', operatepw)
                        user.safe_code = make_md5(operatepw)
                        resp['msg'].append('操作密码修改成功')
                    if auth_code:
                        user.auth_code = make_auth_code()
                        resp['msg'].append('秘钥修改成功')
                        resp['auth_code'] = user.auth_code
                    if proxy_id:
                        user_proxy = UserProfile.objects.filter(id=proxy_id, is_proxy=False, is_active=True)
                        if user_proxy:
                            new_user = user_proxy[0]
                            new_c = new_user.username

                            old_c = user.username
                            old_user = UserProfile.objects.filter(id=user.proxy_id)
                            if old_user:
                                old_user_name = old_user[0].username
                            else:
                                old_user_name = ''
                            user.proxy_id = proxy_id
                            resp['msg'].append('商户调整成功')
                            user.save()
                            serializer = UserDetailSerializer(user)
                            resp['data'] = serializer.data

                            content = '商户调整:' + str(old_c) + '属:' + str(old_user_name) + ' 调整给:' + str(new_c)
                            log.add_logs('3', content, self.request.user.id)

                        else:
                            resp['msg'].append('调整失败,代理不存在')

                    # code = 200
                    user.save()

                else:
                    code = 404
                    resp['msg'].append('操作对象不存在')
            else:
                if password == password2:
                    if password:
                        print('admin修改密码中..........')
                        self.request.user.set_password(password)
                        code = 200
                        resp['msg'].append('密码修改成功')
                        self.request.user.save()
                else:
                    code = 404
                    resp['msg'].append('输入密码不一致')

                if original_safe_code:
                    if make_md5(original_safe_code) == self.request.user.safe_code:
                        if safe_code == safe_code2:
                            if safe_code:
                                print('admin修改操作密码中..........')
                                safe_code = make_md5(safe_code)
                                self.request.user.safe_code = safe_code
                                code = 200
                                resp['msg'].append('操作密码修改成功')
                                self.request.user.save()
                        else:
                            code = 404
                            resp['msg'].append('操作密码输入不一致')

                    else:
                        code = 404
                        resp['msg'].append('操作密码错误')
                else:
                    code = 404
                    resp['msg'].append('操作密码错误1')

        # tuoxie 修改 tuoxie001
        if not self.request.user.is_proxy and not self.request.user.is_superuser:
            id_list = [user_obj.id for user_obj in UserProfile.objects.filter(proxy_id=self.request.user.id)]
            if get_proxyid:
                if int(get_proxyid) in id_list:
                    user = UserProfile.objects.filter(id=get_proxyid)[0]
                    # 引入日志
                    log = MakeLogs()
                    if add_money:
                        user.total_money = '%.2f' % (Decimal(user.total_money) + Decimal(add_money))
                        resp['msg'].append('加款成功')
                        # 加日志
                        if not ramark_info:
                            ramark_info = '无备注!'
                        content = '用户:' + str(self.request.user.username) + ' 对 ' + str(
                            user.username) + ' 加款 ' + ' 金额 ' + str(add_money) + ' 元。' + ' 备注:' + str(ramark_info)
                        log.add_logs('3', content, self.request.user.id)
                        # 更新代理余额
                        self.request.user.total_money = '%.2f' % (
                                    Decimal(self.request.user.total_money) - Decimal(add_money))
                        self.request.user.save()
                    if minus_money:
                        if Decimal(minus_money) <= Decimal(user.total_money) and Decimal(self.request.user.total_money) >= Decimal(minus_money):
                            user.total_money = '%.2f' % (Decimal(user.total_money) - Decimal(minus_money))
                            resp['msg'].append('扣款成功')
                            # 加日志
                            if not ramark_info:
                                ramark_info = '无备注!'
                            content = '用户:' + str(self.request.user.username) + ' 对 ' + str(
                                user.username) + ' 扣款 ' + ' 金额 ' + str(minus_money) + ' 元。' + ' 备注:' + str(ramark_info)
                            log.add_logs('3', content, self.request.user.id)
                            # 更新代理余额
                            self.request.user.total_money = '%.2f' % (
                                        Decimal(self.request.user.total_money) - Decimal(minus_money))
                            self.request.user.save()
                        else:
                            code = 404
                            resp['msg'].append('余额不足,扣款失败')

                    if password == password2:
                        if password:
                            user.set_password(password)
                            resp['msg'].append('密码修改成功')

                            # 加日志
                            content = '用户:' + str(self.request.user.username) + ' 对 ' + str(user.username) + '修改密码'
                            log.add_logs('3', content, self.request.user.id)
                    else:
                        # code = 404
                        resp['msg'].append('输入密码不一致')

                    if notify_url:
                        user.notify_url = notify_url
                        resp['msg'].append('回调修改成功')

                    if auth_code:
                        user.auth_code = make_auth_code()
                        resp['msg'].append('秘钥修改成功')
                        resp['auth_code'] = user.auth_code
                        # resp['auth_code'].append(str(user.auth_code))
                    if str(is_active):
                        if is_active == 'true':
                            is_active = True
                        if is_active == 'false':
                            is_active = False
                        resp['msg'].append('用户状态修改成功')
                        user.is_active = is_active
                    if service_rate:
                        resp['msg'].append('费率修改成功')
                        old_c = user.service_rate
                        user.service_rate = float(service_rate)

                        # 加日志
                        content = '用户:' + str(self.request.user.username) + ' 对 ' + str(user.username) + ' 原费率_' + str(
                            old_c) + ' 改为_' + str(service_rate)
                        log.add_logs('3', content, self.request.user.id)
                    if safe_code == safe_code2:
                        if password:
                            print('代理修改商户操作密码中..........')
                            self.request.user.safe_code = make_md5(safe_code)
                            resp['msg'].append('操作密码修改成功')
                    else:
                        # code = 404
                        resp['msg'].append('操作输入密码不一致')
                    # code = 200
                    user.save()
                else:
                    code = 404
                    resp['msg'].append('修改代理号不存在')

        # 修改tuoxie本身数据
        if not get_proxyid and not self.request.user.is_proxy:
            qq = self.request.data.get('qq', '')
            user = self.request.user

            # if add_money:
            #     user.total_money = '%.2f' % (Decimal(user.total_money) + Decimal(add_money))
            #     resp['msg'].append('加款成功')
            # if minus_money:
            #     if Decimal(minus_money) < Decimal(user.total_money):
            #         user.total_money = '%.2f' % (Decimal(user.total_money) - Decimal(minus_money))
            #         resp['msg'].append('扣款成功')
            #     else:
            #         code = 404
            #         resp['msg'].append('余额不足,扣款失败')

            if password == password2:
                if password:
                    user.set_password(password)
                    resp['msg'].append('密码修改成功')
            else:
                code = 404
                resp['msg'].append('输入密码不一致')

            if notify_url:
                user.notify_url = notify_url
                resp['msg'].append('回调修改成功')
            if qq:
                user.qq = qq

            if auth_code:
                user.auth_code = make_auth_code()
                resp['msg'].append(user.auth_code)

            if service_rate:
                resp['msg'].append('费率修改成功')
                user.service_rate = service_rate
            user.save()

        # tuoxie001 修改自己
        if self.request.user.is_proxy:
            user = self.get_object()
            if password:
                if password == password2:
                    user.set_password(password)
                    resp['msg'].append('密码修改成功')
                elif password != password2:
                    code = 404
                    resp['msg'].append('输入密码不一致')
                else:
                    code = 403
                    resp['msg'].append('改账号无权限')
            if notify_url:
                user.notify_url = notify_url
                resp['msg'].append('回调修改成功')
            if auth_code:
                user.auth_code = make_auth_code()
                resp['msg'].append(user.auth_code)

            if service_rate:
                resp['msg'].append('费率修改失败')

            if original_safe_code:
                if make_md5(original_safe_code) == self.request.user.safe_code:
                    if safe_code == safe_code2:
                        if safe_code:
                            print('admin修改操作密码中..........')
                            safe_code = make_md5(safe_code)
                            self.request.user.safe_code = safe_code

                            resp['msg'].append('操作密码修改成功')
                    else:
                        code = 404
                        resp['msg'].append('操作密码输入不一致')

                else:
                    code = 404
                    resp['msg'].append('操作密码错误')
            user.save()
        return Response(data=resp, status=code)
Example #6
0
    def update(self, request, *args, **kwargs):
        admin_user = self.request.user
        user = self.get_object()
        resp = {'msg': []}
        code = 200
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        password = self.request.data.get('password', '')
        password2 = self.request.data.get('password2', '')
        auth_code = self.request.data.get('auth_code', '')
        safe_code = self.request.data.get('safe_code', '')
        safe_code2 = self.request.data.get('safe_code2', '')
        add_money = serializer.validated_data.get('add_money')
        desc_money = serializer.validated_data.get('desc_money')
        remark = serializer.validated_data.get('remark')
        is_active = serializer.validated_data.get('is_active', '')
        is_google = serializer.validated_data.get('is_google', '')
        proxy_q = UserProfile.objects.filter(id=user.proxy_id)
        print(type(user.total_money), 99)
        if not proxy_q:
            code = 400
            resp['msg'] = '对应代理不存在'
            return Response(data=resp, status=code)
        proxy_user = proxy_q[0]
        log = MakeLogs()
        if add_money:
            print('add_money', add_money)
            # user.total_money = '%.2f' % (Decimal(user.total_money) + add_money)
            # user.money = '%.2f' % (Decimal(user.total_money) + add_money)
            user.total_money = ((user.total_money) + add_money)
            user.money = ((user.total_money) + add_money)
            # 加日志
            if not remark:
                remark = '无备注!'
            content = '用户:' + str(admin_user.username) + ' 对 ' + str(
                user.username) + ' 加款 ' + ' 金额 ' + str(
                    add_money) + ' 元。' + ' 备注:' + str(remark)
            log.add_logs('3', content, admin_user.id)
            # 更新代理余额
            # proxy_user.total_money = '%.2f' % (proxy_user.total_money + add_money)
            # proxy_user.money = '%.2f' % (proxy_user.money + add_money)
            proxy_user.total_money = (proxy_user.total_money + add_money)
            proxy_user.money = (proxy_user.money + add_money)
            user.save()
            proxy_user.save()
        if desc_money:
            print(type(desc_money), type(user.total_money))
            if desc_money <= (user.total_money) and (
                    proxy_user.total_money) >= desc_money:
                # user.total_money = '%.2f' % (Decimal(user.total_money) - desc_money)
                # user.money = '%.2f' % (user.money - desc_money)
                user.total_money = ((user.total_money) - desc_money)
                user.money = (user.money - desc_money)
                # 加日志
                if not remark:
                    remark = '无备注!'
                content = '用户:' + str(admin_user.username) + ' 对 ' + str(
                    user.username) + ' 扣款 ' + ' 金额 ' + str(
                        desc_money) + ' 元。' + ' 备注:' + str(remark)
                log.add_logs('3', content, admin_user.id)
                # 更新代理余额
                # proxy_user.total_money = '%.2f' % (proxy_user.total_money - desc_money)
                # proxy_user.money = '%.2f' % (proxy_user.money - desc_money)
                proxy_user.total_money = (proxy_user.total_money - desc_money)
                proxy_user.money = (proxy_user.money - desc_money)
                proxy_user.save()
            else:
                code = 400
                resp['msg'] = '对应代理不存在'
                return Response(data=resp, status=code)
        if password:
            if password == password2:
                user.set_password(password)
            elif password != password2:
                code = 400
        if auth_code:
            user.auth_code = make_auth_code()
        if safe_code == safe_code2:
            if safe_code:
                print('admin修改 商户 操作密码中..........')
                safe_code = make_md5(safe_code)
                user.safe_code = safe_code
        else:
            code = 400
        if str(is_active):
            if is_active:
                user.is_active = is_active
            if is_active == False:
                user.is_active = is_active
        if str(is_google):
            if is_google:
                pass
                # user.is_active = is_active
            if is_google == False:
                user.is_google = is_google
                user.save()
                g_q = Google2Auth.objects.filter(user_id=user.id)
                if g_q:
                    g_q[0].delete()

        user.save()
        serializer = AdminUserDetailSerializer(user)
        return Response(data=serializer.data, status=code)