コード例 #1
0
def company(request):
    response = Response.ResponseObj()
    if request.method == "GET":
        forms_obj = SelectForm(request.GET)
        if forms_obj.is_valid():
            current_page = forms_obj.cleaned_data['current_page']
            length = forms_obj.cleaned_data['length']
            print('forms_obj.cleaned_data -->', forms_obj.cleaned_data)
            order = request.GET.get('order', '-create_date')
            field_dict = {
                'id': '',
                'name': '__contains',
                'create_date': '',
                'oper_user__username': '******',
            }
            q = conditionCom(request, field_dict)
            print('q -->', q)
            objs = models.xzh_company.objects.filter(q).order_by(order)
            count = objs.count()

            if length != 0:
                start_line = (current_page - 1) * length
                stop_line = start_line + length
                objs = objs[start_line:stop_line]

            # 返回的数据
            ret_data = []

            for obj in objs:
                #  如果有oper_user字段 等于本身名字
                if obj.oper_user:
                    oper_user_username = obj.oper_user.username
                else:
                    oper_user_username = ''
                # print('oper_user_username -->', oper_user_username)
                #  将查询出来的数据 加入列表
                ret_data.append({
                    'id':
                    obj.id,
                    'name':
                    obj.name,
                    'create_date':
                    obj.create_date.strftime('%Y-%m-%d %H:%M:%S'),
                    'oper_user__username':
                    oper_user_username,
                })
            #  查询成功 返回200 状态码
            response.code = 200
            response.msg = '查询成功'
            response.data = {
                'ret_data': ret_data,
                'data_count': count,
            }
        else:
            response.code = 402
            response.msg = "请求异常"
            response.data = json.loads(forms_obj.errors.as_json())
    return JsonResponse(response.__dict__)
コード例 #2
0
def user_billing(request):
    response = Response.ResponseObj()
    forms_obj = SelectForm(request.GET)
    if forms_obj.is_valid():
        current_page = forms_obj.cleaned_data['current_page']
        length = forms_obj.cleaned_data['length']
        print('forms_obj.cleaned_data -->', forms_obj.cleaned_data)
        order = request.GET.get('order', '-create_date')
        field_dict = {
            'id': '',
            'username': '******',
            'create_date': '__contains',
            'belong_user_id': '',
        }
        q = conditionCom(request, field_dict)
        print('q -->', q)
        objs = models.user_billing.objects.select_related(
            'belong_user').filter(q).order_by(order)
        count = objs.count()

        if length != 0:
            start_line = (current_page - 1) * length
            stop_line = start_line + length
            objs = objs[start_line:stop_line]

        # 返回的数据
        ret_data = []
        for obj in objs:
            #  将查询出来的数据 加入列表
            ret_data.append({
                'id': obj.id,
                'belong_user_id': obj.belong_user_id,  # 归属人ID
                'belong_user': obj.belong_user.username,
                'create_date': obj.create_date.strftime('%Y-%m-%d'),
                'create_user_id': obj.create_user_id,
                'create_user': obj.create_user.username,
                'start_time': obj.start_time,
                'stop_time': obj.stop_time,
                'billing_cycle_id': obj.billing_cycle,
                'billing_cycle': obj.get_billing_cycle_display(),
                'note_text': obj.note_text,
            })
        #  查询成功 返回200 状态码
        response.code = 200
        response.msg = '查询成功'
        response.data = {
            'ret_data': ret_data,
            'count': count,
        }

    else:
        response.code = 301
        response.data = json.loads(forms_obj.errors.as_json())

    return JsonResponse(response.__dict__)
