Ejemplo n.º 1
0
def api_platform_user_detail():
    # 获取登录入口
    entry = request.values.get('entry')
    target_user = UserRDS(uid=request.values.get('target_uid'))
    jiameiVip = JiameiVip.query(uid=target_user.uid)
    vips = []
    for j in jiameiVip:
        vipcard = VipCard(cardid=j.cardid)
        vipcard.num = j.remain
        vips.append(vipcard)


    newtarget_user = target_user.to_dict()
    newtarget_user['vips'] = vips
    preorders = PreOrder.query(uid=target_user.uid)
    if len(preorders) > 0:
        haspreorder = True
        preorder = preorders[0].to_dict()
    else:
        preorder = {}
        haspreorder = False
    newtarget_user['preorder'] = preorder
    newtarget_user['haspreorder'] = haspreorder
    marketrecords = CRMMarketRecord.query(uid=request.values.get('target_uid'))
    marketrecords = [cr.to_dict() for cr in marketrecords]
    return render_template('%s/user_detail.html' % ('user' if entry=='mine' else 'platform'),
        user=newtarget_user,
        isstaff=True if Staff(uid=target_user.uid).exists else False,
        levels={l.levelid: l.to_dict() for l in UserLevel.query()},
        third_accounts=target_user.third_accounts, userconfig=userconfig, ThirdAccountType=ThirdAccountType, marketrecords=marketrecords)
Ejemplo n.º 2
0
def api_ajax_thirdaccount_unbind():
    '''ajax异步查询用户信息'''
    thirdtype = request.values.get('thirdtype')
    target_uid = request.values.get('target_uid')
    user = User(uid=target_uid)
    thirdid = user.third_accounts.get(thirdtype)
    td = ThirdAccount(thirdtype=thirdtype, thirdid=thirdid)
    thirdinfo = td.thirdinfo
    user.unbind(thirdtype)
    userRds = UserRDS(uid=target_uid)
    userRds.is_subscribe_miniapp = 'false'
    userRds.save()
    return apphelper.format_ok_response()
Ejemplo n.º 3
0
def api_platform_user_query():
    page_size = 20
    form = {
        'name': request.values.get('name'),
        'is_subscribe': request.values.get('is_subscribe'),
        'is_deleted': request.values.get('is_deleted'),
        'next_page': int(request.values.get('next_page') or 1),
        'is_subscribe_miniapp': request.values.get('is_subscribe_miniapp')
    }

    kwargs = {
        'is_subscribe': form.get('is_subscribe'),
        'is_deleted': request.values.get('is_deleted'),
        'limit': page_size,
        'offset': (form.get('next_page')-1)*page_size,
        'is_subscribe_miniapp': request.values.get('is_subscribe_miniapp')
    }
    if form.get('name'):
        try:
            int(form.get('name'))
        except:
            kwargs['name'] = form.get('name')
        else:
            if len(form.get('name')) == 11:
                kwargs['phone'] = form.get('name')
            else:
                kwargs['uid'] = form.get('name')
    users = UserRDS.query(**kwargs)
    newusers = []
    for u in users:
        jiameiVip = JiameiVip.query(uid=u.uid)
        vips = []
        for j in jiameiVip:
            vipcard = VipCard(cardid=j.cardid)
            vipcard.num = j.remain
            vips.append(vipcard)
        u = u.to_dict()
        u['vips'] = [vip.to_dict() for vip in vips]
        newusers.append(u)
    users = newusers
    # 查询总数
    total_count = UserRDS.query(count=True, **kwargs)
    total_pages = (total_count + page_size - 1) / page_size
    if request.values.get('type') == "ajax":
        # 兼容非跳转页面查询
        return apphelper.format_ok_response(data=users)
    else:
        return render_template('platform/user_query.html', form=form, users=users,  page=form.get('next_page'), total_count=total_count, total_pages=total_pages)
def api_common_user_select():
    temp = request.query_string.split('?')

    form = {
        'name': request.values.get('name'),
        'redirect_url': temp[0].split('=')[1],
        'redirect_url_query_string': temp[1] if len(temp) > 1 else '',
        'query_all': request.values.get('query_all')
    }

    if form.get('name'):
        kwargs = {}
        try:
            int(form.get('name'))
        except:
            kwargs['name'] = form.get('name')
        else:
            if len(form.get('name')) == 11:
                kwargs['phone'] = form.get('name')
            else:
                kwargs['uid'] = form.get('name')
        users = UserRDS.query(limit=None, offset=None, **kwargs)
        users = [User(uid=u.uid).to_dict() for u in users]
    else:
        users = []
    return render_template('common/user_select.html', users=users, form=form)
Ejemplo n.º 5
0
def api_platform_user_setdelete():
    user = UserRDS.query(uid=request.values.get('uid'))
    if len(user)<1:
        raise BadRequest(description='用户不存在!')
    deleted = request.values.get('deleted')
    user[0].is_deleted = deleted
    user[0].save()
    return apphelper.format_ok_response()
Ejemplo n.º 6
0
def api_ajax_query_2():
    '''ajax异步查询用户信息'''
    name = request.values.get('name')
    if name:
        kwargs = {}
        try:
            int(name)
        except:
            kwargs['name'] = name
        else:
            if len(name) == 11:
                kwargs['phone'] = name
            else:
                kwargs['uid'] = name

        users = UserRDS.query(limit=None, offset=None, **kwargs)
    else:
        users = []

    data = {'users': [u.to_dict() for u in users]}
    return apphelper.format_ok_response(data=data)
