Пример #1
0
def role_relate_module(request):
    """角色关联模块"""
    try:
        # 接收参数
        module_checked_id = request.POST.get('module_checked_id')
        role_id = request.POST.get('role_id')

        # 删除该角色拥有的所有权限
        Permission.objects.filter(role__id=role_id).delete()

        # 如果模块为空,则直接return
        if not module_checked_id:
            return JsonResponse(Message(msg='操作成功').result())

        # 查询角色和模块
        role = Role.objects.get(pk=role_id)
        module = Module.objects.filter(
            pk__in=module_checked_id.split(',')).all()

        # 循环插入数据
        for m in module:
            Permission.objects.create(role=role, module=m)

        return JsonResponse(Message(msg='操作成功').result())
    except Exception as e:
        return JsonResponse(Message(code=400, msg='操作失败').result())
Пример #2
0
def update_module(request):
    """修改模块信息"""
    try:
        # 接收参数
        data = request.POST.dict()
        id = data.pop('id')

        # 如果权限值被修改,判断是否存在,已存在,提示错误
        opt_value = data.get('optValue')
        # 查询原来的模块信息
        m = Module.objects.get(pk=id)
        # 判断是否权限值被修改
        if opt_value != m.optValue:
            # 判断是否存在
            Module.objects.get(optValue=opt_value)
            return JsonResponse(Message(code=400, msg='权限值已存在,请重新选择').result())
    except Module.DoesNotExist as e:
        pass

    # 如果父级id存在并且父级id被修改
    parent = data.pop('parent')
    if parent and parent != str(m.parent_id):
        p = Module.objects.get(pk=parent)
        data['parent'] = p

    # 修改数据
    Module.objects.filter(pk=id).update(**data, updateDate=datetime.now())
    return JsonResponse(Message(msg='修改成功').result())
Пример #3
0
def update_serve(request):
    """修改服务"""
    try:
        # 接收参数
        data = request.POST.dict()
        # 弹出数据
        data.pop('csrfmiddlewaretoken')
        id = data.pop('id')
        # 准备数据
        state = data.get('state')
        # 如果是已分配,已处理,已归档...
        if '已分配' == state:
            data['assignTime'] = datetime.now()

        if '已处理' == state:
            data['serviceProceTime'] = datetime.now()

        data['updateDate'] = datetime.now()
        # 修改
        CustomerServe.objects.filter(pk=id).update(**data)
        # 返回数据
        return JsonResponse(Message(msg='操作成功').result())
    except Exception as e:
        print(e)
        return JsonResponse(Message(code=400, msg='操作失败').result())
Пример #4
0
def select_customer_by_id(request):
    """根据主键查询客户信息"""
    try:
        # 接收参数
        id = request.GET.get('id')
        # 查询
        c = Customer.objects.values().filter(pk=id)
        # 返回数据
        return JsonResponse(Message(obj=list(c)).result())
    except Customer.DoesNotExist as e:
        return JsonResponse(Message(code=400, msg='error').result())
Пример #5
0
def update_user(request):
    """修改用户信息"""
    try:
        # 接收参数
        data = request.POST.dict()
        id = data.pop('id')

        user = User.objects.get(pk=id)

        username = data.get('username')
        # 如果用户名被更改,判断用户名是否存在
        if username and username != user.username:
            User.objects.get(username=username)
            return JsonResponse(Message(code=400, msg='用户名已存在,请重新添加').result())
    except User.DoesNotExist as e:
        pass

    try:
        # 如果邮箱被更改,判断邮箱是否存在
        email = data.get('email')
        if email and email != user.email:
            User.objects.get(email=email)
            return JsonResponse(Message(code=400, msg='邮箱已存在,请重新添加').result())
    except User.DoesNotExist as e:
        pass

    # 加密密码
    # 使用md5加密
    u_pwd = data.pop('password')
    if u_pwd:
        # 使用md5加密
        data['password'] = md5(u_pwd.encode(encoding='utf-8')).hexdigest()

    data.pop('roles')
    role_ids = request.POST.getlist('roles')
    '''
    # 删除所有该用户的角色
    UserRole.objects.filter(user__id=id).delete()

    # 修改用户角色中间表
    roles = Role.objects.filter(pk__in=role_ids).all()
    for role in roles:
        UserRole.objects.create(user=user, role=role)
    '''

    # 修改数据
    data['update_date'] = datetime.now()
    User.objects.filter(pk=id).update(**data)

    # 修改用户角色中间表
    result = create_userrole(role_ids, user)

    return JsonResponse(result)
