예제 #1
0
def add_tea_score(request):
    """
    @api {post} /huodong/sx_summer/s/add_tea_score [暑假活动 学生]学生登录教师加积分
    @apiGroup sx_summer
    @apiParamExample {json} 请求示例
       {}
    @apiSuccessExample {json} 成功返回
        {
          "message": "",
          "error": "",
          "data": {}
          "response": "ok",
          "next": ""
        }
    @apiSuccessExample {json} 失败返回
       {"message": "", "error": "no_app_id", "data": "", "response": "fail", "next": ""}
    """
    user = request.user
    if user.is_teacher:
        return ajax_json.jsonp_fail(request, message=u"学生用户才能登录")
    tea = com_stu.get_user_tea(user.unit.id) if user.unit else 0
    if not tea:
        return ajax_json.jsonp_ok(request)
    score = STU_LOGIN_SCORE if not user.openstatus(2) else STU_LOGIN_SCORE * 2
    for t in tea:
        num = common.get_score_add_num(APP_ID_TEA, t.id, 'stu_login_%s' % user.id)
        if num:
            return ajax_json.jsonp_ok(request)
        common.add_score(APP_ID_TEA, t.id, score, 'stu_login_%s' % user.id, u'学生%s登录活动,加%s积分' % (user.name, score),
                         t.city or 0)
    return ajax_json.jsonp_ok(request)
예제 #2
0
파일: post.py 프로젝트: GUAN-YE/hd_api_djs
def p_send_sms(request):
    """
    @api /huodong/com/tea/send_sms [公共]教师发短信
    @apiGroup com
    @apiParamExample {json} 请求示例
    {
    active_id:6   活动id
    content:'123' 短息内容
    }
    @apiSuccessExample {json} 成功返回
    {
    "tbkt_token": "NDgwMDAyfTA0MDAzMzcxNTB9MDQwMDc1MDY2Ng",
    "next": "",
    "error": "",
    "message": "",
    "data": {},
    "response": "ok"
    }
    """
    user = request.user
    args = request.QUERY.casts(active_id=int, content=unicode)
    active_id = args.active_id
    content = args.content
    if active_id not in APP_ID_ALL or not user.is_teacher:
        return ajax_json.jsonp_fail(request, message=u'只有教师能发短信')
    has_send = common.get_user_item_today(user.id, active_id, 'send_sms')
    if has_send:
        return ajax_json.jsonp_ok(request)
    else:
        common.send_sms(request, user, content)
        common.update_score_com(user.id, active_id, 'send_sms', user.id, user.city, user.unit.id, 0, user.grade_id)
    return ajax_json.jsonp_ok(request)
예제 #3
0
def test(request):
    num = db.default.score_gift.get(id=688).num
    if num > 0:
        with db.default as c:
            row = c.fetchone_dict("select num from score_gift  where id=688 for update")
            # 判断是否发完
            if row.num == 0:
                return ajax_json.jsonp_ok(request)
            c.execute("update score_gift set num=%s where id=688" % (row.num - 1))
        db.tbkt_web.execute('INSERT INTO `active_award`(user_name,award_type,user_id,active_id)VALUES(1,1,1,66)')
        print num
    return ajax_json.jsonp_ok(request)
예제 #4
0
파일: post.py 프로젝트: GUAN-YE/hd_api_djs
def p_share(request):
    """
    @api /huodong/com/share [公共]学生分享
    @apiGroup com
    @apiParamExample {json} 请求示例
       {
            active_id:6   活动id
        }
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": "",
            "response": "ok",
            "error": ""
        }
    """
    user = request.user
    active_id = int(request.QUERY.get('active_id', 0))
    if active_id not in APP_ID_ALL:
        return ajax_json.jsonp_fail(request, message=u'缺少参数')
    if user.is_teacher:
        return ajax_json.jsonp_fail(request, message=u'教师不能参与学生分享!')
    if common.get_user_item_today(user.id, active_id, 'share'):
        return ajax_json.jsonp_fail(request, message=u'已分享过了!')

    active = db.tbkt_active_slave.active.select('subject_id').get(id=active_id)
    subject_id = active.subject_id / 10
    is_open = user.openstatus(subject_id)
    common.update_score_com(user.id, active_id, 'share', user.id, user.city, user.unit.id, is_open, user.grade_id)
    return ajax_json.jsonp_ok(request)
