Ejemplo n.º 1
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='已发送开通短信')
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
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"每天只能分享一次")
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
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})
Ejemplo n.º 11
0
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)
Ejemplo n.º 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)
Ejemplo n.º 13
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})
Ejemplo n.º 14
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)
Ejemplo n.º 15
0
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})
Ejemplo n.º 16
0
def p_award(request):
    """
    @api {post} /huodong/com/award [公共 ]活动抽奖
    @apiGroup com
    @apiParamExample {json} 请求示例
       {
            app_id:1   活动id
        }
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {
                "award_type": 1,
                "name": "ipad",
                "is_award": 1
            },
            "response": "ok",
            "error": ""
        }
    @apiSuccessExample {json} 失败返回
       {"message": "积分不足", "error": "", "data": "", "response": "fail", "next": ""}
    """
    user = request.user
    args = request.QUERY.casts(app_id=int)
    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_sort = TEA_AWARD_SORT2 if user.is_teacher else STU_AWARD_SORT2
    lottery_cost = LOTTERY_COST.get(int(app_id), 0)
    if not lottery_cost:
        return ajax_json.jsonp_fail(request, message=u'缺少参数')
    # 抽奖
    award = Award(app_id=app_id, active_id=active_id, user=user, lottery_cost=lottery_cost)
    result, why = award.draw_award(award_sort=award_sort)
    if not result:
        return ajax_json.jsonp_fail(request, message=why)
    return ajax_json.jsonp_ok(request, data=why)
