def menutypes(): if request.method == 'POST': if auto.decodejwt(request.form['jwtstr']): try: pdict = {'_id': request.form["restaurant_id"]} item = mongo.restaurant.find(tools.orderformate(pdict, table), { "menu.name": 1, "menu.id": 1, "_id": 0 }) data = {} list = [] for i in item: for j in i['menu']: #如果需要修改优惠菜和推荐菜 就取消下面这句判断 暂定只修改菜品和酒水 if j['name'] != '优惠菜' and j['name'] != '推荐菜': list.append(j) data['list'] = list result = tool.return_json(0, "success", True, data) return json_util.dumps(result, ensure_ascii=False, indent=2) except Exception, e: print e result = tool.return_json(0, "field", False, None) return json_util.dumps(result, ensure_ascii=False, indent=2) else: result = tool.return_json(0, "field", False, None) return json_util.dumps(result, ensure_ascii=False, indent=2)
def redishslist(): if request.method == 'POST': if auto.decodejwt(request.form['jwtstr']): try: pdict = {'_id': request.form["restaurant_id"]} item = mongo.restaurant.find(tools.orderformate(pdict, table), {"menu": 1}) dishs_dict = {} dishs_list = [] for i in item: for dishs in i['menu']: if dishs['name'] == request.form[ 'name'] and dishs['name'] != '优惠菜' and dishs[ 'name'] != '推荐菜' and dishs[ 'dish_type'] == '1' and dishs[ 'dishs'] != []: for dish in dishs['dishs']: json = {} json['dish_id'] = dish['id'] json['price'] = dish['price'] json['name'] = dish['name'] json['discount_price'] = dish['discount_price'] json['type'] = dish['type'] dishs_list.append(json) dishs_dict['dishs_list'] = dishs_list result = tool.return_json(0, "success", True, dishs_dict) return json_util.dumps(result, ensure_ascii=False, indent=2) except Exception, e: print e result = tool.return_json(0, "field", False, None) return json_util.dumps(result, ensure_ascii=False, indent=2) else: result = tool.return_json(0, "field", False, None) return json_util.dumps(result, ensure_ascii=False, indent=2)
def updateorder(): if request.method == 'POST': if auto.decodejwt(request.form['jwtstr']): try: pdict = { 'username': request.form["username"], 'phone': request.form["phone"], 'demand': request.form["demand"], 'numpeople': request.form["numpeople"], 'room_id': request.form["room_id"], 'preset_time': datetime.datetime.strptime(request.form["preset_time"], "%Y-%m-%d %H:%M:%S") } mongo.order.update_one( {'_id': ObjectId(request.form['id'])}, {"$set": tools.orderformate(pdict, table)}) #mfrom-消息来源id|mto-发送给谁id数组,下划线分隔|title-消息标题|info-消息内容|goto("0")-跳转页位置|channel(订单)-调用位置|type-0系统发 1商家发 2用户发|totype-0发给商家 1发给用户 # appname(foodmap_user,foodmap_shop)-调用的APP|msgtype(message,notice)-是消息还是通知|target(all,device)-全推或单推|ispush(True,False)-是否发送推送| order = mongo.order.find({"_id": ObjectId(request.form['id'])}) r_id = '' user_id = '' for o in order: r_id = o['restaurant_id'] user_id = o['webuser_id'] flag = request.form.get('flag', '') if user_id != '' and flag != '1': item = tool.tuisong(mfrom=str(r_id), mto=str(user_id), title='您的餐位预订已修改', info='快去看看吧', goto='19', channel='商家拒单', type='1', totype='1', appname='foodmap_user', msgtype='notice', target='device', ext='{"goto":"19","id":"' + request.form['id'] + '"}', ispush=True) json = {"status": 1, "msg": ""} result = tool.return_json(0, "success", True, json) return json_util.dumps(result, ensure_ascii=False, indent=2) except Exception, e: print e result = tool.return_json(0, "field", False, None) return json_util.dumps(result, ensure_ascii=False, indent=2) else: result = tool.return_json(0, "field", False, None) return json_util.dumps(result, ensure_ascii=False, indent=2)
def dishroomorder(): if request.method == 'POST': if auto.decodejwt(request.form['jwtstr']): try: pdict = {'_id': request.form["id"]} item = mongo.order.find(tools.orderformate(pdict, table)) json = {} for i in item: for key in i.keys(): if key == '_id': json['id'] = str(i[key]) elif key == 'total': json['total'] = str(i[key]) elif key == 'demand': json['demand'] = i[key] elif key == 'dis_message': json['dis_message'] = i[key] elif key == 'preset_time': json['preset_time'] = i[key].strftime( '%Y年%m月%d日 %H:%M') elif key == 'restaurant_id': json['restaurant_id'] = str(i[key]) json['roomlist'] = public.getroomslist( i[key], i['preset_time'].strftime("%Y-%m-%d"))['list'] else: pass result = tool.return_json(0, "success", True, json) return json_util.dumps(result, ensure_ascii=False, indent=2) except Exception, e: print e result = tool.return_json(0, "field", False, None) return json_util.dumps(result, ensure_ascii=False, indent=2) else: result = tool.return_json(0, "field", False, None) return json_util.dumps(result, ensure_ascii=False, indent=2)
def restaurant_discountinfos(): if request.method == 'POST': if auto.decodejwt(request.form['jwtstr']): try: pdict = {'_id': request.form["restaurant_id"]} item = mongo.restaurant.find( tools.orderformate(pdict, table), { "restaurant_discount.message": 1, "restaurant_discount.start_time": 1, "restaurant_discount.end_time": 1, "_id": 1 }) for i in item: json = {} for key in i.keys(): if key == '_id': json['id'] = str(i[key]) elif key == 'restaurant_discount': json['message'] = i["restaurant_discount"][ "message"] try: json['start_time'] = i["restaurant_discount"][ "start_time"].strftime('%Y年%m月%d日') json['end_time'] = i["restaurant_discount"][ "end_time"].strftime('%Y年%m月%d日') except Exception, e: json['start_time'] = i["restaurant_discount"][ "start_time"] json['end_time'] = i["restaurant_discount"][ "end_time"] else: json[key] = i[key] result = tool.return_json(0, "success", True, json) return json_util.dumps(result, ensure_ascii=False, indent=2) except Exception, e: print e result = tool.return_json(0, "field", False, None) return json_util.dumps(result, ensure_ascii=False, indent=2)
def updatemembers(): if request.method == 'POST': if auto.decodejwt(request.form['jwtstr']): try: pdict = { 'nickname': request.form["nickname"], 'birthday': request.form["birthday"], 'phone': request.form["phone"], 'restaurant_id': request.form["restaurant_id"] } mongo.members.update_one( {'_id': ObjectId(request.form['id'])}, {"$set": tools.orderformate(pdict, table)}) json = {"status": 1, "msg": ""} result = tool.return_json(0, "success", True, json) return json_util.dumps(result, ensure_ascii=False, indent=2) except Exception, e: print e result = tool.return_json(0, "field", False, None) return json_util.dumps(result, ensure_ascii=False, indent=2) else: result = tool.return_json(0, "field", False, None) return json_util.dumps(result, ensure_ascii=False, indent=2)
def orderinfos(): if request.method == 'POST': if auto.decodejwt(request.form['jwtstr']): try: pdict = {'_id': request.form["id"]} item = mongo.order.find(tools.orderformate(pdict, table)) for i in item: json = {} for key in i.keys(): if key == '_id': json['id'] = str(i[key]) elif key == 'restaurant_id': json['restaurant_id'] = str(i[key]) ritem = mongo.restaurant.find( {"_id": ObjectId(i[key])}, {"dishes_discount": 1}) for r in ritem: json['discount'] = str( r['dishes_discount']['discount']) elif key == 'webuser_id': json['webuser_id'] = str(i[key]) elif key == 'preset_time': json['preset_time'] = i[key].strftime( '%Y年%m月%d日 %H:%M:%S') elif key == 'add_time': json['add_time'] = i[key].strftime( '%Y年%m月%d日 %H:%M:%S') elif key == 'room_id': item = mongo.restaurant.find( {"_id": ObjectId(i['restaurant_id'])}, {"rooms": 1}) json['rname'] = '' for t in item: for r in t['rooms']: if r['room_id'] == i['room_id']: json['rname'] = r['room_name'] elif key == 'webuser_id': json['webuser_id'] = str(i[key]) elif key == 'total': json['total'] = str(i[key]) elif key == 'deposit': if float(i['total']) - float(i['deposit']) < 0: json['deposit'] = 0 else: json['deposit'] = str( '%.2f' % (float('%.2f' % (float(i['total']) - float(i['deposit']))) * 0.1)) elif key == 'preset_dishs': pdlist = [] if i[key] != None: for pd in i[key]: pdjson = {} pdjson['id'] = pd['id'] pdjson['price'] = str(pd['price']) pdjson['num'] = pd['num'] pdjson['name'] = pd['name'] pdjson['discount_price'] = str( pd['discount_price']) pdlist.append(pdjson) json['preset_dishs'] = pdlist elif key == 'preset_wine': pdlist = [] if i[key] != None: for pd in i[key]: pdjson = {} pdjson['id'] = pd['id'] pdjson['price'] = str(pd['price']) pdjson['num'] = pd['num'] pdjson['name'] = pd['name'] pdjson['discount_price'] = str( pd['discount_price']) pdlist.append(pdjson) json['preset_wine'] = pdlist else: json[key] = i[key] result = tool.return_json(0, "success", True, json) return json_util.dumps(result, ensure_ascii=False, indent=2) except Exception, e: print e result = tool.return_json(0, "field", False, None) return json_util.dumps(result, ensure_ascii=False, indent=2) else: result = tool.return_json(0, "field", False, None) return json_util.dumps(result, ensure_ascii=False, indent=2)
def findcoupons(): if request.method == 'POST': try: if auto.decodejwt(request.form['jwtstr']): checkcoupons(request.form['restaurant_id']) pdict = { 'restaurant_id': request.form['restaurant_id'], 'kind': '1' } kind = int(request.form['kind']) json = {} if kind == 1: item = mongo.coupons.find(tools.orderformate( pdict, table)).sort("addtime", pymongo.DESCENDING) for i in item: json = {} for key in i.keys(): if key == '_id': json['id'] = str(i[key]) elif key == 'restaurant_id': json['restaurant_id'] = str(i[key]) elif key == 'button': json['button'] = str(i[key]) elif key == 'rule': if i[key] == '0': json['rule'] = i[key] json['rulename'] = '无门槛' elif i[key] == '1': json['rule'] = i[key] json['rulename'] = '全品满' + str( i['money']) + '元可使用' elif i[key] == '2': json['rule'] = i[key] json['rulename'] = '菜品满' + str( i['money']) + '元可使用' elif i[key] == '3': json['rule'] = i[key] json['rulename'] = '酒类满' + str( i['money']) + '元可使用' else: json['rule'] = '' elif key == 'showtime_start': json['showtime_start'] = i[key].strftime( '%Y年%m月%d日') elif key == 'content': if i['type'] == '1': if i['rule'] == '0': json['content'] = '下单即减' + str( i['cross-claim']) + '元' elif i['rule'] == '1': json['content'] = '全品满' + str( i['money']) + '元' + '减' + str( i['cross-claim']) + '元' elif i['rule'] == '2': json['content'] = '菜品满' + str( i['money']) + '元' + '减' + str( i['cross-claim']) + '元' elif i['rule'] == '3': json['content'] = '酒类满' + str( i['money']) + '元' + '减' + str( i['cross-claim']) + '元' else: pass elif i['type'] == '2': if i['rule'] == '0': json['content'] = '下单即打' + str( i['cross-claim']) + '折' elif i['rule'] == '1': json['content'] = '全品满' + str( i['money']) + '元' + '打' + str( i['cross-claim']) + '折' elif i['rule'] == '2': json['content'] = '菜品满' + str( i['money']) + '元' + '打' + str( i['cross-claim']) + '折' elif i['rule'] == '3': json['content'] = '酒类满' + str( i['money']) + '元' + '打' + str( i['cross-claim']) + '折' else: pass else: json['content'] = i['content'] elif key == 'showtime_end': json['showtime_end'] = i[key].strftime( '%Y年%m月%d日') elif key == 'indate_start': json['indate_start'] = i[key].strftime( '%Y年%m月%d日') elif key == 'indate_end': json['indate_end'] = i[key].strftime( '%Y年%m月%d日') elif key == 'addtime': json['addtime'] = i[key].strftime('%Y年%m月%d日') else: json[key] = i[key] json['status'] = '' elif kind == 2: pdict['kind'] = 2 item = mongo.coupons.find(tools.orderformate( pdict, table)).sort("addtime", pymongo.DESCENDING) for i in item: json = {} for key in i.keys(): if key == '_id': json['id'] = str(i[key]) elif key == 'restaurant_id': json['restaurant_id'] = str(i[key]) elif key == 'button': json['button'] = i[key] elif key == 'rule': if i[key] == '0': json['rule'] = i[key] json['rulename'] = '无门槛' elif i[key] == '1': json['rule'] = i[key] json['rulename'] = '全品满' + str( i['money']) + '元可使用' elif i[key] == '2': json['rule'] = i[key] json['rulename'] = '菜品满' + str( i['money']) + '元可使用' elif i[key] == '3': json['rule'] = i[key] json['rulename'] = '酒类满' + str( i['money']) + '元可使用' else: json['rule'] = '' elif key == 'content': if i['type'] == '1': if i['rule'] == '0': json['content'] = '下单即减' + str( i['cross-claim']) + '元' elif i['rule'] == '1': json['content'] = '全品满' + str( i['money']) + '元' + '减' + str( i['cross-claim']) + '元' elif i['rule'] == '2': json['content'] = '菜品满' + str( i['money']) + '元' + '减' + str( i['cross-claim']) + '元' elif i['rule'] == '3': json['content'] = '酒类满' + str( i['money']) + '元' + '减' + str( i['cross-claim']) + '元' else: pass elif i['type'] == '2': if i['rule'] == '0': json['content'] = '下单即打' + str( i['cross-claim']) + '折' elif i['rule'] == '1': json['content'] = '全品满' + str( i['money']) + '元' + '打' + str( i['cross-claim']) + '折' elif i['rule'] == '2': json['content'] = '菜品满' + str( i['money']) + '元' + '打' + str( i['cross-claim']) + '折' elif i['rule'] == '3': json['content'] = '酒类满' + str( i['money']) + '元' + '打' + str( i['cross-claim']) + '折' else: pass else: json['content'] = i['content'] elif key == 'showtime_start': json['showtime_start'] = i[key].strftime( '%Y年%m月%d日') elif key == 'showtime_end': json['showtime_end'] = i[key].strftime( '%Y年%m月%d日') elif key == 'indate_start': json['indate_start'] = i[key].strftime( '%Y年%m月%d日') elif key == 'indate_end': json['indate_end'] = i[key].strftime( '%Y年%m月%d日') elif key == 'addtime': json['addtime'] = i[key].strftime('%Y年%m月%d日') else: json[key] = i[key] json['status'] = '' else: pdict['kind'] = 3 pageindex = int(request.form['pageindex']) pagenum = 10 star = (int(pageindex) - 1) * pagenum end = (pagenum * int(pageindex)) item = mongo.coupons.find(tools.orderformate( pdict, table)).sort("addtime", pymongo.DESCENDING)[star:end] status = [] list = [] for i in item: data = {} for key in i.keys(): if key == '_id': data['id'] = str(i[key]) elif key == 'restaurant_id': data['restaurant_id'] = str(i[key]) elif key == 'rule': if i[key] == '0': data['rule'] = i[key] data['rulename'] = '无门槛' elif i[key] == '1': data['rule'] = i[key] data['rulename'] = '全品满' + str( i['money']) + '元可使用' elif i[key] == '2': data['rule'] = i[key] data['rulename'] = '菜品满' + str( i['money']) + '元可使用' elif i[key] == '3': data['rule'] = i[key] data['rulename'] = '酒类满' + str( i['money']) + '元可使用' else: data['rule'] = '' elif key == 'content': if i['type'] == '1': if i['rule'] == '0': data['content'] = '下单即减' + str( i['cross-claim']) + '元' elif i['rule'] == '1': data['content'] = '全品满' + str( i['money']) + '元' + '减' + str( i['cross-claim']) + '元' elif i['rule'] == '2': data['content'] = '菜品满' + str( i['money']) + '元' + '减' + str( i['cross-claim']) + '元' elif i['rule'] == '3': data['content'] = '酒类满' + str( i['money']) + '元' + '减' + str( i['cross-claim']) + '元' else: pass elif i['type'] == '2': if i['rule'] == '0': data['content'] = '下单即打' + str( i['cross-claim']) + '折' elif i['rule'] == '1': data['content'] = '全品满' + str( i['money']) + '元' + '打' + str( i['cross-claim']) + '折' elif i['rule'] == '2': data['content'] = '菜品满' + str( i['money']) + '元' + '打' + str( i['cross-claim']) + '折' elif i['rule'] == '3': data['content'] = '酒类满' + str( i['money']) + '元' + '打' + str( i['cross-claim']) + '折' else: pass else: data['content'] = i['content'] elif key == 'showtime_start': data['showtime_start'] = i[key].strftime( '%Y年%m月%d日') elif key == 'showtime_end': data['showtime_end'] = i[key].strftime( '%Y年%m月%d日') elif key == 'indate_start': data['indate_start'] = i[key].strftime( '%Y年%m月%d日') elif key == 'indate_end': data['indate_end'] = i[key].strftime( '%Y年%m月%d日') elif key == 'addtime': data['addtime'] = i[key].strftime('%Y年%m月%d日') else: data[key] = i[key] if datetime.datetime.now() < i['indate_start']: data['status'] = '未开始' status.append('未开始') elif i['indate_start'] < datetime.datetime.now( ) < i['indate_end']: data['status'] = '进行中' status.append('进行中') else: data['status'] = '已结束' status.append('已结束') list.append(data) flag = False if not ('进行中' in status and '未开始' in status): flag = True json['list'] = list json['isinsert'] = flag result = tool.return_json(0, "success", True, json) return json_util.dumps(result, ensure_ascii=False, indent=2) else: result = tool.return_json(0, "field", True, None) return json_util.dumps(result, ensure_ascii=False, indent=2) except Exception, e: print e result = tool.return_json(0, "field", True, e) return json_util.dumps(result, ensure_ascii=False, indent=2)
def couponsinfo(): if request.method == 'POST': try: if auto.decodejwt(request.form['jwtstr']): pdict = {'_id': request.form['coupons_id']} item = mongo.coupons.find(tools.orderformate(pdict, table)) json = {} for i in item: for key in i.keys(): if key == '_id': json['id'] = str(i[key]) elif key == 'restaurant_id': json['restaurant_id'] = str(i[key]) elif key == 'kind': if i[key] == '1' or i[key] == '2': json['button'] = i[key] elif key == 'rule': if i[key] == '0': json['rule'] = i[key] json['rulename'] = '无门槛' elif i[key] == '1': json['rule'] = i[key] json['rulename'] = '全品满' + str( i['money']) + '元可使用' elif i[key] == '2': json['rule'] = i[key] json['rulename'] = '菜品满' + str( i['money']) + '元可使用' elif i[key] == '3': json['rule'] = i[key] json['rulename'] = '酒类满' + str( i['money']) + '元可使用' else: json['rule'] = '' elif key == 'content': if i['type'] == '1': if i['rule'] == '0': json['content'] = '下单即减' + str( i['cross-claim']) + '元' elif i['rule'] == '1': json['content'] = '全品满' + str( i['money']) + '元' + '减' + str( i['cross-claim']) + '元' elif i['rule'] == '2': json['content'] = '菜品满' + str( i['money']) + '元' + '减' + str( i['cross-claim']) + '元' elif i['rule'] == '3': json['content'] = '酒类满' + str( i['money']) + '元' + '减' + str( i['cross-claim']) + '元' else: pass elif i['type'] == '2': if i['rule'] == '0': json['content'] = '下单即打' + str( i['cross-claim']) + '折' elif i['rule'] == '1': json['content'] = '全品满' + str( i['money']) + '元' + '打' + str( i['cross-claim']) + '折' elif i['rule'] == '2': json['content'] = '菜品满' + str( i['money']) + '元' + '打' + str( i['cross-claim']) + '折' elif i['rule'] == '3': json['content'] = '酒类满' + str( i['money']) + '元' + '打' + str( i['cross-claim']) + '折' else: pass else: json['content'] = i['content'] elif key == 'showtime_start': json['showtime_start'] = i[key].strftime( '%Y年%m月%d日') elif key == 'showtime_end': json['showtime_end'] = i[key].strftime('%Y年%m月%d日') elif key == 'indate_start': json['indate_start'] = i[key].strftime('%Y年%m月%d日') elif key == 'indate_end': json['indate_end'] = i[key].strftime('%Y年%m月%d日') elif key == 'addtime': json['addtime'] = i[key].strftime('%Y年%m月%d日') else: json[key] = i[key] if datetime.datetime.now() < i['indate_start']: json['status'] = '未开始' elif i['indate_start'] < datetime.datetime.now( ) < i['indate_end']: json['status'] = '进行中' else: json['status'] = '已结束' result = tool.return_json(0, "success", True, json) return json_util.dumps(result, ensure_ascii=False, indent=2) else: result = tool.return_json(0, "field", False, None) return json_util.dumps(result, ensure_ascii=False, indent=2) except Exception, e: print e result = tool.return_json(0, "field", True, e) return json_util.dumps(result, ensure_ascii=False, indent=2)
def allmembers(): if request.method == 'POST': if auto.decodejwt(request.form['jwtstr']): try: pdict = {'restaurant_id': request.form["restaurant_id"]} pageindex = request.form["pageindex"] pagenum = 10 star = (int(pageindex) - 1) * pagenum end = (pagenum * int(pageindex)) if int(request.form['user_tpye']) == 0: pdict["status"] = 0 item = mongo.members.find(tools.orderformate( pdict, table))[star:end] count = mongo.members.find(tools.orderformate( pdict, table)).count() data = {} list = [] for i in item: json = {} for key in i.keys(): if key == '_id': json['id'] = str(i[key]) elif key == 'restaurant_id': json['restaurant_id'] = str(i[key]) elif key == 'addtime': json['addtime'] = i[key].strftime( '%Y年%m月%d日 %H:%M') else: json[key] = i[key] json['user_type'] = 0 list.append(json) data['list'] = list data['count'] = count jwtmsg = auto.decodejwt(request.form["jwtstr"]) result = tool.return_json(0, "success", jwtmsg, data) return json_util.dumps(result, ensure_ascii=False, indent=2) else: idlist = [] concern = mongo.concern.find( tools.orderformate(pdict, table)) for i in concern: for j in i.keys(): if j == 'webuser_id': idlist.append(ObjectId(i[j])) item = mongo.webuser.find({'_id': { '$in': idlist }})[star:end] count = mongo.webuser.find({ '_id': { '$in': idlist } }).count() data = {} list = [] for i in item: json = {} for key in i.keys(): if key == '_id': json['id'] = str(i[key]) elif key == 'automembers_id': json['automembers_id'] = str(i[key]) elif key == 'addtime': json['addtime'] = i[key].strftime( '%Y年%m月%d日 %H:%M') elif key == 'birthday': json['birthday'] = i[key] elif key == 'gender': json['gender'] = int(i[key]) else: json[key] = i[key] json['user_type'] = 1 list.append(json) data['list'] = list data['count'] = count result = tool.return_json(0, "success", True, data) return json_util.dumps(result, ensure_ascii=False, indent=2) except Exception, e: print e result = tool.return_json(0, "field", False, None) return json_util.dumps(result, ensure_ascii=False, indent=2) else: result = tool.return_json(0, "field", False, None) return json_util.dumps(result, ensure_ascii=False, indent=2)
def membersinfo(): if request.method == 'POST': if auto.decodejwt(request.form['jwtstr']): # try: pdict = {'_id': request.form['id']} odict = { 'restaurant_id': request.form["restaurant_id"], 'webuser_id': request.form['id'] } if int(request.form['user_tpye']) == 0: item = mongo.members.find_one( {'_id': ObjectId(request.form['id'])}) json = {} for key in item.keys(): if key == '_id': json['id'] = str(item[key]) elif key == 'restaurant_id': json['restaurant_id'] = str(item[key]) elif key == 'addtime': json['addtime'] = item[key].strftime('%Y年%m月%d日 %H:%M') elif key == 'birthday': json['birthday'] = item[key] else: json[key] = item[key] result = tool.return_json(0, "success", True, json) return json_util.dumps(result, ensure_ascii=False, indent=2) else: item = mongo.webuser.find_one(tools.orderformate(pdict, table)) totals = mongo.order.find(tools.orderformate(odict, table), { 'preset_time': 1, 'total': 1 }).sort('add_time', pymongo.DESCENDING)[0:2] comment = mongo.comment.find( { "restaurant_id": request.form["restaurant_id"], "user_id": request.form['id'] }, { "post_date": 1, "user_info.user_name": 1, "comment_text": 1 }).sort('post_date', pymongo.DESCENDING)[0:2] commentlist = [] for c in comment: commentdict = {} for d in c.keys(): if d == 'post_date': commentdict['post_date'] = c[d].strftime( '%Y年%m月%d日 %H:%M') elif d == 'comment_text': commentdict['comment_text'] = c[d] elif d == 'user_info': commentdict['user_name'] = c['user_info'][ 'user_name'] commentlist.append(commentdict) totallist = [] for i in totals: total = {} for t in i.keys(): if t == '_id': total['id'] = str(i[t]) elif t == 'preset_time': total['preset_time'] = str(i[t]) else: total[t] = i[t] totallist.append(total) data = {} json = {} for key in item.keys(): if key == '_id': json['id'] = str(item[key]) elif key == 'restaurant_id': json['restaurant_id'] = str(item[key]) elif key == 'addtime': json['addtime'] = item[key].strftime('%Y年%m月%d日 %H:%M') elif key == 'birthday': json['birthday'] = item[key] else: json[key] = item[key] data['info'] = json data['total'] = totallist data['comment'] = commentlist result = tool.return_json(0, "success", True, data) return json_util.dumps(result, ensure_ascii=False, indent=2) # except Exception,e: # print e # result=tool.return_json(0,"field",False,None) # return json_util.dumps(result,ensure_ascii=False,indent=2) else: result = tool.return_json(0, "field", False, None) return json_util.dumps(result, ensure_ascii=False, indent=2) else: return abort(403)