예제 #5
0
파일: post.py 프로젝트: GUAN-YE/hd_api_djs
def p_sign(request):
    """
    @api /huodong/com/sign [公共]学生签到
    @apiGroup com
    @apiParamExample {json} 请求示例
       {
            active_id:6   活动id
        }
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": "",
            "response": "ok",
            "error": ""
        }
    """
    user = request.user
    args = request.QUERY.casts(active_id=int)
    active_id = args.active_id
    if not active_id:
        return ajax_json.jsonp_fail(request, message=u'缺少参数')
    active = db.tbkt_active_slave.active.select('subject_id').get(id=active_id)
    if common.get_user_item_today(user.id, active_id, 'sign'):
        return ajax_json.jsonp_fail(request, message=u'已签到过了!')
    subject_id = active.subject_id / 10
    is_open = user.openstatus(subject_id)
    common.update_score_com(user.id, active_id, 'sign', user.id, user.city, user.unit.id, is_open, user.grade_id)
    return ajax_json.jsonp_ok(request)
예제 #6
0
파일: post.py 프로젝트: GUAN-YE/hd_api_djs
def p_score_info(request):
    """
    @api /huodong/com/user/detail [公共]用户积分详情
    @apiGroup com
    @apiParamExample {json} 请求示例
   {
        active_id:6   活动id
    }
    @apiSuccessExample {json} 成功返回
    {
        "message": "",
        "next": "",
        "data": [
            {
                "item_name": "做作业",
                "add_date": "09月12日 11:43:52",
                "score": 120
            }
        ],
        "response": "ok",
        "error": ""
    }
    """
    user = request.user
    active_id = int(request.QUERY.get('active_id', 0))
    args = request.QUERY.casts(p=int)
    page = args.p or 1
    data = common.user_score_detail(user, active_id, page)
    return ajax_json.jsonp_ok(request, data)
예제 #7
0
파일: post.py 프로젝트: GUAN-YE/hd_api_djs
def p_today_item(request):
    """
        @api {post} /huodong/com/user/today_item [公共]返回当日某加分项是否加分
        @apiGroup com
        @apiParamExample {json} 请求示例
           {
                active_id:6   活动id
                item: send_sms   加分项 如:sign :签到,send_sms:发作业,stu_do_task 做作业 等
            }
        @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {
                "status":True,True加过分,Flase未加分
            },
            "response": "ok",
            "error": ""
        }
        @apiSuccessExample {json} 失败返回
           {"message": "", "error": "", "data": "", "response": "fail", "next": ""}
        """
    user_id = request.user_id
    args = request.QUERY.casts(active_id=int, item=str)
    if not args.active_id or not args.item:
        return ajax_json.jsonp_fail(request, message=u'缺少参数')
    status = common.get_user_item_today(user_id, args.active_id, args.item)
    data = {'status':status}
    return ajax_json.jsonp_ok(request, data)
예제 #8
0
def r_info(request):
    """
    @api /huodong/sx/normal/com/info [数学常态活动]积分信息 
    @apiGroup math_normal
    @apiSuccessExample {json} 成功返回
    {
        "message": "",
        "next": "",
        "data": {
            "score": 0,   # 用户积分
            "num": 0,
            "top": 0
        },
        "response": "ok",
        "error": ""
    }
    """
    user, active_id = base(request)
    out = Struct()
    out.open_add = -1
    if user.type == 1:
        out.open_add = common.stu_open_add_score(user)

    info = common.get_user_score(user, active_id)
    out.score = info.score
    cost = TEA_LOTTERY_COST if user.is_teacher else STU_LOTTERY_COST
    out.num = info.score/cost
    out.top = info.rank_no
    out.user_id=user.id
    out.is_teacher = user.is_teacher
    return ajax_json.jsonp_ok(request, out)
예제 #9
0
def get_status(request):
    """
    @api {post}  /huodong/tea/task/status  返回剩余金币数量和是否可以领取的状态
    @apiGroup tea_coin
    @apiParamExample {json} 请求示例
        {}
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {
                    "status": 0,            #是否可以领取金币 0 不可以 1 可以 2 领取过
                    "num":2000              #剩余金币数量
                    }
            "response": "ok",
            "error": ""
        }

    :return:
    """

    user = request.user
    tea_unit_ids = [u.id for u in user.units]
    data = common.get_status(user)
    return ajax_json.jsonp_ok(request, data)
