def get_platforms(): """ 获取所有平台配置 :return: { 平台ID: { is_sms:bool, # 是否允许发短信 is_open:bool, # 是否允许开通 is_setprofile: bool, # 是否允许个人设置 open_type:[] # 开通方式: 1微信 2支付宝 3验证码开通 } } """ global _platforms global _platforms_expire now = time.time() if now < _platforms_expire: return _platforms or {} hub = tbktapi.Hub() r = hub.com.get('/system/platforms') if not r: return {} data = r.data data = map(Struct, data) _platforms = {r.id: r for r in data} _platforms_expire = now + PLATFORM_CACHE_TIMEOUT return _platforms
def test_submit(user_id, week_id, info, user_city): """ 提交知识点测试结果 :param user_id: :param week_id: :param info:用户提交题目信息 :param user_city: :return: """ nowt = int(time.time()) q_info = knowledge_qid_info(user_id, week_id) len_info = q_info.q_num test = db.tbkt_active.full_score_test.get(week_id=week_id, user_id=user_id, type=2, status=0, grade_id=user_grade(user_id)) # 查询用户本周未完成记录 如果在原来的基础上添加新的记录 否则新建测试记录 if test and test.status == 0: out = [] save_info = json.loads(test.text) for i in save_info: out.append(i) for i in info: out.append(i) if len_info == len(out): status = 1 else: status = 0 db.tbkt_active.full_score_test.filter( user_id=user_id, type=2, week_id=week_id, status=0, grade_id=user_grade(user_id)).update( status=status, text=json.dumps(out), ) return if len_info == len(info): status = 1 else: status = 0 with db.tbkt_active as active: active.full_score_test.create(user_id=user_id, grade_id=user_grade(user_id), week_id=week_id, type=2, text=json.dumps(info), status=status, add_time=nowt, city=user_city) return
def pk_pop(user_id, user_city): """ 用户pk弹框 :param user_id: :param user_city: :return: """ # 本周一的时间戳 with db.default as dd: data = Struct() data.status = 0 data.border_url = "" data.border_id = 0 # 获取上周前100名的用户id b_time, _ = time_stamp() week = db.tbkt_active.full_score_week_list.select("id").filter(begin_time__lt=b_time)\ .order_by("-begin_time").first() if not week: return data rank_id = rank_user_id(user_id, week.id, user_city) if not rank_id: return data user_ids = [i.user_id for i in rank_id] if user_id in user_ids: # 获取竞技边框信息 border = dd.border.get(remark="竞技", status=1) if not border: return data # 竞技边框 id border_id = border.id # 竞技边框url border_url = get_absurl(border.border_url) # 保存前100名用户获取竞技头像之前的边框 user_border = dd.user_border_detail.get(user_id=user_id, status=1) if user_border: # 如果用户用使用中的边框,则更新上次使用状态改为1 dd.user_border_detail.filter(id=user_border.id).update( once_border_id=1) get_pk_border = dd.user_border_detail.get(user_id=user_id, border_id=border_id) if get_pk_border: return data dd.user_border_detail.create(user_id=user_id, border_id=border_id, add_time=int(time.time())) data.border_url = border_url data.border_id = border_id data.status = 1 return data
def set_user_book(user_id, grade_id): """ 设置教材 :param user_id: :param grade_id: :return: """ with db.tbkt_active as active: book = active.full_score_book_set.get(user_id=user_id) if not book: active.full_score_book_set.create(user_id=user_id, grade_id=grade_id, add_time=int(time.time())) else: active.full_score_book_set.filter(id=book.id).update( grade_id=grade_id)
def get_open_status(user_id, sids): """ 获取学科开通状态 ----------------------- 2017-6-19 王晨光 ----------------------- :param user: User :param sids: [学科ID] :return: {学科ID: 开通状态(1/0)} """ mslist = db.ketang_slave.mobile_subject.filter( user_id=user_id, subject_id__in=sids).select('subject_id', 'open_date', 'cancel_date', 'pay_type')[:] data = [] nowt = int(time.time()) msdict = {m.subject_id: m for m in mslist} for sid in sids: m = msdict.get(sid) if m: status = 1 if nowt >= m.open_date and ( m.cancel_date <= 0 or nowt < m.cancel_date) and m.open_date > 0 else 0 data.append({ 'status': status, 'subject_id': sid, 'open_date': from_unixtime(m.open_date), 'cancel_date': from_unixtime(m.cancel_date) if m.cancel_date > 0 else '', 'pay_type': m.pay_type, }) else: data.append({ 'status': 0, 'subject_id': sid, 'open_date': '', 'cancel_date': '', 'pay_type': 0, }) return data
def user_index(user_id): """ 正式第一周 rc测试 """ # c = config() # 读取测试环境配置信息, rc环境替换为程序配置 grade_id = user_grade(user_id) out = Struct() out.know_status = -1 # 知识训练场 out.wrong_status = -1 # 高频错题 out.pk_status = -1 # 每周竞技 out.month_status = -1 # 每月竞技 out.is_open = 0 # 是否在开放日期里 out.once_open = 1 # 往期回顾是否开放 out.once_week = [] out.id = 0 week_day = datetime.date.today().weekday() week_info = db.tbkt_active.full_score_week_list.select( "id", "name", "begin_time", "end_time").order_by("begin_time") b_time, e_time = time_stamp() for i in week_info: if b_time <= i.begin_time < e_time: # 如果开始在本周之内,则算是本周课程 out.name = i.name out.id = i.id i.open_time = i.begin_time + 9 * 3600 out.open_time = time.strftime("%m月%d日 %H点", time.localtime(i.open_time)) out.chance_over = pk_num(user_id, i.id).have_chance if week_day in (5, 6): # 在开课天里,返回状态关闭往期回顾 out.once_open = 1 if int(time.time()) >= i.open_time: # 达到开课时间点 out.is_open = 1 out.once_open = 0 out.know_status, out.wrong_status, out.pk_status = user_knowledge_info( user_id, i.id, grade_id) if out.pk_status == 1 and out.chance_over > 0: out.pk_status = 0 if i.begin_time < b_time: # 如果开始时间小于本周开始时间,则算是往期课程 out.once_week.append(dict(id=i.id, name=i.name)) out.once_week = sorted(out.once_week, key=lambda x: (-x["id"])) return out
def video_submit(user_id, knowledge_id, week_id, city): """ 保存用户提交看视频的记录 :param user_id: :param knowledge_id: 用户观看知识点视频的knowledge_id :param week_id: 知识训练场的week_id :param city: 保存用户地市 :return: """ grade_id = user_grade(user_id) # 获取用户设置教材id nowt = int(time.time()) # 查看用户查看视频记录 info = db.tbkt_active.full_score_test.get(user_id=user_id, week_id=week_id, grade_id=grade_id, type=1) if info and info.status == 1: return source = get_source(week_id, grade_id) if not source: return num = len(source) with db.tbkt_active as active: if not info: status = 1 if num == 1 else 0 active.full_score_test.create(grade_id=grade_id, week_id=week_id, status=status, add_time=nowt, user_id=user_id, type=1, city=city, text=knowledge_id), return added = info.text.split(",") if str(knowledge_id) in added: return status = 1 if num - len(added) == 1 else 0 added.append(knowledge_id) active.full_score_test.filter(id=info.id).update(text=join(added), status=status)
def pk_submit(user_id, week_id, info, score, user_city): """ 每周竞技提交 :param user_id: 用户id :param week_id: 课程id :param info: 提交数据 :param score: 成绩 :param user_city: 用户城市id :return: """ grade_id = user_grade(user_id) have_chance = pk_num(user_id, week_id).have_chance if have_chance <= 0: return {} score = score if score > 0 else 0 nowt = int(time.time()) pk_info = db.tbkt_active.full_score_test.get(type=3, user_id=user_id, week_id=week_id, grade_id=grade_id, status=1) out = Struct() out.pk_status = 1 if score else 0 out.score = score if pk_info and pk_info.score >= score: out.max_score = pk_info.score out.pk_status = 0 else: out.max_score = score with db.tbkt_active as active: active.full_score_test.create(user_id=user_id, grade_id=user_grade(user_id), week_id=week_id, type=3, city=user_city, text=json.dumps(info), status=1, score=score, add_time=nowt) out.rank = pk_result(user_id, week_id, user_city) # 结果页数据返回排行 out.num = pk_num(user_id, week_id).have_chance # 用户剩余pk次数 return out
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="发送成功")