async def update(self, id, application): (success, result) = self.check_state(application) if success == False: return (success, result) condition = {'_id': ObjectId(id)} application = {'$set': application} await self.db.update({'_id': ObjectId(id)}, application, self.colName) return (True, '')
async def get_vcoin_number(self,user_id): condition = {'_id':ObjectId(user_id)} user = await self.db.get_document_one(condition) if 'vcoin' in user: return user['vcoin'] else: return -1
async def get_signup_days(self,user_id): condition = {'_id':ObjectId(user_id)} user = await self.db.get_document_one(condition) if 'signup_days' in user: return user['signup_days'] else: return []
async def post(self): user_info=await self.user_info jsonObj=self.json_body mode_id=jsonObj['mode_id'] mtype=jsonObj['mtype'] seatNumber=int(jsonObj['seatNumber']) mode = await self.db.mode.get_by_id(mode_id) if mode['type'] != 'seat': raise ResourceNotExistError('w') ntime=self.get_timestamp() if mode['endTime']<ntime or mode['beginTime']>ntime: raise ResourceNotExistError('') if str(user_info['_id']) in mode['function']['userList']: raise ResourceNotExistError('') joinMap = mode['function']['joinMap'] if str(user_info['_id']) not in joinMap.keys(): await self.db.mode.update(mode_id,{'$set':{'function.joinMap.%s'%(str(user_info['_id'])):{'chooseList':[]}}}) if mtype =='select': await self.db.mode.updateS( {'_id':ObjectId(mode_id),'function.userList':{'$ne':str(user_info['_id'])},'function.seatStateList.%d'%(seatNumber):0}, {'$addToSet':{'joinList':str(user_info['_id']),'function.userList':str(user_info['_id']),'function.joinMap.%s.chooseList'%(str(user_info['_id'])):{'seatNumber':seatNumber,'type':mtype,'time':ntime}},'$set':{'function.seatStateList.%d'%(seatNumber):1,'function.seatUserList.%d'%(seatNumber):str(user_info['_id'])}} ) mode = await self.db.mode.get_by_id(mode_id) if mode['function']['seatUserList'][seatNumber] == str(user_info['_id']): re="OK" else: re='NO' elif mtype =='reselect': await self.db.mode.updateS( {'_id':ObjectId(mode_id),'function.seatStateList.%d'%(seatNumber):1,'function.seatUserList.%d'%(seatNumber):str(user_info['_id'])}, {'$addToSet':{'joinList':str(user_info['_id']),'function.joinMap.%s.chooseList'%(str(user_info['_id'])):{'seatNumber':seatNumber,'type':mtype,'time':ntime}},'$pull':{'function.userList':str(user_info['_id'])},'$set':{'function.seatStateList.%d'%(seatNumber):0,'function.seatUserList.%d'%(seatNumber):''}} ) mode = await self.db.mode.get_by_id(mode_id) if mode['function']['seatUserList'][seatNumber] == str(user_info['_id']): re="NO" else: re='OK' self.finish_success(result=re)
async def get_by_id(self, id): condition = {'_id':ObjectId(id)} master = await self.db.get_document_one(condition, self.colName) return master
async def get(self): user_info = await self.user_info ntime = self.get_timestamp() pagesize = int(self.get_argument('pagesize', default=10)) time = float(self.get_argument('time', default=ntime)) master = await self.db.master.get_by_user(str(user_info['_id'])) if master: condition = { 'master': str(master['userId']), 'orderTime': { '$lt': time }, 'state': { '$ne': 'off' } } order_list = await self.db.order.get_order_free( condition=condition, sortby='orderTime', sort='-') #将未完成支付的订单筛选出来,不显示 orderlist = [] for order in order_list: if order['state'] == 'nonpay' or order['state'] == 'paying': pass else: orderlist.append(order) only_need_number = self.get_argument('only_number', default=0) if int(only_need_number) == 1: self.finish_success(result=len(orderlist)) return for i in range(0, len(orderlist)): #对完成支付的状态进行转换 if orderlist[i]['state'] == 'accpaid': pass #orderlist[i]['state']='to_confirm' master = await self.db.master.get_by_user( orderlist[i]['master']) user = await self.db.user.get_by_id( ObjectId(orderlist[i]['trainee'])) event = await self.db.event.get_by_id(orderlist[i]['belonged']) orderlist[i] = { '_id': orderlist[i]['_id'], 'orderNumber': orderlist[i]['orderNumber'], 'eventCover': event['coverPhoto'], 'eventTitle': event['title'], 'state': orderlist[i]['state'], 'price': orderlist[i]['price'], 'masterName': master['realName'], 'masterCover': master['avatar'], 'avatar': master['avatar'], 'time': orderlist[i]['orderTime'], 'belongedType': orderlist[i]['belongedType'], 'userName': user['realName'], 'userAvatar': user['avatar'], 'userUniversity': user['university'], 'usercampus': user['campus'], } self.finish_success(result=orderlist) else: raise PermissionDeniedError("不是达人")
async def remove_like(self, comment_id, user_id): condition = {'_id': ObjectId(comment_id)} comment = {'$pull': {'likeUserList': str(user_id)}} await self.db.update(condition, comment, self.colName)
async def remove_reply(self, comment_id, reply): condition = {'_id': ObjectId(comment_id)} comment = {'$pull': {'replyList': reply}} await self.db.update(condition, comment, self.colName)
async def insert_comment_id(self,order_id,comment_id): condition = {'_id':ObjectId(order_id)} order = {'$set':{'comment_id':str(comment_id)}} await self.db.update(condition, order, self.colName)
async def update(self, id, notice): condition = {'_id': ObjectId(id)} notice = {'$set': notice} await self.db.update(condition, notice, self.colName)
async def update(self, id, userteam): condition = {'_id': ObjectId(id)} userteam = {'$set': userteam} await self.db.update(condition, userteam, self.colName)
async def get_by_id(self, tip_id): condition = {'_id': ObjectId(tip_id)} tip = await self.db.get_document_one(condition, self.colName) return tip
async def update(self, id, tip_order): condition = {'_id': ObjectId(id)} post = {'$set': tip_order} await self.db.update(condition, post, self.colName)
async def update(self, id, iconfig): condition = {'_id': ObjectId(id)} iconfig = {'$set': iconfig} await self.db.update(condition, iconfig, self.colName)
async def update(self,id,category): condition = {'_id':ObjectId(id)} behave = {'$set':category} await self.db.update(condition, behave, self.colName)
async def remove_user(self, id, user_id): condition = {'_id': ObjectId(id)} label = {'$pull': {'userList': user_id}} await self.db.update(condition, label, self.colName)
async def handle(self, id): condition = {'_id': ObjectId(id)} notice = {'$set': {'state': '1'}} await self.db.update(condition, notice, self.colName)
async def insert_member(self, userteam_id, user_id): condition = {'_id': ObjectId(userteam_id)} userteam = {'$addToSet': {'teamMember': user_id}} await self.db.update(condition, userteam, self.colName)
async def insert_source(self, id, source): condition = {'_id': ObjectId(id)} notice = {'$addToSet': {'source': source}} await self.db.update(condition, notice, self.colName)
async def remove_member(self, userteam_id, user_id): condition = {'_id': ObjectId(userteam_id)} userteam = {'$pull': {'teamMember': user_id}} await self.db.update(condition, userteam, self.colName)
async def insert_reply(self, comment_id, reply): condition = {'_id': ObjectId(comment_id)} comment = {'$addToSet': {'replyList': reply}} await self.db.update(condition, comment, self.colName)
async def get_by_id(self, id): mode = await self.db.mode.find_one({'_id':ObjectId(id)}) return mode
async def insert_like(self, comment_id, user_id): condition = {'_id': ObjectId(comment_id)} comment = {'$addToSet': {'likeUserList': str(user_id)}} await self.db.update(condition, comment, self.colName)
async def insert_join(self,id,user_id): await self.db.mode.update({'id':ObjectId(id)},{'$addToSet':{'joinList':user_id}})
async def update(self, id, comment): condition = {'_id': ObjectId(id)} comment = {'$set': comment} await self.db.update(condition, comment, self.colName)
async def update(self,id,mode): await self.db.mode.update({'_id':ObjectId(id)},mode)
async def get(self): user_info = await self.user_info order_id = self.get_argument('order_id', default=None) order = await self.db.order.get_by_id(order_id) if order is None: raise ResourceNotExistError("订单不存在") if order['trainee'] != str( user_info['_id']) and order['master'] != str(user_info['_id']): raise PermissionDeniedError("并不是你的订单") event = self.db.event.brief_event(await self.db.event.get_by_id( order['belonged'])) master = self.db.master.brief_master(await self.db.master.get_by_user( order['master'])) #if order['state']=='nonpay' or order['state']=='paying': # raise ResourceNotExistError("订单无法查看") #对完成支付的状态进行转换 if order['state'] == 'accpaid': pass #order['state']='to_confirm' comment = { 'star': [5.0, 5.0, 5.0], 'content': '', } if 'comment_id' in order and order['comment_id'] != '': one_comment = await self.db.comment.get_by_id( ObjectId(order['comment_id'])) if one_comment: comment['star'] = one_comment['star'] comment['content'] = one_comment['content'] if event['coverPhoto'] != '': coverP = event['coverPhoto'] else: coverP = event['photosDisplay'][0] trainee = await self.db.user.get_by_id(order['trainee']) orderDetail = { '_id': order['_id'], 'orderNumber': order['orderNumber'], 'eventCover': coverP, 'eventTitle': event['title'], 'eventId': event['_id'], 'state': order['state'], 'price': order['price'], 'master': order['master'], 'trainee': order['trainee'], 'masterName': master['realName'], 'masterCover': master['avatar'], 'userName': trainee['realName'], 'userAvatar': trainee['avatar'], 'avatar': master['avatar'], 'time': order['orderTime'], 'realPhone': order['realPhone'], 'remarkInfo': order['remarkInfo'], 'realName': order['realName'], 'identity': user_info['identity'], 'university': user_info['university'], 'campus': user_info['campus'], 'comment': comment, 'comment_id': order['comment_id'], 'belongedType': order['belongedType'], 'masterContact': master['masterContact'], } self.finish_success(result=orderDetail)
async def update(self, id, label): condition = {'_id': ObjectId(id)} label = {'$set': label} await self.db.update(condition, label, self.colName)
async def update(self, id, master): condition = {'_id':ObjectId(id)} master = {'$set':master} await self.db.update(condition, master, self.colName)
async def insert_user(self, id, user_id): condition = {'_id': ObjectId(id)} label = {'$addtoSet': {'userList': user_id}} await self.db.update(condition, label, self.colName)