예제 #10
0
def p_submit(request):
    """
    @api {post} /huodong/sx_summer/s/submit [暑假活动 学生]提交
    @apiGroup sx_summer
    @apiParamExample {json} 请求示例
        {
        "type":1,   1卷子,3个性化
        "object_id":"19858",    paper_id /个性化测试id
        "status":1,1 完成 0 未完成
        "data":[{"ask_list":[{"ask_id":61745,"option":"C","result":1}],"question_id":45949}...]
        }
    @apiSuccessExample {json} 成功返回
        {"message": "", "error": "", "data": {"test_id": "109257"}, "response": "ok", "next": ""}
    @apiSuccessExample {json} 失败返回
       {"message": "", "error": "", "data": "", "response": "fail", "next": ""}
    """
    user = request.user
    if user.is_teacher:
        return ajax_json.jsonp_fail(request, message=u"学生用户才能使用")
    args = request.QUERY.casts(object_id=int, status=int, data='json', type=int)
    status = args.status
    data = args.data or []
    if args.type == 3:
        result = com_stu.test_special(user.id, args.object_id, status, data)
    else:
        result = com_stu.test_submit(user, args.object_id, status, data, args.type)

    return ajax_json.jsonp_ok(request,result)
예제 #11
0
def p_award_all(request):
    """
    @api {post} /huodong/sx_summer/s/award/all [暑假活动 学生]活动结果页 抽奖结果
    @apiGroup sx_summer
    @apiParamExample {json} 请求示例
       {
            p:1,
            app_id:35,   #35 学生   36 教师
        }
    @apiSuccessExample {json} 成功返回
        {
          "message": "",
          "error": "",
          "data": {}
          "response": "ok",
          "next": ""
        }
    @apiSuccessExample {json} 失败返回
       {"message": "", "error": "no_app_id", "data": "", "response": "fail", "next": ""}
    """
    args = request.QUERY.casts(p=int, app_id=int)
    page = args.p or 1
    user = request.user
    is_smx = 0 if user.city and int(user.city) != 411200 else 1
    app_id = args.app_id
    if not app_id or app_id not in ALL_APP_ID:
        return ajax_json.jsonp_fail(request, error='no_app_id')
    app_id = args.app_id or APP_ID_STU
    award,total = common.get_all_award_detail(app_id, is_smx, page)
    return ajax_json.jsonp_ok(request, {'award':award,'total':total})
예제 #12
0
def p_rank_result(request):
    """
    @api {post} /huodong/sx_summer/s/rank/result [暑假活动 学生]活动结果页 排行结果
    @apiGroup sx_summer
    @apiParamExample {json} 请求示例
       {
            p:1,
            app_id:35,    35:学生   36:教师
        }
    @apiSuccessExample {json} 成功返回
        {
          "message": "",
          "error": "",
          "data": {}
          "response": "ok",
          "next": ""
        }
    @apiSuccessExample {json} 失败返回
       {"message": "", "error": "no_app_id", "data": "", "response": "fail", "next": ""}
    """
    args = request.QUERY.casts(p=int, app_id=int, is_smx=int)
    page = args.p or 1
    user = request.user
    is_smx = 0 if user.city and int(user.city) != 411200 else 1
    app_id = args.app_id
    if not app_id or app_id not in [APP_ID_TEA, APP_ID_STU]:
        return ajax_json.jsonp_fail(request, error='no_app_id')
    rank, _ = common.get_rank(app_id, page or 1, is_smx)
    rank, total = common.add_rank_award(app_id, is_smx, rank)
    if _ < total:
        total = _
    data = {'rank': rank, 'total': total}
    return ajax_json.jsonp_ok(request, data)
예제 #13
0
def send_open(request):
    """
    @api {post} /huodong/summer_word/t/send_open [暑假活动-教师] 开通班级下学生学科
    @apiGroup summer_word
    @apiParamExample {json} 请求示例
       {}
    @apiSuccessExample {json} 成功返回
       {"message": "", "error": "", "data": ', "response": "ok", "next": ""}
    @apiSuccessExample {json} 失败返回
       {"message": "", "error": "", "data": "", "response": "fail", "next": ""}
    """
    user = request.user
    # 发开通短信
    unit_class_id = [u.id for u in user.units]
    hub = tbktapi.Hub(request)
    student = []
    for i in unit_class_id:
        r = hub.com.post('/class/students', {"unit_id": i})
        if r and r.response == 'ok':
            data = r.data
            student += (data.get('students', []))
    phones = ','.join(str(s['phone_number']) for s in student if s.get('status',0) not in [2,9])
    platform_id = int(user.platform_id) if user and user.platform_id else 1
    r = hub.bank.post('/cmcc/open', {'phone_number': phones, 'subject_id': 9, "platform_id": platform_id})
    if not r:
        return ajax_json.jsonp_fail(request, message='服务器开小差了')
    if r.response == 'fail':
        return ajax_json.jsonp_fail(request, message=r.message)
    return ajax_json.jsonp_ok(request, message='已发送开通短信')
