Example #1
0
        def inner(request, *args, **kwargs):
            rand_str = request.GET.get('rand_str')
            timestamp = request.GET.get('timestamp', '')
            user_id = request.GET.get('user_id')
            # print('user_id -->', user_id)
            # print('timestamp -->', timestamp)
            # print('rand_str -->', rand_str)
            objs = table_obj.objects.filter(id=user_id)
            if objs:
                obj = objs[0]
                # print('str_encrypt(timestamp + obj.token) -->', str_encrypt(timestamp + obj.token))
                # print('rand_str -->', rand_str)
                if str_encrypt(timestamp + obj.token) == rand_str:
                    flag = True
                else:
                    flag = False
            else:
                flag = False

            if not flag:
                response = Response.ResponseObj()
                response.code = 400
                response.msg = "token异常"
                return JsonResponse(response.__dict__)
            return func(request, *args, **kwargs)
Example #2
0
def updatePwd(request):
    response = Response.ResponseObj()
    user_id = request.GET.get('user_id')
    user_objs = models.xzh_userprofile.objects.filter(id=user_id)

    if user_objs:
        user_obj = user_objs[0]
        user_obj_role = user_obj.role_id

        oldPwd = request.POST.get('oldPwd')
        newPwd = request.POST.get('newPwd')
        if newPwd and oldPwd:
            print('oldPwd-------> ',oldPwd)
            oldPwd = account.str_encrypt(oldPwd) # 加密 密码
            if oldPwd == user_obj.password:
                newPwd = account.str_encrypt(newPwd)
                token = account.get_token(newPwd + str(int(time.time()) * 1000)) #  token
                user_objs.update(password=newPwd, token=token)
                response.code = 200
                response.msg = '修改成功'
            else:
                response.code = 301
                response.msg = '旧密码验证错误'
        else:
            response.code = 301
            response.msg = '参数错误'

    else:
        response.code = 500
        response.msg = '非法请求'

    return JsonResponse(response.__dict__)
def queryAgain(request):
    response = Response.ResponseObj()
    user_id = request.GET.get('user_id')
    o_id = request.GET.get('o_id')
    userObjs = models.xzh_userprofile.objects
    role_id = userObjs.filter(id=user_id)[0].role_id
    start = datetime.datetime.now().strftime('%Y-%m-%d 00:00:00')
    stop = datetime.datetime.now().strftime('%Y-%m-%d 23:59:59')
    now = datetime.datetime.now().strftime('%Y-%m-%d')
    print('start, stop---> ', start, stop, now)
    if int(role_id) in [64, 66]:
        user_obj = userObjs.filter(id=o_id)
        if user_obj:
            fugaiobj = models.xzh_fugai_baobiao.objects.filter(id=o_id)
            fugaiobj.update(status=1)
            models.xzh_keywords_detail.objects.filter(create_date=now).filter(
                xzh_keywords__user_id=fugaiobj[0].user_id).delete()
            obj = models.xzh_keywords.objects.filter(
                user_id=fugaiobj[0].user_id).filter(select_date__lte=stop,
                                                    select_date__gte=start)
            obj.update(select_date=None)
            models.xzh_fugai_baobiao_detail.objects.filter(
                xzh_fugai_baobiao__user_id=fugaiobj[0].user_id).filter(
                    create_date=now).delete()
            response.code = 200
            response.msg = '重查成功'
        else:
            response.code = 301
            response.msg = '无此用户'
    else:
        response.code = 301
        response.msg = '该角色不可操作'
    return JsonResponse(response.__dict__)
Example #4
0
def user_oper(request, oper_type, o_id):
    response = Response.ResponseObj()
    if oper_type == 'select':
        objs = models.xcx_userprofile.objects.filter(id=o_id)
        count = objs.count()
        data_list = []
        for obj in objs:
            lunbotu = ''
            if obj.lunbotu:
                lunbotu = json.loads(obj.lunbotu)
            hospital_logoImg = ''
            if obj.hospital_logoImg:
                hospital_logoImg = eval(obj.hospital_logoImg)[0].get('url')
            data_list.append({
                'lunbotu': lunbotu,
                'hospital_logoImg': hospital_logoImg,
                'hospital_phone': obj.hospital_phone,
                'hospital_introduction': obj.hospital_introduction,
                'hospital_address': obj.hospital_address,
                'hospital_menzhen': obj.hospital_menzhen,
                'username': obj.username,
                'id': obj.id,
            })
        print('v====>', data_list)
        response.code = 200
        response.msg = '查询成功'
        response.data = {'data_list': data_list, 'count': count}
    else:
        response.code = 402
        response.msg = '请求异常'
    return JsonResponse(response.__dict__)
Example #5
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__)
Example #6
0
def theScheduler(request):
    response = Response.ResponseObj()
    userObjs = models.xzh_userprofile.objects
    articleObjs = models.xzh_article.objects

    resule_data = {'task_id': None, 'flag': False}

    if not resule_data['flag']:
        getCookieObjs = userObjs.filter(is_debug=False, role_id=61,
                                        userType=1)  # 获取栏目 及 cookie
        if getCookieObjs:
            resule_data['flag'] = True
            resule_data['task_id'] = 1
            print('获取栏目')

    if not resule_data['flag']:
        now_date = datetime.datetime.now()
        q = Q()
        q.add(Q(send_time__lte=now_date) | Q(send_time__isnull=True),
              Q.AND)  # 判断是否定时发送
        sendArticleObjs = articleObjs.select_related('belongToUser').filter(
            article_status=1, belongToUser__is_debug=1).filter(q)
        if sendArticleObjs:
            resule_data['flag'] = True
            resule_data['task_id'] = 2
            print('发布文章')

    if not resule_data['flag']:
        timedRefreshAuditObjs = articleObjs.filter(
            article_status=2,
            is_audit=0,
            aid__isnull=False,
            belongToUser__website_backstage=1)
        if timedRefreshAuditObjs:
            resule_data['flag'] = True
            resule_data['task_id'] = 3
            print('判断是否审核')

    # if not resule_data['flag']:
    #     now = datetime.datetime.now()
    #     deletionTime = (now - datetime.timedelta(hours=2)).strftime('%Y-%m-%d %H:%M:%S')
    #     deletionTime = datetime.datetime.strptime(deletionTime, '%Y-%m-%d %H:%M:%S')
    #     q = Q(Q(deletionTime__isnull=True) | Q(deletionTime__lte=deletionTime))
    #     q.add(Q(role_id=61) & Q(userType=1) & Q(website_backstage_url__isnull=False), Q.AND)
    #     q.add(Q(website_backstage=1), Q.AND) # 暂时
    #     deleteQuery = models.xzh_userprofile.objects.select_related('role').filter(q)
    #     if deleteQuery:
    #         print('deleteQuery---------------> ',deleteQuery[0].id)
    #         resule_data['flag'] = True
    #         resule_data['task_id'] = 4
    #         print('爬取客户网站,判断文章是否删除')

    response.code = 200
    response.msg = '查询成功'
    response.data = resule_data
    return JsonResponse(response.__dict__)
