コード例 #1
0
def index(request, user_id, is_open, t_id, class_id, city):
    """
    获取首页的排名和积分
    :param request:
    :param user_id:  用户id
    :return:
    """

    add_time = time.time()
    t = time.localtime(add_time)
    zero_time = time.mktime(
        time.strptime(time.strftime('%Y-%m-%d 00:00:00', t),
                      '%Y-%m-%d %H:%M:%S'))
    activity_record = db.tbkt_active_slave.yw_activity_record_hd.get(
        user_id=user_id, add_time__gte=zero_time)
    if not activity_record:
        #首次进入老师加积分,调用增加积分的接口
        db.tbkt_active.yw_activity_record_hd.create(user_id=user_id,
                                                    add_time=add_time)
        if t_id and city != 411200:
            update_score(t_id, 5, 'attend', user_id, 0, 0, is_open)
    if is_open == 1:
        is_open_db = db.tbkt_active_slave.yw_activity_record_hd.get(
            user_id=user_id, is_open=1)
        if not is_open_db:
            db.tbkt_active.yw_activity_record_hd.create(user_id=user_id,
                                                        is_open=1)
            if city != 411200:
                update_score(user_id, 4, 'isfrist', user_id, 0, class_id,
                             is_open)
                return "开通成功!获得 1000积分"
コード例 #2
0
def recording_integral(recording_id, share_time, state, user_id, is_open,
                       class_id, city):
    """
    每天最新一次分享加分
    :param recording_id:  录音id
    :param share_time: 最新一次分享时间
    :param state: 状态
    :param user_id: 用户id
    :return:
    """

    add_time = time.time()
    t = time.localtime(add_time)
    zero_time = time.mktime(
        time.strptime(time.strftime('%Y-%m-%d 00:00:00', t),
                      '%Y-%m-%d %H:%M:%S'))
    if state == 1 or (zero_time > share_time and state == 2):
        #当天首次分享
        recording_hd = db.tbkt_active.yw_recording_hd.filter(
            user_id=user_id, id=recording_id).update(state=2,
                                                     add_time=add_time)
        # 首次分享学生加分
        if city != 411200:
            update_score(user_id, 4, 'share', user_id, 0, class_id, is_open)
        return 1
コード例 #3
0
def share_activity(user_id, class_id, is_open, city):
    """
    学生端分享活动页加分
    :param user_id: 用户id
    :return:
    """

    t = time.localtime(time.time())
    zero_time = time.mktime(
        time.strptime(time.strftime('%Y-%m-%d 00:00:00', t),
                      '%Y-%m-%d %H:%M:%S'))
    ballot_record = db.tbkt_active.yw_ballot_record_hd.filter(ip=user_id)
    if ballot_record:
        add_time = ballot_record[0].add_time
        if add_time != zero_time:
            ballot_record.update(add_time=zero_time)
            if city != 411200:
                a = update_score(user_id, 4, 'activity_share', user_id, 0,
                                 class_id, is_open)
                return 1

    else:
        db.tbkt_active.yw_ballot_record_hd.create(ip=user_id,
                                                  add_time=zero_time)
        if city != 411200:
            a = update_score(user_id, 4, 'activity_share', user_id, 0,
                             class_id, is_open)
            return 1
    return 0
コード例 #4
0
ファイル: common.py プロジェクト: GUAN-YE/hd_api_djs
def stu_open_add_score(user):
    # 学生开通加分
    if int(user.city) != 411200:
        return
    is_open = user.openstatus(2)
    if is_open:
        if db.tbkt_active.active_score_user_detail.get(user_id=user.id, active_id=STU_ACTIVE_ID, item_no='stu_open'):
            return 0
        else:
            update_score(user.id, STU_ACTIVE_ID, OPEN_ITEM, user.id, user.city, user.unit.id)
            return 1
コード例 #5
0
def add_score(user_id, active_id, item_no, add_user, city, unit_id):
    """
    功能说明:                英语常态活动加减积分
    -----------------------------------------------
    修改人                    修改时间
    -----------------------------------------------
    张帅男                    2017-9-11
    """
    if int(city) == 411200:
        return
    if active_id != 3:
        return
    if item_no not in ITEM:
        return
    common.update_score(user_id, active_id, item_no, add_user, city, unit_id, is_open=0)
    return
