Ejemplo n.º 1
0
def do_sign():
    if 'flag' not in session:
        current_app.logger.error("'flag' not in session,yiban id %s" %
                                 g.user.id)
        return error('请在易班客户端扫码进入此页面')

    t = datetime.now()
    minutes = t.hour * 60 + t.minute
    if minutes < 450:
        return error('签到时间未到,请在早上7:30-8:30之间签到')
    if minutes > 510:
        return error('签到时间已过,请在早上7:30-8:30之间签到')

    result, location = check_valid(int(session['flag']),
                                   float(request.form.get('latitude', 0)),
                                   float(request.form.get('longitude', 0)))
    if not result:
        e = ErrorLog(float(request.form.get('latitude', 0)),
                     float(request.form.get('longitude', 0)), g.user.id,
                     int(session['flag']))
        e.save()
        return error(
            '位置信息有误,请尝试打开手机WIFI提高定位精度 <a href="javascript:;" class="open-popup" data-target="#info">详情</a>'
        )

    one_day = timedelta(days=1)
    today = date.today()
    yesterday = today - one_day
    type = get_type(session['flag'])

    if type == 0:
        if g.user.last_read < yesterday:
            g.user.continue_read = 1
        elif g.user.last_read == yesterday:
            g.user.continue_read += 1
        elif g.user.last_read == today:
            return error('今天已经签过到了')
        g.user.last_read = today
        g.user.total_read += 1
    else:
        if g.user.last_run < yesterday:
            g.user.continue_run = 1
        elif g.user.last_run == yesterday:
            g.user.continue_run += 1
        elif g.user.last_run == today:
            return error('今天已经签过到了')
        g.user.last_run = today
        g.user.total_run += 1
    sign = SignLog(int(session['flag']), request.form.get('location_des', ''),
                   request.form.get('latitude', ''),
                   request.form.get('longitude', ''), g.yiban_id,
                   session.get('flag', 1))
    db.session.add(sign)
    db.session.add(g.user)
    db.session.commit()
    ranking = SignLog.query.filter(SignLog.type == type,
                                   SignLog.time == today).count()
    return success({'ranking': ranking, 'location': location})
Ejemplo n.º 2
0
def get_rank():
    if 'both' not in request.args:
        type = get_type(session.get('flag', 0))
        if type == 0:
            data = _get_read_rank()
        else:
            data = _get_run_rank()
    else:
        data = {'run': _get_run_rank(), 'read': _get_read_rank()}
    return success(data)
Ejemplo n.º 3
0
def get_flag():
    all = Map.query.all()
    data = []
    for i in all:
        data.append({
            'id': i.id,
            'type': i.type,
            'name': i.name,
            'latitude': float(i.latitude),
            'longitude': float(i.longitude)
        })
    return success(data)
Ejemplo n.º 4
0
def set_flag():
    if request.form.get('type'):
        type = int(request.form.get('type', 0))
        latitude = float(request.form.get('latitude', 0))
        longitude = float(request.form.get('longitude', 0))
        name = request.form.get('name', '')
    if not request.form.get('id'):
        m = Map(type, name, latitude, longitude)
        m.save()
        return success('成功创建')
    else:
        id = int(request.form.get('id'))
        m = Map.query.get(id)
        if request.form.get('delete'):
            m.delete()
            return success('成功删除')
        else:
            m.type = type
            m.name = name
            m.latitude = latitude
            m.longitude = longitude
            m.save()
            return success('成功更新')
    return success('参数错误')
Ejemplo n.º 5
0
def share():
    token = session.get('token')
    content = request.form.get('content')
    if not (token and content):
        return error('分享失败')
    data = SHARE_DATA
    data['access_token'] = token
    data['content'] = content

    res = json.loads(
        urllib2.urlopen(url='https://openapi.yiban.cn/share/send_share',
                        data=urlencode(data)).read())
    if res.get('status') == 'success':
        return success()
    else:
        print res.get('info', []).get('msgCN')
        return error('分享失败')
Ejemplo n.º 6
0
def user_info():
    id = request.args.get('id')
    if not id:
        return error()
    user = User.query.get(int(id))
    if not user:
        return error('用户不存在!')
    all = User.query.count()
    run_rank = User.query.filter(User.continue_run < user.continue_run).count()
    read_rank = User.query.filter(
        User.continue_read < user.continue_read).count()
    data = {
        'info': {
            'name': user.name,
            'head': user.head_img,
        },
        'run': {
            'total': user.total_run,
            'continue': user.continue_run,
            'rank': int(run_rank / float(all) * 100)
        },
        'read': {
            'total': user.total_read,
            'continue': user.continue_read,
            'rank': int(read_rank / float(all) * 100)
        },
        'history': []
    }

    tmp = user.sign_set.join(Map).order_by(SignLog.id.desc()).limit(10).all()
    for i in tmp:
        time = '%d/%d' % (i.time.month, i.time.day)
        data['history'].append({
            'type_id': i.type,
            'location_des': i.map.name,
            'latitude': i.latitude,
            'longitude': i.longitude,
            'time': time
        })

    return success(data)
Ejemplo n.º 7
0
def get_count_info():
    if 'both' in request.args:
        all = User.query.count()
        run_rank = User.query.filter(
            User.continue_run < g.user.continue_run).count()
        read_rank = User.query.filter(
            User.continue_read < g.user.continue_read).count()
        data = {
            'run': {
                'total': g.user.total_run,
                'continue': g.user.continue_run,
                'rank': int(run_rank / float(all) * 100)
            },
            'read': {
                'total': g.user.total_read,
                'continue': g.user.continue_read,
                'rank': int(read_rank / float(all) * 100)
            }
        }
    else:
        all = User.query.count()
        type = get_type(session.get('flag', 1))
        if type == 0:
            rank_count = User.query.filter(
                User.continue_read < g.user.continue_read).count()
        else:
            rank_count = User.query.filter(
                User.continue_run < g.user.continue_run).count()

        data = {
            'type': type,
            'total': g.user.total_read,
            'continue': g.user.continue_read,
            'rank': int(rank_count / float(all) * 100)
        }
    return success(data)