Example #1
0
    def get(self):
        try:
            bookid = int(self.get_argument('bookid'))
            page = int(self.get_argument('page')) - 1
        except Exception as e:
            Parameter_error(self, e)
            return
        Yesterday = (datetime.datetime.now() - datetime.timedelta(days=1))
        Yesterday_1 = Yesterday.strftime('%Y-%m-%d 23:59:59')
        Yesterday_2 = Yesterday.strftime('%Y-%m-%d 00:00:00')

        followss = self.session_db.query(Follows).filter(
            Follows.follow_booke == bookid).offset(page * 10).limit(10)
        Return_data = {}
        if not page:
            Yesterday_count = self.session_db.query(Follows).filter(
                Follows.follow_booke == bookid, Follows.set_time < Yesterday_1,
                Follows.set_time > Yesterday_2).count()
            count = self.session_db.query(Follows).filter(
                Follows.follow_booke == bookid).count()
            Return_data['count'] = count
            Return_data['Yesterday_count'] = Yesterday_count
        data_list = []
        for follow in followss:
            user = self.session_db.query(
                User.name).filter(User.id == follow.follow_nameid).first()
            data = {'name': user.name, 'set_time': follow.set_time}
            data_list.append(data)
        Return_data['eercode'] = 0
        Return_data['eermegs'] = '成功'
        Return_data['data'] = data_list
        self.write(Return_data)
Example #2
0
 def get(self):
     try:
         page = int(self.get_argument('page')) - 1
         session = Session(self)
         userid = session.data.get('user_id')
     except Exception as e:
         Parameter_error(self, e)
         return
     count = self.session_db.query(Recharge).filter(
         Recharge.userid == userid).count()
     recharges = self.session_db.query(Recharge).filter(
         Recharge.userid == userid).offset(page * 10).limit(10)
     recharge_data = [{
         'id': recharge.id,
         'rech_title': recharge.rech_title,
         'rech_num': recharge.rech_num,
         'set_time': str(recharge.set_time)
     } for recharge in recharges]
     Return_data = {
         'eercode': 0,
         'eermegs': '成功',
         'data': recharge_data,
         'count': count
     }
     self.write(Return_data)
Example #3
0
 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)
Example #4
0
 def get(self):
     try:
         bookid = int(self.get_argument('bookid'))
     except Exception as e:
         Parameter_error(self, e)
     CatalogS = self.session_db.query(Catalog).filter(
         Catalog.bookid == bookid).all()
     data_list = []
     for Catalo in CatalogS:
         chapters = self.session_db.query(
             Chapter.id, Chapter.chapter_title,
             Chapter.set_time).filter(Chapter.Catalog_id == Catalo.id,
                                      Chapter.recycle == 'flass')
         data = {'catalog': Catalo.Catalog_title, 'catalog_id': Catalo.id}
         data['chapters'] = []
         for chapte in chapters:
             chapters_data = {
                 'chapter_id': chapte.id,
                 'chapter_title': chapte.chapter_title,
                 'set_time': str(chapte.set_time)
             }
             data['chapters'].append(chapters_data)
         data_list.append(data)
     Return_data = {'eercode': 0, 'eermegs': '请求成功', 'data': data_list}
     self.write(Return_data)
Example #5
0
 def get(self):
     try:
         page = self.get_argument('page', None)
         if page:
             page = int(page) - 1
     except Exception as e:
         Parameter_error(self, e)
         return
     authoID = Session(self, 'autho_session_id').data['authon_id']
     if page:
         authon_data = self.session_db.query(Bookes).filter(
             Bookes.authoid == authoID).offset(page * 5).limit(5)
     else:
         authon_data = self.session_db.query(Bookes).filter(
             Bookes.authoid == authoID).limit(5)
     pages = self.session_db.query(Bookes).filter(
         Bookes.authoid == authoID).count()
     data_list = []
     for i in authon_data:
         data = {
             'id': i.id,
             'bookname': i.bookname,
             'booktype': i.booktype,
         }
         data_list.append(data)
     Return_data = {
         'eercode': 0,
         'eermegs': '请求成功',
         'data': data_list,
         'count': pages
     }
     self.write(Return_data)
Example #6
0
 def get(self):
     try:
         bookid=int(self.get_argument('now_bookid'))
     except Exception as e:
         Parameter_error(self,e)
         return
     books=self.session_db.query(Bookes).filter(Bookes.id!=bookid).limit(4)
     book_data=[{'bookid':book.id,'bookname':book.bookname,'bookimg':book.book_img,'introduce':book.introduce} for book in books]
     Return_data={'eercode':0,'eermegs':'请求成功','data':book_data}
     self.write(Return_data)