Example #7
0
def get_keyword_task(request, oper_type):
    response = Response.ResponseObj()
    redis_rc = redis.Redis(host='redis_host',
                           port=6379,
                           db=4,
                           decode_responses=True)
    if oper_type == 'insertTask':
        # redis_rc = redis.Redis(host='127.0.0.1', port=6379, db=4, decode_responses=True)
        start_time = time.time()
        print('start_time --->', start_time)
        dtime = datetime.datetime.now() - datetime.timedelta(minutes=10)
        now_date = datetime.datetime.now().strftime("%Y-%m-%d")

        q = Q(select_date__lt=now_date) | Q(select_date__isnull=True) & Q(
            get_date__lt=dtime) | Q(get_date__isnull=True)

        print('q -->', q)
        stop_check_objs = models.xzh_fugai_baobiao.objects.filter(
            stop_check=True)  # 查询 那些用户 停查 排除停查客户
        user_list = []
        for i in stop_check_objs:
            user_list.append(i.user_id)

        objs = models.xzh_keywords.objects.select_related('user').exclude(
            user_id__in=user_list).filter(q)[:1000]
        # print(objs.query)
        retData = []
        for obj in objs:

            # obj = objs[random.randint(0, objs.count())]
            ret_data = {
                'keywords_id': obj.id,
                'keywords': obj.keywords,
                'xiongZhangHaoIndex': obj.user.xiongZhangHaoIndex,
                'user_id': obj.user_id
            }
            obj.get_date = datetime.datetime.now()
            obj.save()
            # retData.append(ret_data)
            redis_rc.lpush('keyword', ret_data)
        stop_time = time.time()
        print('stop_time --->', stop_time, stop_time - start_time)
        # print('retData=============> ',retData)
        response.code = 200
        response.msg = '查询成功'

    elif oper_type == 'againInsertTask':
        len_keyword = redis_rc.llen('keyword')
        if len_keyword <= 200:
            response.code = 200
            response.msg = 'redis小于二百条更新'
            tasks.get_keyword_task.delay()
        else:
            response.code = 200
            response.msg = 'redis大于二百条不更新'
    return JsonResponse(response.__dict__)
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__)
def SearchSecondaryDomainName(request, article):
    response = Response.ResponseObj()
    print('article_id============> ', article)
    article_id = article.split('.html')[0]
    objs = models.xzh_article.objects.get(id=article_id)
    if objs:
        return render(request, 'index.html',
                      {'my_message': objs.DomainNameText})
    else:
        response.code = 301
        response.msg = '无此id'
        return JsonResponse(response.__dict__)
Example #10
0
def keyword_article_back_url(request, oper_type):
    response = Response.ResponseObj()
    if request.method == 'POST':
        keywords = request.POST.get('keywords')
        keywords_id = request.POST.get('keywords_id')
        rank = request.POST.get('rank')
        url = request.POST.get('url')
        user_id = request.POST.get('user_id')
        fugai_type = request.POST.get('fugai_type')
        print('user_id, rank, keywords_id, keywords, url=========> ', user_id,
              rank, keywords_id, keywords, url)
        if oper_type == 'judgeLink':
            flag = False
            if user_id and rank and keywords_id and keywords and url:
                articleObjs = models.xzh_article.objects.filter(
                    belongToUser_id=user_id, back_url__isnull=False)
                if articleObjs and articleObjs[0].belongToUser.guanwang:
                    articleObj = articleObjs[0]
                    guanwang = articleObj.belongToUser.guanwang
                    if url in guanwang or url == guanwang or guanwang in url:
                        flag = True
                for i in articleObjs:
                    # back_url = 'http://ask.39.net/question/36242269.html'
                    back_url = i.back_url
                    if url in back_url or url == back_url or back_url in url:
                        flag = True
                        break
            response.code = 200
            response.msg = '查询成功'
            response.data = flag

        elif oper_type == 'saveModels':
            if user_id and rank and keywords_id and keywords and url:
                print('=-=----------------保存结果', fugai_type)
                keywordObjs = models.xzh_keywords_detail.objects.filter(
                    xzh_keywords_id=keywords_id)
                # keywordObjs = models.xzh_keywords.objects.filter(id=keywords_id)
                if keywordObjs:
                    fugaiType = 1
                    if fugai_type and int(
                            fugai_type) == 2:  # 判断是 移动端 还是 PC 端  2为PC
                        fugaiType = 2

                    keywordObjs.create(xzh_keywords_id=keywords_id,
                                       url=url,
                                       rank=rank,
                                       fugai_type=fugaiType)
            response.code = 200
    else:
        response.code = 402
        response.msg = '请求异常'
    return JsonResponse(response.__dict__)
Example #11
0
def user(request):
    response = Response.ResponseObj()
    token = 'd7361566c366c19fabaa91c5f46c3086'
    timestamp = 123
    user_id = 9
    response.code = 200
    response.msg = '查询成功'
    response.data = {
        'token': token,
        'timestamp': timestamp,
        'user_id': user_id
    }
    return JsonResponse(response.__dict__)