コード例 #6
0
def ballot_integral(user_id, class_id, ch_Code, city_id):
    """

    :param recording_id:  录音id
    :param is_open: #是否开通
    :return:
    """

    recording = db.tbkt_active.yw_recording_hd.filter(ch_Code=ch_Code,
                                                      user_id=user_id)
    if not recording[0]:
        return 0

    recording_ballot = recording[0].ballot_num
    recording.update(ballot_num=recording_ballot + 1)
    is_open = get_open(user_id)
    if city_id != 411200:
        update_score(user_id, 4, 'ticket', user_id, 0, class_id, is_open)
    return 1
コード例 #7
0
def recommend_article(user_id, ch_Code, city):
    """
    老师推荐文章入库
    :param request:
    :param user_id: 用户id
    :param ch_ID: 章节id
    :return:
    """
    add_time = time.time()

    detail = db.tbkt_active_slave.yw_article_recommend_hd.get(user_id=user_id,
                                                              ch_Code=ch_Code)
    if not detail:
        article_recommend = db.tbkt_active.yw_article_recommend_hd.create(
            user_id=user_id, ch_Code=ch_Code, add_time=add_time)
        if city != 411200:
            update_score(user_id, 5, 'recomt', user_id, 0, 0, 0)
        #调用加积分接口
        return article_recommend
    return 0
コード例 #8
0
ファイル: views.py プロジェクト: GUAN-YE/hd_api_djs
def r_share(request):
    """
    @api /huodong/sx/normal/stu/share [数学常态活动]学生分享
    @apiGroup math_normal
    @apiSuccessExample {json} 成功返回
    {
        "message": "",
        "next": "",
        "data": "",
        "response": "ok",
        "error": ""
    }
    """
    user = request.user
    if user.is_teacher or int(user.city) != 411200:
        return ajax.jsonp_fail(request, message='教师不能参与学生分享!')
    if not common.get_user_share(user.id, STU_ACTIVE_ID, SHARD):
        return ajax.jsonp_fail(request)
    is_open = 0  #user.openstatus(2)
    update_score(user.id, STU_ACTIVE_ID, SHARD, user.city, user.unit.id,
                 is_open)
    return ajax.jsonp_ok(request)
コード例 #9
0
def p_update_score(request):
    """
    @api {post} /huodong/active/add_score [活动]活动加减分
    @apiGroup active
    @apiParamExample {json} 请求示例
       {
            "user_id": 2465828,             # 要加分的用户id
            "active_id": 3,                 # 活动id
            "item_no": "mouse"              # 活动加减分规则标识
            "city": 4500000,                # 省,市, 区
            "unit_id": ""                   # 班级
            "is_open":                      # 用户开通状态 0:未开通, 1: 开通
       }
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {
            },
            "response": "ok",
            "error": ""
        }
    @apiSuccessExample {json} 失败返回
       {"message": "", "error": "", "data": "", "response": "fail", "next": ""}
    """
    """
    功能说明:                活动加减分
    参数:item_no, 要加减分的学习模块或作业模块, 英文名
    -----------------------------------------------
    修改人                    修改时间
    -----------------------------------------------
    张帅男                    2017-9-11
    """
    args = request.loads() or request.QUERY.casts(user_id=int,
                                                  active_id=int,
                                                  item_no=str,
                                                  city=str,
                                                  unit_id=int,
                                                  grade_id=int,
                                                  is_open=int)
    item_no = args.item_no or ""
    user_id = args.user_id or 0
    active_id = args.active_id or 0
    city = args.city or 0
    unit_id = args.unit_id or 0
    grade_id = args.grade_id or 0
    is_open = int(args.is_open or 0)

    add_user_id = request.user.id

    if not item_no:
        return jsonp_fail(request, message="no item_no")

    if not user_id:
        return jsonp_fail(request, message="no active_user_id")

    if not active_id:
        return jsonp_fail(request, message="no active_id")

    common.update_score(user_id, active_id, item_no, add_user_id, city,
                        unit_id, is_open, grade_id)
    return jsonp_ok(request)