Example #7
0
 def get(self):
     try:
         bookid=int(self.get_argument('bookid'))
         page=int(self.get_argument('page'))-1
     except Exception as e:
         Parameter_error(self,e)
         return
     count=self.session_db.query(Comment).filter(Comment.bookid==bookid).count()
     comment=self.session_db.query(Comment).filter(Comment.bookid==bookid).order_by(Comment.set_time.desc()).offset(page*10).limit(10)
     comment_data=[{'Comment_title':i.Comment_title,'conten':i.conten,'set_time':str(i.set_time),'username':self.session_db.query(User.name).filter(User.id==i.userid).first().name} for i in comment]
     Return_data={'eercode':0,'eermegs':'获取评论成功','data':comment_data,'count':count}
     self.write(Return_data)
Example #8
0
 def get(self):
     try:
         bookid = int(self.get_argument('bookid'))
     except Exception as e:
         Parameter_error(self, e)
         return
     recycs = self.session_db.query(Chapter).filter(
         Chapter.booke_id == bookid, Chapter.recycle == 'true').all()
     recyc_data = [{
         'chapter_title': recy.chapter_title,
         'id': recy.id
     } for recy in recycs]
     Retrun_data = {'eercode': 0, 'eermegs': '成功', 'data': recyc_data}
     self.write(Retrun_data)
Example #9
0
 def get(self):
     try:
         catalog_id = int(self.get_argument('cagtalog_id'))
     except Exception as e:
         Parameter_error(self, e)
         return
     catalog = self.session_db.query(Catalog).filter(
         Catalog.id == catalog_id).first()
     catalog_data = {
         'catalog_title': catalog.Catalog_title,
         'conten': catalog.conten
     }
     Return_data = {'eercode': 0, 'eermegs': '请求成功', 'data': catalog_data}
     self.write(Return_data)
Example #10
0
 def get(self):
     try:
         bookid = int(self.get_argument('bookid'))
     except Exception as e:
         Parameter_error(self, e)
         return
     catalogs = self.session_db.query(Catalog).filter(
         Catalog.bookid == bookid).all()
     catalog_data = [{
         'id': catalog.id,
         'Catalog_title': catalog.Catalog_title,
         'bookid': catalog.bookid
     } for catalog in catalogs]
     Return_data = {'eercode': 0, 'eercode': '请求成功', 'data': catalog_data}
     self.write(Return_data)
Example #11
0
 def get(self):
     try:
         bookid = int(self.get_argument('bookid'))
     except Exception as e:
         Parameter_error(self, e)
     userid = Session(self).data.get('user_id')
     self.session_db.query(Follows).filter(
         Follows.follow_booke == bookid,
         Follows.follow_nameid == userid).delete()
     try:
         self.session_db.commit()
         Return_data = {'eercode': 0, 'eermegs': '删除成功'}
         self.write(Return_data)
         return
     except Exception as e:
         Data_eeror(self, e)
         return
Example #12
0
 def get(self):
     try:
         bookid=int(self.get_argument('bookid'))
         page=self.get_argument('page',None)
         if page:
             page=int(page)-1
     except Exception as e:
         Parameter_error(self,e)
         return
     count=self.session_db.query(Income).filter(Income.income_booke==bookid).count()
     if page:
         incomes = self.session_db.query(Income).filter(Income.income_booke == bookid).order_by(Income.set_time.desc()).offset(page*10).limit(10)
     else:
         incomes=self.session_db.query(Income).filter(Income.income_booke==bookid).order_by(Income.set_time.desc()).limit(10)
     income_data=[{'id':income.id,'title':income.income_title,'income_num':income.income_num,'set_time':str(income.set_time)} for income in incomes]
     Return_data={'eercode':0,'eermegs':'成功','data':income_data,'count':count}
     self.write(Return_data)
Example #13
0
 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)
Example #14
0
 def post(self):
     try:
         bookid = int(self.get_json.get('bookid'))
         cataloh_title = self.get_json.get('Cataloh_title')
         conten = self.get_json.get('conten')
     except Exception as e:
         Parameter_error(self, e)
         return
     catalog = Catalog(bookid=bookid,
                       Catalog_title=cataloh_title,
                       conten=conten)
     self.session_db.add(catalog)
     try:
         self.session_db.commit()
         Return_data = {'eercode': 0, 'eermegs': '请求成功'}
         self.write(Return_data)
         return
     except Exception as e:
         Data_eeror(self, e)
         return
Example #15
0
 def post(self):
     bookids = self.get_json.get('bookids')
     if not bookids:
         Parameter_error(self, '参数错误')
         return
     else:
         userid = Session(self).data.get('user_id')
         bookids = tuple(bookids)
         self.session_db.query(Follows).filter(
             Follows.follow_booke.in_(bookids),
             Follows.follow_nameid == userid).delete(
                 synchronize_session=False)
         try:
             self.session_db.commit()
             Return_data = {'eercode': 0, 'eermegs': '删除成功'}
             self.write(Return_data)
             return
         except Exception as e:
             Data_eeror(self, e)
             return