예제 #14
0
파일: views.py 프로젝트: GUAN-YE/hd_api_djs
def user_index(request):
    """
    @api /huodong/full/class/user/list [满分课堂] 首页
    @apiGroup full_class
    @apiSuccessExample {json} 成功返回
    {
        "message": "",
        "next": "",
        "data": {
            "know_status": -1,    # 知识训练场
            "month_status": -1,   # 月竞技
            "pk_status": -1,      # 每周竞技
            "wrong_status": -1,   # 挑战错题
            "is_open": 0,         # 是否在开放时间
            "open_time": "04月21日 09点",   # 开放时间点
            "once_week": [                 # 往期课程  
                {
                    "name": "第一周",     # 名字
                    "id": 1              # 课程id
                },
                {
                    "name": "第二周",
                    "id": 2
                }
            ], 
            "id": 3,               # 本周课程id
            "name": "第三周"        # 本周课程名字
        },
        "response": "ok",
        "error": ""
    }
    """
    user_id = request.user_id
    data = common.user_index(user_id)
    return ajax_json.jsonp_ok(request, data)
예제 #15
0
def p_active_info(request):
    """
    @api {post} /huodong/sx_summer/s/rank/result [暑假活动 学生]活动结果页 排行结果
    @apiGroup sx_summer
    @apiParamExample {json} 请求示例
       {
            p:1,
            app_id:35,    35:学生   36:教师
        }
    @apiSuccessExample {json} 成功返回
        {
          "message": "",
          "error": "",
          "data": {status:True } # True 未结束,False :结束
          "response": "ok",
          "next": ""
        }
    @apiSuccessExample {json} 失败返回
       {"message": "", "error": "no_app_id", "data": "", "response": "fail", "next": ""}
    """
    args = request.QUERY.casts(app_id=int)
    app_id = args.app_id
    if not app_id or app_id not in [APP_ID_STU, APP_ID_TEA]:
        return ajax_json.jsonp_fail(request, error='no_app_id')
    status  = common.get_active_status(app_id)
    return ajax_json.jsonp_ok(request, {'status': status})
예제 #16
0
def p_set_grade(request):
    """
    @api {post} /huodong/sx_summer/s/set_grade [暑假活动 学生]设置年级
    @apiGroup sx_summer
    @apiParamExample {json} 请求示例
       {'grade_id':1}
    @apiSuccessExample {json} 成功返回
        {"message": "", "error": "", "data": [], "response": "ok", "next": ""}
    @apiSuccessExample {json} 失败返回
        {
          "message": "已设置过班级,不能重复设置",
          "error": "",
          "data": "",
          "response": "fail",
          "next": ""
        }
    """
    user = request.user
    args = request.QUERY.casts(grade_id=int)
    if not args.grade_id:
        return ajax_json.jsonp_fail(request, error=u'no_grade_Id')
    if args.grade_id not in range(1, 7):
        return ajax_json.jsonp_fail(request, error='wrong_grade_id')
    grade = db.tbkt_web.active_user_book.get(active_id=com_stu.ACTIVE_ID, user_id=user.old_user_id)
    if grade:
        return ajax_json.jsonp_fail(request, message=u'已设置过班级,不能重复设置')
    db.tbkt_web.active_user_book.create(active_id=com_stu.ACTIVE_ID, user_id=user.old_user_id, book_id=args.grade_id)
    return ajax_json.jsonp_ok(request)