Пример #6
0
def ok_reprieve(request):
    """确认流失"""
    try:
        # 修改客户流失表,添加流失信息,修改state状态为1
        # 接收参数
        loss_id = request.POST.get('loss_id')
        lossReason = request.POST.get('lossReason')
        # 查询
        CustomerLoss.objects.filter(pk=loss_id) \
            .update(lossReason=lossReason, state=1, confirmLossTime=datetime.now(), updateDate=datetime.now())
        # 返回数据
        return JsonResponse(Message(msg='操作成功').result())
    except CustomerLoss.DoesNotExist as e:
        return JsonResponse(Message(code=400, msg='操作失败').result())
Пример #7
0
def create_customer(request):
    """添加用户信息"""
    try:
        # 接收参数
        data = request.POST.dict()
        # 弹出csrftoken
        data.pop('csrfmiddlewaretoken')
        # 生成客户编号
        result = ''
        for i in range(0, 3):
            result += str(randint(0, 9))

        khno = 'KH' + datetime.now().strftime('%Y%m%d%H%M%S') + result
        # 添加信息
        data['khno'] = khno
        Customer.objects.create(**data)

        # 清除缓存信息
        redis_keys = cache.keys('customer*')  # 模糊匹配所有kye,返回列表
        for k in redis_keys:
            cache.delete(k)

        # return JsonResponse({'code': 200, 'msg': '添加成功'})
        return JsonResponse(Message(msg='添加成功').result())
    except Exception as e:
        pass
Пример #8
0
def delete_product(request):
    """删除产品信息"""
    # 接收参数
    ids = request.GET.get('id')
    # 逻辑删除
    Product.objects.filter(pk__in=ids.split(',')).update(isValid=0, updateDate=datetime.now())
    return JsonResponse(Message(msg='删除成功').result())
Пример #9
0
def delete_role(request):
    """删除角色信息"""
    # 接收参数
    ids = request.GET.get('ids')
    Role.objects.filter(pk__in=ids.split(',')).update(
        isValid=0, updateDate=datetime.now())
    return JsonResponse(Message(msg='删除成功').result())
Пример #10
0
def create_role(request):
    """添加角色信息"""
    try:
        # 接收参数
        data = request.POST.dict()
        data.pop('id')

        # 如果角色已存在,提示错误
        roleName = data.get('roleName')
        Role.objects.get(roleName=roleName)
        return JsonResponse(Message(code=400, msg='角色名已存在,请重新添加').result())
    except Role.DoesNotExist as e:
        pass

    # 添加数据
    Role.objects.create(**data)
    return JsonResponse(Message(msg='添加成功').result())
Пример #11
0
def delete_datadic(request):
    """删除数据字典"""
    # 接收参数
    ids = request.GET.get('id')
    ids = ids.split(',')
    # 逻辑删除
    DataDic.objects.filter(pk__in=ids).update(isValid=0, updateDate=datetime.now())
    return JsonResponse(Message(msg='删除成功').result())
Пример #12
0
def create_datadic(request):
    """添加数据字典"""
    # 接收参数
    dataDicName = request.POST.get('dataDicName')
    dataDicValue = request.POST.get('dataDicValue')

    DataDic.objects.create(dataDicName=dataDicName, dataDicValue=dataDicValue)
    return JsonResponse(Message(msg='添加成功').result())
Пример #13
0
def delete_contact(request):
    """删除客户交往记录"""
    # 接收参数
    data = request.POST.dict()
    # 弹出主键
    id = data.pop('id')
    # 逻辑删除
    Contact.objects.filter(pk=id).update(isValid=0, updateDate=datetime.now())
    return JsonResponse(Message(msg='删除成功').result())