Example #12
0
def init_fugai_baobiao(request):
    response = Response.ResponseObj()

    user_objs = models.xzh_userprofile.objects.filter(role_id=61)
    for user_obj in user_objs:
        user_id = user_obj.id

        data = {
            'user_id': user_id,
            'keywords_num': 0,
            'status': 1,
            'today_cover': 0,
            'total_cover': 0,
            'publish_num': 0,
        }
        xzh_keywords_objs = models.xzh_keywords.objects.filter(user_id=user_id)
        data['keywords_num'] = xzh_keywords_objs.count()  # 关键词数

        if data['keywords_num'] > 0:
            now_date = datetime.datetime.now().strftime("%Y-%m-%d")
            q = Q(select_date__lt=now_date) | Q(select_date__isnull=True)
            if xzh_keywords_objs.filter(q).count() == 0:
                data['status'] = 2  # 查询完成

            xzh_keywords_detail_objs = models.xzh_keywords_detail.objects.filter(
                xzh_keywords__user_id=user_id)
            data['today_cover'] = xzh_keywords_detail_objs.filter(
                create_date=now_date).count()  # 今日覆盖
            data['total_cover'] = xzh_keywords_detail_objs.count()  # 总覆盖
        else:
            data['status'] = 2
        data['publish_num'] = models.xzh_article.objects.filter(
            user_id=user_id).count()  # 总发布篇数

        xzh_fugai_baobiao_objs = models.xzh_fugai_baobiao.objects.filter(
            user_id=user_id)
        if xzh_fugai_baobiao_objs:  # 已经存在信息
            xzh_fugai_baobiao_objs.update(**data)
        else:
            models.xzh_fugai_baobiao.objects.create(**data)

    response.code = 200
    response.msg = "初始化完成"
    return JsonResponse(response.__dict__)
def userGetCookieOper(request, oper_type):
    response = Response.ResponseObj()
    # 进行获取cookie 和 栏目
    if oper_type == 'getTheDebugUser':
        print(
            '=======================进行获取cookie 和 栏目============================'
        )
        objs = models.xzh_userprofile.objects.filter(
            is_debug=False, role_id=61).order_by('create_date')
        if objs:
            obj = objs[0]
            website_backstage_url = obj.website_backstage_url.strip()
            userid = obj.website_backstage_username
            pwd = obj.website_backstage_password
            cookie = ''
            if obj.cookies:
                cookie = eval(obj.cookies)
            response.data = {
                'website_backstage': obj.website_backstage,
                'website_backstage_url': website_backstage_url,
                'userid': userid,
                'pwd': pwd,
                'cookie': cookie,
                'o_id': obj.id
            }
        response.msg = '查询成功'
        response.code = 200

    elif oper_type == 'updateModel':
        print(
            '==============================登录cookie 与栏目 写入数据==============================='
        )
        oid = request.POST.get('oid')
        retData = request.POST.get('retData')
        cookie = request.POST.get('cookie')
        print('cookie------cookie-------->', cookie)
        models.xzh_userprofile.objects.filter(id=oid).update(
            column_all=retData, is_debug=1, cookies=cookie)
        response.code = 200
    else:
        response.code = 402
        response.msg = '请求失败'

    return JsonResponse(response.__dict__)
Example #14
0
def login(request):
    response = Response.ResponseObj()
    username = request.POST.get('username')
    password = request.POST.get('password')
    # 查询数据库
    userprofile_objs = models.xzh_userprofile.objects.filter(
        username=username,
        # md5加密 密码
        password=account.str_encrypt(password),
        status=1)

    if userprofile_objs:
        # 如果有数据 查询第一条对象
        userprofile_obj = userprofile_objs[0]
        token = userprofile_obj.token
        # 如果没有token 则生成 token
        # if not userprofile_obj.token:
        #     token = account.get_token(account.str_encrypt(password))
        #     userprofile_obj.token = token
        # else:

        response.code = 200
        response.msg = '登录成功'
        time.time()
        # company_id = ''
        # if userprofile_obj.company_id:
        #     company_id = userprofile_obj.company_id
        response.data = {
            'token': token,
            'user_id': userprofile_obj.id,
            'set_avator': userprofile_obj.set_avator,
            'username': userprofile_obj.username,
            'role_id': userprofile_obj.role_id,
        }

        userprofile_obj.last_login_date = datetime.datetime.now()
        userprofile_obj.save()
    else:
        response.code = 401
        response.msg = "账号或密码错误"
    return JsonResponse(response.__dict__)
def img_upload(request, oper_type):
    response = Response.ResponseObj()
    if oper_type == 'upload':
        file_obj = request.FILES.get('file')
        file_name = str(int(time.time())) + file_obj.name
        file_abs_name = os.path.join("statics", 'xiaochengxu', file_name)
        with open(file_abs_name, "wb") as f:
            for chunk in file_obj.chunks():
                f.write(chunk)

        path_name = 'http://192.168.10.207:8003' + '/statics/xiaochengxu/' + file_name
        # path_name = 'http://xiongzhanghao.zhugeyingxiao.com:8003' + '/statics/xiaochengxu/' + file_name
        print('path_name=========> ', path_name)
        response.code = 200
        response.msg = '上传成功'
        response.data = path_name

    else:
        response.code = 402
        response.msg = '请求异常'
    return JsonResponse(response.__dict__)
Example #16
0
def select_keywords_cover(request):
    response = Response.ResponseObj()
    if request.method == "GET":
        redis_rc = redis.Redis(host='redis_host',
                               port=6379,
                               db=4,
                               decode_responses=True)
        # redis_rc = redis.Redis(host='127.0.0.1', port=6379, db=4, decode_responses=True)
        task_keyword = redis_rc.lpop('keyword')
        if task_keyword:
            task_keyword = eval(task_keyword)
            keywords_id = task_keyword.get('keywords_id')
            print('keywords_id=========> ', keywords_id)
            objs = models.xzh_keywords.objects.filter(id=keywords_id)
            obj = objs[0]
            obj.get_date = datetime.datetime.now()
            obj.save()
            response.data = task_keyword
            response.code = 200

    else:  # 提交查询关键词覆盖的结果
        # {'url': 'http://author.baidu.com/home/1611292686377463', 'keywords': '四川肛肠医院', 'rank': 4, 'keywords_id': 834}
        print('保存查覆盖结果')
        form_obj = AddForm(request.POST)
        if form_obj.is_valid():
            rank = form_obj.cleaned_data.get('rank')
            keywords_id = form_obj.cleaned_data.get('keywords_id')
            models.xzh_keywords.objects.filter(id=keywords_id).update(
                select_date=datetime.datetime.now())
            print('rank -->', rank, type(rank))
            if rank > 0:
                models.xzh_keywords_detail.objects.create(
                    xzh_keywords_id=form_obj.cleaned_data.get('keywords_id'),
                    url=form_obj.cleaned_data.get('url'),
                    rank=form_obj.cleaned_data.get('rank'),
                )
        else:
            print('form_obj.errors.as_json() -->', form_obj.errors.as_json())
    return JsonResponse(response.__dict__)