예제 #17
0
파일: post.py 프로젝트: GUAN-YE/hd_api_djs
def p_send_sms(request):
    """
    @api {post} /huodong/sx_summer/t/send_sms [暑假活动 教师]发送短信
    @apiGroup sx_summer
    @apiParamExample {json} 请求示例
       {'content':'家长您好....'}
    @apiSuccessExample {json} 成功返回
        {"message": "", "error": "", "data": ', "response": "ok", "next": ""}
    @apiSuccessExample {json} 失败返回
       {"message": "", "error": "", "data": "", "response": "fail", "next": ""}
    """

    user = request.user
    args = request.QUERY.casts(content=unicode)
    if not args.content.strip():
        return ajax_json.jsonp_fail(request, message=u'请输入短息内容')
    open_num = common.get_score_add_num(APP_ID_TEA, user.id, 'send_sms')
    if open_num < SEND_SMS_NUM:
        common.add_score(APP_ID_TEA, user.id, SEND_SMS_SCORE, 'send_sms', u'发送通知短信', user.city or 0)
    content = args.content
    unit_class_id = ','.join(str(u.id) for u in user.units)

    hub = tbktapi.Hub(request)
    hub.sms.post('/sms/send', {'unit_id': unit_class_id, 'content': content})
    return ajax_json.jsonp_ok(request)
예제 #18
0
def user_share(request):
    """
    @api {post} /huodong/sx_summer/s/share [暑假活动 学生]分享
    @apiGroup sx_summer
    @apiParamExample {json} 请求示例
       {}
    @apiSuccessExample {json} 成功返回
        {
          "message": "分享成功,加10分",
          "error": "",
          "data": "",
          "response": "ok",
          "next": ""
        }
    @apiSuccessExample {json} 失败返回
       {"message": "每天只能分享一次", "error": "", "data": "", "response": "fail", "next": ""}
    """
    user = request.user
    if user.is_teacher:
        return ajax_json.jsonp_fail(request, message=u"学生用户才能加分")
    share_num = common.get_score_add_num(APP_ID_STU, user.id, 'share')
    score = SHARE_SCORE
    if share_num < SHARE_NUM:
        unit = user.unit.id if user.unit else 0
        common.add_score(APP_ID_STU, user.id, score, 'share', u'分享', user.city or 0, unit or 0)
        return ajax_json.jsonp_ok(request, message=u'分享成功,加%s分' % score)
    return ajax_json.jsonp_fail(request, message=u"每天只能分享一次")
예제 #19
0
파일: post.py 프로젝트: GUAN-YE/hd_api_djs
def p_award_recent(request):
    """
    @api {post} /huodong/com/award/recent  [公共] 获取最近10位中奖用户
    @apiGroup com
    @apiParamExample {json} 请求示例
       {
            app_id:1   活动id
        }
    @apiSuccessExample {json} 成功返回
    {
        "message": "",
        "next": "",
        "data": [
            {
                "url": "http://flv.tbkt.cn/upload_media/knowledge/img/2015/09/21/20150921113843806676.png",
                "user_name": "李果果",
                "award_type": "3",
                "award_name": "三等奖",
                "time": "2017-09-12 16:34:58"
            }
        ],
        "response": "ok",
        "error": ""
    }
    @apiSuccessExample {json} 失败返回
       {"message": "", "error": "no_app_id", "data": "", "response": "fail", "next": ""}
    """
    args = request.QUERY.casts(app_id=int)
    user = request.user
    app_id = args.app_id
    if app_id not in APP_ID_ALL:
        return ajax_json.jsonp_fail(request, message=u'缺少参数')
    active_id = TEA_ACTIVE_ID if user.is_teacher else STU_ACTIVE_ID
    award_list = Award(app_id=app_id, active_id=active_id).recent_award()
    return ajax_json.jsonp_ok(request, award_list)
예제 #20
0
def send_sms(request):
    """
    @api {post} /huodong/summer_word/t/send_sms [暑假活动-教师] 发短信给班级下学生
    @apiGroup summer_word
    @apiParamExample {json} 请求示例
       {'content':'家长您好....',type:1 开通短信 0 普通短息}
    @apiSuccessExample {json} 成功返回
       {"message": "积分成功", "error": "", "data": ', "response": "ok" , "next": ""}
    @apiSuccessExample {json} 失败返回
       {"message": "发送短信,每天只能加分一次", "error": "", "data": "null", "response": "fail", "next": ""}
    """
    # 普通短信
    item_no = 'send_sms'
    add_score = 50

    user = request.user
    user_id = user.id
    args = request.QUERY.casts(content=unicode, type=int)

    if not args.content.strip():
        return ajax_json.jsonp_fail(request, message='内容不能为空')
    # 开通短信
    if args.type == 1:
        item_no = 'send_open'
        add_score = 100

    # 群发短信
    unit_class_id = [u.id for u in user.units]           # user.units 教师所在年级的班级
    unit_ids = ','.join(str(t) for t in unit_class_id)
    hub = tbktapi.Hub(request)
    hub.sms.post('/sms/send', {'platform_id': user.platform_id, 'unit_id': unit_ids, 'content': args.content})

    # 积分明细查当天发送短信次数
    cut_time = time.time()
    ling_time = cut_time - cut_time % 86400
    sql = """ SELECT count(id) FROM score_user_detail
                  WHERE user_id = %s AND item_no = '%s' AND app_id=%s AND add_date > '%s';""" \
          % (user_id, item_no, APP_ID_TEA, ling_time)
    rs = db.slave.fetchone_dict(sql)

    # 是否更新积分主表
    if rs and rs['count(id)'] > 0:
        return ajax_json.jsonp_ok(request, message='发送短信,每天只能加分一次')
    else:
        # 写积分明细表、主表
        update_score(user, APP_ID_TEA, item_no, add_score=add_score)
    return ajax_json.jsonp_ok(request, message='积分成功')