コード例 #3
0
def article(request):
    response = Response.ResponseObj()
    if request.method == "GET":
        forms_obj = SelectForm(request.GET)
        if forms_obj.is_valid():
            current_page = forms_obj.cleaned_data['current_page']
            length = forms_obj.cleaned_data['length']
            print('forms_obj.cleaned_data -->', forms_obj.cleaned_data)
            order = request.GET.get('order', '-create_date')
            field_dict = {
                'id': '',
                'title': '__contains',
                'create_date': '',
                'summary': '__contains',
                'content': '__contains',
                'article_status': '',
                'belongToUser_id': '',
                'article_type': '',
            }
            q = conditionCom(request, field_dict)

            print('q -->', q)
            objs = models.xcx_article.objects.select_related(
                'belongToUser').filter(q).order_by(order)
            count = objs.count()

            if length != 0:
                start_line = (current_page - 1) * length
                stop_line = start_line + length
                objs = objs[start_line:stop_line]

            # 返回的数据
            ret_data = []

            for obj in objs:
                print('obj.id--------------> ', obj.id)
                #  将查询出来的数据 加入列表
                ret_data.append({
                    'id':
                    obj.id,
                    'title':
                    obj.title,
                    'content':
                    obj.content,
                    'create_date':
                    obj.create_date.strftime('%Y-%m-%d %H:%M:%S'),
                    'user_id':
                    obj.user.id,
                    'user_name':
                    obj.user.username,
                    'belongToUser_id':
                    obj.belongToUser_id,
                    'belongToUser_name':
                    obj.belongToUser.username,
                    'article_type_id':
                    obj.article_type,
                    'suoluetu':
                    obj.suoluetu,
                    'article_type':
                    obj.get_article_type_display(),
                    'article_introductionid':
                    obj.article_introduction,
                })
            #  查询成功 返回200 状态码
            response.code = 200
            response.msg = '查询成功'
            response.data = {'ret_data': ret_data, 'count': count}
        else:
            response.code = 402
            response.msg = "请求异常"
            response.data = json.loads(forms_obj.errors.as_json())
    return JsonResponse(response.__dict__)
コード例 #4
0
def user(request):
    response = Response.ResponseObj()
    forms_obj = SelectForm(request.GET)
    if forms_obj.is_valid():
        current_page = forms_obj.cleaned_data['current_page']
        length = forms_obj.cleaned_data['length']
        print('forms_obj.cleaned_data -->', forms_obj.cleaned_data)
        order = request.GET.get('order', '-create_date')
        field_dict = {
            'id': '',
            # 'role_id': '',
            'username': '******',
            'create_date': '',
            'oper_user__username': '******',
            'is_debug': 'bool',
        }
        q = conditionCom(request, field_dict)
        print('q -->', q)
        objs = models.xcx_userprofile.objects.filter(q).order_by(order)
        count = objs.count()

        if length != 0:
            start_line = (current_page - 1) * length
            stop_line = start_line + length
            objs = objs[start_line:stop_line]

        # 返回的数据
        ret_data = []

        for obj in objs:
            username = ''
            oper_user_id = ''
            if obj.oper_user_id:
                oper_user_id = obj.oper_user_id
                username = obj.oper_user.username
            #  将查询出来的数据 加入列表

            ret_data.append({
                'id':
                obj.id,
                'username':
                obj.username,
                'oper_user_id':
                oper_user_id,
                'oper_user':
                username,  # 操作人
                # 'lunbotu': json.loads(obj.lunbotu),                 # 轮播图
                'lunbotu':
                obj.lunbotu,  # 轮播图
                'hospital_logoImg':
                obj.hospital_logoImg,  # logo图片
                'hospital_phone':
                obj.hospital_phone,  # 医院电话
                'hospital_introduction':
                obj.hospital_introduction,  # 医院简介
                'hospital_address':
                obj.hospital_address,  # 医院地址
                'hospital_menzhen':
                obj.hospital_menzhen,  # 门诊时间
                'x_shaft':
                obj.x_shaft,  # X轴
                'y_shaft':
                obj.y_shaft,  # Y轴
                'create_date':
                obj.create_date.strftime('%Y-%m-%d %H:%M:%S'),
            })

            #  查询成功 返回200 状态码
            response.code = 200
            response.msg = '查询成功'
            response.data = {'ret_data': ret_data}
    else:
        response.code = 301
        response.data = json.loads(forms_obj.errors.as_json())
    return JsonResponse(response.__dict__)
