def create_withdraw(self, paypal, user_id): now = datetime.datetime.now() now.strftime('%Y-%m-%d %H:%M:%S') withdraw = Withdraw(paypal, user_id, now, 0) session.add(withdraw) session.commit() return withdraw
def update_user_info(self, user_id, **kwargs): user_data = session.query(User).filter(User.id == user_id) if user_data: for key in kwargs: user_data.update({key: kwargs[key]}) session.commit() return user_data.first() else: return user_data
def login(self, third_party_uuid, username, icon, device_token): exist_user_data = session.query(User).filter( User.third_party_uuid == third_party_uuid).first() if exist_user_data: return exist_user_data new_user_data = User(third_party_uuid, username, icon, device_token) session.add(new_user_data) session.commit() return new_user_data
def create_question(self, **kwargs): now = datetime.datetime.now() now.strftime('%Y-%m-%d %H:%M:%S') question = Question(kwargs['content'], kwargs['price'], kwargs['public'], kwargs['ask_uuid'], kwargs['answer_uuid'], 0, now, 0) session.add(question) session.commit() if question: user = session.query(User).filter(User.id == question.ask_user_id) user.update({'ask_num': User.ask_num + 1}) session.commit() return question
def answer_question(self, id, length, url): question = session.query(Question).filter(Question.id == id) if question: question.update({'voice_length': length}) question.update({'voice_url': url}) question.update({'state': 1}) session.commit() user = session.query(User).filter( User.id == question.first().answer_user_id) user.update({'answer_num': User.answer_num + 1}) user.update({'earning': User.earning + question.first().price}) user.update({'income': User.income + question.first().price}) session.commit() return question.first() else: return question
def set_heard_user(self, question_id, user_id): heard = Heard(question_id, user_id) session.add(heard) session.commit() if heard: user = session.query(User).filter(User.id == user_id) user.update({'heard_num': User.heard_num + 1}) session.commit() question = session.query(Question).filter(Question.id == question_id) question.update({'listener_num': Question.listener_num}) session.commit() return heard