예제 #21
0
def user_rank(request):
    """
    @api {post} /huodong/pds_xcq/user_rank [活动]用户排名
    @apiGroup pds_xcq
    @apiParamExample {json} 请求示例
       {"page_no": 0}           # 每次请求10条
    @apiSuccessExample {json} 成功返回
       {
        "message": "",
        "next": "",
           "data": {
        "rank": [
                {
                    "user_name": "张大帅",
                    "score": 30,
                    "class_name": "401班"
                },{},...
            ]
        },
        "response": "ok",
        "error": ""
        }
    @apiSuccessExample {json} 失败返回
       {"message": "", "error": "", "data": "", "response": "fail", "next": ""}
    """
    """
    用户排名
    :param request:
    :return:
    :author: 张嘉麒
    """
    user = request.user
    nowt = time.time()
    # 不满足条件
    if user.school_id != SCHOOL or user.grade_id != 4:
        return ajax_json.jsonp_ok(request, u'不满足条件')
    app_id = APP_ID
    if nowt >= 1525795199:
        return jsonp_fail(request, u'超过了活动时间')
    args = request.QUERY.casts(page_no=int)
    page_no = args.page_no or 0
    if page_no == 0:
        page_no = 1
    # 获取与用户排名
    data = common.user_rank(page_no, app_id)
    return ajax_json.jsonp_ok(request, data)
예제 #22
0
파일: post.py 프로젝트: GUAN-YE/hd_api_djs
def p_unit_rank(request):
    """
    @api {post} /huodong/sx_summer/t/unit_rank [暑假活动 教师]排行
    @apiGroup sx_summer
    @apiParamExample {json} 请求示例
       {
            p:1,
        }
    @apiSuccessExample {json} 成功返回
        {
          "message": "",
          "error": "",
          "data": [
          "rank":
            {
              "user_id": "1185342",
              "num": 1,
              "user_name": "郭小帅",
              "score": "370",
              "school_name": "睢县河堤乡姜庄小学"
            },
            {
              "user_id": "2180866",
              "num": 2,
              "user_name": "杨铮",
              "score": "110",
              "school_name": "睢县河堤乡姜庄小学"
            }...
          ],
          "response": "ok",
          "next": ""
        }
    @apiSuccessExample {json} 失败返回
       {"message": "", "error": "no_app_id", "data": "", "response": "fail", "next": ""}
    """

    args = request.QUERY.casts(p=int)
    page = args.p
    user = request.user
    units = user.units
    if not units:
        return ajax_json.jsonp_ok(request, {'rank': [], 'total': 0})
    unit_ids = [u.id for u in units]
    rank, total = common.get_unit_rank(unit_ids, page or 1)
    return ajax_json.jsonp_ok(request, {'rank': rank, 'total': total})