コード例 #5
0
def user(request):
    response = Response.ResponseObj()
    forms_obj = SelectForm(request.GET)

    if forms_obj.is_valid():
        user_id = request.GET.get('user_id')
        userObj = models.xzh_userprofile.objects.get(id=user_id)
        current_page = forms_obj.cleaned_data['current_page']
        length = forms_obj.cleaned_data['length']
        print('forms_obj.cleaned_data -->', forms_obj.cleaned_data)
        order = request.GET.get('order', '-create_date')
        field_dict = {
            'id': '',
            'role_id': '',
            # 'username': '******',
            'create_date': '',
            'oper_user__username': '******',
            'is_debug': 'bool',
        }
        user_id = request.GET.get('user_id')
        print('user_id-------------------> ', user_id)
        userObjs = models.xzh_userprofile.objects.filter(id=user_id)
        if userObjs:
            userObj = userObjs[0]
            userObjRole = userObj.role_id


            q = conditionCom(request, field_dict)
            role_id = request.GET.get('role_id')
            if role_id:
                q.add(Q(role_id=role_id), Q.AND)
            print('q -->', q)
            username = request.GET.get('username')
            if username:
                q.add(Q(username__contains=username), Q.AND)
            if int(userObjRole) == 61:
                q.add(Q(id=user_id), Q.AND)

            user_objs = models.xzh_userprofile.objects.select_related('role').filter(q)
            if userObj.role_id == 64:                 # 超级管理员
                objs = user_objs.order_by(order)
            elif userObj.role_id == 66:                 # 管理员
                objs = user_objs.order_by(order).exclude(role_id=64)
            else:
                objs = user_objs.order_by(order).exclude(role_id__in=[64,66])
            count = objs.count()

            if length != 0:
                start_line = (current_page - 1) * length
                stop_line = start_line + length
                objs = objs[start_line: stop_line]

            # 返回的数据
            ret_data = []
            index = 0

            now = datetime.date.today()
            print('now-----------> ',now)
            for obj in objs:
                billingObjs = obj.user_biling_belong_user.order_by('-stop_time')[:1]
                dueTime = '~'
                if billingObjs:
                    stop_time = billingObjs[0].stop_time  # 用户到期时间
                    if stop_time > now:
                        dueTime = (stop_time - now).days
                    elif stop_time == now:
                        dueTime = 0     # 今天到期

                #  如果有oper_user字段 等于本身名字
                if obj.oper_user:
                    oper_user_username = obj.oper_user.username
                else:
                    oper_user_username = ''
                # print('oper_user_username -->', oper_user_username)
                role_name = ''
                role_id = ''
                if obj.role:
                    role_id = obj.role_id
                    role_name = obj.role.name

                is_debug = '已调试' if obj.is_debug else '未调试'

                #  将查询出来的数据 加入列表
                ret_data.append({
                    'id': obj.id,
                    'username': obj.username,
                    'get_status_display': obj.get_status_display(),
                    'status': obj.status,
                    'role_id': role_id,
                    'role_name': role_name,
                    'website_backstage_id': obj.website_backstage,
                    'website_backstage_name': obj.get_website_backstage_display(),
                    'website_backstage_username': obj.website_backstage_username,
                    'website_backstage_password': obj.website_backstage_password,
                    'create_date': obj.create_date.strftime('%Y-%m-%d %H:%M:%S'),
                    'oper_user__username': oper_user_username,
                    'website_backstage_url': obj.website_backstage_url,
                    'is_debug': is_debug,
                    'website_backstage_token': obj.website_backstage_token,
                    'website_backstage_appid': obj.website_backstage_appid,
                    'xiongZhangHaoIndex': obj.xiongZhangHaoIndex,
                    'secondaryDomainName': obj.secondaryDomainName,
                    'xiong_zhang_hao_user': obj.xiong_zhang_hao_user,
                    'xiong_zhang_hao_pwd': obj.xiong_zhang_hao_pwd,
                    'fans_search_keyword': obj.fans_search_keyword,
                    'index':index,
                    'dueTime':dueTime,
                    'guanwang':obj.guanwang,
                })
                index += 1

            #  查询成功 返回200 状态码
            response.code = 200
            response.msg = '查询成功'
            response.data = {
                'ret_data': ret_data,
                'data_count': count,
                'website_backstage_choices': models.xzh_userprofile.website_backstage_choices,
                'billing_cycle_choices': models.user_billing.billing_cycle_choices,
            }
        else:
            response.code = 500
            response.msg = '非法用户'

    else:
        response.code = 301
        response.msg = json.loads(forms_obj.errors.as_json())

    return JsonResponse(response.__dict__)
