def post(self): try: bookid=int(self.get_json.get('bookid')) except Exception as e: logging.error(e) Return_data = {'eercode': 400, 'eermegs': '参数错误'} self.write(Return_data) return session=Session(self) userid=session.data['user_id'] if self.session_db.query(Follows).filter(Follows.follow_nameid==userid,Follows.follow_booke==bookid).first(): Return_data = {'eercode': 100, 'eermegs': '已经存在'} self.write(Return_data) return follows=Follows(follow_nameid=userid,follow_booke=bookid,set_time=get_now()) self.session_db.add(follows) self.session_db.query(Bookes).filter(Bookes.id==bookid).update({Bookes.collect_num:Bookes.collect_num+1}) try: self.session_db.commit() Return_data = {'eercode': 0, 'eermegs': '加入书架成功'} except Exception as e: self.session_db.rollback() logging.error(e) Return_data = {'eercode': 200, 'eermegs': '数据库错误'} self.write(Return_data)
def post(self): try: bookid = int(self.get_json.get('bookid')) chapter_title = self.get_json.get('Chapter') conten = self.get_json.get('conten') catalog_id = int(self.get_json.get('Catalog_id')) except Exception as e: Parameter_error(self, e) return font_num = len(conten) chapter = Chapter(booke_id=bookid, chapter_title=chapter_title, conten=conten, set_time=get_now(), Catalog_id=catalog_id, font_num=font_num) self.session_db.add(chapter) self.session_db.query(Bookes).filter(Bookes.id == bookid).update( {Bookes.font_num: Bookes.font_num + font_num}) try: self.session_db.commit() Retrun_data = {'eercode': 0, 'eermegs': '添加章节成功'} except: self.session_db.rollback() Retrun_data = {'eercode': 200, 'eermegs': '数据库错误'} self.write(Retrun_data)
def post(self): try: bookid = int(self.get_json.get('bookid')) coin = int(self.get_json.get('coin')) except Exception as e: Parameter_error(self, e) return session = Session(self) userid = session.data.get('user_id') if self.session_db.query(User).filter( User.id == userid).first().coin - coin < 0: Return_data = {'eercode': 300, 'eermegs': '大佬你的余额不足'} self.write(Return_data) return book = self.session_db.query(Bookes).filter( Bookes.id == bookid).first() #查询该书 self.session_db.query(User).filter(User.id == userid).update( {User.coin: User.coin - coin}) #修改用户的阅读币 title = '打赏了%s' % book.bookname recharge = Recharge(rech_title=title, rech_num=coin, rech_bookid=bookid, userid=userid, set_time=get_now()) #创建一个消费记录 self.session_db.add(recharge) self.session_db.query(Autho).filter(Autho.id == book.authoid).update( {Autho.coin: Autho.coin + coin}) #修改作者的阅读币 title = '%s打赏了%s' % (session.data.get('name'), coin) income = Income(income_title=title, authoid=book.authoid, income_booke=bookid, set_time=get_now(), income_num=coin) self.session_db.add(income) try: self.session_db.commit() Return_data = {'eercode': 0, 'eermegs': '打赏成功'} self.write(Return_data) except Exception as e: Data_eeror(self, e) return
def post(self): user=self.get_json.get('user') pswd=self.get_json.get('pswd') email=self.get_json.get('email') Phone=self.get_json.get('Phone') if self.session_db.query(User).filter(User.name==user).first(): Return_data={'eercode':100,'eermesg':'该用户已经存在'} self.write(Return_data) return user=User(name=user,pswd=pswd,email=email,Phone=Phone,set_time=get_now()) try: self.session_db.add(user) self.session_db.commit() Return_data = {'eercode': 0, 'eermesg': '注册成功'} except: self.session_db.rollback() #失败 ,回滚 Return_data={'eercode':200,'eermesg':'数据库错误'} self.write(Return_data)
def post(self): email=self.get_json.get('email') name=self.get_json.get('name') pswd=self.get_json.get('pswd') if self.session_db.query(Autho).filter(Autho.email==email).first(): Return_data={'eercode':100,'eermesg':'该邮箱已经注册'} self.write(Return_data) return authon=Autho(email=email,name=name,pswd=pswd,set_time=get_now()) self.session_db.add(authon) try: self.session_db.commit() Return_data={'eercode':0,'eermesg':'注册成功'} except Exception as e: Return_data = {'eercode':200,'eermesg':'数据库错误'} logging.error(e) self.session_db.rollback()#回滚 self.write(Return_data)
def post(self): try: bookid=int(self.get_json.get('bookid')) title=self.get_json.get('title') conten=self.get_json.get('conten') except Exception as e: Parameter_error(self,e) #参数错误的公共函数 return session=Session(self) userid=session.data['user_id'] comment=Comment(Comment_title=title,conten=conten,set_time=get_now(),bookid=bookid,userid=userid) self.session_db.add(comment) try: self.session_db.commit() Return_data = {'eercode': 0, 'eermegs': '留言成功'} self.write(Return_data) except Exception as e: Data_eeror(self,e)
def post(self): try: money = int(self.get_argument('money')) * 100 except Exception as e: Parameter_error(self, e) return session = Session(self) userid = session.data.get('user_id') rechaRecord = RechaRecord(coin=money, userid=userid, set_time=get_now()) self.session_db.add(rechaRecord) self.session_db.query(User).filter(User.id == userid).update( {User.coin: User.coin + money}) try: self.session_db.commit() Return_data = {'eercode': 0, 'eermegs': '请求成功'} self.write(Return_data) except Exception as e: Data_eeror(self, e) return
def post(self): bookname = self.get_json.get('bookname') booktype = self.get_json.get('booktype') booktag = self.get_json.get('booktag') book_sex = self.get_json.get('book_sex') introduce = self.get_json.get('introduce') free = self.get_json.get('free') authonid = get_session_authonid(self) bookimg = 'https://qidian.qpic.cn/qdbimg/349573/c_6233251403829601/180' if self.session_db.query(Bookes).filter( Bookes.bookname == bookname).first(): Return_data = {'eercode': 100, 'eermegs': '该作品名字已经存在'} self.write(Return_data) return book = Bookes(bookname=bookname, booktype=booktype, introduce=introduce, booktag=booktag, set_time=get_now(), authoid=authonid, book_sex=book_sex, free=free, book_img=bookimg) self.session_db.add(book) book_id = self.session_db.query( Bookes.id).filter(Bookes.bookname == bookname).first().id catalog = Catalog(Catalog_title='第一卷', bookid=book_id, conten='默认创建的第一卷') self.session_db.add(catalog) try: self.session_db.commit() Return_data = {'eercode': 0, 'eermegs': '创建作品成功'} except Exception as e: print(e) self.session_db.rollback() Return_data = {'eercode': 200, 'eermegs': '数据库错误'} self.write(Return_data)