Example #17
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__)
Example #18
0
def user_oper(request, oper_type, o_id):
    response = Response.ResponseObj()
    user_id = request.GET.get('user_id')
    if request.method == "POST":
        form_data = {
            'o_id': o_id,
            'oper_user_id': request.GET.get('user_id'),
            'password': request.POST.get('password'),
            'username': request.POST.get('username'),
            'lunbotu': request.POST.get('lunbotu'),  # 轮播图
            'hospital_logoImg': request.POST.get('hospital_logoImg'),  # logo图片
            'hospital_phone': request.POST.get('hospital_phone'),  # 医院电话
            'hospital_introduction':
            request.POST.get('hospital_introduction'),  # 医院简介
            'hospital_address': request.POST.get('hospital_address'),  # 医院地址
            'hospital_menzhen': request.POST.get('hospital_menzhen'),  # 门诊时间
            'x_shaft': request.POST.get('x_shaft'),  # X轴
            'y_shaft': request.POST.get('y_shaft'),  # Y轴
        }
        if oper_type == "add":
            print('form_data----->', form_data)
            #  创建 form验证 实例(参数默认转成字典)
            forms_obj = AddForm(form_data)
            if forms_obj.is_valid():
                print("验证通过")
                print('forms_obj.cleaned_data==> ', forms_obj.cleaned_data)
                models.xcx_userprofile.objects.create(**forms_obj.cleaned_data)
                response.code = 200
                response.msg = "添加成功"
            else:
                print("验证不通过")
                # print(forms_obj.errors)
                response.code = 301
                # print(forms_obj.errors.as_json())
                response.msg = json.loads(forms_obj.errors.as_json())

        elif oper_type == "update":
            # 获取需要修改的信息
            forms_obj = UpdateForm(form_data)
            if forms_obj.is_valid():
                print("验证通过")
                formObjs = forms_obj.cleaned_data
                objs = models.xcx_userprofile.objects.filter(id=o_id)
                if objs:
                    #  更新 数据
                    response.code = 200
                    response.msg = "修改成功"
                    objs.update(**formObjs)
                else:
                    response.code = 301
                    response.msg = '无此ID'
            else:
                print("验证不通过")
                # print(forms_obj.errors)
                response.code = 301
                # print(forms_obj.errors.as_json())
                #  字符串转换 json 字符串
                response.msg = json.loads(forms_obj.errors.as_json())

        elif oper_type == "delete":
            # 删除 ID
            if o_id == user_id:
                response.code = 301
                response.msg = '不能删除自己'
            else:
                objs = models.xcx_userprofile.objects.get(id=o_id)
                if objs:
                    objs.delete()
                    response.code = 200
                    response.msg = "删除成功"
                else:
                    response.code = 302
                    response.msg = '删除ID不存在'
            response.data = {}

    else:
        # 查询该用户所有栏目
        response.code = 402
        response.msg = "请求异常"

    return JsonResponse(response.__dict__)
