def POST(self, version='v1'): web.header('Content-Type', 'application/json') param = web.input(app_id='', dev_id='', ver_code='', session='', tick='') if '' in (param.app_id, param.dev_id, param.ver_code, param.session, param.tick): return json.dumps({'ret': -2, 'msg': '参数错误'}) # 检查session登录 uname = app_helper.app_logged(param.session) if uname is None: return json.dumps({'ret': -4, 'msg': '无效的session'}) #-------------------------------------------------- r4 = app_helper.get_user_detail(uname['userid']) ret_data = { "name": r4['nickname'], "image": r4['img_url'], # 用户头像 "tel": r4['mobile'], # 用户注册手机号 "user_type": uname['type'], # 用户类型 # 店员信息 "shop_name": r4['shop_name'], "real_name": r4['real_name'], "shop_nickname": r4['shop_nickname'], "contact_info": r4['contact_info'], # 店主信息 "licence_pic": app_helper.image_url(r4['licence_pic']) if r4['licence_pic'] != '' else r4['licence_pic'], "shop_pic": [app_helper.image_url(x) for x in r4['shop_pic']], } # 返回 return json.dumps({ 'ret': 0, 'data': ret_data, })
def POST(self): web.header('Content-Type', 'application/json') param = web.input(session_id='') if param.session_id == '': return json.dumps({'ret': -1, 'msg': 'session_id参数错误'}) uname = app_helper.wx_logged(param.session_id) if uname is None: return json.dumps({'ret': -4, 'msg': '无效的session_id'}) #-------------------------------------------------- r4 = app_helper.get_user_detail(uname['userid']) ret_data = { "name": r4['nickname'], "image": r4['img_url'], # 用户头像 "tel": r4['mobile'], # 用户注册手机号 "user_type": uname['type'], # 用户类型 # 店员信息 "shop_name": r4.get('shop_name', ''), "real_name": r4.get('real_name', ''), "shop_nickname": r4.get('shop_nickname', ''), "contact_info": r4.get('contact_info', ''), # 店主信息 "licence_pic": app_helper.image_url(r4['licence_pic']) if r4.get('licence_pic', '') != '' else '', "shop_pic": [app_helper.image_url(x) for x in r4.get('shop_pic', [])], } # 返回 return json.dumps({ 'ret': 0, 'data': ret_data, })
def POST(self, version='v1'): web.header('Content-Type', 'application/json') param = web.input(app_id='', dev_id='', ver_code='', session='', tick='') if '' in (param.app_id, param.dev_id, param.ver_code, param.session, param.tick): return json.dumps({'ret': -2, 'msg': '参数错误'}) # 检查session登录 uname = app_helper.app_logged(param.session) if uname is None: return json.dumps({'ret': -4, 'msg': '无效的session'}) #-------------------------------------------------- heart_data = [] r2 = db.heart_info.find({'userid': uname['userid']}) for i in r2: r3 = db.obj_store.find_one({'obj_id': i['obj_id']}) if r3 is None: continue r4 = db.progress_info.find_one({ 'userid': uname['userid'], 'obj_id': i['obj_id'] }) if r4 is None: progress = 0 else: progress = r4['progress'] if len(r3['image']) > 0: # 取第1张图 image_url = app_helper.image_url(r3['image'][0]) else: image_url = '' heart_data.append({ "object_id": i['obj_id'], "title": r3['title'], "type": 1, # 类型: 1 课程, 2 专辑 "object_type": 1 if r3['media'] == 'video' else 2, # 1- 视频 2 - 音频 "length": r3['length'], # 长度,单位 分钟 "progress": progress, # 进度百分比,如果是未购买课程,此字段为-1 "image": image_url, }) ret_data = { "heart": heart_data, } # 返回 return json.dumps({ 'ret': 0, 'data': ret_data, })
def POST(self): web.header('Content-Type', 'application/json') param = web.input(session_id='', object_id='') if param.object_id == '': return json.dumps({'ret': -2, 'msg': '参数错误'}) if param.session_id == '': return json.dumps({'ret': -1, 'msg': 'session_id参数错误'}) uname = app_helper.wx_logged(param.session_id) if uname is None: return json.dumps({'ret': -4, 'msg': '无效的session_id'}) #-------------------------------------------------- if param.object_id[0] == '1': # 课程 r3 = db.obj_store.find_one({'obj_id': param.object_id}) else: # 专辑 r3 = db.topic_store.find_one({'tpc_id': param.object_id}) if r3 is None: return json.dumps({'ret': -5, 'msg': '错误的object_id'}) if len(r3['image']) > 0: # 取第1张图, image_url = app_helper.image_url(r3['image'][0]) else: image_url = '' #专辑里面的视频音频分享 # http://wxpretty.f8cam.com/static/wx/test2/albumMedia.html?object_id=10000053&object_id_album=20000054 #专辑分享 # http://wxpretty.f8cam.com/static/wx/test2/testAlbum.html?object_id=20000037 #视频分享: # http://wxpretty.f8cam.com/static/wx/test2/test.html?object_id=10000036 #if param.object_id[0]=='1': # 课程 # if r3['obj_type']=='topic': # 专辑课程 # share_url = 'http://%s/static/wx/test2/albumMedia.html?'\ # 'object_id=%s&object_id_album=%s'%(setting.wx_host,r3['obj_id'],r3['tpc_id']) # else: # share_url = 'http://%s/static/wx/test2/test.html?object_id=%s'%(setting.wx_host,r3['obj_id']) #else: # 专辑 # share_url = 'http://%s/static/wx/test2/testAlbum.html?object_id=%s'%(setting.wx_host,r3['tpc_id']) ret_data = { "object_id": param.object_id, # 唯一代码 "type": 1 if param.object_id[0] == '1' else 2, # 类型: 1 课程, 2 专辑 "share_title": r3['title'], "share_content": r3['description'], "share_img": image_url, # 分享图片 #"share_url" : share_url, # 分享的链接 } # 返回 return json.dumps({ 'ret': 0, 'data': ret_data, })
def POST(self, version='v1'): web.header('Content-Type', 'application/json') param = web.input(app_id='', dev_id='', ver_code='', session='', tick='', nickname='', headimage='', image_type='') if '' in (param.app_id, param.dev_id, param.ver_code, param.session, param.tick): return json.dumps({'ret': -2, 'msg': '参数错误'}) # 检查session登录 uname = app_helper.app_logged(param.session) if uname is None: return json.dumps({'ret': -4, 'msg': '无效的session'}) #-------------------------------------------------- update_set = {} if len(param['nickname']) > 0: update_set['nickname'] = param['nickname'] if len(param['headimage']) > 0: if param['image_type'].upper() not in ('JPG', 'PNG'): return json.dumps({'ret': -5, 'msg': 'image_type取值错误'}) data = urllib.unquote_plus(param['headimage']) #print data #print len(data) # 保存图片 filename = app_helper.write_image(param['image_type'], data) update_set['img_url'] = app_helper.image_url(filename) # 图片url if len(update_set) > 0: # 只保存在手机号码账户里 type==1 db.app_user.update_one({ 'userid': uname['userid'], 'type': 1 }, {'$set': update_set}) # 获取当前设置 r4 = app_helper.get_user_detail(uname['userid']) # 返回 return json.dumps({ 'ret': 0, 'data': { 'headimage_url': r4['img_url'], } })
def POST(self): web.header('Content-Type', 'application/json') param = web.input(session_id='') if param.session_id == '': return json.dumps({'ret': -1, 'msg': 'session_id参数错误'}) uname = app_helper.wx_logged(param.session_id) if uname is None: return json.dumps({'ret': -4, 'msg': '无效的session_id'}) #-------------------------------------------------- now_tick = int(time.time()) # 拉取符合条件的banner, 时间区间,是否可用 r2 = db.banner_info.find( { 'available': 1, '$and': [{ 'start_tick': { '$lt': now_tick } }, { 'expire_tick': { '$gt': now_tick } }], }, sort=[('sort_weight', 1)]) banner_data = [] for i in r2: banner_data.append({ 'image': app_helper.image_url(i['image']), 'click': i['click_url'], }) # 返回 return json.dumps({ 'ret': 0, 'data': { 'banner': banner_data, } })
def POST(self, version='v1'): web.header('Content-Type', 'application/json') param = web.input(app_id='', dev_id='', ver_code='', tick='') if '' in (param.app_id, param.dev_id, param.ver_code, param.tick): return json.dumps({'ret': -2, 'msg': '参数错误'}) #-------------------------------------------------- now_tick = int(time.time()) # 拉取符合条件的banner, 时间区间,是否可用 r2 = db.banner_info.find( { 'available': 1, '$and': [{ 'start_tick': { '$lt': now_tick } }, { 'expire_tick': { '$gt': now_tick } }], }, sort=[('sort_weight', 1)]) banner_data = [] for i in r2: banner_data.append({ 'image': app_helper.image_url(i['image']), 'click': i['click_url'], }) # 返回 return json.dumps({ 'ret': 0, 'data': { 'banner': banner_data, } })
def POST(self): web.header('Content-Type', 'application/json') param = web.input(session_id='', category='', page_size='', page_index='') if '' in (param.page_size, param.page_index): return json.dumps({'ret': -2, 'msg': '参数错误'}) if param.session_id == '': return json.dumps({'ret': -1, 'msg': 'session_id参数错误'}) uname = app_helper.wx_logged(param.session_id) if uname is None: return json.dumps({'ret': -4, 'msg': '无效的session_id'}) #-------------------------------------------------- cate_id = param['category'].strip( ) if param['category'].strip() != '' else app_helper.DEFAULT_CATEGORY r2 = db.online_cate_obj.find({ 'cate_id': cate_id, 'available': 1, }, sort=[('sort_weight', 1)]) obj_list = [i['obj_id'] for i in r2] r3 = db.obj_store.find({ 'obj_id': { '$in': obj_list }, 'try_time': { '$gt': 0 }, }) obj_data = {} for i in r3: obj_data[i['obj_id']] = i # 所有试听数据 try_obj_list = [] for i in obj_list: if i not in obj_data.keys(): continue if obj_data[i].get('status') != 'PASSED': # 审核未通过,应该是上架后又有修改 continue if len(obj_data[i]['image']) > 0: # 取第1张图 image_url = app_helper.image_url(obj_data[i]['image'][0]) else: image_url = '' try_obj_list.append({ 'object_id': obj_data[i]['obj_id'], 'title': obj_data[i]['title'], 'title2': obj_data[i]['title2'], 'speaker': obj_data[i]['speaker'], 'type': 1 if obj_data[i]['media'] == 'video' else 2, # 1- 视频 2 - 音频 'image': image_url, 'length': obj_data[i]['length'], # 长度,单位:秒 'try_time': obj_data[i]['try_time'], # 试听长度,单位:秒 }) # 取指定区间的 start_pos = int(param.page_size) * int(param.page_index) end_pos = start_pos + int(param.page_size) try_obj_list_page = try_obj_list[start_pos:end_pos] ret_data = { "try": try_obj_list_page, "total": len(try_obj_list_page), # 返回的课程数量,小于 page_size说明到末尾 "page_size": param.page_size, # 分页尺寸,与调用参数相同 "page_index": param.page_index, # 页索引 } #print ret_data # 返回 return json.dumps({ 'ret': 0, 'data': ret_data, })
def POST(self): web.header('Content-Type', 'application/json') param = web.input(session_id='', page_size='', page_index='') if '' in (param.page_size, param.page_index): return json.dumps({'ret': -2, 'msg': '参数错误'}) if param.session_id == '': return json.dumps({'ret': -1, 'msg': 'session_id参数错误'}) uname = app_helper.wx_logged(param.session_id) if uname is None: return json.dumps({'ret': -4, 'msg': '无效的session_id'}) #-------------------------------------------------- course_list = [] # 用户自己买的课程 r2 = db.user_property.find( { 'userid': uname['userid'], 'status': 'paid', 'obj_type': 'course' }, sort=[('_id', 1)], # 按时间倒序 #skip=int(param.page_size)*int(param.page_index), #limit=int(param.page_size) ) course_list = [x['obj_id'] for x in r2] # 被授权的课程 r4 = db.employee_auth.find({'employee_userid': uname['userid']}) for x in r4: for y in x['object_list']: if y not in course_list: course_list.append(y) # 取指定区间的 start_pos = int(param.page_size) * int(param.page_index) end_pos = start_pos + int(param.page_size) course_list = course_list[start_pos:end_pos] course_data = [] for i in course_list: r3 = db.obj_store.find_one({'obj_id': i}) if r3 is None: continue if len(r3['image']) > 0: # 取第1张图 image_url = app_helper.image_url(r3['image'][0]) else: image_url = '' # 已授权店员数,只统计本店主的店员数 auth_num = db.employee_auth.find({ 'owner_userid': uname['userid'], 'object_list': r3['obj_id'] }).count() # 测试成绩 r5 = db.test_info.find_one({ 'userid': uname['userid'], 'obj_id': r3['obj_id'] }) score = r5['score'] if r5 else -1 # 完成进度 r6 = db.progress_info.find_one({ 'userid': uname['userid'], 'obj_id': r3['obj_id'] }) progress = r6['progress'] if r6 else 0 # 是否有测试题 r7 = db.exam_info.find({ 'obj_id': r3['obj_id'], 'available': 1 }).count() course_data.append({ "object_id": r3['obj_id'], # 内部唯一标识 "title": r3['title'], "title2": r3['title2'], "speaker": r3['speaker'], "type": 1 if r3['media'] == 'video' else 2, # 1- 视频 2 - 音频 "image": image_url, # 课程主图 "length": r3['length'], # 长度,单位:分钟 "progress": progress, # 课程进度百分比,0表示未上课,100表示已上课 "exam_score": score, # 课后测试成绩,-1表示未测试 "auth_num": auth_num, # 已授权店员数 , "have_exam": 1 if r7 > 0 else 0, # 是否有课后测试,2017-06-09 }) ret_data = { "course": course_data, "total": len(course_data), # 返回的课程数量,小于 page_size说明到末尾 "page_size": param.page_size, # 分页尺寸,与调用参数相同 "page_index": param.page_index, # 页索引 } # 返回 return json.dumps({ 'ret': 0, 'data': ret_data, })
def POST(self, version='v1'): web.header('Content-Type', 'application/json') param = web.input(app_id='', dev_id='', ver_code='', session='', tick='', category='', pic1='', pic1_type='') if '' in (param.app_id, param.dev_id, param.ver_code, param.session, param.tick, param.category): return json.dumps({'ret': -2, 'msg': '参数错误'}) # 检查session登录 uname = app_helper.app_logged(param.session) if uname is None: return json.dumps({'ret': -4, 'msg': '无效的session'}) #-------------------------------------------------- if param['category'].upper() not in ('LICENCE', 'PHOTO'): return json.dumps({'ret': -5, 'msg': '无效的category取值'}) if param['pic1_type'].upper() not in ('JPG', 'PNG'): return json.dumps({'ret': -6, 'msg': '无效的图片类型取值'}) # 保存图片 if len(param['pic1'].strip()) > 0: pic1_filename = app_helper.write_image( param['pic1_type'], urllib.unquote_plus(param['pic1'])) else: pic1_filename = '' # 删除图片 # 更新数据 update_set = {} if param['category'].upper() == 'LICENCE': db.app_user.update_one({ 'userid': uname['userid'], 'type': 1 }, {'$set': { 'upload_licence': pic1_filename }}) else: if pic1_filename == '': # 删除已上传的图片 db.app_user.update_one({ 'userid': uname['userid'], 'type': 1 }, {'$set': { 'shop_pic': [] }}) else: db.app_user.update_one({ 'userid': uname['userid'], 'type': 1 }, {'$push': { 'shop_pic': pic1_filename }}) # 准备返回值 ret_data = { "pic1_url": app_helper.image_url(pic1_filename) if pic1_filename != '' else pic1_filename, } # 返回 return json.dumps({ 'ret': 0, 'data': ret_data, })
def POST(self, version='v1'): web.header('Content-Type', 'application/json') param = web.input(app_id='', dev_id='', ver_code='', session='', page_size='', page_index='', tick='') if '' in (param.app_id, param.dev_id, param.ver_code, param.page_size, param.page_index, param.tick): return json.dumps({'ret': -2, 'msg': '参数错误'}) if param.session != '': # 检查session登录 uname = app_helper.app_logged(param.session) if uname is None: return json.dumps({'ret': -4, 'msg': '无效的session'}) else: uname = None #-------------------------------------------------- r2 = db.online_topic_obj.find({ 'available': 1, }, sort=[('sort_weight', 1)]) tpc_list = [i['tpc_id'] for i in r2] # 取指定区间的 start_pos = int(param.page_size) * int(param.page_index) end_pos = start_pos + int(param.page_size) tpc_list_page = tpc_list[start_pos:end_pos] r3 = db.topic_store.find({'tpc_id': {'$in': tpc_list_page}}) tpc_data = {} for i in r3: tpc_data[i['tpc_id']] = i # 准备返回数据 ret_tpc_list = [] for i in tpc_list_page: if tpc_data[i].get('status') != 'PASSED': # 审核未通过,应该是上架后又有修改 continue r4 = db.obj_store.find({ 'obj_type': 'topic', 'tpc_id': tpc_data[i]['tpc_id'] }) topic_count = r4.count() # 专辑内课程数 if topic_count > 0: media = r4[0]['media'] else: media = 'audio' # 默认为音频 if len(tpc_data[i]['image']) > 0: # 取第1张图 image_url = app_helper.image_url(tpc_data[i]['image'][0]) else: image_url = '' ret_tpc_list.append({ 'object_id': tpc_data[i]['tpc_id'], 'title': tpc_data[i]['title'], 'title2': tpc_data[i]['title2'], 'type': 1 if media == 'video' else 2, # 1- 视频 2 - 音频 'image': image_url, 'length': topic_count, # 长度,单位:几个课程 }) ret_data = { "topic": ret_tpc_list, "total": len(ret_tpc_list), # 返回的课程数量,小于 page_size说明到末尾 "page_size": param.page_size, # 分页尺寸,与调用参数相同 "page_index": param.page_index, # 页索引 } # 返回 return json.dumps({ 'ret': 0, 'data': ret_data, })
def POST(self, version='v1'): web.header('Content-Type', 'application/json') param = web.input(app_id='', dev_id='', ver_code='', session='', object_id='', tick='') if '' in (param.app_id, param.dev_id, param.ver_code, param.object_id, param.tick): return json.dumps({'ret' : -2, 'msg' : '参数错误'}) if param.session!='': # 检查session登录 uname = app_helper.app_logged(param.session) if uname is None: return json.dumps({'ret' : -4, 'msg' : '无效的session'}) else: uname = None #-------------------------------------------------- r3 = db.obj_store.find_one({ 'obj_id' : param.object_id, }) if r3 is None: return json.dumps({'ret' : -5, 'msg' : '错误的object_id'}) if len(r3['image'])>1: # 取第2张图, 讲师头像 image_url = app_helper.image_url(r3['image'][1]) else: image_url = '' if len(r3['image'])>0: # 取第1张图 image_url_1 = app_helper.image_url(r3['image'][0]) else: image_url_1 = '' # 评价条数 r4 = db.comment_info.find({'obj_id':param.object_id}).count() # 是否已购买或已授权, 不需要试听 can_use = False score = -1 is_heart = 0 if uname is not None: # 检查 是否是已购买 r6 = db.user_property.find_one({ 'userid' : uname['userid'], 'obj_id' : param.object_id, 'status' : 'paid', }) if r6: can_use = True else: # 检查 是否是已授权 r7 = db.employee_auth.find_one({ 'employee_userid' : uname['userid'], 'object_list' : param.object_id, }) if r7: can_use = True # 测试成绩 r5 = db.test_info.find_one({'userid':uname['userid'], 'obj_id':param.object_id}) score = r5['score'] if r5 else -1 # 检查是否已收藏 r8 = db.heart_info.find_one({'userid':uname['userid'],'obj_id':param.object_id}) is_heart = 0 if r8 is None else 1 # 音频/视频下载链接 media_url = '' if len(r3.get('media_file',''))>0: if r3['media']=='audio': # 音频 media_url = app_helper.audio_url(r3['media_file']) elif r3.has_key('transcoded_filename') and (r3['transcoded_filename'] not in ['FAIL','CODING']): media_url = app_helper.video_url(r3['transcoded_filename']) # 讲师介绍音频 if len(r3.get('speaker_media',''))>0: speaker_url = app_helper.audio_url(r3['speaker_media']) else: speaker_url = '' # 是否有测试题 exam_cnt = db.exam_info.find({'obj_id':param.object_id, 'available':1}).count() # 返回的数据 ret_data = { "object_id" : param.object_id, # 唯一代码 "title" : r3['title'], "title2" : r3['title2'], "abstract" : r3['description'], "type" : 1 if r3['media']=='video' else 2, "speaker_head" : image_url, # 讲师头像图片url "speaker_audio" : speaker_url, # 讲师音频介绍链接 "course_video" : media_url, # 课程视频链接 "try_length" : 0 if can_use else max(r3['try_time'], 1), # 0 - 已购买,不是试听,>0 - 可试听的长度,单位 秒 "volume" : r3['volume'], # 销量 "comment_num" : r4, # 学员评价总条数 "exam_score" : score, # 课后测试成绩,-1表示未测试 "service_tel" : app_helper.CS_TEL, 'speaker' : r3['speaker'], 'price' : r3['price'], # 价格 单位:分 'image' : image_url_1, # 课程主图 "have_exam" : 1 if exam_cnt>0 else 0, # 是否有课后测试,2017-06-09 "is_heart" : is_heart, # 是否已收藏,2017-06-09 } # 返回 return json.dumps({ 'ret' : 0, 'data' : ret_data, })
def POST(self, version='v1'): web.header('Content-Type', 'application/json') param = web.input(app_id='', dev_id='', ver_code='', session='', category='', page_size='', page_index='', sort_by='1', tick='') if '' in (param.app_id, param.dev_id, param.ver_code, param.page_size, param.page_index, param.tick): return json.dumps({'ret': -2, 'msg': '参数错误'}) if param.session != '': # 检查session登录 uname = app_helper.app_logged(param.session) if uname is None: return json.dumps({'ret': -4, 'msg': '无效的session'}) else: uname = None #-------------------------------------------------- cate_id = param['category'].strip( ) if param['category'].strip() != '' else app_helper.DEFAULT_CATEGORY r2 = db.online_cate_obj.find({ 'cate_id': cate_id, 'available': 1, }, sort=[('sort_weight', 1)]) obj_list = [i['obj_id'] for i in r2] if param.sort_by == '2': # 按销量排序 r3 = db.obj_store.find({'obj_id': {'$in': obj_list}}) obj_data = {} for i in r3: obj_data[i['obj_id']] = i print obj_list obj_list = sorted(obj_list, key=lambda x: obj_data[x].get('volume', 0), reverse=True) print obj_list # 取指定区间的 start_pos = int(param.page_size) * int(param.page_index) end_pos = start_pos + int(param.page_size) obj_list_page = obj_list[start_pos:end_pos] else: # 按sort weight排序,性能比按销量高 # 取指定区间的 start_pos = int(param.page_size) * int(param.page_index) end_pos = start_pos + int(param.page_size) obj_list_page = obj_list[start_pos:end_pos] r3 = db.obj_store.find({'obj_id': {'$in': obj_list_page}}) obj_data = {} for i in r3: obj_data[i['obj_id']] = i # 准备返回数据 ret_obj_list = [] for i in obj_list_page: if obj_data[i].get('status') != 'PASSED': # 审核未通过,应该是上架后又有修改 continue if len(obj_data[i]['image']) > 0: # 取第1张图 image_url = app_helper.image_url(obj_data[i]['image'][0]) else: image_url = '' ret_obj_list.append({ 'object_id': obj_data[i]['obj_id'], 'title': obj_data[i]['title'], 'title2': obj_data[i]['title2'], 'speaker': obj_data[i]['speaker'], 'type': 1 if obj_data[i]['media'] == 'video' else 2, # 1- 视频 2 - 音频 'image': image_url, 'length': obj_data[i]['length'], # 长度,单位:秒 'price': obj_data[i]['price'], # 价格 单位:分 'volume': obj_data[i]['volume'], # 销量 }) ret_data = { "course": ret_obj_list, "total": len(ret_obj_list), # 返回的课程数量,小于 page_size说明到末尾 "page_size": param.page_size, # 分页尺寸,与调用参数相同 "page_index": param.page_index, # 页索引 } # 返回 return json.dumps({ 'ret': 0, 'data': ret_data, })
def POST(self): web.header('Content-Type', 'application/json') param = web.input(session_id='', object_id='') if param.object_id=='': return json.dumps({'ret' : -2, 'msg' : '参数错误'}) if param.session_id=='': return json.dumps({'ret' : -1, 'msg' : 'session_id参数错误'}) uname = app_helper.wx_logged(param.session_id) if uname is None: return json.dumps({'ret' : -4, 'msg' : '无效的session_id'}) #-------------------------------------------------- r2 = db.topic_store.find_one({ 'tpc_id' : param.object_id, }) if r2 is None: return json.dumps({'ret' : -5, 'msg' : '错误的object_id'}) r3 = db.obj_store.find({ 'obj_type' : 'topic', 'tpc_id' : param.object_id, }) # 专辑内课程数据 course_data = [] for i in r3: if len(i['image'])>0: # 取第1张图 image_url = app_helper.image_url(i['image'][0]) else: image_url = '' course_data.append({ "object_id" : i['obj_id'], # 内部唯一标识 "title" : i['title'], "title2" : i['title2'], "speaker" : i['speaker'], "type" : 1 if i['media']=='video' else 2, # 1- 视频 2 - 音频 "image" : image_url, # 课程主图 "length" : i['length'], # 长度,单位:秒 "price" : i['price'], # 价格,整数,单位:分 "volume" : r2.get('volume',0), #i['volume'], # 销量,整数 (专辑课程销量与专辑销量相同?) }) # 取专辑图片 if len(r2['image'])>0: # 取第1张图 image_url = app_helper.image_url(r2['image'][0]) else: image_url = '' # 返回数据 ret_data = { "object_id" : param.object_id, # 唯一代码 "title" : r2['title'], "title2" : r2['title2'], "abstract" : r2['description'], "topic_image" : image_url, # 专辑图片url "booked_num" : r2.get('volume',0), # 订阅人数, 销量 "course" : course_data, } # 返回 return json.dumps({ 'ret' : 0, 'data' : ret_data, })