コード例 #6
0
def program(request):
    response = Response.ResponseObj()
    if request.method == "GET":
        forms_obj = SelectForm(request.GET)
        if forms_obj.is_valid():
            current_page = forms_obj.cleaned_data['current_page']
            length = forms_obj.cleaned_data['length']
            print('forms_obj.cleaned_data -->', forms_obj.cleaned_data)
            order = request.GET.get('order', '-create_date')
            field_dict = {
                'id': '',
                'create_date': '',
                'program_name': '__contains',
                'program_type': '',
                'program_text': '',
                'belongToUser_id': '',
            }
            q = conditionCom(request, field_dict)

            print('q -->', q)
            objs = models.xcx_program_management.objects.select_related(
                'belongUser').filter(q).order_by(order)
            count = objs.count()

            if length != 0:
                start_line = (current_page - 1) * length
                stop_line = start_line + length
                objs = objs[start_line:stop_line]

            # 返回的数据
            ret_data = []
            num = 0
            for obj in objs:

                print('obj.id--------------> ', obj.id)
                #  将查询出来的数据 加入列表
                ret_data.append({
                    'id':
                    obj.id,
                    'program_name':
                    obj.program_name,
                    'belongUser_id':
                    obj.belongUser_id,
                    'belongUser':
                    obj.belongUser.username,
                    'program_type_id':
                    obj.program_type,
                    'program_type':
                    obj.get_program_type_display(),
                    'create_date':
                    obj.create_date.strftime('%Y-%m-%d %H:%M:%S'),
                })
                if int(obj.program_type) == 2:
                    ret_data[num]['program_text'] = obj.program_text
                num += 1
            #  查询成功 返回200 状态码
            response.code = 200
            response.msg = '查询成功'
            response.data = {
                'ret_data': ret_data,
                'type_list': models.xcx_program_management.program_type_choices
            }
        else:
            response.code = 402
            response.msg = "请求异常"
            response.data = json.loads(forms_obj.errors.as_json())
    return JsonResponse(response.__dict__)