예제 #23
0
파일: post.py 프로젝트: GUAN-YE/hd_api_djs
def p_rank(request):
    """
    @api {post} /huodong/com/rank [公共] 分页返回活动积分排行
    @apiGroup com
    @apiParamExample {json} 请求示例
       {
            grade_id:1  按年级排行时需要传入
            unit_id:123   按班级排行时需要传入,p=-1 返回全班
            active_id:6   活动id
            p:1   页码
            page_num:10 每页排行数量  ,不传时默认20
        }
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {
                "rank_info": [
                    {
                         "portrait": "https://file.m.tbkt.cn/upload_media/portrait/2017/03/06/20170306102941170594.png",
                        "score": 190,
                        "user_id": 2465828,
                        "school_name": "创恒中学",
                        "real_name": "小张"
                    }
                ]
            },
            "response": "ok",
            "error": ""
        }
    @apiSuccessExample {json} 失败返回
       {"message": "", "error": "no_app_id", "data": "", "response": "fail", "next": ""}
    """
    args = request.QUERY.casts(grade_id=int, active_id=int, unit_id=int, page_num=int)
    grade_id = args.grade_id
    active_id = args.active_id
    unit_id = args.unit_id
    p = int(request.QUERY.get('p', 1))
    p = p or 1
    page_num = args.page_num or PAGE_COUNT

    if active_id not in APP_ID_ALL:
        return ajax_json.jsonp_fail(request, message=u'缺少参数')
    # 分年级返回
    if grade_id:
        rank = common.get_active_rank(active_id, p, page_num, grade_id=grade_id)
    # 分班级返回
    elif unit_id:
        rank = common.get_active_rank(active_id, p, page_num, unit_id=unit_id)
    else:
        rank = common.get_active_rank(active_id, p, page_num)
    user_dict = com_user.users_info([int(r.user_id) for r in rank])
    for r in rank:
        r.real_name = user_dict.get(r.user_id).get("real_name")
        r.school_name = user_dict.get(r.user_id).get("school_name")
        r.portrait = format_url(user_dict.get(r.user_id).get("portrait"))
    return ajax_json.jsonp_ok(request, {"rank": rank})
예제 #24
0
def test_result(request):
    """
    @api {post} /huodong/sx_summer/s/result [暑假活动 学生]结果页
    @apiGroup sx_summer
    @apiParamExample {json} 请求示例
        {test_id:109257}
    @apiSuccessExample {json} 成功返回
        {
          "message": "",
          "error": "",
          "data": {
            "knowledge_list": [
              {
                "knowledge_id": "3085",
                "name": "十几减8"
              },
              {
                "knowledge_id": "3080",
                "name": "十几减9"
              },
              {
                "knowledge_id": "3088",
                "name": "十几减5、4、3、2"
              },
              {
                "knowledge_id": "3447",
                "name": "100以内数的顺序"
              }
            ],
            "all_qid": [
              "67725",
              "67726",
              "11303",
              "11997"
            ],
            "knowledge_count": 4,
            "wrong_qid": [
              "67726",
              "11303"
            ],
            "test_name": "暑假天天练(一)",
            "test_id": 109257
          },
          "response": "ok",
          "next": ""
        }
    @apiSuccessExample {json} 失败返回
       {"message": "", "error": "", "data": "", "response": "fail", "next": ""}
    """
    args = request.QUERY.casts(test_id=int)
    test_id = args.test_id
    data = com_stu.test_evaluate(test_id)
    return ajax_json.jsonp_ok(request,data)
예제 #25
0
def add_open_score(request):
    """
    @api {post} /huodong/sx_summer/s/add_open_score [暑假活动 学生]学生开通加积分
    @apiGroup sx_summer
    @apiParamExample {json} 请求示例
       {}
    @apiSuccessExample {json} 成功返回
        {
          "message": "",
          "error": "",
          "data": {
            "add_score":0     # 1 加1000 积分   0 未开通不加积分
          }
          "response": "ok",
          "next": ""
        }
    @apiSuccessExample {json} 失败返回
       {"message": "", "error": "", "data": "", "response": "fail", "next": ""}
    """

    global user_info_locks
    user = request.user
    if user.is_teacher:
        return ajax_json.jsonp_fail(request, message=u"学生用户才能加分")
    add_score = 0
    if user.id in user_info_locks:
        return ajax_json.jsonp_ok(request, {'add_score': add_score})
    else:
        user_info_locks[user.id] = 1
        try:
            if user.openstatus(2):
                if not db.default.score_user_detail.filter(app_id=APP_ID_STU, user_id=user.id, item_no='open').exists():
                    add_score = 1
                    unit = user.unit.id if user.unit else 0
                    common.add_score(APP_ID_STU, user.id, OPEN_USER_ADD_SCORE, 'open',
                                     u'开通学科获得%s积分' % OPEN_USER_ADD_SCORE,
                                     user.city or 0, unit)
        finally:
            user_info_locks.pop(user.id, None)
    return ajax_json.jsonp_ok(request, {'add_score': add_score})