Пример #14
0
def create_user(request):
    """添加用户信息"""
    try:
        # 接收参数
        data = request.POST.dict()
        data.pop('id')

        # 如果用户名已存在,提示错误
        username = data.get('username')
        User.objects.get(username=username)
        return JsonResponse(Message(code=400, msg='用户名已存在,请重新添加').result())
    except User.DoesNotExist as e:
        pass

    try:
        # 如果邮箱已存在,提示错误
        email = data.get('email')
        User.objects.get(email=email)
        return JsonResponse(Message(code=400, msg='邮箱已存在,请重新添加').result())
    except User.DoesNotExist as e:
        pass

    # 加密密码
    # 使用md5加密
    data['password'] = md5(
        data.get('password').encode(encoding='utf-8')).hexdigest()

    data.pop('roles')
    # role_ids = data.pop('roles_hidden')
    role_ids = request.POST.getlist('roles')

    # 添加数据
    user = User.objects.create(**data)

    # 插入用户角色中间表
    result = create_userrole(role_ids, user, is_create=True)
    '''
    # 插入用户角色中间表
    roles = Role.objects.filter(pk__in=role_ids).all()
    for role in roles:
        UserRole.objects.create(user=user, role=role)
    '''

    return JsonResponse(result)
Пример #15
0
def update_contact(request):
    """修改客户交往记录"""
    # 接收参数
    data = request.POST.dict()
    # 弹出主键
    id = data.pop('id')
    # 修改参数
    data['updateDate'] = datetime.now()
    Contact.objects.filter(pk=id).update(**data)
    return JsonResponse(Message(msg='修改成功').result())
Пример #16
0
def update_datadic(request):
    """修改数据字典"""
    # 接收参数
    id = request.POST.get('id')
    dataDicName = request.POST.get('dataDicName')
    dataDicValue = request.POST.get('dataDicValue')

    DataDic.objects.filter(pk=id).update(dataDicName=dataDicName, dataDicValue=dataDicValue,
                                         updateDate=datetime.now())
    return JsonResponse(Message(msg='修改成功').result())
Пример #17
0
def update_reprieve(request):
    """修改客户流失信息"""
    # 接收参数
    data = request.POST.dict()
    # 弹出主键
    id = data.pop('id')
    # 修改参数
    data['updateDate'] = datetime.now()
    CustomerReprieve.objects.filter(pk=id).update(**data)
    return JsonResponse(Message(msg='修改成功').result())
Пример #18
0
def create_serve(request):
    """创建服务"""
    try:
        # 接收参数
        data = request.POST.dict()
        # 弹出csrfmiddlewaretoken
        data.pop('csrfmiddlewaretoken')
        # 准备数据
        data['state'] = '已创建'
        data['createPeople'] = request.session.get('username_session')

        serviceRequest = data.pop('serviceRequest')
        print(serviceRequest)
        # 创建
        # CustomerServe.objects.create(**data)
        # 返回数据
        return JsonResponse(Message(msg='创建成功').result())
    except Exception as e:
        return JsonResponse(Message(code=400, msg='创建失败').result())
Пример #19
0
def delete_reprieve(request):
    """删除客户开发计划"""
    # 接收参数
    data = request.POST.dict()
    # 弹出主键
    id = data.pop('id')
    # 逻辑删除
    CustomerReprieve.objects.filter(pk=id).update(isValid=0,
                                                  updateDate=datetime.now())
    return JsonResponse(Message(msg='删除成功').result())
Пример #20
0
def create_reprieve(request, loss_id):
    """添加客户流失信息"""
    # 接收参数
    data = request.POST.dict()
    # 弹出isNewRecord
    data.pop('isNewRecord')
    # 插入数据
    cl = CustomerLoss.objects.get(pk=loss_id)
    data['customerLoss'] = cl
    CustomerReprieve.objects.create(**data)
    return JsonResponse(Message(msg='添加成功').result())