コード例 #7
0
def fugai_baobiao(request):
    print('fugai_baobiao --->', fugai_baobiao)
    response = Response.ResponseObj()
    if request.method == "GET":
        response = Response.ResponseObj()

        forms_obj = SelectForm(request.GET)
        if forms_obj.is_valid():
            current_page = forms_obj.cleaned_data['current_page']
            length = forms_obj.cleaned_data['length']
            print('forms_obj.cleaned_data -->', forms_obj.cleaned_data)
            user_id = request.GET.get('user_id')
            order = request.GET.get('order', '-create_date')
            field_dict = {
                'id': '',
                'status': '',
                'create_date': '',
            }
            userObjs = models.xzh_userprofile.objects.filter(id=user_id)
            if userObjs:
                userObj = userObjs[0]
                userObjRole = userObj.role_id

                # request_obj = {
                #     'GET': {
                #         'id': request.GET.get('id'),
                #         'create_date': request.GET.get('create_date'),
                #         'user_id': request.GET.get('uid'),
                #     }
                # }
                q = conditionCom(request, field_dict)

                print('q -->', q)
                if int(userObjRole) == 61:
                    q.add(Q(user_id=user_id), Q.AND)
                objs = models.xzh_fugai_baobiao.objects.select_related(
                    'user').filter(q).filter(user__role_id=61).order_by(
                        'stop_check', order)
                uid = request.GET.get('uid')
                print('uid -->', uid)
                if uid:
                    objs = objs.filter(user_id=uid)
                count = objs.count()

                if length != 0:
                    start_line = (current_page - 1) * length
                    stop_line = start_line + length
                    objs = objs[start_line:stop_line]

                # 返回的数据
                ret_data = []
                index = 0
                for obj in objs:
                    index += 1
                    print('obj.id----------------------------------------> ',
                          obj.id)
                    #  将查询出来的数据 加入列表
                    ret_data.append({
                        'id':
                        obj.id,
                        'user_id':
                        obj.user_id,
                        'username':
                        obj.user.username,
                        'keywords_num':
                        obj.keywords_num,
                        'today_cover':
                        obj.today_cover,
                        'total_cover':
                        obj.total_cover,
                        'publish_num':
                        obj.publish_num,
                        'status':
                        obj.get_status_display(),
                        'create_date':
                        obj.create_date.strftime('%Y-%m-%d %H:%M:%S'),
                        'keywordIndex':
                        index,
                        'stop_check':
                        obj.stop_check
                    })
                #  查询成功 返回200 状态码
                response.code = 200
                response.msg = '查询成功'
                response.data = {
                    'ret_data': ret_data,
                    'data_count': count,
                    'status_choices': models.xzh_fugai_baobiao.status_choices,
                }
            else:
                response.code = 500
                response.msg = '非法用户'
        else:
            response.code = 301
            response.data = json.loads(forms_obj.errors.as_json())
    else:
        response.code = 402
        response.msg = '请求异常'
    return JsonResponse(response.__dict__)
コード例 #8
0
ファイル: role.py プロジェクト: itcastpeng/XiongZhangHaoApi-
def role(request):
    response = Response.ResponseObj()
    if request.method == "GET":
        forms_obj = SelectForm(request.GET)
        if forms_obj.is_valid():
            current_page = forms_obj.cleaned_data['current_page']
            length = forms_obj.cleaned_data['length']
            print('forms_obj.cleaned_data -->', forms_obj.cleaned_data)
            order = request.GET.get('order', '-create_date')
            user_id = request.GET.get('user_id')
            userObjs = models.xzh_userprofile.objects.filter(id=user_id)

            print('user_id-----------------------------------> ',user_id)
            field_dict = {
                'id': '',
                'name': '__contains',
                'create_date': '',
                'oper_user__username': '******',
            }
            q = conditionCom(request, field_dict)
            print('q -->', q)
            objs = models.xzh_role.objects.filter(q).order_by(order)
            if int(userObjs[0].role_id) == 66:
                objs = models.xzh_role.objects.filter(q).order_by(order).exclude(id=64)
            elif int(userObjs[0].role_id) == 61:
                objs = models.xzh_role.objects.filter(q).order_by(order).exclude(id__in=[64, 66])
            count = objs.count()

            if length != 0:
                start_line = (current_page - 1) * length
                stop_line = start_line + length
                objs = objs[start_line: stop_line]

            # 返回的数据
            ret_data = []

            for obj in objs:
                # 获取选中的id,然后组合成前端能用的数据
                permissionsList = []
                permissionsData = []
                if obj.permissions:
                    permissionsList = [i['id'] for i in obj.permissions.values('id')]
                    permissionsData = init_data(selected_list=permissionsList)

                #  如果有oper_user字段 等于本身名字
                if obj.oper_user:
                    oper_user_username = obj.oper_user.username
                else:
                    oper_user_username = ''
                # print('oper_user_username -->', oper_user_username)
                #  将查询出来的数据 加入列表
                ret_data.append({
                    'id': obj.id,
                    'name': obj.name,
                    'create_date': obj.create_date.strftime('%Y-%m-%d %H:%M:%S'),
                    'oper_user__username': oper_user_username,
                    'permissionsData': json.dumps(permissionsData)
                })
            #  查询成功 返回200 状态码
            response.code = 200
            response.msg = '查询成功'
            response.data = {
                'ret_data': ret_data,
                'data_count': count,
            }
        else:
            response.code = 402
            response.msg = "请求异常"
            response.data = json.loads(forms_obj.errors.as_json())
    return JsonResponse(response.__dict__)