Example #16
0
 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
Example #17
0
 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
Example #18
0
 def post(self):
     try:
         chaperid = int(self.get_json.get('chaptrid'))
     except Exception as e:
         Parameter_error(self, e)
     authonid = get_session_authonid(self)
     bookid = self.session_db.query(
         Chapter.booke_id).filter(Chapter.id == chaperid).first().booke_id
     if self.session_db.query(Bookes).filter(
             Bookes.id == bookid, Bookes.authoid == authonid).first():
         self.session_db.query(Chapter).filter(
             Chapter.id == chaperid).delete()
         try:
             self.session_db.commit()
             Return_data = {'eercode': 0, 'eermegs': '成功'}
             self.write(Return_data)
         except Exception as e:
             Data_eeror(self, e)
             return
     else:
         Return_data = {'eercode': 110, 'eermegs': '你不能删除不属于你的'}
         self.write(Return_data)
Example #19
0
 def post(self):
     try:
         Chaperid = int(self.get_json.get('chapetid'))
     except Exception as e:
         Parameter_error(self, e)
         return
     authonid = get_session_authonid(self)
     bookid = self.session_db.query(
         Chapter.booke_id).filter(Chapter.id == Chaperid).first().booke_id
     if self.session_db.query(Bookes).filter(
             Bookes.id == bookid, Bookes.authoid == authonid).first():
         self.session_db.query(Chapter).filter(
             Chapter.id == Chaperid).update({Chapter.recycle: 'true'})
         try:
             self.session_db.commit()
             Retrun_data = {'eercode': 0, 'eermegs': '成功'}
             self.write(Retrun_data)
         except Exception as e:
             Data_eeror(self, e)
             return
     else:
         Return_data = {'eercode': 110, 'eermegs': '这条数据不属于你'}
         self.write(Return_data)