Ejemplo n.º 17
0
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)
Ejemplo n.º 18
0
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)
Ejemplo n.º 19
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='积分成功')
Ejemplo n.º 20
0
def p_list(request):
    """
    @api {post} /huodong/sx_summer/s/list [暑假活动 学生]试卷列表
    @apiGroup sx_summer
    @apiParamExample {json} 请求示例
       {
        grade_id:1
       }
    @apiSuccessExample {json} 成功返回
    {
      "message": "",
      "error": "",
      "data": {
        "苏教版": [
          {
            "status": "-1",-1:未作  0: 未完成,1:已完成
            "name": "二年级",
            "paper_name": "暑假天天练(一)",
            "v_name": "苏教版",
            "id": "231",
            "paper_id": "19828"
          },
          {
            "status": "0",
            "name": "二年级",
            "paper_name": "暑假天天练(二)",
            "v_name": "苏教版",
            "id": "231",
            "paper_id": "19829"
          }]
          "人教版":[...]
      },
      "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="no_grade_Id")
    paper = com_stu.get_paper_list(args.grade_id, user.old_user_id)
    return ajax_json.jsonp_ok(request,paper)
Ejemplo n.º 21
0
def p_award_all(request):
    """
    @api {post} /huodong/com/award/all  [公共] 分页返回中奖用户
    @apiGroup com
    @apiParamExample {json} 请求示例
       {
            app_id:1   抽奖奖品对应id
            p:1   页码
        }
    @apiSuccessExample {json} 成功返回
    {
        "message": "",
        "next": "",
        "data": {
            "total": 1,
            "detail": [
                {
                    "city": "410200",
                    "user_id": 378394,
                    "name": "三等奖",
                    "url": "http://flv.tbkt.cn/upload_media/knowledge/img/2015/09/21/20150921113843806676.png",
                    "school_name": "鼓楼区杨砦小学",
                    "real_name": "李果果",
                    "award_type": "3",
                    "time": "2017-09-12 18:30:21"
                }
            ]
        },
        "response": "ok",
        "error": ""
    }
    @apiSuccessExample {json} 失败返回
       {"message": "", "error": "no_app_id", "data": "", "response": "fail", "next": ""}
    """
    args = request.QUERY.casts(app_id=int, p=int)
    user = request.user
    app_id = args.app_id
    p = args.p or 1
    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
    detail, total = Award(app_id=app_id, active_id=active_id).all_award_detail(p)
    return ajax_json.jsonp_ok(request, {'detail': detail, 'total': total})
Ejemplo n.º 22
0
def get_coin(request):
    """
    @api {post} /huodong/tea/task/get/coin  领取金币
    @apiGroup tea_coin
    @apiParamExample {json} 请求示例
        {}
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": "",
            "response": "ok",
            "error": ""
        }
    """
    user_id = request.user_id
    num = db.tbkt_active.active_score_gift.select("end_num").get(active_id=14)
    if num.end_num == 0:
        return ajax_json.jsonp_fail(request, data=u"金币领完了")
    data = common.get_coin(user_id)
    return ajax_json.jsonp_ok(request, data)
Ejemplo n.º 23
0
def p_user_info(request):
    """
        @api {post} /huodong/com/user/info [公共]首页
        @apiGroup com
        @apiParamExample {json} 请求示例
           {
                active_id:6   活动id
            }
        @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {
                "score": 210,
                "rank_no": 1,
                "is_sign":True,True签过,Flase未签
            },
            "response": "ok",
            "error": ""
        }
        @apiSuccessExample {json} 失败返回
           {"message": "", "error": "", "data": "", "response": "fail", "next": ""}
        """
    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'缺少参数')
    user_id = request.user_id
    grade_id = 0
    unit_id = 0
    # 按年级排名
    if active_id in [6, 11]:
        grade_id = user.grade_id
    # 按班级排名
    if active_id in [10]:
        unit_id = user.unit.id if user.unit else 0
    data = common.get_user_rank(active_id, user_id, grade_id=grade_id,unit_id=unit_id)
    is_sign = common.get_user_item_today(user_id, active_id, 'sign')
    data['is_sign'] = is_sign
    return ajax_json.jsonp_ok(request, data)
Ejemplo n.º 24
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})
Ejemplo n.º 25
0
def p_send_open(request):
    """
    @api {post} /huodong/sx_summer/t/send_open [暑假活动 教师]发送开通短信
    @apiGroup sx_summer
    @apiParamExample {json} 请求示例
       {}
    @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_open')
    if open_num < SEND_OPEN_NUM:
        common.add_score(APP_ID_TEA, user.id, SEND_OPEN_SCORE, 'send_open', u'发送开通短信', user.city or 0)
    content = args.content
    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', []))
    platform_id = int(user.platform_id) if user and user.platform_id else 1
    phones = ','.join(str(s['phone_number']) for s in student if s.get('status',0) not in [2,9])
    r = hub.bank.post('/cmcc/open', {'phone_number': phones, 'subject_id': 2, "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)

    hub = tbktapi.Hub(request)
    hub.sms.post('/sms/send', {'phone': phones, 'unit_id': unit_class_id, 'content': content})
    return ajax_json.jsonp_ok(request)
Ejemplo n.º 26
0
def user_award(request):
    """
    @api {post} /huodong/sx_summer/s/award/detail  [暑假活动 抽奖]抽奖详情
    @apiGroup sx_summer
    @apiParamExample {json} 请求示例
       {app_id:45}    # 36:教师,  35:学生,
    @apiSuccessExample {json} 成功返回
        {
          "message": "",
          "error": "",
          "data": {
                my_award:['2017年6月23日 22:35',  '精美雨伞一个'...],
                all_award:['张晓燕在抽奖活动中获得精美天堂太阳伞1个'...]
                is_smx: 1    1:表示三门峡获奖情况
                }
          "response": "ok",
          "next": ""
        }
    @apiSuccessExample {json} 失败返回
       {"message": "", "error": "no_app_id", "data": "", "response": "fail", "next": ""}
    """
    user = request.user
    is_smx = 0 if user.city and int(user.city) != 411200 else 1
    args = request.QUERY.casts(app_id=int)
    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 = APP_ID_STU
    if app_id in TEA_APP_IDS:
        _app_id = APP_ID_TEA
    my_award = common.get_user_award(_app_id, user.old_user_id, is_smx)
    all_award = common.get_award_detail(_app_id, is_smx)
    data = {
        'my_award': my_award,
        'all_award': all_award,
        'is_smx': is_smx
    }
    return ajax_json.jsonp_ok(request, data)
Ejemplo n.º 27
0
def submit(request):
    """
    @api {post} /huodong/sx_questionnaire/submit [问卷调查] 提交
    @apiGroup  sx_questionnaire
    @apiParamExample {json} 请求示例
       {data:[{qid:1,option:'A,C',content:'叮叮叮,当当当'},{qid:2,option:''A,B,C,content:''}]}
    @apiSuccessExample {json} 成功返回
       {
        "message": "",
        "next": "",
        "data": {},
        "response": "ok",
        "error": ""
        }
    @apiSuccessExample {json} 失败返回
       {"message": "", "error": "请勿重复提交", "data": "", "response": "fail", "next": ""}

    """
    args = request.QUERY.casts(data='json')
    data = args.data
    _result, err = common.submit(request.user, data)
    if result:
        return ajax_json.jsonp_ok(request, {'result': _result})
    return ajax_json.jsonp_fail(request, error=err)
Ejemplo n.º 28
0
def p_setbook(request):
    """
    @api {post} /huodong/mid_term/book/set [期中提分试卷]设置用户教材/教辅
    @apiGroup mid_term
    @apiParamExample {json} 请求示例
        {"book_id":教材/教辅ID}
    @apiSuccessExample {json} 成功返回
    {
        "message": "",
        "next": "",
        "data": "",
        "response": "ok",
        "error": ""
    }
    """
    args = request.QUERY.casts(book_id=int)
    book_id = args.book_id or 0

    if not book_id:
        return ajax.jsonp_fail(request, message='参数错误: book_id')

    user_id = request.user_id
    common.setbook(user_id, book_id)
    return ajax.jsonp_ok(request)
Ejemplo n.º 29
0
def p_getbook(request):
    """
    @api {post} /huodong/mid_term/book/get [期中提分试卷]获取用户设置的活动教材
    @apiGroup mid_term
    @apiParamExample {json} 请求示例
        {
            "subject_id" : 21 / 91  # 21为数学  91为英语
        }
    @apiSuccessExample {json} 成功返回
    {
        "message": "",
        "next": "",
        "data": {},
        "response": "ok",
        "error": ""
    }
    """
    args = request.QUERY.casts(subject_id=int)
    subject_id = args.subject_id or 0
    if not subject_id:
        return ajax.jsonp_fail(request, "没有subject_id")
    user_id = request.user_id
    data = common.getbook(user_id, subject_id)
    return ajax.jsonp_ok(request, data)
Ejemplo n.º 30
0
def p_award(request):
    """
    @api {post} /huodong/sx_summer/t/award [暑假活动 抽奖]教师抽奖
    @apiGroup sx_summer
    @apiParamExample {json} 请求示例
       {app_id:35}   36:数学教师     42 :语文教师   ,  34:英语教师
    @apiSuccessExample {json} 成功返回
        {
          "message": "很遗憾,您本次未抽中任何奖品!",
          "error": "",
          "data": {award:1} 1~4 中奖,5: 谢谢参与,6 积分不足
          "response": "ok",
          "next": ""
        }
    @apiSuccessExample {json} 失败返回
       {"message": "手速太快了,请稍后尝试", "error": "", "data": "", "response": "fail", "next": ""}
    """

    user = request.user
    is_smx = 0 if user.city and int(user.city) != 411200 else 1
    args = request.QUERY.casts(app_id=int)
    app_id = args.app_id
    if not app_id or app_id not in TEA_APP_IDS:
        return ajax_json.jsonp_fail(request, error='no_app_id')

    lottery_cost = TEA_LOTTERY_COST

    if not common.get_active_status(app_id):
        return ajax_json.jsonp_fail(request, message=u'活动已经结束')

    # 判断用户是否有抽奖资格
    # 语文
    if app_id == YW_APP_ID_TEA:
        lottery_able = common.get_yuwen_lottery_able(request, app_id, user, lottery_cost)
    else:
        lottery_able = db.default.score_user.filter(app_id=app_id, user_id=user.id,
                                                    score__gte=lottery_cost).exists()

    if not lottery_able:
        return ajax_json.jsonp_ok(request, data={'award': 6}, message=u'您的积分已不足,快去赚积分吧!')

    # 抽奖
    # 获取获奖奖项
    if is_smx:
        award_type = probability.get_smx_user_award_type(user.old_user_id)
    else:
        award_type = probability.get_user_award_type(user.old_user_id)

    # 语文
    if app_id == YW_APP_ID_TEA:
        # 抽奖扣分结果
        re_result = common.yw_reduce_score(request, app_id, user, lottery_cost)
        if re_result:
            # 确认抽奖情况,保存获奖记录
            award, award_name = common.get_award_result(app_id, user, award_type, is_smx)
        else:
            award, award_name = 0, 0
    else:
        # 数学英语 抽奖扣分
        unit = user.unit.id if user.unit else 0
        cc = common.add_score(app_id, user.id, -lottery_cost, 'lottery', u'抽奖-%s积分' % lottery_cost, user.city or 0,
                              unit)
        if cc:
            # 确认抽奖情况,保存获奖记录
            award, award_name = common.get_award_result(app_id, user, award_type, is_smx)
        else:
            award, award_name = 0, 0

    if not (award and award_name):
        return ajax_json.jsonp_ok(request, data={'award': 5}, message=u'很遗憾,您本次未抽中任何奖品!')
    return ajax_json.jsonp_ok(request, data={'award': award}, message=u'恭喜获奖,获得%s!' % award_name)