コード例 #9
0
def userStatistics(request):
    response = Response.ResponseObj()
    forms_obj = SelectForm(request.GET)
    if forms_obj.is_valid():
        current_page = forms_obj.cleaned_data['current_page']
        length = forms_obj.cleaned_data['length']
        print('forms_obj.cleaned_data -->', forms_obj.cleaned_data)
        order = request.GET.get('order', '-create_date')
        days = request.GET.get('days', 30)
        field_dict = {
            'id': '',
            'username': '******',
            'create_date': '__contains',
            'belong_user_id': '',
        }
        user_id = request.GET.get('user_id')
        print('user_id-------------------> ', user_id)
        userObjs = models.xzh_userprofile.objects.filter(id=user_id)
        if userObjs:
            userObj = userObjs[0]
            userObjRole = userObj.role_id

            q = conditionCom(request, field_dict)

            now = datetime.datetime.now()
            nowDate = now.strftime('%Y-%m-%d')
            if days:
                stop = nowDate
                if int(days) == 7:
                    time_Y_M_D = (
                        now - datetime.timedelta(days=6)).strftime('%Y-%m-%d')
                else:
                    time_Y_M_D = (
                        now - datetime.timedelta(days=30)).strftime('%Y-%m-%d')
                start = time_Y_M_D
                q.add(
                    Q(create_date__lte=stop) & Q(create_date__gte=start),
                    Q.AND)
            print('q -->', q)
            if int(userObjRole) == 61:
                q.add(Q(belong_user_id=userObj.id), Q.AND)
            objs = models.user_statistics.objects.select_related(
                'belong_user').filter(q).order_by(order)
            count = objs.count()

            if length != 0:
                start_line = (current_page - 1) * length
                stop_line = start_line + length
                objs = objs[start_line:stop_line]

            # 返回的数据
            ret_data = []

            for obj in objs:
                #  将查询出来的数据 加入列表
                create_date = obj.create_date.strftime('%Y-%m-%d')
                if obj.zhoumo:
                    create_date = create_date + ' ' + '(周末)'
                if int(userObjRole) in [66, 64]:
                    ret_data.append({
                        'id': obj.id,
                        'belong_user_id': obj.belong_user_id,  # 归属人ID
                        # 'belong_user':obj.belong_user.username, # 归属人名字
                        'public_num': obj.public_num,  # 发布数量
                        'fans_num': obj.fans_num,  # 粉丝数量
                        'zhishu': obj.zhishu,  # 指数
                        'zhanxianliang': obj.zhanxianliang,  # 展现量
                        'dianjiliang': obj.dianjiliang,  # 点击量
                        'index_show': obj.index_show,  # 熊掌号主页展示条数 (主页收录)
                        # 'index_show_url':obj.index_show_url,  # 熊掌号主页展示url
                        'create_date': create_date,  # 创建时间
                        'baidu_shoulu': obj.baidu_shoulu,  # 百度收录数量
                        # 'baidu_shoulu_url':obj.baidu_shoulu_url,  # 百度收录链接
                        'admin_shoulu': obj.admin_shoulu,  # 熊掌号后台收录条数
                        # 'admin_shoulu_url':obj.admin_shoulu_url,  # 熊掌号后台收录url
                    })
                else:
                    if obj.admin_shoulu > obj.baidu_shoulu:
                        shoulu = obj.admin_shoulu
                    else:
                        shoulu = obj.baidu_shoulu
                    if shoulu < obj.index_show:
                        shoulu = obj.index_show

                    ret_data.append({
                        'id': obj.id,
                        'belong_user_id': obj.belong_user_id,  # 归属人ID
                        'public_num': obj.public_num,  # 发布数量
                        'fans_num': obj.fans_num,  # 粉丝数量
                        'zhishu': obj.zhishu,  # 指数
                        'zhanxianliang': obj.zhanxianliang,  # 展现量
                        'dianjiliang': obj.dianjiliang,  # 点击量
                        'index_show': obj.index_show,  # 熊掌号主页展示条数 (主页收录)
                        'shoulu': shoulu,
                        'create_date': create_date,  # 创建时间
                    })

            user_obj = models.user_statistics.objects.values(
                'belong_user_id', 'belong_user__username').distinct()  # 查询所有用户
            if int(userObjRole) == 61:
                user_obj = user_obj.filter(belong_user_id=userObj.id)

            userList = []
            for i in user_obj:
                userList.append({
                    'id': i.get('belong_user_id'),
                    'name': i.get('belong_user__username')
                })
            #  查询成功 返回200 状态码
            response.code = 200
            response.msg = '查询成功'
            response.data = {
                'ret_data': ret_data,
                'count': count,
                'userList': userList
            }
        else:
            response.code = 500
            response.msg = '非法用户'
    else:
        response.code = 301
        response.data = json.loads(forms_obj.errors.as_json())

    return JsonResponse(response.__dict__)