Пример #21
0
def create_contact(request, c_id):
    """添加客户交往记录"""
    # 接收参数
    data = request.POST.dict()
    # 弹出isNewRecord
    data.pop('isNewRecord')
    # 插入数据
    c = Customer.objects.get(pk=c_id)
    data['customer'] = c
    Contact.objects.create(**data)
    return JsonResponse(Message(msg='添加成功').result())
Пример #22
0
def create_userrole(role_ids, user, is_create=False):
    """添加用户角色中间表"""
    if not is_create:
        # 删除所有该用户的角色
        # user.userrole_set.all().delete()
        UserRole.objects.filter(user__id=user.id).delete()

    roles = Role.objects.filter(pk__in=role_ids).all()
    for role in roles:
        UserRole.objects.create(user=user, role=role)

    return Message(msg='操作成功').result()
Пример #23
0
def select_order_by_id(request):
    """根据订单主键查询订单"""
    try:
        # 接收参数
        order_id = request.GET.get('order_id')

        # 查询
        co = CustomerOrders.objects.values().filter(pk=order_id)

        # 返回信息
        return JsonResponse(Message(obj=list(co)).result())
    except CustomerOrders.DoesNotExist as e:
        pass
Пример #24
0
def create_module(request):
    """添加模块信息"""
    try:
        # 接收参数
        data = request.POST.dict()
        data.pop('id')

        # 如果权限值已存在,提示错误
        opt_value = data.get('optValue')
        Module.objects.get(optValue=opt_value)
        return JsonResponse(Message(code=400, msg='权限值已存在,请重新选择').result())
    except Module.DoesNotExist as e:
        pass

    # 如果有父级菜单查询父级对象插入
    parent = data.pop('parent')
    if parent:
        p = Module.objects.get(pk=parent)
        data['parent'] = p

    # 添加数据
    Module.objects.create(**data)
    return JsonResponse(Message(msg='添加成功').result())
Пример #25
0
def update_role(request):
    """修改角色信息"""
    try:
        # 接收参数
        data = request.POST.dict()
        id = data.pop('id')

        # 如果角色被修改,判断是否存在,已存在,提示错误
        roleName = data.get('roleName')
        # 查询原来的角色信息
        r = Role.objects.get(pk=id)
        # 判断角色是否被修改
        if roleName != r.roleName:
            # 判断是否存在
            Role.objects.get(roleName=roleName)
            return JsonResponse(Message(code=400, msg='角色名已存在,请重新添加').result())
    except Role.DoesNotExist as e:
        pass

    # 修改数据
    data['updateDate'] = datetime.now()
    Role.objects.filter(pk=id).update(**data)
    return JsonResponse(Message(msg='添加成功').result())
Пример #26
0
def delete_customer(request):
    """删除客户信息"""
    try:
        # 接收参数
        ids = request.GET.get('ids')
        # 分割字符串
        ids = ids.split(',')
        # 删除
        cs = Customer.objects.filter(pk__in=ids).update(
            isValid=0, updateDate=datetime.now())

        # 清除缓存信息
        redis_keys = cache.keys('customer*')  # 模糊匹配所有kye,返回列表
        for k in redis_keys:
            cache.delete(k)

        return JsonResponse(Message(msg='删除成功').result())
    except Exception as e:
        pass
Пример #27
0
def update_customer(request):
    """修改客户信息"""
    try:
        # 接收参数
        data = request.POST.dict()
        # 弹出csrftoken
        data.pop('csrfmiddlewaretoken')
        # 弹出主键
        id = data.pop('id')
        # 修改信息
        data['updateDate'] = datetime.now()
        Customer.objects.filter(pk=id).update(**data)

        # 清除缓存信息
        redis_keys = cache.keys('customer*')  # 模糊匹配所有kye,返回列表
        for k in redis_keys:
            cache.delete(k)

        # return JsonResponse({'code': 200, 'msg': '添加成功'})
        return JsonResponse(Message(msg='修改成功').result())
    except Exception as e:
        pass
Пример #28
0
def delete_module(request):
    """删除模块信息"""
    # 接收参数
    ids = request.GET.get('ids')
    Module.objects.filter(pk__in=ids.split(',')).delete()
    return JsonResponse(Message(msg='删除成功').result())