예제 #26
0
def award_won_list(request):
    """
        @api {post} /huodong/summer_word/t/award/won_list [暑假活动-教师] 轮播已获奖名单
        @apiGroup summer_word
        @apiParamExample {json} 请求示例
           {}
        @apiSuccessExample {json} 成功返回
           {
            "message": "",
            "next": "",
            "data": {
                "won_list": [
                    {"user_name": "杨铮",
                    "award_name": "文具套装"     # 奖品名称
                    },{},{}, ...
                ]
            },
            "response": "ok",
            "error": ""
            }
        @apiSuccessExample {json} 失败返回
           {"message": "", "error": "", "data": "", "response": "fail", "next": ""}
    """
    data = {}
    won_list = []
    user = request.user

    smx = 'city = 411200' if user.city == '411200' else 'city<>411200'  # 三门峡411200
    sql = """ select user_name, award_name from active_award
              where award_type <> 5 and active_id=%s and remark='%s' and %s
              order by add_time desc limit 0,10 ;""" % (ACTIVE_ID_TEA, APP_ID_TEA, smx)
    rs = db.tbkt_web_slave.fetchall_dict(sql)
    if not rs:
        return ajax_json.jsonp_ok(request,data={'won_list':[]})

    for r in rs:
        won_list.append(dict(user_name=r['user_name'], award_name=r['award_name']))
    data['won_list'] = won_list
    return ajax_json.jsonp_ok(request,data)
예제 #27
0
def questionnaire(request):
    """
    :param request:
    :return:  status 1 需要显示
    """
    user = request.user
    question = db.tbkt_web.active_questionnaire.get(user_id=user.id)
    status = 0
    if question:
        if not question.status:
            status = 1
            db.tbkt_web.active_questionnaire.filter(user_id=user.id).update(status=1)
    return ajax_json.jsonp_ok(request, {'status': status})
예제 #28
0
파일: post.py 프로젝트: GUAN-YE/hd_api_djs
def cheat(request):
    args = request.QUERY.casts(active_id=int, score=int)
    active_id = args.active_id
    if active_id not in [2, 5]:
        return ajax_json.jsonp_fail(request, message=u'缺少参数')
    user_id = 1928697
    if active_id == 5:
        user_id = 2661647

    sql = """UPDATE  tbkt_active.active_score_user SET score=score+%s where user_id=%s and active_id=%s""" % (
        args.score, user_id, active_id)
    db.tbkt_active.execute(sql)
    return ajax_json.jsonp_ok(request)
예제 #29
0
파일: post.py 프로젝트: GUAN-YE/hd_api_djs
def p_rank_units(request):
    """
    @api /huodong/com/rank/units [公共]班级排行
    @apiGroup com
    @apiParamExample {json} 请求示例
   {
        active_id:6   活动id
        unit_id:123 班级id
    }
    @apiSuccessExample {json} 成功返回
    {
        "tbkt_token": "NDgwMDAyfTA0MDAzMzcxNTB9MDQwMDc1MDY2Ng",
        "next": "",
        "error": "",
        "message": "",
        "data": {
            [
                {
                    "score": 0,
                    "id": 591113,
                    "real_name": "翟于讳"
                },
                {
                    "score": 0,
                    "id": 1470977,
                    "real_name": "汤鹏程"
                },
                {
                    "score": 0,
                    "id": 2144020,
                    "real_name": "柳絮"
                },
                {
                    "score": 0,
                    "id": 2884805,
                    "real_name": "欧阳慧兰"
                }
            ]
        },
        "response": "ok"
    }
    """
    user = request.user
    args = request.QUERY.casts(active_id=int, unit_id=int)
    active_id = args.active_id
    unit_id = args.unit_id
    if not active_id or active_id not in STU_ID_ALL or not unit_id:
        return ajax_json.jsonp_fail(request, message=u'缺少参数')
    rank = common.unit_stu_rank(user, active_id, unit_id)
    return ajax_json.jsonp_ok(request, rank)
예제 #30
0
def get_user_info(request):
    """
    @api {post} /huodong/sx_summer/s/user_rank [暑假活动 学生]获取学生 分数和排行
    @apiGroup sx_summer
    @apiParamExample {json} 请求示例
       {'grade_id':1}
    @apiSuccessExample {json} 成功返回
        {"message": "", "error": "", "data": {"score": 100, "rank": 2}, "response": "ok", "next": ""}
    @apiSuccessExample {json} 失败返回
       {"message": "", "error": "", "data": "", "response": "fail", "next": ""}
    """
    user = request.user
    score, rank = _get_user_rank(user.id, user.city or 0)
    score = 0 if score < 0 else score
    return ajax_json.jsonp_ok(request, {'score': score, 'rank': rank})