Example #19
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__)
Example #20
0
def user_oper(request, oper_type, o_id):
    response = Response.ResponseObj()
    user_id = request.GET.get('user_id')
    user_objs = models.xzh_userprofile.objects.filter(id=user_id)

    if user_objs:
        user_obj = user_objs[0]
        user_obj_role = user_obj.role_id
        if request.method == "POST":
            if int(user_obj_role) == 61:
                response.code = 301
                response.msg = '权限不足'
            else:
                if oper_type == "add":
                    form_data = {
                        'oper_user_id': request.GET.get('user_id'),
                        'username': request.POST.get('username'),
                        'role_id': request.POST.get('role_id'),
                        'password': request.POST.get('password'),
                        'website_backstage': request.POST.get('website_backstage'),
                        'website_backstage_username': request.POST.get('website_backstage_username'),
                        'website_backstage_url': request.POST.get('website_backstage_url'),
                        'website_backstage_password': request.POST.get('website_backstage_password'),
                        'website_backstage_token': request.POST.get('website_backstage_token'),
                        'website_backstage_appid': request.POST.get('website_backstage_appid'),
                        'xiongZhangHaoIndex': request.POST.get('xiongZhangHaoIndex'),
                        'secondaryDomainName': request.POST.get('secondaryDomainName'),
                        'xiong_zhang_hao_user': request.POST.get('xiong_zhang_hao_user'),
                        'xiong_zhang_hao_pwd': request.POST.get('xiong_zhang_hao_pwd'),
                        'fans_search_keyword': request.POST.get('fans_search_keyword'),
                        'guanwang': request.POST.get('guanwang'),                       # 官网
                    }
                    print('form_data----->',form_data)
                    #  创建 form验证 实例(参数默认转成字典)

                    if int(form_data.get('role_id')) == 64 or int(form_data.get('role_id')) == 66:
                        forms_obj = AdminAddForm(form_data)
                    else:
                        forms_obj = AddForm(form_data)
                    if forms_obj.is_valid():
                        print("验证通过")
                        models.xzh_userprofile.objects.create(**forms_obj.cleaned_data)

                        response.code = 200
                        response.msg = "添加成功"

                    else:
                        print("验证不通过")
                        response.code = 301
                        response.msg = json.loads(forms_obj.errors.as_json())

                elif oper_type == "update":
                    # 获取需要修改的信息
                    form_data = {
                        'o_id': o_id,
                        'username': request.POST.get('username'),
                        'role_id': request.POST.get('role_id'),
                        'website_backstage': request.POST.get('website_backstage'),
                        'website_backstage_url': request.POST.get('website_backstage_url'),
                        'website_backstage_username': request.POST.get('website_backstage_username'),
                        'website_backstage_password': request.POST.get('website_backstage_password'),
                        'website_backstage_token': request.POST.get('website_backstage_token'),
                        'website_backstage_appid': request.POST.get('website_backstage_appid'),
                        'xiongZhangHaoIndex': request.POST.get('xiongZhangHaoIndex'),
                        'xiong_zhang_hao_user': request.POST.get('xiong_zhang_hao_user'),
                        'xiong_zhang_hao_pwd': request.POST.get('xiong_zhang_hao_pwd'),
                        'fans_search_keyword': request.POST.get('fans_search_keyword'),
                        'guanwang': request.POST.get('guanwang'),  # 官网
                    }
                    flag = False
                    if int(form_data.get('role_id')) in [64, 66]:
                        forms_obj = AdminUpdateForm(form_data)
                    else:
                        flag = True
                        forms_obj = UpdateForm(form_data)
                    if forms_obj.is_valid():
                        print("验证通过")
                        print(forms_obj.cleaned_data)
                        o_id = forms_obj.cleaned_data['o_id']
                        username = forms_obj.cleaned_data['username']
                        role_id = forms_obj.cleaned_data['role_id']
                        objs = models.xzh_userprofile.objects.filter(
                            id=o_id
                        )
                        #  更新 数据
                        if objs:
                            if flag:
                                website_backstage = forms_obj.cleaned_data['website_backstage']
                                website_backstage_url = forms_obj.cleaned_data['website_backstage_url']
                                website_backstage_username = forms_obj.cleaned_data['website_backstage_username']
                                website_backstage_password = forms_obj.cleaned_data['website_backstage_password']
                                website_backstage_token = forms_obj.cleaned_data['website_backstage_token']
                                website_backstage_appid = forms_obj.cleaned_data['website_backstage_appid']
                                xiongZhangHaoIndex = forms_obj.cleaned_data['xiongZhangHaoIndex']
                                xiong_zhang_hao_pwd = forms_obj.cleaned_data['xiong_zhang_hao_pwd']
                                xiong_zhang_hao_user = forms_obj.cleaned_data['xiong_zhang_hao_user']
                                fans_search_keyword = forms_obj.cleaned_data['fans_search_keyword']
                                guanwang = forms_obj.cleaned_data['guanwang']

                                #  查询数据库  用户id
                                objs.update(
                                    username=username,
                                    role_id=role_id,
                                    website_backstage=website_backstage,
                                    website_backstage_url=website_backstage_url,
                                    website_backstage_username=website_backstage_username,
                                    website_backstage_password=website_backstage_password,
                                    website_backstage_appid=website_backstage_appid,
                                    website_backstage_token=website_backstage_token,
                                    xiongZhangHaoIndex=xiongZhangHaoIndex,
                                    xiong_zhang_hao_user=xiong_zhang_hao_user,
                                    xiong_zhang_hao_pwd=xiong_zhang_hao_pwd,
                                    fans_search_keyword=fans_search_keyword,
                                    guanwang=guanwang,
                                )
                            else:
                                objs.update(
                                    username=username,
                                    role_id=role_id,
                                )
                            response.code = 200
                            response.msg = "修改成功"
                        else:
                            response.code = 303
                            response.msg = '修改ID不存在'

                    else:
                        print("验证不通过")
                        # print(forms_obj.errors)
                        response.code = 301
                        # print(forms_obj.errors.as_json())
                        #  字符串转换 json 字符串
                        response.msg = json.loads(forms_obj.errors.as_json())

                # 删除 用户
                elif oper_type == "delete":
                    if o_id == user_id:
                        response.code = 301
                        response.msg = '不能删除自己'
                    elif int(o_id) == 54:
                        response.code = 301
                        response.msg = '不能删除该用户'
                    else:
                        objs = models.xzh_userprofile.objects.get(id=o_id)
                        if objs:
                            userObjs = models.xzh_article.objects.filter(belongToUser_id=o_id)
                            if userObjs:
                                response.code = 301
                                response.msg = '含有文章子级,请先删除该用户文章'
                            else:
                                objs.delete()
                                response.code = 200
                                response.msg = "删除成功"
                        else:
                            response.code = 302
                            response.msg = '删除ID不存在'
                    response.data = {}

                # 启用 用户  ×
                elif oper_type == "update_status":
                    status = request.POST.get('status')
                    print('status -->', status)
                    objs = models.xzh_userprofile.objects.filter(id=o_id)
                    if objs:
                        objs.update(status=status)
                        response.code = 200
                        response.msg = "状态修改成功"
                    else:
                        response.code = 301
                        response.msg = "用户ID不存在"

                # 启用 用户
                elif oper_type == 'updateStatus':
                    userObj = models.xzh_userprofile.objects
                    objs = userObj.filter(id=user_id)
                    if objs and int(objs[0].role_id) in [64, 66]:
                        obj = userObj.filter(id=o_id)
                        print('obj.status==============> ',obj[0].status)
                        if int(obj[0].status) == 1:
                            status = 2
                        else:
                            status = 1
                        obj.update(status=status)
                        response.code = 200
                        response.msg = '修改成功'
                    else:
                        response.code = 301
                        response.msg = '该角色不可修改状态'


        else:
            # 查询该用户所有栏目
            if oper_type == 'getColumn':
                Id = request.GET.get('Id')
                obj = models.xzh_userprofile.objects.get(id=Id)
                response.code = 200
                response.msg = '查询成功'
                response.data = obj.column_all
                if not response.data:
                    response.data = json.dumps([])


            else:
                response.code = 402
                response.msg = "请求异常"

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

    return JsonResponse(response.__dict__)
def fugai_baobiao_oper(request, oper_type, o_id):
    response = Response.ResponseObj()
    user_id = request.GET.get('user_id')
    userObjs = models.xzh_userprofile.objects.filter(id=user_id)
    if userObjs:
        userObj = userObjs[0]
        userObjRole = userObj.role_id
        if request.method == "POST":
            pass
        else:
            # 覆盖报表展开详情
            if oper_type == 'detail':
                # baobiao_obj = models.xzh_fugai_baobiao.objects.filter(id=o_id, user_id=user_id)
                # if baobiao_obj:
                objs = models.xzh_fugai_baobiao_detail.objects.filter(
                    xzh_fugai_baobiao_id=o_id).order_by('-create_date')

                # 返回的数据
                ret_data = []

                forms_obj = SelectForm(request.GET)
                if forms_obj.is_valid():
                    current_page = forms_obj.cleaned_data['current_page']
                    length = forms_obj.cleaned_data['length']
                    data_count = objs.count()

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

                        #  将查询出来的数据 加入列表
                        ret_data.append({
                            'id':
                            obj.id,
                            'link_num':
                            obj.link_num,
                            'cover_num':
                            obj.cover_num,
                            'baobiao_url':
                            obj.baobiao_url,
                            'create_date':
                            obj.create_date.strftime('%Y-%m-%d')
                        })
                    #  查询成功 返回200 状态码
                    response.code = 200
                    response.msg = '查询成功'
                    response.data = {
                        'ret_data': ret_data,
                        'data_count': data_count,
                    }
                # else:
                #     response.code = 301
                #     response.msg = '数据异常'
            # 停查
            elif oper_type == 'stopCheck':
                if int(userObjRole) != 61:
                    objs = models.xzh_fugai_baobiao.objects.filter(id=o_id)
                    flag = True
                    if objs[0].stop_check:
                        flag = False
                    objs.update(stop_check=flag)
                    response.code = 200
                    response.msg = '修改成功'
                else:
                    response.code = 301
                    response.msg = '权限不足'

            else:
                response.code = 402
                response.msg = "请求异常"
    else:
        response.code = 500
        response.msg = '非法用户'
    return JsonResponse(response.__dict__)