コード例 #10
0
def article(request):

    response = Response.ResponseObj()

    if request.method == "GET":
        forms_obj = SelectForm(request.GET)

        if forms_obj.is_valid():
            current_page = forms_obj.cleaned_data['current_page']
            length = forms_obj.cleaned_data['length']
            print('forms_obj.cleaned_data -->', forms_obj.cleaned_data)
            order = request.GET.get('order', '-create_date')
            user_id = request.GET.get('user_id')
            start_time = request.GET.get('start_time')
            field_dict = {
                'id': '',
                # 'title': '__contains',
                'create_date': '',
                'summary': '__contains',
                'content': '__contains',
                'article_status': '',
                'belongToUser_id': '',
            }
            userObjs = models.xzh_userprofile.objects.filter(id=user_id)

            if userObjs:
                userObj = userObjs[0]
                userObjRole = userObj.role_id
                q = conditionCom(request, field_dict)
                print('start_time============>',start_time)
                title = request.GET.get('title')

                if title:
                    q.add(Q(title__contains=title), Q.AND)

                if start_time:
                    start_time = json.loads(start_time)
                    stop_time = start_time[1]
                    start_time = start_time[0]
                    q.add(Q(create_date___gte=start_time) & Q(create_date__lte=stop_time), Q.AND)

                print('q -->', q)

                if int(userObjRole) == 61:
                    print('=====================')
                    q.add(Q(belongToUser_id=userObj.id), Q.AND)
                objs = models.xzh_article.objects.select_related('user', 'belongToUser').filter(q).order_by(order)
                count = objs.count()

                if length != 0:
                    start_line = (current_page - 1) * length
                    stop_line = start_line + length
                    objs = objs[start_line: stop_line]

                # 返回的数据
                ret_data = []

                for obj in objs:
                    # print('obj.id--------------> ',obj.id)
                    #  将查询出来的数据 加入列表
                    column = eval(obj.column_id) if obj.column_id else {}
                    # print('column============> ', column)
                    back_url = obj.back_url if obj.back_url else ''
                    articlePicName = ''
                    if obj.articlePicName:
                        articlePicName = obj.articlePicName
                    send_time = obj.send_time.strftime('%Y-%m-%d %H:%M:%S') if obj.send_time else ''
                    belongToUser = ''
                    belongToUser_id = ''
                    if obj.belongToUser:
                        belongToUser_id = obj.belongToUser_id
                        belongToUser = obj.belongToUser.username
                    create_user_id = obj.user.id
                    create_user_name = obj.user.username
                    if int(userObjRole) == 61:
                        create_user_id = 0
                        create_user_name = ''

                    ret_data.append({
                        'id': obj.id,
                        'title':obj.title,
                        'summary':obj.summary,
                        'content':obj.content,
                        'column_id':column.get('Id'),
                        'column_name':column.get('name'),
                        'create_date':obj.create_date.strftime('%Y-%m-%d %H:%M:%S'),
                        'user_id': create_user_id,
                        'user_name': create_user_name,
                        'belongToUser_id':belongToUser_id,
                        'belongToUser_name': belongToUser,
                        'article_status': obj.get_article_status_display(),
                        'note_content':obj.note_content,
                        'back_url':back_url,
                        'send_time':send_time,
                        'is_audit':obj.is_audit,
                        'article_status_id':obj.article_status,
                        'is_delete':obj.is_delete,
                        'manualRelease':obj.manualRelease,
                        'articlePicName':articlePicName,
                    })

                #  查询成功 返回200 状态码
                response.code = 200
                response.msg = '查询成功'
                response.data = {
                    'ret_data': ret_data,
                    'data_count': count,
                    'article_status':models.xzh_article.article_status_choices,
                }

            else:
                response.code = 500
                response.msg = '非法用户'

        else:
            response.code = 402
            response.msg = "请求异常"
            response.data = json.loads(forms_obj.errors.as_json())

    return JsonResponse(response.__dict__)
