def p_update_student(request): """ @api {post} /class/student/update [班级]更新学生信息 @apiGroup class @apiParamExample {json} 请求示例 {"user_id":学生ID, "name":姓名, "sex":1男2女} @apiSuccessExample {json} 成功返回 {"message": "", "next": "", "data": "", "response": "ok", "error": ""} @apiSuccessExample {json} 失败返回 { "message": "名字必须是2-5个汉字", "next": "", "data": "", "response": "fail", "error": "" } """ args = request.QUERY.casts(user_id=int, name=unicode, sex=int) student_id = args.user_id or 0 name = args.name or u'' sex = args.sex or 0 if name and not is_chinese_word(name): return ajax.jsonp_fail(request, message='姓名长度为2-5个汉字') user = request.user if not common.is_mystudent(user, student_id): return ajax.jsonp_fail(request, message='权限错误') thread_pool.call(common.update_student_info, student_id, name, sex) return ajax.jsonp_ok(request)
def p_change_border(request): """ @api {get} /account/border/change [个人设置]用户更换边框 @apiGroup account @apiParamExample {json} 请求示例 { "border_id":1 } @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": {}, "response": "ok", "error": "" } """ user_id = request.user_id args = request.QUERY.casts(border_id=int) border_id = args.border_id if not border_id: return ajax.jsonp_fail(request, u'缺少参数') success, why = common.change_border(user_id, border_id) if not success: return ajax.jsonp_fail(request, why) return ajax.jsonp_ok(request, success)
def p_name(request): """ @api {post} /account/name [个人设置]修改名字 @apiGroup account @apiParamExample {json} 请求示例 {"name":"新名字"} @apiSuccessExample {json} 成功返回 {"message": "", "error": "", "data": "", "response": "ok", "next": ""} @apiSuccessExample {json} 失败返回 {"message": "修改失败,请重试", "error": "", "data": "", "response": "fail", "next": ""} """ args = request.QUERY.casts(name=unicode) name = args.name user = request.user data = {'flag': "0", 'user_id': user.id} if not name: return ajax.jsonp_fail(request, message="姓名不能为空") if not is_chinese_word(name): return ajax.jsonp_fail(request, message="姓名长度为2-5个汉字") if user.type == 1: result = common.real_name_filter(name) if not result: data = {'flag': "1", 'user_id': user.id} return ajax.jsonp_ok(request, data) user.set_name(name) return ajax.jsonp_ok(request, data)
def p_password(request): """ @api {post} /account/password [个人设置]修改密码 @apiGroup account @apiParamExample {json} 请求示例 {"old_pwd":"111111","new_pwd":"2222222"} @apiSuccessExample {json} 成功返回 {"message": "", "error": "", "data": "", "response": "ok", "next": ""} @apiSuccessExample {json} 失败返回 {"message": "两次输入密码不一致", "error": "", "data": "", "response": "fail", "next": ""} """ args = request.QUERY.casts(old_pwd=str, new_pwd=str) old_pwd = args.old_pwd or '' new_pwd = args.new_pwd or '' if len(new_pwd) < 6 or len(new_pwd) > 16: return ajax.jsonp_fail(request, message='密码长度为6-16个字符') user = request.user if old_pwd and not user.check_password(old_pwd): return ajax.jsonp_fail(request, message="当前密码错误") users = user.set_password(new_pwd) # 发短信 content = u"密码修改成功," + ','.join(u'账号%s的新密码为%s' % (u.username, new_pwd) for u in users) + u",请牢记!" hub = tbktapi.Hub(request) hub.sms.post('/sms/send', { 'platform_id': user.platform_id, 'phone': user.phone, 'content': content }) return ajax.jsonp_ok(request)
def set_recording(request): """ @api {post} /huodong/reading/set_recording [学生端]上传录音 @apiGroup yw_reading @apiParamExample {json} 请求示例 { "video_url": "http://tbktfile.jxrrt.cn/yuwen/201709StuVideos/b99255c5.mp3" # 音频地址 "tid": 1 #文章id } @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": { }, "response": "ok", "error": "" } """ user = request.user args = request.QUERY.casts(video_url=str, tid=int) video_url = args.video_url tid = args.tid if not (video_url.startswith('http') and video_url.endswith('.mp3')): return jsonp_fail(request, message="参数错误") if not video_url or not tid: return jsonp_fail(request, message="缺少参数") data = common.set_video(user, video_url, tid) if not data: return jsonp_fail(request, message="添加失败") return jsonp_ok(request, data)
def invite_get_power(request): """ @api {get} /huodong/winter_activity/invite_get_power [寒假活动]邀请获得能量接口 @apiGroup winter_activity @apiParamExample {json} 请求示例 { } @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": [ ], "response": "ok", "error": "" } @apiSuccessExample {json} 失败返回 {"message": "", "error": "", "data": "", "response": "fail", "next": ""} """ if not common.end_acitvtiy(): return ajax.jsonp_fail(request, "活动已经结束") user_id = request.user_id data = common.invite_get_power(user_id) if not data: return ajax.jsonp_fail(request, "当日邀请次数超过五次") return ajax.jsonp_ok(request, data)
def happy_arena(request): """ @api {get} /huodong/winter_activity/happy_arena [寒假活动]欢乐竞技场入口 @apiGroup winter_activity @apiParamExample {json} 请求示例 { } @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": { "is_type":1,#类型,1.诗词大战pk,2.成语游戏pk }, "response": "ok", "error": "" } @apiSuccessExample {json} 失败返回 {"message": "", "error": "", "data": "", "response": "fail", "next": ""} """ if not common.end_acitvtiy(): return ajax.jsonp_fail(request, "活动已经结束") user_id = request.user_id time_limit = common.time_limmit() if not time_limit: return ajax.jsonp_fail(request, "未到开放时间!") open_status = common.get_user_open_status(user_id) if not open_status: return ajax.jsonp_fail(request, "欢乐竞技场仅开通用户可以参加!") data = common.get_type(user_id) return ajax.jsonp_ok(request, data)
def p_cancel(request): """ @api {post} /account/cancelsms [短信]取消定时短信 @apiGroup account @apiParamExample {json} 请求示例 {"id":短信ID, "schedule_time":定时时间} @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": { "success": true }, "response": "ok", "error": "" } """ args = request.QUERY.casts(id=int, schedule_time=str) object_id = args.id schedule_time = args.schedule_time if not object_id: return ajax.jsonp_fail(request, message='缺少参数: id') if not schedule_time: return ajax.jsonp_fail(request, message='缺少参数: schedule_time') hub = tbktapi.Hub(request) url = '/sms/cancel' d = dict(id=object_id, schedule_time=schedule_time, platform_id=request.user.platform_id) r = hub.sms.post(url, d) if not r: return ajax.jsonp_fail(request, message='服务器开小差') return ajax.jsonp_ok(request, r)
def p_wish_vote(request): """ @api {get} /gift/wish/vote [金豆商城] 愿望墙愿望投票 @apiGroup gift @apiParamExample {json} 请求示例 { "type":1 :投票,-1:撤销投票 "wish_id: 124 愿望id } @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": {} "response": "ok", "error": "" } """ args = request.QUERY.casts(type=int, wish_id=int) vote_type = args.type wish_id = args.wish_id if not vote_type or not wish_id or vote_type not in [-1, 1]: return ajax.jsonp_fail(request, error=u'参数错误') user_id = request.user_id status = common.vote_wish(wish_id, user_id, vote_type) if not status: return ajax.jsonp_fail(request, error=u'投票失败,请重试') return ajax.jsonp_ok(request)
def p_wish_submit(request): """ @api {get} /gift/wish/submit [金豆商城] 愿望墙愿望提交 @apiGroup gift @apiParamExample {json} 请求示例 {"wish":"呵呵" 愿望内容} @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": [] "response": "ok", "error": "" } """ user_id = request.user_id args = request.QUERY.casts(wish=unicode) wish = args.wish.strip() if not wish: return ajax.jsonp_fail(request, error=u'愿望内容不能为空') if len(wish) > 120: return ajax.jsonp_fail(request, error=u'愿望内容过长') today_wish = common.get_today_user_wish(user_id) if today_wish: return ajax.jsonp_fail(request, error=u'今天已发布过愿望') common.save_wish(wish, user_id) return ajax.jsonp_ok(request)
def r_sign(request): """ @api /huodong/sx/normal/stu/sign [数学常态活动]学生签到 @apiGroup math_normal @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": { "msg": "签到获取60积分" }, "response": "ok", "error": "" } @apiSuccessExample {json} 其他返回 { "message": "已签到", "next": "", "data": "", "response": "fail", "error": "" } """ user = request.user return ajax.jsonp_fail(request, message='活动已结束!') if user.is_teacher or int(user.city) != 411200: return ajax.jsonp_fail(request, message='教师不能参与学生签到!') status, msg = common.stu_sign(user, STU_ACTIVE_ID, SIGN) if not status: return ajax.jsonp_fail(request, message=msg, data='') return ajax.jsonp_ok(request, {'msg': msg})
def use_props(request): """ @api {post} /huodong/winter_activity/use_props [寒假活动]使用道具 @apiGroup winter_activity @apiParamExample {json} 请求示例 { "has_use_double" : 1// 代表使用了双倍积分卡 "has_use_flower" : 1 // 代表使用鲜花 "has_use_egg" : 1 // 代表使用鸡蛋 "has_use_sunglasses" : 1 // 代表使用墨镜 "has_use_magnifier" : 1 // 代表使用放大镜 "has_use_eraser" :1 //代表适用橡皮擦 "ids" : [score_id, score_detail_id, happy_score_id, pk_happy_record_id] //双倍积分卡需要修改记录的数组 } @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": { }, "response": "ok", "error": "" } """ if not common.end_acitvtiy(): return ajax.jsonp_fail(request, "活动已经结束") args = request.QUERY.casts(has_use_double=int, has_use_flower=int, has_use_egg=int, has_use_sunglasses=int, has_use_magnifier=int, has_use_eraser=int, ids='json') user_id = request.user_id # 道具信息 add_time = args.add_time has_use_double = args.has_use_double or 0 has_use_flower = args.has_use_flower or 0 has_use_egg = args.has_use_egg or 0 has_use_sunglasses = args.has_use_sunglasses or 0 has_use_magnifier = args.has_use_magnifier or 0 has_use_eraser = args.has_use_eraser or 0 ids = args.ids or [] # 双倍积分卡及使用 if has_use_double and ids: common.use_double(ids, user_id, add_time) # 减少消耗道具(除双倍积分卡外) props = common.post_props_details(user_id, 0, has_use_flower, has_use_egg, has_use_sunglasses, has_use_magnifier, has_use_eraser, add_time) if props: return ajax.jsonp_fail(request, props) return ajax.jsonp_ok(request)
def send_sms(request): """ @api {post} /huodong/reading/send_sms [教师端]发送试卷短信 @apiGroup yw_reading @apiParamExample {json} 请求示例 { "unit_id": "555428,515192", # 班级ID "title": "静夜思,锄禾", # 逗号分隔的title数组 "begin_time": "2017-01-05 09:10:00", # (可选)定时作业时间 "sendpwd": 1/0, # 是否下发帐号密码 "sendscope": 1/0, # 短信发送范围 0给所有学生发短信 1只给开通的学生发短信 "object_id":"试卷ID,可多个, 逗号分隔" } @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data":"", "response": "ok", "error": "" } @apiSuccessExample {json} 失败返回 { "message": , "next": "", "data": "请设置作业的完成时间", "response": "fail", "error": "" } """ args = request.QUERY.casts(type=int, unit_id=str, title=unicode, begin_time='timestamp', sendpwd=int, sendscope=int, object_id=str) unit_id = args.unit_id or '' unit_ids = [int(s) for s in unit_id.split(',') if s] title = args.title or u'' now = int(time.time()) begin_time = args.begin_time or now sendpwd = args.sendpwd or 0 sendscope = args.sendscope or 0 object_id = args.object_id or '' # 很多很多卷子 object_ids = [int(s) for s in object_id.split(',') if s] title_array = [s for s in title.split(u',')] if not unit_id: return jsonp_fail(request, message='请选择您要发布的班级') if begin_time < now: return jsonp_fail(request, message='定时发布时间不得小于当前系统时间') user = request.user # title = title or "%s作业" % begin_time.strftime("%m月%d日") # 1已发 2待发 status = 1 if begin_time <= now else 2 data = common.send_sms(request, user, status, unit_ids, title, begin_time, sendpwd, sendscope, object_ids, title_array) return jsonp_ok(request, data)
def wrap(request, *args, **kw): user = request.user if not user: return ajax.jsonp_fail(request, error='no_user', message="请您先登录") elif not user.is_teacher: return ajax.jsonp_fail(request, error='no_user', message="请用教师帐号登录") elif not user.units: return ajax.jsonp_fail(request, error='no_class', message="请先加入一个班级") else: return f(request, *args, **kw)
def submit_paper(request): """ @api {post} /huodong/rz/submit_paper [汝州活动二期]试卷提交 @apiGroup RzPaperActive @apiParamExample {json} 请求示例 { “status”: "1" # 1 完成(提交), 2 未完成(保存) "data": [{"question_id":"3104", "ask_id":"3292","answer":"A","option_id":19321,"result":1}, {"question_id":"3300", "ask_id":"3500","answer":"A","option_id":19321,"result":0}] } @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": "", "response": "ok", "error": "" } @apiSuccessExample {json} 失败返回 {"message": "", "error": "", "data": "", "response": "fail", "next": ""} """ """ 功能说明: 汝州活动-提交试卷 ----------------------------------------------- 修改人 修改时间 ----------------------------------------------- 张帅男 2017-12-22 """ args = request.loads() or request.QUERY.casts(status=int, data='json') user = request.user user_id = user.id unit = user.unit if not unit: return jsonp_fail(request, message=u'没有班级') grade_id = int(unit.get('grade_id', 0)) if not grade_id: return jsonp_fail(request, message=u'没有年级') status = int(args.status) if status not in (1, 2): return jsonp_fail(request, u'wrong status: %s' % status) if not args.data: return jsonp_fail(request, u'no_data') if type(args.data) != list: args.data = json.loads(args.data) status = 1 if status == 1 else 0 test = db.tbkt_active_slave.active_paper.select('id').get( user_id=user_id, active_id=ACTIVE_ID, paper_id=grade_id) if not test: return jsonp_fail(request, message=u'没有这个测试') rz_com.paper_submit(user_id, ACTIVE_ID, grade_id, status, args.data) return jsonp_ok(request)
def p_join(request): """ @api {post} /class/join [班级]加入班级接口 @apiGroup class @apiParamExample {json} 请求示例 {"dept_id": 部门ID, "grade_id":年级, "class_id":班级} 或者 {"unit_id": 班级ID} @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": { "unit_id": 580564 # 新班级ID }, "response": "ok", "error": "" } @apiSuccessExample {json} 失败返回 { "message": "您已经在当前班级", "next": "", "data": "", "response": "fail", "error": "" } """ args = request.QUERY.casts(dept_id=int, grade_id=int, class_id=int, unit_id=int) dept_id = args.dept_id or 0 grade_id = args.grade_id or 0 class_id = args.class_id or 0 unit_id = args.unit_id or 0 user = request.user cache.user_profile.delete(user.id) cache.user_units.delete(user.id) if unit_id: ok, error = common.joinclass_id(user, unit_id) if not ok: return ajax.jsonp_fail(request, message=error) return ajax.jsonp_ok(request, {'unit_id': unit_id}) if not dept_id: return ajax.jsonp_fail(request, message="缺少参数") if grade_id < 1 or grade_id > 9: return ajax.jsonp_fail(request, message="参数错误: grade_id") if class_id < 0 or class_id > 30: return ajax.jsonp_fail(request, message="参数错误: class_id") unit_id, error = common.joinclass(user, dept_id, grade_id, class_id) if not unit_id: return ajax.jsonp_fail(request, message=error) return ajax.jsonp_ok(request, {'unit_id': unit_id})
def p_outside_task_submit(request): """ @api {post} /im/outside/task/submit [IM]课外活动-作业提交 @apiGroup IM @apiParamExample {json} 请求示例 { "message_id": 作业id(tbkt_com.message), "type": 1.图片 2.音频 3.视频, "content": 活动描述文字, "url": type=1.图片url type=2.音频url type=3.视频url } @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": { "test_id": 1 }, "response": "ok", "error": "" } @apiSuccessExample {json} 失败返回 { "message": "缺少参数", "next": "", "data": "", "response": "fail", "error": "" } """ args = request.QUERY.casts(message_id=int, type=int, content=unicode, url="json") msg_id = args.message_id url_type = args.type content = args.content url = args.url or [] user_id = request.user_id if not msg_id: return ajax.jsonp_fail(request, message="找不到这个作业") if not url_type: return ajax.jsonp_fail(request, message="你要上传什么类型的作业?") if not content and (not url or not url[0]): return ajax.jsonp_fail(request, message="请输入活动心得 或者 上传内容") test_id = common.outside_task_submit(msg_id, user_id, content, url_type, url) return ajax.jsonp_ok(request, {"test_id": test_id})
def ask_for_debris(request): """ @api {post} /huodong/summer_activity/sapp/ask_for_debris [暑假活动]索取碎片 @apiGroup summer2018 @apiParamExample {json} 请求示例 { "ask_for_id" : 123456 // 索取的用户id "subject_id" : 2 5 9 "debris" : "hat" // "shoe" "background" "pants" "cloth" } @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": [ {"user_id" : 1234564, "portrait": "很长很长的Url", "real_name": "张三"}, {"user_id" : 1234564, "portrait": "很长很长的Url", "real_name": "张三"}, {"user_id" : 1234564, "portrait": "很长很长的Url", "real_name": "张三"}, ] "response": "ok", "error": "" } @apiSuccessExample {json} 失败返回 {"message": "", "error": "", "data": "", "response": "fail", "next": ""} """ """ 索取碎片 """ args = request.QUERY.casts(ask_for_id=int, subject_id=int, debris=str) subject_id = args.subject_id or 0 ask_for_id = args.ask_for_id or 0 debris = args.debris or '' if not ask_for_id or not subject_id or not debris: return ajax.jsonp_fail(request, message=u'参数错误') nowt = int(time.time()) if nowt < PHASE_1_START_TIME: return ajax.jsonp_fail(request, message=u'活动未开启') elif nowt < PHASE_1_END_TIME: phase = 1 elif nowt < PHASE_2_START_TIME: phase = 3 elif nowt < PHASE_2_END_TIME: phase = 2 else: phase = 4 if phase in (3, 4): return ajax.jsonp_fail(request, message=u'活动未开启') user = request.user data = common.ask_for_debris(user, ask_for_id, phase, subject_id, debris) return ajax.jsonp_ok(request, data)
def wrap(request, *args, **kw): user = request.user if not user: return ajax.jsonp_fail(request, error='no_user', message="请您先登录") elif user.grade_id > 6: return ajax.jsonp_fail(request, error='no authority', message="请使用小学学生账号登录") elif user.type != 1: return ajax.jsonp_fail(request, error='no authority', message="请使用小学学生账号登录") else: return f(request, *args, **kw)
def get_rank(request): """ @api {post} /huodong/summer_activity/sapp/get_rank [暑假活动]排行榜 @apiGroup summer2018 @apiParamExample {json} 请求示例 { "p" : 1, // 分页 从1开始 "subject_id" : 2 5 9 } @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": { "person_rank" : "500+" // 用户个人排名 str形式 "open_num" : 100 //用户个人开启次数 "rank" : [ {"user_id": 123456, "open_num": 10, "real_name": "张三", "school_name":"北大附小"} ] } "response": "ok", "error": "" } @apiSuccessExample {json} 失败返回 {"message": "", "error": "", "data": "", "response": "fail", "next": ""} """ """ 排行榜 """ args = request.QUERY.casts(p=int, subject_id=int) subject_id = args.subject_id or 0 page = args.p or 0 if not page or not subject_id: return ajax.jsonp_fail(request, message=u'参数错误') nowt = int(time.time()) if nowt < PHASE_1_START_TIME: return ajax.jsonp_fail(request, message=u'活动未开启') elif nowt < PHASE_1_END_TIME: phase = 1 elif nowt < PHASE_2_START_TIME: phase = 3 elif nowt < PHASE_2_END_TIME: phase = 2 else: phase = 4 if phase in (3, 4): return ajax.jsonp_fail(request, message=u'活动未开启') user = request.user data = common.get_rank(user.id, page, subject_id, user.unit.unit_class_id) return ajax.jsonp_ok(request, data)
def p_register_student(request): """ @api {post} /account/register/student [登录]快速注册学生帐号 @apiDescription 输入手机号和开通验证码注册 @apiGroup account @apiParamExample {json} 请求示例 {"platform_id":平台ID, "phone_number":"15981867201", "dept_type":学段(1小学,2初中), "code":二次开通短信验证码} *platform_id: 参考平台列表接口 @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": { "username": "******", # 新账号 "password": "******", # 新密码 "user_id": 10831971 # 用户ID }, "response": "ok", "error": "" } @apiSuccessExample {json} 失败返回 { "message": "请填写移动手机号", "error": "", "data": "", "response": "fail", "next": "" } """ args = request.QUERY.casts(phone_number=str, platform_id=int, dept_type=int, code=str) phone = args.phone_number or '' platform_id = args.platform_id or 1 dept_type = args.dept_type code = args.code if not phone: return ajax.jsonp_fail(request, message='手机号不能为空') # if not platform_id: # return ajax.jsonp_fail(request, message='请选择省份') if not dept_type or int(dept_type) not in (1, 2): return ajax.jsonp_fail(request, message='请选择学段') if not code: return ajax.jsonp_fail(request, message='验证码不能为空') if not code.isdigit() and len(code) != 6: return ajax.jsonp_fail(request, message='请输入正确的验证码') if not is_chinamobile(phone): return ajax.jsonp_fail(request, message='请输入正确的移动手机号') if validate_phone_platform(phone, platform_id) == False: return ajax.jsonp_fail(request, message='手机号与省份不匹配') if db.user_slave.auth_user.filter(phone=phone, type=1): return ajax.jsonp_fail(request, error="taken", message='手机号已被注册, 是否找回密码?') data = common.register_student(platform_id, phone, dept_type, code) if not data: return ajax.jsonp_fail(request, message='帐号已存在') return ajax.jsonp_ok(request, data)
def p_sendmany(request): """ @api {post} /account/sendmany [短信]发多条短信 @apiGroup account @apiParamExample {json} 请求示例 {"phone":"15981867201,15981867202", "content":"您的验证码是111", "schedule_time":"140415112622"} *schedule_time: 可选, 定时发送时间, 如: 140415112622 代表14年04月15日11点26分22秒 @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": { "id": 2787448, # 短信ID "success": true }, "response": "ok", "error": "" } @apiSuccessExample {json} 失败返回 { "message": "请填写短信内容", "next": "", "data": "", "response": "fail", "error": "" } """ args = request.QUERY.casts(phone=str, content=unicode, schedule_time=str) phones = args.phone or '' content = args.content or '' schedule_time = args.schedule_time or '' phones = phones.split(',') phones = [s for s in phones if is_chinamobile(s)] if not phones: return ajax.jsonp_fail(request, message='请输入移动手机号') if not content: return ajax.jsonp_fail(request, message='请填写短信内容') hub = tbktapi.Hub(request) url = '/sms/send' d = dict(phone=join(phones), content=content, schedule_time=schedule_time, platform_id=request.user.platform_id) r = hub.sms.post(url, d) if not r: return ajax.jsonp_fail(request, message='服务器开小差') return ajax.jsonp_ok(request, r.data)
def get_ask_message(request): """ @api {post} /huodong/summer_activity/sapp/get_ask_message [暑假活动]我的碎片消息----消息 @apiGroup summer2018 @apiParamExample {json} 请求示例 { "subject_id" : 2 // 2代表数学 5 代表语文 9 代表英语 "p" : 1 // 页数 从1 开始 } @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": [ { "ask_for_user":123, "real_name":"张三", "add_time":"12月11日" , "ask_thing": "cloth" }, { "ask_for_user":123, "real_name":"张三", "add_time":"12月11日", "ask_thing": "cloth" }, { "ask_for_user":123, "real_name":"张三", "add_time":"12月11日" , "ask_thing": "cloth" }, ] "response": "ok", "error": "" } @apiSuccessExample {json} 失败返回 {"message": "", "error": "", "data": "", "response": "fail", "next": ""} """ """ 我的碎片消息----消息 """ args = request.QUERY.casts(subject_id=int, p=int) subject_id = args.subject_id or 0 page = args.p or 0 if not subject_id or not page: return ajax.jsonp_fail(request, message=u'参数错误') nowt = int(time.time()) if nowt < PHASE_1_START_TIME: return ajax.jsonp_fail(request, message=u'活动未开启') elif nowt < PHASE_1_END_TIME: phase = 1 elif nowt < PHASE_2_START_TIME: phase = 3 elif nowt < PHASE_2_END_TIME: phase = 2 else: phase = 4 if phase in (3, 4): return ajax.jsonp_fail(request, message=u'活动未开启') user = request.user data = common.get_ask_message(user, subject_id, phase, page) return ajax.jsonp_ok(request, data)
def give_debris(request): """ @api {post} /huodong/summer_activity/sapp/give_debris [暑假活动]赠送碎片 @apiGroup summer2018 @apiParamExample {json} 请求示例 { "give_user_id" : 123456 //赠与的用户id "subject_id" : 2 5 9 "debris" : "hat" // "shoe" "background" "pants" "cloth" } @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": // 如果失败了会返回fail message会带信息, 如果成功啥也不反回 "response": "ok", "error": "" } @apiSuccessExample {json} 失败返回 {"message": "", "error": "", "data": "", "response": "fail", "next": ""} """ """ 赠送碎片 """ args = request.QUERY.casts(give_user_id=int, subject_id=int, debris=str) subject_id = args.subject_id or 0 give_user_id = args.give_user_id or 0 debris = args.debris or '' if not give_user_id or not subject_id or not debris: return ajax.jsonp_fail(request, message=u'参数错误') nowt = int(time.time()) if nowt < PHASE_1_START_TIME: return ajax.jsonp_fail(request, message=u'活动未开启') elif nowt < PHASE_1_END_TIME: phase = 1 elif nowt < PHASE_2_START_TIME: phase = 3 elif nowt < PHASE_2_END_TIME: phase = 2 else: phase = 4 if phase in (3, 4): return ajax.jsonp_fail(request, message=u'活动未开启') user = request.user data = common.give_debris(user, give_user_id, phase, subject_id, debris) if data: return ajax.jsonp_fail(request, message=data) return ajax.jsonp_ok(request, data)
def p_book(request): """ @api {get} /account/book [个人设置]获取当前教材/教辅 @apiGroup account @apiParamExample {json} 请求示例 {"subject_id":学科ID, "type":1教材 2教辅} @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": { "press_name": "西南师范大学出版社", # 出版社 "name": "小学数学四年级上册", # 默认书名 "subject_id": 21, # 学科 "grade_id": 4, # 年级 "volume": 1, # 1上册 2下册 3全册 "version_name": "2015新版", # 版本 "id": 888 # 教材/教辅ID }, "response": "ok", "error": "" } @apiSuccessExample {json} 失败返回 { "message": "缺少参数: type", "next": "", "data": "", "response": "fail", "error": "" } """ args = request.QUERY.casts(subject_id=int, type=int) subject_id = args.subject_id or 0 type = args.type or 0 if not subject_id: return ajax.jsonp_fail(request, message='缺少参数: subject_id') if not type: return ajax.jsonp_fail(request, message='缺少参数: type') if type not in (1, 2): return ajax.jsonp_fail(request, message='参数值错误: type') user = request.user if type == 1: book = user.get_book(subject_id) elif type == 2: book = user.get_pbook(subject_id) return ajax.jsonp_ok(request, book)
def p_feedback(request): """ @api {post} /account/feedback [登录]意见反馈 @apiGroup account @apiParamExample {json} 请求示例 {"type":请求类型(1意见建议 2错误反馈 3其他), "content":"反馈内容", "app":机型(android/ios/pc)} @apiSuccessExample {json} 成功返回 { "message": "", "error": "", "data": "", "response": "ok", "next": "" } @apiSuccessExample {json} 失败返回 { "message": "验证码错误,请重新获取", "error": "", "data": "", "response": "fail", "next": "" } """ args = request.QUERY.casts(type=int, content=unicode, app=str) type = args.type or 1 content = args.content or u'' app = args.app or '' user_id = request.user_id if not content: return ajax.jsonp_fail(request, '请填写内容') common.feedback(user_id, type, content, app) return ajax.jsonp_ok(request)
def set_message(request): """ @api {post} /huodong/reading/set_message [学生端]发布留言 @apiGroup yw_reading @apiParamExample {json} 请求示例 { "tid": 6 # 文章id "content" : "荣誉,可是要付出代价的" } @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": [ ] "response": "ok", "error": "" } """ user = request.user args = request.QUERY.casts(tid=int, content=str) tid = args.tid content = args.content if not tid or not content: return jsonp_fail(request, message="缺少参数") data = common.set_message(user, tid, content) return jsonp_ok(request, data)
def get_recording(request): """ @api {get} /huodong/reading/get_recording [学生端]获取用户的录音(最多五个) @apiGroup yw_reading @apiParamExample {json} 请求示例 { "tid": 6 # 文章id } @apiSuccessExample {json} 成功返回 { "message": "next": "", "data": { "status": 0, 1/0, 等于1 已经上传过录音 等于0 则未上传过录音 "video_detail": [ { "recording_length": 5, "user_name": "refresh", "user_id": 7646093, "id": 2, "recording_path": "http://tbktfile.jxrrt.cn/yuwen/201709StuVideos/b99255c5-fc6f-4f60-8b98-fb90f18e6e06.mp3" },{},{},{}, ] }, "response": "ok", "error": "" } """ user = request.user args = request.QUERY.casts(tid=int) tid = args.tid if not tid: return jsonp_fail(request, message="缺少参数") data = common.get_video(user, tid) return jsonp_ok(request, data)
def get_coin(request): """ @api {post} /huodong/reading/get_coin [教师端]领取金币 @apiGroup yw_reading @apiParamExample {json} 请求示例 { } @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": { "num" : 0/20/40 # 20领取的金币数量 0 领取失败 } "response": "ok", "error": "" } """ user = request.user data = common.get_coin(user) if data == u'金币不足': return jsonp_fail(request, message=data) return jsonp_ok(request, data)
def view_paper(request): """ @api {get} /huodong/reading/view_paper [教师端]预览试卷 @apiGroup yw_reading @apiParamExample {json} 请求示例 { "tid“ : 100 } @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": { "title": "aaaaa", # 文章标题 "article_content": "aaa", #文章内容 } "response": "ok", "error": "" } """ args = request.QUERY.casts(tid=int) tid = args.tid if not tid: return jsonp_fail(request, message="缺少参数") data = common.view_paper(tid) return jsonp_ok(request, data)