Example #22
0
def articleScriptOper(request, oper_type):
    response = Response.ResponseObj()
    # 发送文章
    if oper_type == 'sendArticle':
        print('==============================sendArticle==sendArticle')
        now_date = datetime.datetime.now()
        q = Q()
        q.add(Q(send_time__lte=now_date) | Q(send_time__isnull=True), Q.AND)
        objs = models.xzh_article.objects.select_related(
            'belongToUser').filter(q).filter(
                article_status=1,
                belongToUser__is_debug=1).order_by('create_date')
        print('objs========================> ', objs)
        if objs:
            obj = objs[0]
            if obj.title and obj.column_id and obj.summary and obj.content:
                # models.xzh_article.objects.filter(id=obj.id).update(
                #     articlePublishedDate=datetime.datetime.now()
                # )
                result_data = {
                    'website_backstage':
                    objs[0].belongToUser.website_backstage,
                    'website_backstage_url':
                    objs[0].belongToUser.website_backstage_url.strip(),
                    'website_backstage_username':
                    objs[0].belongToUser.website_backstage_username,
                    'website_backstage_password':
                    objs[0].belongToUser.website_backstage_password,
                    'cookies':
                    objs[0].belongToUser.cookies,
                    'title':
                    objs[0].title,
                    'summary':
                    objs[0].summary,
                    'content':
                    objs[0].content,
                    'typeid':
                    eval(objs[0].column_id).get('Id'),  # 此处I 为大写请勿更改
                    'o_id':
                    objs[0].id
                }
                if obj.articlePicName:
                    result_data['picname'] = obj.articlePicName

                response.data = result_data
        response.code = 200

    # 更改状态和备注
    elif oper_type == 'sendArticleModels':
        resultData = request.POST.get('resultData')
        o_id = request.POST.get('o_id')
        print('====================', resultData)
        print(request.POST)
        print(request.GET)
        if resultData:
            resultData = eval(resultData)
            code = int(resultData.get('code'))
            objs = models.xzh_article.objects.filter(id=o_id)
            website_backstage = objs[0].belongToUser.website_backstage
            print('code==========> ', code)
            print("=============resultData.get('huilian')=======> ",
                  resultData.get('huilian'))
            print("=============resultData.get('aid')=======> ",
                  resultData.get('aid'))
            article_status = 3
            note_content = ''
            huilian = ''
            aid = 0
            is_audit = False
            if code == 200:  # 发布成功
                article_status = 2
                if int(website_backstage) == 2 or int(website_backstage) == 3:
                    article_status = 4  # 如果是 pcv9 或 FTP 不需要审核
                    is_audit = 1

                huilian = resultData.get('huilian')
                aid = resultData.get('aid')

            elif code == 300:  # 标题重复
                note_content = '标题重复'

            elif code == 305:  # 登录失败
                note_content = '模板文件不存在, 请选择子级菜单'

            elif code == 301:
                note_content = '客户网站标题未查到, 请验证'

            else:  # 发布失败
                note_content = '发布失败'
            # print('note_content============> ', note_content)
            objs.update(article_status=article_status,
                        back_url=huilian,
                        aid=aid,
                        note_content=note_content,
                        is_audit=is_audit)

    # 判断文章是否审核
    elif oper_type == 'refreshAudit':
        objs = models.xzh_article.objects.filter(
            article_status=2,
            is_audit=0,
            aid__isnull=False,
            belongToUser__website_backstage=1)
        if objs:
            obj = objs[0]
            print('定时刷新文章是否审核----------------->', obj.id)
            result_data = {
                'website_backstage_url':
                obj.belongToUser.website_backstage_url,
                'website_backstage_username':
                obj.belongToUser.website_backstage_username,
                'website_backstage_password':
                obj.belongToUser.website_backstage_password,
                'cookies': obj.belongToUser.cookies,
                'o_id': obj.id,
                'aid': obj.aid,
                'userType': obj.belongToUser.userType,
            }
            response.data = result_data
        response.code = 200

    # 文章审核更新数据库
    elif oper_type == 'refreshAuditModel':
        o_id = request.POST.get('o_id')
        status = request.POST.get('status')
        userType = request.POST.get('userType')
        article_status = 2
        if userType and o_id:
            if status == 'True':
                print('=================')
                article_status = 4
                if int(userType) == 2:  # 判断是否为特殊用户
                    article_status = 6
        print('status, o_id============> ', status, o_id, 'userType:',
              userType, 'article_status: ', article_status)
        models.xzh_article.objects.filter(id=o_id).update(
            is_audit=status, article_status=article_status)
        response.code = 200

    # 提交文章到熊掌号
    elif oper_type == 'submitXiongZhangHao':
        print('===')
        objs = models.xzh_article.objects.filter(is_audit=True,
                                                 article_status=4)
        note_content = ''
        id_list = []
        for obj in objs:
            id_list.append(obj.id) if obj.id not in id_list else id_list

            appid = obj.belongToUser.website_backstage_appid
            token = obj.belongToUser.website_backstage_token
            print('appid, token------------------> ', appid, token)
            if obj.back_url:
                if token and appid:
                    submitUrl = 'http://data.zz.baidu.com/urls?appid={appid}&token={token}&type=realtime'.format(
                        appid=appid, token=token)
                    ret = requests.post(submitUrl, data=obj.back_url)
                    print('ret.text------------------->', ret.text)
                    if json.loads(ret.text).get('error'):
                        note_content = json.loads(ret.text).get('message')
                    elif json.loads(ret.text).get('not_same_site'):
                        print(
                            '======================================不是本站url或未处理的url============================'
                        )
                        note_content = '不是本站url或未处理的url'
                    elif json.loads(ret.text).get('not_valid'):
                        print(
                            '==---------------------------不合法的url=-----------------------------'
                        )
                        note_content = '不合法的url'
                    else:
                        note_content = ''
                        obj.article_status = 5
                else:
                    note_content = 'appid 或 token 有问题, 建议重新获取token'
                obj.note_content = note_content
                obj.save()
                continue
        response.code = 200

    else:
        response.code = 402
        response.msg = '请求失败'

    return JsonResponse(response.__dict__)