Example #20
0
 def get(self):
     try:
         booktype=self.get_argument('booktype',None)
         font_num=self.get_argument('font_num',None)
         action=self.get_argument('action',None)
         update_time=self.get_argument('update_time',None)
         page=int(self.get_argument('page'))-1
         book_sex=self.get_argument('book_sex')
         free=self.get_argument('free')
         order_by=self.get_argument('order_by')
         get_tyep=self.get_argument('type',None)
         if order_by=='综合':
             order_by=Bookes.id
         if order_by=='字数':
             order_by=Bookes.font_num
         if order_by=='点击':
             order_by=Bookes.collect_num
         if order_by=='时间':
             order_by=Bookes.set_time
     except Exception as e:
         Parameter_error(self,e)
         return
     TIMES='2018-2-23 0:00:00'
     if not update_time:
         update_time =TIMES
     else:
         update_time = datetime.datetime.strftime((datetime.datetime.now() - datetime.timedelta(days=int(update_time))), '%Y-%m-%d %H:%M:%S')
     if not font_num:
         font_le =-1
         font_lt = 10000000000
     else:
         font_list = font_num.split('-')
         font_le = int(font_list[0]) * 10000
         font_lt = font_list[1]
         if font_lt != '$':
             font_lt = int(font_lt) * 10000
         else:
             font_lt = 10000000000
     if free=='免费':
         if get_tyep=='all':
             count=self.session_db.query(Bookes).filter(Bookes.free == '免费', Bookes.book_sex == book_sex).count()
             books = self.session_db.query(Bookes).filter(Bookes.free == '免费', Bookes.book_sex == book_sex).order_by(order_by.desc()).offset(
                 page * 10).limit(10)
         else:
             if booktype and action:
                 count=self.session_db.query(Bookes).filter(Bookes.free == '免费',Bookes.booktype == booktype, Bookes.action == action,
                                                              Bookes.set_time > update_time,
                                                              Bookes.font_num > font_le, Bookes.font_num < font_lt,
                                                              Bookes.book_sex == book_sex).count()
                 books = self.session_db.query(Bookes).filter(Bookes.free == '免费',Bookes.booktype == booktype, Bookes.action == action,
                                                              Bookes.set_time > update_time,
                                                              Bookes.font_num > font_le, Bookes.font_num < font_lt,
                                                              Bookes.book_sex == book_sex).order_by(order_by.desc()).offset(page * 10).limit(
                      10)
             elif booktype and not action:
                 count=self.session_db.query(Bookes).filter(Bookes.free == '免费',Bookes.booktype == booktype,
                                                              Bookes.set_time > update_time,
                                                              Bookes.font_num > font_le, Bookes.font_num < font_lt,
                                                              Bookes.book_sex == book_sex).count()
                 books = self.session_db.query(Bookes).filter(Bookes.free == '免费',Bookes.booktype == booktype,
                                                              Bookes.set_time > update_time,
                                                              Bookes.font_num > font_le, Bookes.font_num < font_lt,
                                                              Bookes.book_sex == book_sex).order_by(order_by.desc()).offset(page * 10).limit(
                     10)
             elif not booktype and action:
                 count=self.session_db.query(Bookes).filter(Bookes.free == '免费',Bookes.action == action, Bookes.set_time > update_time,
                                                              Bookes.font_num > font_le, Bookes.font_num < font_lt,
                                                              Bookes.book_sex == book_sex).count()
                 books = self.session_db.query(Bookes).filter(Bookes.free == '免费',Bookes.action == action, Bookes.set_time > update_time,
                                                              Bookes.font_num > font_le, Bookes.font_num < font_lt,
                                                              Bookes.book_sex == book_sex).order_by(order_by.desc()).offset(page * 10).limit(
                      10)
             else:
                 count=self.session_db.query(Bookes).filter(Bookes.free == '免费',Bookes.set_time > update_time,
                                                              Bookes.font_num > font_le, Bookes.font_num < font_lt,
                                                              Bookes.book_sex == book_sex).count()
                 books = self.session_db.query(Bookes).filter(Bookes.free == '免费',Bookes.set_time > update_time,
                                                              Bookes.font_num > font_le, Bookes.font_num < font_lt,
                                                              Bookes.book_sex == book_sex).order_by(order_by.desc()).offset(page * 10).limit(
                      10)
     elif free=='all':
         if get_tyep == 'all':
             count=self.session_db.query(Bookes).filter(Bookes.book_sex == book_sex).count()
             books = self.session_db.query(Bookes).filter(Bookes.book_sex == book_sex).order_by(order_by.desc()).offset(
                 page * 10).limit(10)
         else:
             if booktype and action:
                 count=self.session_db.query(Bookes).filter(Bookes.booktype == booktype, Bookes.action == action,
                                                              Bookes.set_time > update_time,
                                                              Bookes.font_num > font_le, Bookes.font_num < font_lt,
                                                              Bookes.book_sex == book_sex).count()
                 books = self.session_db.query(Bookes).filter(Bookes.booktype == booktype, Bookes.action == action,
                                                              Bookes.set_time > update_time,
                                                              Bookes.font_num > font_le, Bookes.font_num < font_lt,
                                                              Bookes.book_sex == book_sex).order_by(order_by.desc()).offset(page * 10).limit(
                       10)
             elif booktype and not action:
                 count=self.session_db.query(Bookes).filter(Bookes.booktype == booktype,
                                                              Bookes.set_time > update_time,
                                                              Bookes.font_num > font_le, Bookes.font_num < font_lt,
                                                              Bookes.book_sex == book_sex).count()
                 books = self.session_db.query(Bookes).filter(Bookes.booktype == booktype,
                                                              Bookes.set_time > update_time,
                                                              Bookes.font_num > font_le, Bookes.font_num < font_lt,
                                                              Bookes.book_sex == book_sex).order_by(order_by.desc()).offset(page * 10).limit(
                     10)
             elif not booktype and action:
                 count=self.session_db.query(Bookes).filter(Bookes.action == action, Bookes.set_time > update_time,
                                                              Bookes.font_num > font_le, Bookes.font_num < font_lt,
                                                              Bookes.book_sex == book_sex).count()
                 books = self.session_db.query(Bookes).filter(Bookes.action == action, Bookes.set_time > update_time,
                                                              Bookes.font_num > font_le, Bookes.font_num < font_lt,
                                                              Bookes.book_sex == book_sex).order_by(order_by.desc()).offset(page * 10).limit(
                     10)
             else:
                 count= self.session_db.query(Bookes).filter(Bookes.set_time > update_time,
                                                              Bookes.font_num > font_le, Bookes.font_num < font_lt,
                                                              Bookes.book_sex == book_sex).count()
                 books = self.session_db.query(Bookes).filter(Bookes.set_time > update_time,
                                                              Bookes.font_num > font_le, Bookes.font_num < font_lt,
                                                              Bookes.book_sex == book_sex).order_by(order_by.desc()).offset(page * 10).limit(
                      10)
     books_data=[{
                 'id':book.id,
                 'bookname':book.bookname,
                  'booktype':book.booktype,
                  'introduce':book.introduce,
                  'book_img':book.book_img,
                  'action':book.action,
                  'font_num':book.font_num} for book in books]
     Return_data={'eercode':0,'eermegs':'成功','data':books_data,'count':count}
     self.write(Return_data)