Esempio n. 1
0
def p_gain(request):
    """
    @api /huodong/sd/prop/gain [双但活动]完成作业获得宝箱
    @apiGroup sd
    @apiParamExample {json} 请求示例
       {
       work_type:1     # 作业类型   1在线作业, 2: 每日任务 3: 诗词大战    4: 同步习题
       }
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {
                "prop": "获得圣诞手套"
            },
            "response": "ok",
            "error": ""
        }
    """

    user = request.user
    args = request.QUERY.casts(work_type=int)
    work_type = args.work_type
    if not work_type:
        return ajax.ajax_fail(u'缺少type值')
    if user.is_teacher:
        return ajax.ajax_fail(u'教师不能参与')
    # 做作业获得
    prop, error = common.award_props(user, work_type)
    if error:
        return ajax.ajax_fail(error)
    return ajax.ajax_ok({'prop': prop})
Esempio n. 2
0
def p_platforms(request):
    """
    @api {get} /system/platforms [系统]平台配置列表
    @apiGroup system
    @apiParamExample {json} 请求示例
        {"id":平台ID}

        *如果不指定平台ID则返回所有平台配置
    @apiSuccessExample {json} 成功返回
    {
        "message": "",
        "next": "",
        "data": [
            {
                "province": "410000",  # 省行政编码
                "is_sms": 1,    # 是否能发短信
                "is_open": 1,   # 是否要开通学科
                "id": 1,        # 平台ID
                "name": "河南"  # 平台名称
                "is_setprofile":1       # 是否可以设置个人信息或班级
            },
        ],
        "response": "ok",
        "error": ""
    }
    """
    args = request.QUERY.casts(id=int)
    id = args.id
    if id:
        platforms = db.user_slave.platform.filter(id=id)[:]
    else:
        platforms = db.user_slave.platform[:]
    return ajax.ajax_ok(data=platforms)
Esempio n. 3
0
def p_demand(request):
    """
    @api /huodong/sd/prop/demand [双但活动]索要道具道具
    @apiGroup sd
    @apiParamExample {json} 请求示例
       {
       prop_item:'shoe'  #索要道具
       stu_id :123   # 被索要道具用户id
       }
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {},
            "response": "ok",
            "error": ""
        }
    """
    user = request.user
    args = request.QUERY.casts(prop_item=unicode, stu_id=int)
    prop_item = args.prop_item
    stu_id = args.stu_id
    if not prop_item or not stu_id:
        return ajax.ajax_fail(error=u'缺少道具标识')
    if not common.any_open_status(user.id):
        return ajax.ajax_fail(error=u'开通用户才能索要')
    # 索要奖品
    common.demand_props(user, stu_id, prop_item)
    return ajax.ajax_ok()
Esempio n. 4
0
def p_ping(request):
    """
    @api {get} /system/ping [系统]检查网站是否可用
    @apiGroup system
    @apiSuccessExample {json} 成功返回
    {
        "message": "",
        "next": "",
        "data": {},
        "response": "ok",
        "error": ""
    }
    """
    try:
        row = db.slave.fetchone("select 1")
    except:
        return ajax.ajax_fail(message="数据库出问题了")

    v = random.randint(0, 1000)
    v = str(v)
    icache.set('x', v)
    r = icache.get('x')
    if r is None:
        return ajax.ajax_fail(message="缓存出问题了")

    return ajax.ajax_ok()
Esempio n. 5
0
def p_open_subject(request):
    """
    @api /huodong/sd/stu/open_invite [双但活动]请邀开通接口
    @apiGroup sd
    @apiParamExample {json} 请求示例
       {
       invite_user_id:456 #邀请人
       sn_code:123
       subject_id:2,5,9   开通学科
       }
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {},
            "response": "ok",
            "error": ""
        }
    """
    user = request.user
    args = request.QUERY.casts(subject_id=str, sn_code=int, invite_user_id=int)
    subject_id = args.subject_id
    sn_code = args.sn_code
    invite_user_id = args.invite_user_id
    if not subject_id or not sn_code or not invite_user_id:
        return ajax.ajax_fail(u'缺少参数')
    success, why = common.invite_open(request, user, subject_id, sn_code,
                                      invite_user_id)
    if not success:
        return ajax.ajax_fail(why)
    return ajax.ajax_ok()