Ejemplo n.º 7
0
def api_platform_user_download():
    page_size = 1000
    form = {
        'name': request.values.get('name'),
        'is_subscribe_miniapp': request.values.get('is_subscribe_miniapp'),
        'is_deleted': request.values.get('is_deleted'),
        'next_page': int(request.values.get('next_page') or 1)
    }

    kwargs = {
        'is_subscribe_miniapp': form.get('is_subscribe_miniapp'),
        'is_deleted': request.values.get('is_deleted'),
        'limit': page_size,
        'offset': (form.get('next_page') - 1) * page_size,
        'name': form.get('name')
    }
    if form.get('name'):
        try:
            int(form.get('name'))
        except:
            kwargs['name'] = form.get('name')
        else:
            if len(form.get('name')) == 11:
                kwargs['phone'] = form.get('name')
            else:
                kwargs['uid'] = form.get('name')
    users = UserRDS.query(**kwargs)
    exports = [[
        '姓名',
        '手机号',
        '会员类型及份数',
        '小程序注册',
        '会员名称及份数',
        '会员是否有效'
    ]]
    if len(users) > 0:
        for user in users:
            name = user.name
            phone = user.phone
            uid = user.uid
            vips = JiameiVip.query(uid=uid)
            vipStr = ''
            vipChinese = ''
            for index in range(0, len(vips),1):
                card = VipCard(cardid=vips[index].cardid)
                if index != (len(vips)-1):
                    vipStr = vipStr + card.card_num+'-'+str(vips[index].remain)+'|'
                    vipChinese = vipChinese +card.name+'*'+str(vips[index].remain)+';'
                else:
                    vipStr = vipStr + card.card_num + '-' + str(vips[index].remain)
                    vipChinese = vipChinese + card.name + '*' + str(vips[index].remain) + ';'
            try:
                if 'weixinminiapp' in user.third_accounts.keys():
                    is_subscribe_miniapp = "是"
                else:
                    is_subscribe_miniapp = "否"
            except:
                is_subscribe_miniapp = "否"
            if user.is_deleted == 'true':
                is_deleted = "无效会员"
            else:
                is_deleted = "有效会员"
            u = [
                name,
                phone,
                vipStr,
                is_subscribe_miniapp,
                vipChinese,
                is_deleted
            ]
            exports.append(u)
    return excel.make_response_from_array(exports, "xlsx", file_name="users")
Ejemplo n.º 8
0
def api_platform_user_upload():
    if request.method == 'POST':
        file = request.files['file']
        f = file.read()
        data = xlrd.open_workbook(file_contents=f)
        table = data.sheets()[0]
        names = data.sheet_names()  # 返回book中所有工作表的名字
        status = data.sheet_loaded(names[0])  # 检查sheet1是否导入完毕
        nrows = table.nrows  # 获取该sheet中的有效行数
        # ncols = table.ncols  # 获取该sheet中的有效列数
        phone_update_line = ''
        phone_error_line = ''
        for index in range(1, nrows, 1):
            # ["姓名", "手机号", "会员编号及份数"]
            u = table.row_values(index)  # 第i行数据
            # 检查手机号合法性
            try:
                phone = str(int(u[1]))
            except:
                phone_error_line = phone_error_line + str(index) + ','
                continue
            ret = re.match(r'^1[356789][0-9]{9}$', phone)
            if not ret:
                phone_error_line = phone_error_line + str(index)+','
                continue
            ta = ThirdAccount(thirdtype=ThirdAccountType.phone, thirdid=phone)
            # 判断用户是否存在
            if ta.exists:
                #用户已存在,更改会员信息
                user = UserRDS.query(phone=ta.thirdid)
                user[0].name = u[0]
                user[0].save()
                # 更新会员 会员格式VIP1-12|VIP2-12
                vips = u[2].split('|')
                phone_update_line = phone_update_line + str(index) + ','
                for v in vips:
                    card_num = v.split('-')[0]
                    remain = v.split('-')[1]
                    card = VipCard.query(card_num=card_num)
                    if len(card) < 1:
                        continue
                    vip = JiameiVip.query(uid=user[0].uid, cardid=card[0].cardid)
                    if len(vip) < 1:
                        #之前未创建会员
                        vip = JiameiVip(vipid=utils.uuid1())
                    else:
                        vip = vip[0]
                    vip.cardid = card[0].cardid
                    vip.uid = user[0].uid
                    vip.remain = remain
                    vip.save()
            #  创建会员并开通相关会员权益
            # 注册用户
            else:
                user = User.signup(config.appids[0], 'console', ThirdAccountType.phone, ta.thirdid)
                user.name = u[0]
                user.save()
                # 开通会员 会员格式VIP1-12|VIP2-12
                vips = u[2].split('|')
                for v in vips:
                    card_num = v.split('-')[0]
                    remain = v.split('-')[1]
                    card = VipCard.query(card_num=card_num)
                    if len(card) < 1:
                        continue
                    vip = JiameiVip(vipid=utils.uuid1())
                    vip.cardid = card[0].cardid
                    vip.uid = user.uid
                    vip.remain = remain
                    vip.save()
        return render_template('platform/user_upload.html', message='会员创建成功', phone_update_line=phone_update_line, phone_error_line=phone_error_line)
    return render_template('platform/user_upload.html')