Exemple #1
0
def admin_set_info():
    u'''
    管理员设置渠道
    '''
    args = request.args
    if request.method == 'POST':
        args = request.form
    channel_id = _int(args.get('channel_id', ''))
    sales_depart_id = _int(args.get('sales_depart_id', ''))
    user = request.environ['user']
    result, msg = False, ''
    try:
        if not channel_id or not sales_depart_id:
            raise Abort(u'无效渠道id或区分id')
        channels = usersvc.get_channels(top=True)
        _channel = [c for c in channels if c['channel_id'] == channel_id]
        if not _channel:
            raise Abort(u'设置的渠道不存在')
        _depart = [
            d for d in _channel[0]['departs']
            if d['sales_depart_id'] == sales_depart_id
        ]
        if not _depart:
            raise Abort(u'设置的渠道和区分错误')
        result = usersvc.set_user_sales_info(user.user_id, channel_id,
                                             sales_depart_id)
        if result:
            user.user_info = usersvc.get_user_local_info(user.user_id)
            user.save_to_session()
    except Abort, e:
        msg = e.msg
Exemple #2
0
def get_channel():
    u'''
    获取渠道信息
    '''
    args = request.args
    if request.method == 'POST':
        args = request.form
    top = True if args.get('top', '') else False
    return usersvc.get_channels(top)
Exemple #3
0
def set_sales_info():
    u'''
    第一次登入需要设置 渠道, 区分信息
    市公司管理不能通过此接口设置 
    '''
    args = request.args
    if request.method == 'POST':
        args = request.form
    channel_id = _int(args.get('channel_id', ''))
    sales_depart_id = _int(args.get('sales_depart_id', ''))
    user = request.environ['user']
    result, msg = False, ''
    try:
        if not channel_id or not sales_depart_id:
            raise Abort(u'无效渠道id或区分id')
        # 检查是否已设置过
        user_info = usersvc.get_user_local_info(user.user_id)
        if user_info['channel_id'] or user_info['sales_depart_id']:
            raise Abort(u'已设置过渠道和区分信息(修改请联系管理人员)')
        # 检查渠道和区分对应关系
        channels = usersvc.get_channels()
        _channel = [c for c in channels if c['channel_id'] == channel_id]
        if not _channel:
            raise Abort(u'设置的渠道不存在')
        _depart = [
            d for d in _channel[0]['departs']
            if d['sales_depart_id'] == sales_depart_id
        ]
        if not _depart:
            raise Abort(u'设置的渠道和区分错误')
        result = usersvc.set_user_sales_info(user.user_id, channel_id,
                                             sales_depart_id)
        if result:
            user.user_info = usersvc.get_user_local_info(user.user_id)
            user.save_to_session()
    except Abort, e:
        msg = e.msg
Exemple #4
0
def menus():
    u'''
    获取菜单 
    '''
    return usersvc.get_channels()
Exemple #5
0
 def test_get_sales_departs(self):
     channels = usersvc.get_channels()
     for ch in channels:
         departs = usersvc.get_sales_departs(ch['channel_id'])
         self.assertTrue(type(departs), list)
Exemple #6
0
 def test_get_channels(self):
     channels = usersvc.get_channels()
     self.assertTrue(type(channels), list)