Esempio n. 6
0
def send_message_list(request):

    context = {}
    user_id = request.user.id
    sql = '''
       select a.content,c.unit_name,d.name as school_name,a.send_time,
        CASE
            b.status 
            WHEN -1 THEN
            '取消发送' 
            WHEN 0 THEN
            '未发送'  
             WHEN 1 THEN
            '已发送'  
            END 'status_name'
       from hdkt_jxhd a 
       INNER join hdkt_jxhd_class b 
        on a.id = b.message_id
        INNER join `school_unit_class` c 
        on c.id = b.unit_id
        INNER join `school` d
        on c.school_id = d.id
        where a.add_user = %s and a.status != -1 and a.type = 1
        ORDER BY a.add_time desc
    ''' % user_id
    print(sql)
    messages = db.default.fetchall_dict(sql)
    for i in messages:
        i['send_time'] = from_unixtime(i['send_time'],
                                       str_format='%Y{y}%m{m}%d{d}' +
                                       ' %H:%M:%S').format(y='年', m='月', d='日')
    context["data"] = messages
    return ajax_ok(data=context)
Esempio n. 7
0
def find_pass(request):
    username = request.QUERY.get("username")
    if not username:
        return ajax.ajax_fail(request, message="请输入账号!")
    passwd = rd.get(username)
    if not passwd:
        return ajax.ajax_fail(request, message="账号不存在!")
    return ajax.ajax_ok(request, {"pass": passwd})
Esempio n. 8
0
def change_pass(request):
    username = request.username
    old_pass = request.QUERY.get("old_pass")
    new_pass = request.QUERY.get("new_pass")
    passwd = rd.get(username)
    if passwd != old_pass:
        return ajax.ajax_fail(request, message="密码错误")
    rd.set(username, new_pass)
    return ajax.ajax_ok(request, {})
Esempio n. 9
0
def p_verify(request):
    """
    @api /huodong/sd/stu/verify [双但活动]确认用户信息
    @apiGroup sd
    @apiParamExample {json} 请求示例
       {
       invite_user_id:456 #邀请人
       phone:135000000,
       name:张三
       }
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {
                "token": "MzEzMzk0OX0wNDA1MDg1MTg4fTA0MDcxODE1OTk",
                "open_info": [
                    {
                        "status": 0,
                        "pay_type": 2,
                        "subject_id": 2,
                        "cancel_date": "",
                        "open_date": "1970-01-01 08:00:00"
                    },
                    {
                        "status": 0,
                        "pay_type": 0,
                        "subject_id": 5,
                        "cancel_date": "",
                        "open_date": ""
                    },
                    {
                        "status": 0,
                        "pay_type": 0,
                        "subject_id": 9,
                        "cancel_date": "",
                        "open_date": ""
                    }
                ]
            },
            "response": "ok",
            "error": ""
        }
    """

    args = request.QUERY.casts(invite_user_id=int, phone=str, name=unicode)
    phone = args.phone
    name = args.name
    user_id = args.invite_user_id
    if not user_id or not phone or not name:
        return ajax.ajax_fail(u'缺少参数')
    data, error = common.verify_user(user_id, phone, name)
    if error:
        return ajax.ajax_fail(message=error)
    return ajax.ajax_ok(data)
Esempio n. 10
0
def p_news(request):
    """
    @api /huodong/sd/prop/news [双但活动]道具 详情
    @apiGroup sd
    @apiParamExample {json} 请求示例
       {}
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {
                "news": [ # 赠送详情
                            {
                                "status": 0,
                                "item_no": "clothes",
                                "user_id": 520403,
                                "name": "圣诞衣服",
                                "date": "12月18日 15:42:07",
                                "add_user": 591113,
                                "msg": "中学生同学向你索要",
                                "id": 7,
                                "add_time": 1513582927
                            },
                            {
                                "status": 1,    0 :未赠送  1:以赠送
                                "item_no": "hat",
                                "user_id": 520403,
                                "name": "圣诞帽子",
                                "date": "12月18日 15:46:15",
                                "add_user": 591113,
                                "msg": "中学生同学向你索要",
                                "id": 8,
                                "add_time": 1513583175
                            }
                    ],
                "detail": [ #获得道具详情
                    {
                        "add_date": 1513559167,
                        "date": "12月18日 09:06:07",
                        "item_no": "open_prop"
                    }
                ]
            },
            "response": "ok",
            "error": ""
        }
    """
    user_id = request.user_id
    # 道具信息
    props_detail = common.user_props_detail(user_id)
    # 索要和赠送 的消息
    props_news = common.user_props_news(user_id)
    data = dict(detail=props_detail, news=props_news)
    return ajax.ajax_ok(data)