コード例 #11
0
def fans(request):
    response = Response.ResponseObj()
    forms_obj = SelectForm(request.GET)
    if forms_obj.is_valid():
        current_page = forms_obj.cleaned_data['current_page']
        length = forms_obj.cleaned_data['length']
        print('forms_obj.cleaned_data -->', forms_obj.cleaned_data)
        order = request.GET.get('order', '-create_date')
        field_dict = {
            'id': '',
            'status': '',
            'username': '******',
            'create_date': '',
            'belong_user_id': '',
            'is_debug': 'bool',
        }
        q = conditionCom(request, field_dict)
        points = request.GET.get('points')

        print('q -->', q)
        objs = models.xzh_add_fans.objects.select_related(
            'belong_user').filter(q).order_by(order)
        count = objs.count()
        if points:  # 查询 用户搜索条件 避免出现重复
            objs = models.xzh_add_fans.objects.select_related(
                'belong_user').values('belong_user_id',
                                      'belong_user__username').distinct()
            ret_data = []
            for obj in objs:
                print('obj----------> ', obj)
                ret_data.append({
                    'belong_user_id':
                    obj.get('belong_user_id'),  # 归属人ID
                    'belong_user':
                    obj.get('belong_user__username'),  # 归属人名字
                })
            response.code = 200
            response.data = {'ret_data': ret_data}
        else:
            if length != 0:
                start_line = (current_page - 1) * length
                stop_line = start_line + length
                objs = objs[start_line:stop_line]

            # 返回的数据
            ret_data = []
            for obj in objs:

                #  将查询出来的数据 加入列表
                ret_data.append({
                    'id':
                    obj.id,
                    'belong_user_id':
                    obj.belong_user_id,  # 归属人ID
                    'belong_user':
                    obj.belong_user.username,  # 归属人名字
                    'befor_add_fans':
                    obj.befor_add_fans,  # 加粉前 粉丝数量
                    'after_add_fans':
                    obj.after_add_fans,  # 加分后 粉丝数量
                    'add_fans_num':
                    obj.add_fans_num,  # 添加的粉丝数量
                    # 'xiongzhanghaoID':obj.xiongzhanghaoID,  # 熊掌号ID
                    # 'search_keyword':obj.search_keyword,    # 熊掌号搜索关键词
                    'status':
                    obj.get_status_display(),
                    'status_id':
                    obj.status,
                    'create_date':
                    obj.create_date.strftime('%Y-%m-%d'),
                    'errorText':
                    obj.errorText,  # 错误日志
                })
            #  查询成功 返回200 状态码
            response.code = 200
            response.msg = '查询成功'
            response.data = {
                'ret_data': ret_data,
                'status': models.xzh_add_fans.status_choices,
                'count': count
            }
    else:
        response.code = 301
        response.data = json.loads(forms_obj.errors.as_json())
    return JsonResponse(response.__dict__)