Example #23
0
def company_oper(request, oper_type, o_id):
    response = Response.ResponseObj()
    if request.method == "POST":

        # 添加公司
        if oper_type == "add":
            form_data = {
                'user_id': o_id,
                'oper_user_id': request.GET.get('user_id'),
                'name': request.POST.get('name'),
            }
            #  创建 form验证 实例(参数默认转成字典)
            forms_obj = AddForm(form_data)
            if forms_obj.is_valid():
                print("验证通过")
                # print(forms_obj.cleaned_data)
                #  添加数据库
                # print('forms_obj.cleaned_data-->',forms_obj.cleaned_data)
                models.xzh_company.objects.create(**forms_obj.cleaned_data)
                response.code = 200
                response.msg = "添加成功"
            else:
                print("验证不通过")
                # print(forms_obj.errors)
                response.code = 301
                # print(forms_obj.errors.as_json())
                response.msg = json.loads(forms_obj.errors.as_json())

        # 修改公司
        elif oper_type == "update":
            # 获取需要修改的信息
            form_data = {
                'o_id': o_id,
                'name': request.POST.get('name'),
            }

            forms_obj = UpdateForm(form_data)
            if forms_obj.is_valid():
                print("验证通过")
                print(forms_obj.cleaned_data)
                o_id = forms_obj.cleaned_data['o_id']
                name = forms_obj.cleaned_data['name']
                #  查询数据库  用户id
                objs = models.xzh_company.objects.filter(id=o_id)
                #  更新 数据
                if objs:
                    objs.update(name=name)

                    response.code = 200
                    response.msg = "修改成功"
                else:
                    response.code = 303
                    response.msg = json.loads(forms_obj.errors.as_json())

            else:
                print("验证不通过")
                # print(forms_obj.errors)
                response.code = 301
                # print(forms_obj.errors.as_json())
                #  字符串转换 json 字符串
                response.msg = json.loads(forms_obj.errors.as_json())

        # 删除公司
        elif oper_type == "delete":
            # 删除 ID
            objs = models.xzh_company.objects.filter(id=o_id)
            if objs:
                objs.delete()
                response.code = 200
                response.msg = "删除成功"
            else:
                response.code = 302
                response.msg = '删除ID不存在'

    else:
        response.code = 402
        response.msg = "请求异常"

    return JsonResponse(response.__dict__)
Example #24
0
def addFansGetTask(request, oper_type):
    response = Response.ResponseObj()
    q = Q()
    q.add(Q(status=2), Q.AND)

    # 判断是否有任务
    if oper_type == 'judgmentTask':
        objs = models.xzh_add_fans.objects.filter(q)[:1]
        flag = False
        if objs:
            flag = True
        response.code = 200
        response.data = {'flag': flag}

    # 获取任务
    elif oper_type == 'getTask':
        objs = models.xzh_add_fans.objects.filter(q).order_by('?')[:1]
        if objs:
            obj = objs[0]
            obj.status = 2
            response.code = 200
            response.msg = '查询成功'
            response.data = obj.belong_user.fans_search_keyword
            obj.save()

    # 加粉前后 查询 粉丝数量
    elif oper_type == 'queryFollowersNum':
        objs = models.xzh_add_fans.objects.all().exclude(status__in=[4, 5])
        for obj in objs:
            appid = obj.belong_user.website_backstage_appid
            if appid:
                requests_obj = requests.session()
                url = 'https://author.baidu.com/home/{}?from=dusite_sresults'.format(
                    appid)
                data = '%22from%22:%22dusite_sresults%22,%22app_id%22:%22{appid}%22'.format(
                    appid=appid)
                url1 = 'https://author.baidu.com/profile?context={%s}&cmdType=&pagelets=root&reqID=0&ispeed=1' % data
                # print('url-------------> ',url)
                # print('url1-------------> ',url1)
                headers = {
                    'User-Agent':
                    'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Mobile Safari/537.36',
                    'Referer':
                    'https://author.baidu.com/home/{}?from=dusite_sresults'.
                    format(appid),
                }
                requests_obj.get(url, headers=headers)
                ret1 = requests_obj.get(url1, headers=headers)
                result = ret1.text.split('BigPipe.onPageletArrive(')[1]
                result = result[:-2]
                if result:
                    html = json.loads(result).get('html')
                    keyword = obj.belong_user.fans_search_keyword.split(
                        '熊掌号')[0].strip()
                    print('html---------------------> ', html, keyword)
                    if html and keyword in html:
                        soup = BeautifulSoup(html, 'lxml')
                        interaction = soup.find('div', id='interaction')
                        # print('interaction--------> ',interaction)
                        fans = interaction.find('div', class_='fans')
                        fans_num = fans.find('span').get_text()
                        obj.after_add_fans = int(fans_num)
                        print('当前粉丝数量------------------------------> ',
                              fans_num)
                        if obj.status == 1:
                            print('粉前查询--------------=============')
                            obj.status = 2
                            obj.befor_add_fans = int(fans_num)

                        elif obj.status == 2:
                            print('加粉中=-------------------=================')
                            if int(fans_num
                                   ) >= obj.add_fans_num + obj.befor_add_fans:
                                obj.status = 3
                        elif obj.status == 3:
                            print('粉后查询==========-----------------=========')
                            obj.status = 4
                            obj.after_add_fans = int(fans_num)
                        else:
                            obj.status = 5
                    else:
                        obj.status = 5
                        obj.errorText = '关键词与xiongzhanghaoID不匹配 或 连接超时, 请联系管理员'
                    obj.save()
            else:
                obj.status = 5
                obj.errorText = 'xiongzhanghaoID异常,请找管理员操作'
                obj.save()
                response.code = 301
                response.msg = '没有查到熊掌号ID'
        response.code = 200
        response.msg = '查询粉丝数量'
    return JsonResponse(response.__dict__)
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__)
Example #26
0
def program_oper(request, oper_type, o_id):
    response = Response.ResponseObj()
    if request.method == "POST":
        form_data = {
            # 'belongUser_id': request.GET.get('user_id'),
            'belongUser_id': 4,
            'program_name': request.POST.get('program_name'),  # 栏目名称
            'program_type': request.POST.get('program_type'),  # 栏目类型
            'suoluetu': request.POST.get('suoluetu'),  # 缩略图
            'program_text': request.POST.get('program_text', '')  # 单页设置内容
        }
        program_type = form_data.get('program_type')
        program_text = form_data.get('program_text')
        if program_type and program_text and int(program_type) == 1:
            response.code = 301
            response.msg = '栏目类型为单页是, 可添加单页内容'
        else:
            print('form_data===============> ', form_data)
            if oper_type == "add":
                #  创建 form验证 实例(参数默认转成字典)
                forms_obj = AddForm(form_data)
                if forms_obj.is_valid():
                    models.xcx_program_management.objects.create(
                        **forms_obj.cleaned_data)
                    response.code = 200
                    response.msg = "添加成功"
                else:
                    print("验证不通过")
                    response.code = 301
                    response.msg = json.loads(forms_obj.errors.as_json())

            elif oper_type == "update":
                # 获取需要修改的信息
                forms_obj = UpdateForm(form_data)
                if forms_obj.is_valid():
                    print("验证通过")
                    #  查询数据库  用户id
                    objs = models.xcx_program_management.objects.filter(
                        id=o_id)
                    #  更新 数据
                    print(forms_obj.cleaned_data)
                    if objs:
                        objs.update(**forms_obj.cleaned_data)
                        response.code = 200
                        response.msg = "修改成功"
                    else:
                        response.code = 301
                        response.msg = '无此栏目'
                else:
                    print("验证不通过")
                    # print(forms_obj.errors)
                    response.code = 301
                    # print(forms_obj.errors.as_json())
                    #  字符串转换 json 字符串
                    response.msg = json.loads(forms_obj.errors.as_json())

            elif oper_type == "delete":
                # 删除 ID
                objs = models.xcx_program_management.objects.filter(id=o_id)
                if objs:
                    articleObj = models.xcx_article.objects.filter(
                        article_program_id=o_id)
                    if not articleObj:
                        objs.delete()
                        response.code = 200
                        response.msg = "删除成功"
                    else:
                        response.code = 301
                        response.msg = '该栏目含有文章, 不可删除'
                else:
                    response.code = 302
                    response.msg = '删除ID不存在'

    else:
        response.code = 402
        response.msg = "请求异常"
    return JsonResponse(response.__dict__)