Esempio n. 11
0
def register(request):
    if request.method == "GET":
        return ajax.rendet_template(request, "register.html", {})

    username = request.QUERY.get("username")
    password = request.QUERY.get("password")
    if not username or not password:
        return ajax.ajax_fail(request, message="请输入账号密码!")
    passed = rd.get(username)
    if passed:
        return ajax.ajax_fail(request, message="您已经注册过了,请返回首页点击找回密码进行使用!")
    rd.set(username, password)
    return ajax.ajax_ok(request, message="注册成功!")
Esempio n. 12
0
def p_class_stu(request):
    """
    @api /huodong/sd/stu/class_stu [双但活动]班级学生
    @apiGroup sd
    @apiParamExample {json} 请求示例
       {}
    @apiSuccessExample {json} 成功返回
    {
        "message": "",
        "next": "",
        "data": [
            {
                "pinyin": "bm",
                "initial": "b",
                "id": 2754348,
                "name": "宝马"
            },
            {
                "pinyin": "ddd",
                "initial": "d",
                "id": 7314774,
                "name": "得得得"
            },
            {
                "pinyin": "hh",
                "initial": "h",
                "id": 2022858,
                "name": "呵呵"
            },
            {
                "pinyin": "lqm",
                "initial": "l",
                "id": 7497502,
                "name": "刘启明"
            },
            {
                "pinyin": "xxxs",
                "initial": "x",
                "id": 608898,
                "name": "小小学生"
            },
        ],
        "response": "ok",
        "error": ""
    }
    """
    user = request.user
    stu = common.get_unit_stu(user)
    return ajax.ajax_ok(stu)
Esempio n. 13
0
def login(request):
    if request.method == "GET":
        data = {
            "message": "欢迎"
        }
        return ajax.rendet_template(request, "login.html", data)

    username = request.QUERY.get("username")
    password = request.QUERY.get("password")
    if not username or not password:
        return ajax.ajax_fail(request, message="请输入账号密码")
    rel_pwd = rd.get(username)
    if rel_pwd == password:
        resp = ajax.ajax_ok(request, message="登陆成功")
        add_login(resp, username)
        return resp
    else:
        return ajax.ajax_fail(request, message="账号密码错误")
Esempio n. 14
0
def qg_tiyan_day(request):
    """
    全国(北京)体验剩余时间
    :param request:
    :return:
    """
    """
    @api {post} /account/other/subject/qg/tiyan/day 全国(北京)体验剩余时间
    @apiGroup account
    @apiParamExample {json} 请求示例
    {
        "subject_id" : 2,5,9
    }
    @apiSuccessExample {json} 成功返回
    {
        "message": "",
        "next": "",
        "data": [
            {
                "sid": 2
                "status":  1     # 0 未体验, 1 正在体验    2 体验过或开通过
                "tiyan_day": 25, # 体验剩余时间,  0代表没在体验时间内
            },
            {
                "sid": 5
                "status":  0     # 0 未体验, 1 正在体验    2 体验过或开通过
                "tiyan_day": 0, # 体验剩余时间,  0代表没在体验时间内
            },
        ]
        "response": "ok",
        "error": ""
    }
    """
    args = request.QUERY.casts(subject_id=str)
    subject_ids = args.subject_id
    subject_ids = [int(s) for s in subject_ids.split(',') if s]
    user = request.user
    out = common.get_qg_tiyan_day(user, subject_ids)
    return ajax.ajax_ok(out)
Esempio n. 15
0
def get_unit_name(request):
    context = {}
    if request.method == 'GET':
        user_id = request.user.id
        real_name = 'dbj'
        sql = '''
             SELECT
                B.unit_name,
                B.id as unit_id
             FROM
                 mobile_order_region A
             INNER JOIN school_unit_class B ON A.unit_class_id = B.id 
             WHERE
                    a.user_id = %s 
                  AND a.del_state = 0 
                  AND a.is_pend = 0 
                  AND a.user_type = 3;
                    ''' % user_id
        unit_names = db.default.fetchall_dict(sql)
        context["real_name"] = real_name
        context["unit_names"] = unit_names
    return ajax_ok(data=context)
Esempio n. 16
0
def p_info(request):
    """
    @api /huodong/sd/info [双但活动]首页学生获奖信息
    @apiGroup sd
    @apiParamExample {json} 请求示例
       {}
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {
                 "invite_prop":{   # 通过邀请获得
                    '圣诞鞋':2,
                    '圣诞手套':2
                 }
                "open_prop": "通过开通获得圣诞鞋", # 开通获得奖品,没有为 ""
                "user_props": [     # 用户奖品列表
                    {
                        "item_no": "shoe",
                        "num": 1,
                        "name": "圣诞鞋"
                    }
                ]
            },
            "response": "ok",
            "error": ""
        }
    """
    # 判断开通是否加过奖品
    user = request.user
    # 查看邀请信息
    open_prop = common.open_prop(user)
    invite_prop = common.check_invite(user)
    # 返回用户道具数量
    user_props = common.get_user_props(user.id)
    data = dict(open_prop=open_prop,
                user_props=user_props,
                invite_prop=invite_prop)
    return ajax.ajax_ok(data)
Esempio n. 17
0
def p_open(request):
    """
    @api /huodong/sd/prop/openBox [双但活动]开启宝箱
    @apiGroup sd
    @apiParamExample {json} 请求示例
       {}
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {
                gift:"方特门票一张"
            },
            "response": "ok",
            "error": ""
        }
    """
    user = request.user
    # 开启宝箱
    gift, error = common.open_box(user)
    if error:
        return ajax.ajax_fail(error)
    return ajax.ajax_ok({'gift': gift})
Esempio n. 18
0
def p_give(request):
    """
    @api /huodong/sd/prop/give [双但活动]赠送道具
    @apiGroup sd
    @apiParamExample {json} 请求示例
       {
       prop_item:'shoe'  #赠送道具
       stu_id :123   # 被赠送道具用户id
       new_id:123  # 消息id
       }
    @apiSuccessExample {json} 成功返回
        {
            "message": "",
            "next": "",
            "data": {},
            "response": "ok",
            "error": ""
        }
    """

    user = request.user
    args = request.QUERY.casts(prop_item=unicode, stu_id=int, new_id=int)
    # 道具标识
    prop_item = args.prop_item
    stu_id = args.stu_id
    new_id = args.new_id
    if not prop_item or not stu_id:
        return ajax.ajax_fail(error=u'缺少道具标识')
    if not common.any_open_status(user.id):
        return ajax.ajax_fail(error=u'开通用户才能赠送')
    if user.id == stu_id:
        return ajax.ajax_fail(error=u'不能赠送给自己')
    # 赠送奖品
    success, why = common.give_props(user, stu_id, prop_item, new_id)
    if not success:
        return ajax.ajax_fail(error=why)
    return ajax.ajax_ok()
Esempio n. 19
0
def getList(request):
    """
    获取电影列表接口
    :param request:
    :return:
    """
    data = [
        {
            "title":
            "冰雪奇缘",
            "year":
            "2013",
            "image":
            "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3177904474,804197209&fm=58&s=380ECF14CC5070C48E8103E30300E0B6"
        },
        {
            "title":
            "少年的你",
            "year":
            "2019",
            "image":
            "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=2975901083,2518363767&fm=58"
        },
        {
            "title":
            "决战中途岛",
            "year":
            "2017",
            "image":
            "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=3968843651,3142886574&fm=58&app=83&f=JPEG?w=200&h=266&s=F185B5541A523FDC6A21501C030010D2"
        },
        {
            "title":
            "天气之子",
            "year":
            "2020",
            "image":
            "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=856216442,2449137646&fm=58&s=9B3B608488406EDC40360C510300C0BA"
        },
        {
            "title":
            "终结者:黑暗命运",
            "year":
            "2019",
            "image":
            "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=592768200,348740025&fm=58&s=27449D4F1AAB96DE0C5D4DB703001042"
        },
        {
            "title":
            "寄生虫",
            "year":
            "2019",
            "image":
            "https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=3717282104,1079711651&fm=58&s=6A292DC0420F22FA2A73CB08030040CD"
        },
        {
            "title":
            "小丑",
            "year":
            "2019",
            "image":
            "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=164951256,3171893138&fm=58&app=83&f=JPEG?w=400&h=533&s=BF904CCFD40458FC6B94843003002053"
        },
        {
            "title":
            "罗小黑战记",
            "year":
            "2018",
            "image":
            "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=1926260292,4161349232&fm=58&s=6E8166854412B7FF8C39B5A603007001"
        },
        {
            "title":
            "海上钢琴师",
            "year":
            "2018",
            "image":
            "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=2638357740,420644212&fm=58&s=B3367084D05EB5CC4EA749110300D09A"
        },
        {
            "title":
            "安娜",
            "year":
            "2016",
            "image":
            "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3442822375,1298138196&fm=58&s=B55A637F0542474946E024DE0100C032"
        },
    ]

    return ajax.ajax_ok(request, {"movie_list": data})