Example #27
0
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__)
Example #28
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__)
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__)
Example #30
0
def role_oper(request, oper_type, o_id):
    response = Response.ResponseObj()
    if request.method == "POST":
        user_id = request.GET.get('user_id')
        if oper_type == "add":
            form_data = {
                'oper_user_id': request.GET.get('user_id'),
                'name': request.POST.get('name'),
                'permissionsList': request.POST.get('permissionsList'),
            }
            #  创建 form验证 实例(参数默认转成字典)
            forms_obj = AddForm(form_data)
            if forms_obj.is_valid():
                print("验证通过")
                # print(forms_obj.cleaned_data)
                #  添加数据库
                # print('forms_obj.cleaned_data-->',forms_obj.cleaned_data)
                print({
                    'name': forms_obj.cleaned_data.get('name'),
                    'oper_user_id': forms_obj.cleaned_data.get('oper_user_id'),
                })
                obj = models.xzh_role.objects.create(**{
                    'name': forms_obj.cleaned_data.get('name'),
                    'oper_user_id': forms_obj.cleaned_data.get('oper_user_id'),
                })

                permissionsList = forms_obj.cleaned_data.get('permissionsList')
                print('permissionsList -->', permissionsList)
                obj.permissions = permissionsList
                obj.save()
                response.code = 200
                response.msg = "添加成功"
                response.data = {'testCase': obj.id}
            else:
                print("验证不通过")
                # print(forms_obj.errors)
                response.code = 301
                # print(forms_obj.errors.as_json())
                response.msg = json.loads(forms_obj.errors.as_json())


        elif oper_type == "update":
            # 获取需要修改的信息
            form_data = {
                'o_id': o_id,
                'name': request.POST.get('name'),
                'permissionsList': request.POST.get('permissionsList'),
            }

            forms_obj = UpdateForm(form_data)
            if forms_obj.is_valid():
                print("验证通过")
                print(forms_obj.cleaned_data)
                o_id = forms_obj.cleaned_data['o_id']
                name = forms_obj.cleaned_data['name']
                permissionsList = forms_obj.cleaned_data['permissionsList']
                #  查询数据库  用户id
                objs = models.xzh_role.objects.filter(
                    id=o_id
                )
                #  更新 数据
                if objs:
                    objs.update(
                        name=name
                    )

                    objs[0].permissions = permissionsList

                    response.code = 200
                    response.msg = "修改成功"
                else:
                    response.code = 303
                    response.msg = '修改数据不存在'

            else:
                print("验证不通过")
                # print(forms_obj.errors)
                response.code = 301
                # print(forms_obj.errors.as_json())
                #  字符串转换 json 字符串
                response.msg = json.loads(forms_obj.errors.as_json())

        elif oper_type == "delete":
            # 删除 ID
            objs = models.xzh_role.objects.filter(id=o_id)
            if objs:
                obj = objs[0]
                userObj = models.xzh_userprofile.objects.get(id=user_id)
                if userObj.role_id == obj.id:
                    response.code = 301
                    response.msg = '当前角色不能删除该角色'
                else:
                    if obj.xzh_userprofile_set.all().count() > 0:
                        response.code = 304
                        response.msg = '含有子级数据,请先删除或转移子级数据'
                    else:
                        objs.delete()
                        response.code = 200
                        response.msg = "删除成功"
            else:
                response.code = 302
                response.msg = '删除ID不存在'

    else:
        # 获取角色对应的权限
        if oper_type == "get_rules":

            objs = models.xzh_role.objects.filter(id=o_id)
            if objs:
                obj = objs[0]
                rules_list = [i['name'] for i in obj.permissions.values('name')]
                print('dataList -->', rules_list)
                response.data = {
                    'rules_list': rules_list
                }

                response.code = 200
                response.msg = "查询成功"

        else:
            response.code = 402
            response.msg = "请求异常"

    return JsonResponse(response.__dict__)