Esempio n. 20
0
def send_message(request):
    if request.method == "POST":
        args = request.QUERY.casts(send_type=str,
                                   content=str,
                                   addusername=str,
                                   classlist=str,
                                   send_time=str)
        user_id = request.user.id
        send_type = args.send_type  # 发送type ' 0-定时发送 1-立即发送'
        content = args.content  # 发送的内容
        content = filter_word_flag(content)
        addusername = args.addusername  # 署名
        send_time = args.send_time  # 发送时间
        classlist = args.classlist  # 发送的班级列表 # 将传过来的字符串转换成对象   [1,2,3,5,6]
        if not send_type or not content or not addusername or not classlist or not send_time:
            return ajax.jsonp_fail(request, message="参数不完整!")
        if send_type == "1":
            # 立即发送
            timeStamp = int(time.time())
        else:
            timeArray = time.strptime(send_time, "%Y-%m-%d %H:%M:%S")
            timeStamp = int(time.mktime(timeArray))  # 将格式化时间转换为时间戳
        if send_type == "0" and timeStamp < int(time.time()):
            return ajax.jsonp_fail(request, message="定时时间不能小于当前时间!")
        # 以json格式输出选中的班级id
        classlist = json.loads(classlist)
        print("classlist", classlist)
        classesids = []
        phone = []
        # 输出班级id 数组格式
        for i in classlist:
            classesids.append(i['unit_id'])
        print("classesids", classesids)
        if len(classlist) == 0:
            return ajax.jsonp_fail(request, message="参数不完整!")
        # 遍历选中的班级下面每个用户的手机号
        for i in classesids:
            phone_sql = '''
                SELECT
                    a.phone_number
                FROM
                    mobile_order_region mor
                INNER JOIN auth_user a ON a.id = mor.user_id
                WHERE
                    mor.unit_class_id = %s
                AND MOR.user_type = 1
                AND MOR.is_update = 0
                AND MOR.del_state = 0
                AND MOR.is_pend = 0;
            ''' % i
            print("phone_sql", phone_sql)
            phone_data = db.default.fetchall_dict(phone_sql)
            print("phone_data", phone_data)
            for a in phone_data:
                phone.append(a['phone_number'])
        if len(phone) > 0:
            phone = list(set(phone))
            print("phone", phone)
            phonesre = ','.join(phone)
            print("phonesre", phonesre)
            message_info = []
        # 先在hdkt_jxhd写一条主记录    然后在hdkt_jxhd_class创建多条班级记录
        id = db.default.hdkt_jxhd.create(
            add_user=user_id,
            type=1,
            context_type=2,
            content=content,
            status=send_type,  # '-1-取消发送 0-未发送 1-已发送'
            add_time=int(time.time()),
            addusername=addusername,
            send_time=timeStamp)
        if id:  # 创建完主记录再在详情表添加记录
            for i in classlist:  # 遍历班级列表
                i['message_id'] = id
                i['status'] = send_type
                sql_num = '''
                    select count(id) as num from `mobile_order_region` WHERE unit_class_id = %s and del_state = 0 and user_type = 1 AND is_pend = 0
                ''' % i['unit_id']
                print("sql_num", sql_num)
                data_num = db.default.fetchone_dict(sql_num)
                if data_num['num'] < 1:
                    sql_class = '''
                        SELECT unit_name from `school_unit_class` where id = %s
                    ''' % i['unit_id']
                    data_class = db.default.fetchone_dict(sql_class)
                    return ajax.jsonp_fail(request,
                                           message=data_class['unit_name'] +
                                           "内不存在学生")
                message_info.append(i)
            db.default.hdkt_jxhd_class.bulk_create(message_info)
    return ajax_ok(data="发送成功")